HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulemassiv-1.0.5.0Haskell2010

Data.Massiv.Array.Manifest.Vector

  • 5 values
  • Packagemassiv-1.0.5.0
  • Exports7
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceVector.hs
valuefromVectorM
  1. :: (MonadThrow m, Typeable v, Vector v a, Manifest r a, Load (ARepr v) ix a, Load r ix a)
  2. => Comp
  3. -> Sz ix

    Resulting size of the array

  4. -> v a

    Source Vector

  5. -> m (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.

valuecastFromVector
  1. :: (Vector v e, Typeable v, Index ix, ARepr v ~ r)
  2. => Comp
  3. -> Sz ix

    Size of the result Array

  4. -> v e

    Source Vector

  5. -> 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 or if some non-standard vector type is supplied. Is suppplied is the boxed Vector then it's all elements will be evaluated toWHNF, therefore complexity will be O(n)

valuetoVector
  1. :: (Manifest r e, Load r ix e, Manifest (ARepr v) e, Vector v e, VRepr (ARepr v) ~ v)
  2. => Array r ix e
  3. -> v e
#

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

Examples

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

Example4 expressions
import Data.Massiv.Array as Aimport Data.Massiv.Array.Manifest.Vector (toVector)import qualified Data.Vector.Storable as VStoVector (makeArrayR S Par (Sz2 5 6) (\(i :. j) -> i + j)) :: VS.Vector Int[0,1,2,3,4,5,1,2,3,4,5,6,2,3,4,5,6,7,3,4,5,6,7,8,4,5,6,7,8,9]

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.

Example2 expressions
import qualified Data.Vector.Unboxed as VUtoVector (makeArrayR S Par (Sz2 5 6) (\(i :. j) -> i + j)) :: VU.Vector Int[0,1,2,3,4,5,1,2,3,4,5,6,2,3,4,5,6,7,3,4,5,6,7,8,4,5,6,7,8,9]