Re: [Haskell-cafe] Data.Vector.Unboxed
If the internal vectors are fixed size, you can easily write a wrapper around Vector Int that converts (Int,Int) indices into indices in the sub-vector. If the internal vectors have dynamic size, you can't declare an Unbox instance, because pointers can't be unboxed; unboxed types are opaque to the garbage collector. At a low level, Vector Int is Vector Word# Word# ByteArray# where Word# are machine words and ByteArray# is like 'const char *' that is understood by the ghc garbage collector. On Wed, Nov 9, 2011 at 1:56 AM, kaffeepause73 wrote: > Hello, > > quick question about unboxed Vectors : > > Is it possible to create an unboxed vector of unboxed vector ? : > > > import qualified Data.Vector.Unboxed as V > > type UnboxedNestedVextor = V.Vector (V.Vector Int) > > Alternatively I would have to use: > > > import qualified Data.Vector.Unboxed as V > > import qualified Data.Vector as VB > > type UnboxedNestedVextor = VB.Vector (V.Vector Int) > > Is there a rule of thumb how much quicker Unboxed Vectors are ? > > Cheers Phil > > > -- > View this message in context: > http://haskell.1045720.n5.nabble.com/Data-Vector-Unboxed-tp4977289p4977289.html > Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Vector.Unboxed
Yes, it does. You can only use members of the Elt class in repa arrays, and Elt has Unbox as a superclass. On Thu, Nov 10, 2011 at 5:03 PM, Yves Parès wrote: > Does Repa always use unboxed Vectors? > But a Repa array can store any element, so how does it handles types which > haven't an unboxed equivalent? Or is the unboxing done automatically? > > > 2011/11/10 Bas van Dijk > >> On 9 November 2011 22:33, kaffeepause73 wrote: >> > Repa is indeed very Interesting, but I have changing vector length in >> the >> > second dimension and later on only want to generate Data on demand. If >> I use >> > Matrices, I will use loads of space for no reason. >> >> Even if it is possible to create an unboxed vector of unboxed vectors, >> if the inner unboxed vectors have variable lengths as you require, >> indexing will become O(n) instead of O(1) because you need to traverse >> the inner unboxed vectors and check their length to find the desired >> index. I'm not sure that's what you want. >> >> > Seems like sticking to Boxed Vector for now is best Choice for me. >> >> Yes your second alternative: a boxed vector of unboxed vectors seems >> to do what you want. >> >> > isn't data.vector also providing multidimensional arrays? >> >> I don't think so. All indexing functions get a single Int argument. Of >> course it's easy to build a layer on top that adds more dimensions. >> >> > So is Repa just another Version of Data.Vector or is it building >> another level on top. >> >> The latter, repa provides a layer on top of vector. >> >> Note that you can also convert Vectors to repa Arrays using: >> >> fromVector :: Shape sh => sh -> Vector a -> Array sh a >> >> I believe its O(1). >> >> > And when to use best which of the two ? >> >> I guess when your vectors are multi-dimensional and you want to >> benefit from parallelism you should use repa instead of vector. >> >> Cheers, >> >> Bas >> >> ___ >> Haskell-Cafe mailing list >> Haskell-Cafe@haskell.org >> http://www.haskell.org/mailman/listinfo/haskell-cafe >> > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Vector.Unboxed
Does Repa always use unboxed Vectors? But a Repa array can store any element, so how does it handles types which haven't an unboxed equivalent? Or is the unboxing done automatically? 2011/11/10 Bas van Dijk > On 9 November 2011 22:33, kaffeepause73 wrote: > > Repa is indeed very Interesting, but I have changing vector length in the > > second dimension and later on only want to generate Data on demand. If I > use > > Matrices, I will use loads of space for no reason. > > Even if it is possible to create an unboxed vector of unboxed vectors, > if the inner unboxed vectors have variable lengths as you require, > indexing will become O(n) instead of O(1) because you need to traverse > the inner unboxed vectors and check their length to find the desired > index. I'm not sure that's what you want. > > > Seems like sticking to Boxed Vector for now is best Choice for me. > > Yes your second alternative: a boxed vector of unboxed vectors seems > to do what you want. > > > isn't data.vector also providing multidimensional arrays? > > I don't think so. All indexing functions get a single Int argument. Of > course it's easy to build a layer on top that adds more dimensions. > > > So is Repa just another Version of Data.Vector or is it building another > level on top. > > The latter, repa provides a layer on top of vector. > > Note that you can also convert Vectors to repa Arrays using: > > fromVector :: Shape sh => sh -> Vector a -> Array sh a > > I believe its O(1). > > > And when to use best which of the two ? > > I guess when your vectors are multi-dimensional and you want to > benefit from parallelism you should use repa instead of vector. > > Cheers, > > Bas > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Vector.Unboxed
On 9 November 2011 22:33, kaffeepause73 wrote: > Repa is indeed very Interesting, but I have changing vector length in the > second dimension and later on only want to generate Data on demand. If I use > Matrices, I will use loads of space for no reason. Even if it is possible to create an unboxed vector of unboxed vectors, if the inner unboxed vectors have variable lengths as you require, indexing will become O(n) instead of O(1) because you need to traverse the inner unboxed vectors and check their length to find the desired index. I'm not sure that's what you want. > Seems like sticking to Boxed Vector for now is best Choice for me. Yes your second alternative: a boxed vector of unboxed vectors seems to do what you want. > isn't data.vector also providing multidimensional arrays? I don't think so. All indexing functions get a single Int argument. Of course it's easy to build a layer on top that adds more dimensions. > So is Repa just another Version of Data.Vector or is it building another > level on top. The latter, repa provides a layer on top of vector. Note that you can also convert Vectors to repa Arrays using: fromVector :: Shape sh => sh -> Vector a -> Array sh a I believe its O(1). > And when to use best which of the two ? I guess when your vectors are multi-dimensional and you want to benefit from parallelism you should use repa instead of vector. Cheers, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Vector.Unboxed
Thanks for the replies. - Looks like there's not a straight forward way and I'm not yet on a level and don't have the time to make fancy wrappers or instances. Repa is indeed very Interesting, but I have changing vector length in the second dimension and later on only want to generate Data on demand. If I use Matrices, I will use loads of space for no reason. Seems like sticking to Boxed Vector for now is best Choice for me. But another question here - isn't data.vector also providing multidimensional arrays? So is Repa just another Version of Data.Vector or is it building another level on top. -- And when to use best which of the two ? Cheers Phil -- View this message in context: http://haskell.1045720.n5.nabble.com/Data-Vector-Unboxed-tp4977289p4979201.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Vector.Unboxed
On 9 November 2011 10:56, kaffeepause73 wrote: > Is it possible to create an unboxed vector of unboxed vector ? : Why do you want to do this? If you want multi-dimensional unboxed arrays you could try out repa: http://www.haskell.org/haskellwiki/Numeric_Haskell:_A_Repa_Tutorial (I believe it uses unboxed Vectors internally). Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Vector.Unboxed
Hi, I don't know about Unboxed, but you can define a newtype wrapper around Data.Vector.Storable that includes the size as a type-level natural. i.e. data Z data S n newtype Vec n a = Vec (Vector a) Then you can define a storable instance for Storable a => Vec n a, and thus you can define a storable vector for Vec n a. Not that you need something like this because storable instances must have fixed size. I don't know if this is also true for Unbox. I've done this using lists as the underlying container inside the typed vectors, but you could use Data.Vector.Storable instead with minimal effort: https://github.com/glutamate/space/blob/master/VectorsL.hs Tom On Wed, Nov 9, 2011 at 9:56 AM, kaffeepause73 wrote: > Hello, > > quick question about unboxed Vectors : > > Is it possible to create an unboxed vector of unboxed vector ? : > >> import qualified Data.Vector.Unboxed as V >> type UnboxedNestedVextor = V.Vector (V.Vector Int) > > Alternatively I would have to use: > >> import qualified Data.Vector.Unboxed as V >> import qualified Data.Vector as VB > > type UnboxedNestedVextor = VB.Vector (V.Vector Int) > > Is there a rule of thumb how much quicker Unboxed Vectors are ? > > Cheers Phil > > > -- > View this message in context: > http://haskell.1045720.n5.nabble.com/Data-Vector-Unboxed-tp4977289p4977289.html > Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Vector.Unboxed
On 9 November 2011 20:56, kaffeepause73 wrote: > Hello, > > quick question about unboxed Vectors : > > Is it possible to create an unboxed vector of unboxed vector ? : > >> import qualified Data.Vector.Unboxed as V >> type UnboxedNestedVextor = V.Vector (V.Vector Int) Only if you can define an Unbox instance for unboxed vectors (and I don't know how feasible that is): http://hackage.haskell.org/packages/archive/vector/0.9/doc/html/Data-Vector-Unboxed.html#t:Unbox > > Alternatively I would have to use: > >> import qualified Data.Vector.Unboxed as V >> import qualified Data.Vector as VB > > type UnboxedNestedVextor = VB.Vector (V.Vector Int) > > Is there a rule of thumb how much quicker Unboxed Vectors are ? > > Cheers Phil > > > -- > View this message in context: > http://haskell.1045720.n5.nabble.com/Data-Vector-Unboxed-tp4977289p4977289.html > Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Data.Vector.Unboxed
Hello, quick question about unboxed Vectors : Is it possible to create an unboxed vector of unboxed vector ? : > import qualified Data.Vector.Unboxed as V > type UnboxedNestedVextor = V.Vector (V.Vector Int) Alternatively I would have to use: > import qualified Data.Vector.Unboxed as V > import qualified Data.Vector as VB type UnboxedNestedVextor = VB.Vector (V.Vector Int) Is there a rule of thumb how much quicker Unboxed Vectors are ? Cheers Phil -- View this message in context: http://haskell.1045720.n5.nabble.com/Data-Vector-Unboxed-tp4977289p4977289.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe