view fmatrix.yeti @ 89:ef650ce77237

Start trying to adapt grids
author Chris Cannam
date Mon, 18 Mar 2013 21:24:04 +0000
parents 0b04bc5d2e53
children
line wrap: on
line source
module fmatrix;

// Basic matrices using primitive array of double as each row

vec = load fvector;

zeroMatrix rows cols = array (map \(vec.zeros cols) [1..rows]);

generate f rows cols =
   (m = zeroMatrix rows cols;
    for [0..rows-1] do row:
        for [0..cols-1] do col:
            m[row][col] := f row col;
        done;
    done;
    m);

constMatrix n = generate do row col: n done;
randomMatrix = generate do row col: Math#random() done;
identityMatrix = constMatrix 1;

width m = if length m > 0 then vec.length m[0] else 0 fi;
cols = width;

height m = length m;
rows = height;

dimensions m = { cols = width m, rows = height m };

copyOf m = array (map vec.copyOf m);

transposed m is array<~double[]> -> array<~double[]> = 
    generate do row col: m[col][row] done (cols m) (rows m);

{
generate, constMatrix, randomMatrix, zeroMatrix, identityMatrix,
width, cols, height, rows, dimensions,
copyOf,
transposed,
}