Fixie Fixie | 1 Dec 12:10 2012
Picon

Are storable-mutable-vectors in two dimensions possible in Haskell?

Hello haskellers

I am struggling with this package: Data.Vector.Storable.Mutable

I am creating vectors like this: MV.new 1000 :: IO (V.MVector (PrimState IO) Int)

Now I would like access to this vectors in linear time, like I could have done in C using pointers.

The problem is that I do not know which datastructure to keep my vectors in. If I put them in a list, the access is very slow. Even a binary tree is very slow compared to a C-version.

I have tried to make an array og vector of storable-mutable vectors, but have not manged to accomplish this - even though there must be a haskell way :-)

Any clues?

Cheers,

Felix


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Dmitry Dzhus | 1 Dec 12:27 2012

Re: Are storable-mutable-vectors in two dimensions possible in Haskell?

01.12.2012, 15:14, "Fixie Fixie" <fixie.fixie <at> rocketmail.com>:
> Hello haskellers
> I am struggling with this package: Data.Vector.Storable.Mutable
> I am creating vectors like this: MV.new 1000 :: IO (V.MVector (PrimState IO) Int)
> Now I would like access to this vectors in linear time, like I could have done in C using pointers.
> The problem is that I do not know which datastructure to keep my vectors in. If I put them in a list, the access
is very slow. Even a binary tree is very slow compared to a C-version.
> I have tried to make an array og vector of storable-mutable vectors, but have not manged to accomplish this
- even though there must be a haskell way :-)

You can use boxed vector as a first-level structure holding pointers
you your storable vectors to perform O(1) indexing on first dimension.

Alternatively, if your matrix is dense, store your data in a
one-dimensional vector and use Repa as a thin wrapper to perform
multi-dimensional indexing (see toIndex/fromIndex
Data.Array.Repa.Shape).

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Fixie Fixie | 1 Dec 12:34 2012
Picon

Vedr: Are storable-mutable-vectors in two dimensions possible in Haskell?

Sounds good. I thought something like this could be the solution.

But it might be that my type-knowledge is not good enough - but I have not been able to do this. Example:

vec1 <- MV.new 1000 :: IO (V.MVector (PrimState IO) Int)

Data.Vector.singleton vec1 -- does not work, gives a lot of type-errs.

Felix


Fra: Dmitry Dzhus <dima <at> dzhus.org>
Til: Fixie Fixie <fixie.fixie <at> rocketmail.com>; Haskell cafe <haskell-cafe <at> haskell.org>
Sendt: Lørdag, 1. desember 2012 12.27
Emne: Re: [Haskell-cafe] Are storable-mutable-vectors in two dimensions possible in Haskell?

01.12.2012, 15:14, "Fixie Fixie" <fixie.fixie <at> rocketmail.com>:
> Hello haskellers
> I am struggling with this package: Data.Vector.Storable.Mutable
> I am creating vectors like this: MV.new 1000 :: IO (V.MVector (PrimState IO) Int)
> Now I would like access to this vectors in linear time, like I could have done in C using pointers.
> The problem is that I do not know which datastructure to keep my vectors in. If I put them in a list, the access is very slow. Even a binary tree is very slow compared to a C-version.
> I have tried to make an array og vector of storable-mutable vectors, but have not manged to accomplish this - even though there must be a haskell way :-)

You can use boxed vector as a first-level structure holding pointers
you your storable vectors to perform O(1) indexing on first dimension.

Alternatively, if your matrix is dense, store your data in a
one-dimensional vector and use Repa as a thin wrapper to perform
multi-dimensional indexing (see toIndex/fromIndex
Data.Array.Repa.Shape).


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane