[Haskell-cafe] Vector library
Pierre-Etienne Meunier
pierreetienne.meunier at gmail.com
Mon Feb 14 11:19:55 CET 2011
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
More information about the Haskell-Cafe
mailing list