[Haskell-cafe] Vector library

2011-02-14 Thread Pierre-Etienne Meunier
Hi,

This is mostly a question for Roman : how do you use your vector library with 
multi-dimensional arrays ? I mean, the array library from the standard 
libraries does something more intelligent than the C-like solution with 
indirections.

For instance, it allows you to program a single function that works for any 
dimensionality of the array.
An example where it is useful ? Right :
Some time ago I wrote a polynomial system solver for polynomials in Bernstein 
form. It needs to perform De Casteljau's algorithm to compute the coefficients 
of the restriction of its argument to a subinterval of [0,1]. The Ix thing 
(mainly the bounds function) allows for writing only one version of the 
function for any number of variables (ok, I needed to write another class to 
tell me there were n variables were when the index was a n-uple, and how to 
iterate over my data in some dimension between 0 and n-1).

I know I could do it with vectors only by wrapping them in another type 
carrying the bounds information, but isn't there any more elegant way to do it 
? Like an optional thing in the vector type, an alternative one, I don't know.

Thanks,
Pierre


Some code example :

instance Restrictable (Double,Double,Double,Double,Double,Double,Double,Double) 
(Int,Int,Int,Int,Int) where
  restriction (a,b,c,d,e,f,g,h) lower upper=
let ((i0,i1,i2,i3,i4),(j0,j1,j2,j3,j4))=bounds lower
dd=rangeSize (i4,j4)
n0=rangeSize (i0,j0)
n1=rangeSize (i1,j1)
n2=rangeSize (i2,j2)
n3=rangeSize (i3,j3)

restr0=restrict 1 (n1*n2*n3) n0 dd a b coefs
restr1=restrict n0 (n2*n3) n1 dd c d restr0
restr2=restrict (n0*n1) n3 n2 dd e f restr1
restr3=restrict (n0*n1*n2) 1 n3 dd g h restr2
in
something

Where restrict is written like :

restrict bef aft nv dd a b coefs=
let idx i j k d=((i*nv+j)*aft + k)*dd + d in
something


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


Re: [Haskell-cafe] Vector library

2011-02-14 Thread Max Bolingbroke
On 14 February 2011 10:19, Pierre-Etienne Meunier
pierreetienne.meun...@gmail.com wrote:
 For instance, it allows you to program a single function that works for any 
 dimensionality of the array.

I don't know how vector handles it, but you may be interested to look
at the repa library
(http://hackage.haskell.org/packages/archive/repa/1.1.0.0/doc/html/Data-Array-Repa.html).
This lets you write dimensionality-polymorphic functions by using the
Shape typeclass:
http://hackage.haskell.org/packages/archive/repa/1.1.0.0/doc/html/Data-Array-Repa-Shape.html#t:Shape

Max

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


Re: [Haskell-cafe] Vector library

2011-02-14 Thread Roman Leshchinskiy
Pierre-Etienne Meunier wrote:

 This is mostly a question for Roman : how do you use your vector library
 with multi-dimensional arrays ? I mean, the array library from the
 standard libraries does something more intelligent than the C-like
 solution with indirections.

Vector doesn't include any support for multidimensional arrays. This is by
design as the library has exactly one purpose: to provide a fast
implementation of contiguous, one-dimensional arrays. As you point out, it
is well possible to build multidimensional arrays on top of it but that
would be a separate library. You might want to take a look at Repa
(http://hackage.haskell.org/package/repa) which does exactly that (it sits
on top of DPH which sits on top of vector). It also gives you parallelism.

FWIW, I don't think we've nailed the right API for multidimensional
arrays yet. It's a hard problem. But we are getting there.

Roman




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