Re: repa: fromVector

2011-05-20 Thread Christian Höner zu Siederdissen
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 b...@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
 
 


pgpwZSsfvrOv6.pgp
Description: PGP signature
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


repa: fromVector

2011-05-19 Thread Christian Höner zu Siederdissen
Hi,

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)

- In principle, this should work with repa as well, I think. The
  question is: does Repa.Internals.Base.fromVector any copying, or
  does it just use the unboxed vector as-is internally?

should I expect any problems? ;-)

Gruss,
Christian


pgp6KOMi3jSnI.pgp
Description: PGP signature
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: repa: fromVector

2011-05-19 Thread Don Stewart
It doesn't do any copying.

On Thu, May 19, 2011 at 3:27 AM, Christian Höner zu Siederdissen
choe...@tbi.univie.ac.at wrote:
 Hi,

 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)

 - In principle, this should work with repa as well, I think. The
  question is: does Repa.Internals.Base.fromVector any copying, or
  does it just use the unboxed vector as-is internally?

 should I expect any problems? ;-)

 Gruss,
 Christian

 ___
 Glasgow-haskell-users mailing list
 Glasgow-haskell-users@haskell.org
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: repa: fromVector

2011-05-19 Thread Ben Lippmeier

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



___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users