massiv- Massiv (Массив) is an Array Library.

Copyright(c) Alexey Kuleshevich 2018
MaintainerAlexey Kuleshevich <>
Safe HaskellNone






fromVector Source #


:: (Typeable v, Vector v a, Mutable (ARepr v) ix a, Mutable r ix a) 
=> Comp 
-> ix

Resulting size of the array

-> v a

Source Vector

-> Array r ix a 

In case when resulting array representation matches the one of vector's it will do a O(1) - conversion using castFromVector, otherwise Vector elements will be copied into a new array. Will throw an error if length of resulting array doesn't match the source vector length.

castFromVector Source #


:: (Vector v e, Typeable v, Mutable r ix e, ARepr v ~ r) 
=> Comp 
-> ix

Size of the result Array

-> v e

Source Vector

-> Maybe (Array r ix e) 

O(1) - conversion from vector to an array with a corresponding representation. Will return Nothing if there is a size mismatch, vector has been sliced before or if some non-standard vector type is supplied.

toVector :: forall r ix e v. (Manifest r ix e, Mutable (ARepr v) ix e, Vector v e, VRepr (ARepr v) ~ v) => Array r ix e -> v e Source #

Convert an array into a vector. Will perform a cast if resulting vector is of compatible representation, otherwise memory copy will occur.


In this example a Storable Array is created and then casted into a Storable Vector in costant time:

>>> import qualified Data.Vector.Storable as VS
>>> toVector (makeArrayR S Par (5 :. 6) (\(i :. j) -> i + j)) :: VS.Vector Int

While in this example Storable Array will first be converted into Unboxed representation in Parallel and only after that will be coverted into Unboxed Vector in constant time.

>>> import qualified Data.Vector.Unboxed as VU
>>> toVector (makeArrayR S Par (5 :. 6) (\(i :. j) -> i + j)) :: VU.Vector Int

castToVector :: forall v r ix e. (Vector v e, Mutable r ix e, VRepr r ~ v) => Array r ix e -> Maybe (v e) Source #

O(1) - conversion from Mutable array to a corresponding vector. Will return Nothing only if source array representation was not one of B, N, P, S or U.

type family ARepr (v :: * -> *) :: * Source #

Match vector type to array representation


type ARepr Vector Source # 
type ARepr Vector = U
type ARepr Vector Source # 
type ARepr Vector = S
type ARepr Vector Source # 
type ARepr Vector = P
type ARepr Vector Source # 
type ARepr Vector = B

type family VRepr r :: * -> * Source #

Match array representation to a vector type


type VRepr U Source # 
type VRepr U = Vector
type VRepr S Source # 
type VRepr S = Vector
type VRepr P Source # 
type VRepr P = Vector
type VRepr N Source # 
type VRepr N = Vector
type VRepr B Source # 
type VRepr B = Vector