annotate matrix.yeti @ 12:2afcb56f57b1

Add (rather clumsy) overlapping framer
author Chris Cannam
date Thu, 13 Dec 2012 16:21:07 +0000
parents 29e39209360b
children 12c6f103ba8e
rev   line source
Chris@1 1 module matrix;
Chris@1 2
Chris@2 3 zeros n = array(map \0 [1..n]);
Chris@2 4 ones n = array(map \1 [1..n]);
Chris@1 5
Chris@2 6 generateMatrix f rows cols = array
Chris@2 7 (map do row: array
Chris@2 8 (map (f row) [0..cols-1])
Chris@2 9 done [0..rows-1]);
Chris@1 10
Chris@2 11 constMatrix n = generateMatrix do row col: n done;
Chris@1 12
Chris@2 13 randomMatrix = generateMatrix do row col: Math#random() done;
Chris@2 14
Chris@2 15 zeroMatrix = constMatrix 0;
Chris@2 16 identityMatrix = constMatrix 1;
Chris@2 17
Chris@2 18 width m = if length m > 0 then length m[0] else 0 fi;
Chris@2 19
Chris@2 20 height m = length m;
Chris@2 21
Chris@3 22 dimensions m = { cols = width m, rows = height m };
Chris@3 23
Chris@2 24 transposed m = array
Chris@2 25 (map do n: array
Chris@2 26 (map do a: a[n-1] done m)
Chris@2 27 done [1..width m]);
Chris@2 28
Chris@2 29 interleaved m = array(concat(transposed m));
Chris@2 30
Chris@3 31 deinterleaved rows v =
Chris@3 32 generateMatrix do row col:
Chris@3 33 v[rows * col + row]
Chris@3 34 done rows (length v / rows);
Chris@2 35
Chris@3 36 {
Chris@3 37 zeros, ones,
Chris@3 38 generateMatrix, constMatrix, randomMatrix, zeroMatrix, identityMatrix,
Chris@3 39 width, height, dimensions,
Chris@3 40 transposed,
Chris@3 41 interleaved, deinterleaved,
Chris@3 42 }
Chris@3 43