On Fri, 30 Nov 2007, Ketil Malde wrote:

> Bryan O'Sullivan <[EMAIL PROTECTED]> writes:
>
> > For higher dimensions, there are enough options in terms of
> > traversal direction and what exactly e.g. a fold should fold over
> > (single elements? lower-dimensional slices?) that a sensible API
> > doesn't exactly leap out.
>
> How about a 'reduce' instead of 'foldl1'?  I think that if you require
> a commutative operator, the order doesn't matter (except for
> efficiency and possible rounding issues, I guess).

For what I have in mind the order of execution matters.

I also think now that slices for higher dimensional arrays are useful,
anyway. If you choose a subrange of indices in the most significant
dimension this would be possible without copying. It would be also
possible to 'reshape' (in MatLab terms) an array without copying, as long
as the number elements remain the same. So you could first transform an
array of arbitrary dimension to a two-dimensional one, say

reshape :: (j,j) -> Array i a -> Array j a

specialised to

reshape :: ((i,(j,k)), (i,(j,k))) -> Array (i,j,k) a -> Array (i,(j,k)) a

then you could slice with respect to the first (most significant)
dimension.

slice :: (i,i) -> Array (i,j) a -> Array (i,j) a

{- | slice with respect to the first dimension and
     start indices of the slice with number of type 'k' -}
sliceRemap :: (i,i) -> k -> Array (i,j) a -> Array (k,j) a

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to