Mercurial > hg > may
diff yetilab/matrix/matrix.yeti @ 97:d5fc902dcc3f
Initial matrix tests
author | Chris Cannam |
---|---|
date | Wed, 20 Mar 2013 22:49:41 +0000 |
parents | a5b4d0f68ca8 |
children | bd135a950af7 |
line wrap: on
line diff
--- a/yetilab/matrix/matrix.yeti Wed Mar 20 21:57:17 2013 +0000 +++ b/yetilab/matrix/matrix.yeti Wed Mar 20 22:49:41 2013 +0000 @@ -59,7 +59,9 @@ }; newStorage rows cols = - array (map \(vec.zeros rows) [1..cols]); + if rows < 1 then array [] + else array (map \(vec.zeros rows) [1..cols]) + fi; zeroMatrix rows cols = make (ColM (newStorage rows cols)); @@ -80,6 +82,16 @@ width m = m.size.columns; height m = m.size.rows; +equal m1 m2 = + (compare d1 d2 = + all id (map2 vec.equal d1 d2); + case m1.data of + RowM d1: + case m2.data of RowM d2: compare d1 d2; _: false; esac; + ColM d1: + case m2.data of ColM d2: compare d1 d2; _: false; esac; + esac); + copyOf m = (copyOfData d = (array (map vec.copyOf d)); make @@ -103,7 +115,7 @@ newMatrix type data is RowMajor () | ColumnMajor () -> list?<list?<number>> -> 'a = (tagger = case type of RowMajor (): RowM; ColumnMajor (): ColM esac; - if empty? data + if empty? data or empty? (head data) then zeroMatrix 0 0 else make (tagger (array (map vec.vector data))) fi); @@ -115,9 +127,10 @@ newMatrix (ColumnMajor ()) [data]; { +constMatrix, randomMatrix, zeroMatrix, identityMatrix, generate, -constMatrix, randomMatrix, zeroMatrix, identityMatrix, width, height, +equal, copyOf, transposed, flipped,