changeset 455:7cbc8d88bbac

Add negative
author Chris Cannam
date Thu, 24 Oct 2013 18:01:38 +0100
parents a926ad176efb
children fb9399820e55
files src/may/complex.yeti src/may/matrix.yeti
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/may/complex.yeti	Thu Oct 24 18:01:26 2013 +0100
+++ b/src/may/complex.yeti	Thu Oct 24 18:01:38 2013 +0100
@@ -68,7 +68,7 @@
     b = imaginary c1;
     c = real c2;
     d = imaginary c2;
-    complex (a * c - b * d) (b * c + a * d)); //!!! need units
+    complex (a * c - b * d) (b * c + a * d)); //!!! needs unit tests
 
 scale r c is number -> ~Cplx -> ~Cplx =
     complex (r * real c) (r * imaginary c);
--- a/src/may/matrix.yeti	Thu Oct 24 18:01:26 2013 +0100
+++ b/src/may/matrix.yeti	Thu Oct 24 18:01:38 2013 +0100
@@ -472,6 +472,16 @@
         newMatrix (typeOf m) (map bf.abs (asColumns m));
     fi;
 
+negative m =
+    if isSparse? m then
+        makeSparse (typeOf m) (size m)
+           (map do { i, j, v }: { i, j, v = (-v) } done (enumerate m))
+    elif isRowMajor? m then
+        newMatrix (typeOf m) (map bf.negative (asRows m));
+    else
+        newMatrix (typeOf m) (map bf.negative (asColumns m));
+    fi;
+
 //!!! doc: filter by predicate, always returns sparse matrix
 filter' f m =
     makeSparse (typeOf m) (size m)
@@ -593,7 +603,7 @@
     fi;
 
 entryWiseProduct m1 m2 = // or element-wise, or Hadamard product
-//!!! todo: faster, sparse version, units
+//!!! todo: faster, sparse version, unit tests
     if (size m1) != (size m2)
     then failWith "Matrices are not the same size: \(size m1), \(size m2)";
     else generate do row col: at' m1 row col * at' m2 row col done (size m1);
@@ -774,6 +784,7 @@
     sum = sum',
     difference,
     abs = abs',
+    negative,
     filter = filter',
     all = all',
     any = any',
@@ -825,6 +836,7 @@
     sum is matrix -> matrix -> matrix,
     difference is matrix -> matrix -> matrix,
     abs is matrix -> matrix,
+    negative is matrix -> matrix,
     filter is (number -> boolean) -> matrix -> matrix,
     all is (number -> boolean) -> matrix -> boolean,
     any is (number -> boolean) -> matrix -> boolean,