
Any chance IArrays (or MArrays) will some day support something like:
resize :: (Ix ix, IArray a e) => a ix e -> (ix,ix) -> a ix e
that is faster than allocating a new array and then copying value-by-value? perhaps make the result a Maybe (a ix e) in the same way that realloc can return null if it can't get you more memory at the end
I suspect that this would be unlikely to be much use, due to GHC's discontiguous block scheme for managing memory. The best you could hope for in most cases would be to fill up the slop in the block of memory at the end of the array.
or even just a simple memcpy like function so you could allocate a new array with the same index and element type and then copy directly from one to the other, like:
arrcopy :: (Ix ix, IArray a e) => (ix -> ix) -> a ix e -> a ix e -> a ix e
which can possibly fail if the indices for the destination don't line up with the source properly?
Doing it by hand *should* result in efficient code, eg. let copyElt i = do x <- readArray a1 i witeArray a2 i x sequence_ [ copyElt i | i <- indices a1 ] should result in a memcpy (or at least a tight loop) for UArrays with Int indices. (it might not though - I recall there are some problems with optimisation of array ops at the moment). Cheers, Simon
participants (1)
-
Simon Marlow