Mercurial > hg > may
view src/may/matrix/test/test_complexmatrix.yeti @ 466:604a93b0b24d
Add equal, conjugate transpose, slices, diagonal, magnitudes and angles
author | Chris Cannam |
---|---|
date | Fri, 25 Oct 2013 14:37:32 +0100 |
parents | d1fbd49b43db |
children | 493d7bfc58ca d7e4ae45fc1d |
line wrap: on
line source
module may.matrix.test.test_complexmatrix; mat = load may.matrix; vec = load may.vector; cm = load may.matrix.complex; complex = load may.complex; load may.vector.type; load may.matrix.type; load may.matrix.complextype; { compare, compareUsing } = load may.test.test; [ "enumerate": \( // 1+0i 0-2i 3+0i // 4-1i 5-3i 0+0i reals = mat.toSparse (mat.newMatrix (RowMajor ()) (map vec.fromList [[1,0,3],[4,5,0]])); imags = mat.toSparse (mat.newMatrix (ColumnMajor ()) (map vec.fromList [[0,-1],[-2,-3],[0,0]])); m = cm.complex reals imags; e = cm.enumerate m; all = [ { i = 0, j = 0, v = complex.complex 1 0 }, { i = 0, j = 1, v = complex.complex 0 (-2) }, { i = 0, j = 2, v = complex.complex 3 0 }, { i = 1, j = 0, v = complex.complex 4 (-1) }, { i = 1, j = 1, v = complex.complex 5 (-3) } ]; sortEntries = sortBy do a b: if a.i == b.i then a.j < b.j else a.i < b.i fi done; compare (sortEntries e) (sortEntries all); ), "magnitudes": \( // 1+0i 0-2i // 0+0i 4-3i reals = mat.newMatrix (RowMajor ()) (map vec.fromList [[1,0],[0,4]]); imags = mat.newMatrix (RowMajor ()) (map vec.fromList [[0,-2],[0,-3]]); m = cm.complex reals imags; mags = cm.magnitudes m; compare (map vec.list (mat.asRows mags)) [[1,2],[0,5]]; ), "angles": \( // 1+0i 0-2i // 0+0i -4-4i reals = mat.newMatrix (RowMajor ()) (map vec.fromList [[1,0],[0,-4]]); imags = mat.newMatrix (RowMajor ()) (map vec.fromList [[0,-2],[0,-4]]); m = cm.complex reals imags; mags = cm.angles m; compare (map vec.list (mat.asRows mags)) [[0,-pi/2],[0,-3*pi/4]]; ), ] is hash<string, () -> boolean>;