# HG changeset patch # User Chris Cannam # Date 1382637207 -3600 # Node ID a8078de882899dd22b89fded731f8de395002328 # Parent ba7824b1f4408e7abd881fae528b96f208ecb9dd Add density, toSparse diff -r ba7824b1f440 -r a8078de88289 src/may/matrix/complex.yeti --- a/src/may/matrix/complex.yeti Thu Oct 24 18:28:06 2013 +0100 +++ b/src/may/matrix/complex.yeti Thu Oct 24 18:53:27 2013 +0100 @@ -96,6 +96,28 @@ imaginary = addParts (multiplyParts b c) (multiplyParts a d); }); +density cm = + case cm.real of + Some m1: + case cm.imaginary of + Some m2: (mat.density m1 + mat.density m2) / 2; + None (): mat.density m1; + esac; + None (): + case cm.imaginary of + Some m2: mat.density m2; + None (): 0.0; + esac; + esac; + +toSparse cm = + (partSparse p = + case p of + Some m: Some (mat.toSparse m); + None (): None (); + esac; + cm with { real = partSparse cm.real, imaginary = partSparse cm.imaginary }); + newComplexMatrix type data = (newPart f type d = mat.newMatrix type @@ -110,6 +132,8 @@ imaginary, sum, product, + density, + toSparse, newComplexMatrix, } as { complex is matrix -> matrix -> complexmatrix, @@ -119,6 +143,8 @@ imaginary is complexmatrix -> matrix, sum is complexmatrix -> complexmatrix -> complexmatrix, product is complexmatrix -> complexmatrix -> complexmatrix, + density is complexmatrix -> number, + toSparse is complexmatrix -> complexmatrix, newComplexMatrix is (ColumnMajor () | RowMajor ()) -> list?> -> complexmatrix, }