# HG changeset patch # User Chris Cannam # Date 1382634098 -3600 # Node ID 7cbc8d88bbac6788f42c699b62067817091a021d # Parent a926ad176efb52b01d64e89ff090c72a9ec08a6c Add negative diff -r a926ad176efb -r 7cbc8d88bbac src/may/complex.yeti --- 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); diff -r a926ad176efb -r 7cbc8d88bbac src/may/matrix.yeti --- 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,