I started an n-dimensional array implementation in extra/arrays/shaped.
Check out this paper on numpy's nd-array: http://arxiv.org/pdf/1102.1523.pdf

The key concepts are having a continuous underlying array, using a shape
slot that can reshape to any other shape with the same product without
changing the underlying array, and the stride for accessing the next
row/column.

The eventual tuple in Factor could look something like:
TUPLE: shaped-array underlying type shape stride ;

The type of underlying is a specialized-array, so maybe you could do away
without the type/stride slots.

What's implemented right now is an array that has an underlying flat array
and handles reshaping, prettyprinting, addition, row/column major arrays,
and creating some n-dimensional arrays full of
zeros/ones/increasing/decreasing values.

It would be cool to support most of the features the numpy nd-arrays
support including the slicing notation.

Any help implementing the above would be awesome.

Doug


On Thu, Feb 7, 2013 at 4:11 PM, Leonard P <leonard14...@gmail.com> wrote:

> 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
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
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
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to