repa: fromVector

Ben Lippmeier benl at ouroborus.net
Fri May 20 04:14:28 CEST 2011


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





More information about the Glasgow-haskell-users mailing list