repa: fromVector
Christian Höner zu Siederdissen
choener at tbi.univie.ac.at
Fri May 20 13:03:32 CEST 2011
Hi,
there is a ticket for 'vector' available with what I need:
http://trac.haskell.org/vector/ticket/15
basically, I need a generalised scan that makes available a partially
initialized vector for each new element.
gen_scan :: Vector v a => Int -> (v a -> a) -> v a
Only that 'a' tends to be a 5-tuple ;-)
A function along those lines is extremely useful in a number of cases. I
hope to have some time to actually dig through the repa sources and see
what is possible.
Gruss,
Christian
* Ben Lippmeier <benl at ouroborus.net> [20.05.2011 04:14]:
>
> On 19/05/2011, at 8:27 PM, Christian Höner zu Siederdissen wrote:
>
> > I'd like to use repa in a rather perverted mode, I guess:
> >
> > for my programs I need to be able to update arrays in place and
> > repeatedly perform operations on them.
> > Right now, it basically works like this (in ST):
> >
> > - create unboxed space using "primitive" (same as unboxed vectors)
> > - unsafefreeze unboxed space
> > - perform calculations on frozen, immutable space
> > - write result into mutable space (which is shared with the unsafefrozen
> > space)
>
> If you care deeply about inplace update, then you could use the parallel array filling functions directly. The ones in D.A.Repa.Internals.Eval*.hs. For 2D images, use the fillVectorBlockwiseP [1] or fillCursoredBlock2P.
>
>
> fillVectorBlockwiseP
> :: Elt a
> => IOVector a -- ^ vector to write elements into
> -> (Int -> a) -- ^ fn to evaluate an element at the given index
> -> Int -- ^ width of image.
> -> IO ()
>
>
> -- | Fill a block in a 2D image, in parallel.
> -- Coordinates given are of the filled edges of the block.
> -- We divide the block into columns, and give one column to each thread.
> fillCursoredBlock2P
> :: Elt a
> => IOVector a -- ^ vector to write elements into
> -> (DIM2 -> cursor) -- ^ make a cursor to a particular element
> -> (DIM2 -> cursor -> cursor) -- ^ shift the cursor by an offset
> -> (cursor -> a) -- ^ fn to evaluate an element at the given index.
> -> Int -- ^ width of whole image
> -> Int -- ^ x0 lower left corner of block to fill
> -> Int -- ^ y0 (low x and y value)
> -> Int -- ^ x1 upper right corner of block to fill
> -> Int -- ^ y1 (high x and y value, index of last elem to fill)
> -> IO ()
>
>
> Actually, it might be worthwhile exporting these in the API anyway.
>
> [1] http://code.ouroborus.net/repa/repa-head/repa/Data/Array/Repa/Internals/EvalBlockwise.hs
> [2] http://code.ouroborus.net/repa/repa-head/repa/Data/Array/Repa/Internals/EvalCursored.hs
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20110520/bb42a668/attachment.pgp>
More information about the Glasgow-haskell-users
mailing list