comparison yetilab/matrix/matrix.yeti @ 101:2bc6534248fe

Tidier comments
author Chris Cannam
date Thu, 21 Mar 2013 21:53:13 +0000
parents 4e52d04887a5
children b6db07468ed1
comparison
equal deleted inserted replaced
100:4e52d04887a5 101:2bc6534248fe
1 1
2 module yetilab.matrix.matrix; 2 module yetilab.matrix.matrix;
3 3
4 // A matrix is an array of fvectors (i.e. primitive double[]s). 4 // A matrix is an array of fvectors (i.e. primitive double[]s).
5 5
6 // A matrix can be either RowMajor, akin to a C multidimensional array 6 // A matrix can be stored in either column-major (the default) or
7 // in which each row is a separate fvector, or ColumnMajor, akin to a 7 // row-major format. Storage order is an efficiency concern only:
8 // FORTAN multidimensional array in which each column is a separate 8 // every API function operating on matrix objects will return the same
9 // fvector. The default is ColumnMajor. Storage order is an efficiency 9 // result regardless of storage order. (The transpose function just
10 // concern only, all operations behave identically regardless. (The 10 // switches the row/column order without moving the elements.)
11 // transpose function just switches the row/column order without
12 // moving the elements.)
13 11
14 vec = load yetilab.block.fvector; 12 vec = load yetilab.block.fvector;
15 block = load yetilab.block.block; 13 block = load yetilab.block.block;
16 bf = load yetilab.block.blockfuncs; 14 bf = load yetilab.block.blockfuncs;
17 15
145 143
146 product m1 m2 = 144 product m1 m2 =
147 if m1.size.columns != m2.size.rows 145 if m1.size.columns != m2.size.rows
148 then failWith "Matrix dimensions incompatible: \(m1.size), \(m2.size) (\(m1.size.columns != m2.size.rows)"; 146 then failWith "Matrix dimensions incompatible: \(m1.size), \(m2.size) (\(m1.size.columns != m2.size.rows)";
149 else 147 else
150 //!!! super-slow!
151 generate do row col: 148 generate do row col:
152 bf.sum (bf.multiply (m1.getRow row) (m2.getColumn col)) 149 bf.sum (bf.multiply (m1.getRow row) (m2.getColumn col))
153 done { rows = m1.size.rows, columns = m2.size.columns } 150 done { rows = m1.size.rows, columns = m2.size.columns }
154 fi; 151 fi;
155 152