changeset 458:a8078de88289

Add density, toSparse
author Chris Cannam
date Thu, 24 Oct 2013 18:53:27 +0100
parents ba7824b1f440
children 2e87f815f5bc
files src/may/matrix/complex.yeti
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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?<list?<cplx>> -> complexmatrix,
 }