The tuple is defined ...
TUPLE: matrix
{ coefficient initial: 1 }
{ #rows integer initial: 0 }
{ #cols integer initial: 0 }
{ data } ;
The idea is to store an n-by-m matrix as a flat sequence, instead of an
array of arrays.
To accomplish this we map element subscripts, (row, col), to a single index
in the flat sequence, data.
Referencing each matrix element with a single index in a flat sequence, we
should be able to use normal sequence operations like map and filter.
The trick is to get the mapping right.
Might go something like this ...
:: ij-to-n ( row col -- n )
row #cols * col + ;
:: n-to-ij ( n -- row col )
col - #cols / ;
: in-row? ( n col -- ? )
swap n-to-ij drop = ;
: in-col? ( n col -- ? )
swap n-to-ij swap drop = ;
: get-row ( row -- seq )
data [ in-row? ] filter-index ;
: get-col ( col -- seq )
data [ in-col? ] filter-index ;
:: in-minor? ( m n -- ? )
m n in-row? not m n in-col? not and ;
: get-minor ( n -- seq )
data [ in-minor? ] filter-index ;
That's just a rough draft without references to real accessors.
Before going that far, not sure how to define constructors and make-matrix.
Any ideas are welcome.
- Leonard
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk