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
01.12.2012, 15:14, "Fixie Fixie" <fixie.fixie@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).
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@dzhus.org> Til: Fixie Fixie <fixie.fixie@rocketmail.com>; Haskell cafe <haskell-cafe@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@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).
participants (2)
-
Dmitry Dzhus -
Fixie Fixie