changeset 453:c11bf7397e0e

Add complexArray, zero
author Chris Cannam
date Thu, 24 Oct 2013 15:13:02 +0100
parents 5256bd5ef4ac
children a926ad176efb
files src/may/complex.yeti src/may/complex/test/test_complex.yeti
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/may/complex.yeti	Thu Oct 24 15:12:57 2013 +0100
+++ b/src/may/complex.yeti	Thu Oct 24 15:13:02 2013 +0100
@@ -73,6 +73,8 @@
 scale r c is number -> ~Cplx -> ~Cplx =
     complex (r * real c) (r * imaginary c);
 
+zero = complex 0 0;
+
 zeros n is number -> array<~Cplx> =
     array (map \(complex 0 0) [1..n]);
 
@@ -82,6 +84,9 @@
 angles cc is list?<~Cplx> -> vector =
     vec.fromList (map angle cc);
 
+complexArray reals imags =
+    array (map2 complex (vec.list reals) (vec.list imags));
+
 {
    real,
    imaginary,
@@ -92,9 +97,11 @@
    add,
    multiply,
    scale,
+   zero,
    zeros,
    magnitudes,
    angles,
+   complexArray
 } as {
    real is cplx -> number,
    imaginary is cplx -> number,
@@ -105,8 +112,10 @@
    add is cplx -> cplx -> cplx,
    multiply is cplx -> cplx -> cplx,
    scale is number -> cplx -> cplx,
+   zero is cplx,
    zeros is number -> array<cplx>,
    magnitudes is list?<cplx> -> vector,
    angles is list?<cplx> -> vector,
+   complexArray is vector -> vector -> array<cplx>
 }
 
--- a/src/may/complex/test/test_complex.yeti	Thu Oct 24 15:12:57 2013 +0100
+++ b/src/may/complex/test/test_complex.yeti	Thu Oct 24 15:13:02 2013 +0100
@@ -1,6 +1,6 @@
 module may.complex.test.test_complex;
 
-{ real, imaginary, complex, magnitude, angle, sum, scale, zeros, magnitudes, angles }
+{ real, imaginary, complex, magnitude, angle, sum, scale, zeros, magnitudes, angles, complexArray, zero }
    = load may.complex;
 
 { compare } = load may.test.test;
@@ -44,6 +44,11 @@
     compare (scale 4 (complex 2 3)) (complex 8 12)
 ),
 
+"zero": \(
+    compare (zero) (complex 0 0) and
+        compare (zero) (head (zeros 5))
+),
+
 "zeros": \(
     compare (zeros 0) (array []) and
         compare (zeros 3) (array [complex 0 0, complex 0 0, complex 0 0])
@@ -61,6 +66,10 @@
        compare (vec.list (angles (array []))) []
 ),
 
+"complexArray": \(
+    compare (complexArray (vec.fromList [0,1,2]) (vec.fromList [-3,4,5]))
+       (array [complex 0 (-3), complex 1 4, complex 2 5])
+),
 
 ] is hash<string, () -> boolean>;