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

Copyright(c) Alexey Kuleshevich 2018
LicenseBSD3
MaintainerAlexey Kuleshevich <lehins@yandex.ru>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Massiv.Array.Manifest.Vector

Description

 
Synopsis

Documentation

fromVector Source #

Arguments

:: (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 #

Arguments

:: (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.

Examples

Expand

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
[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.

>>> import qualified Data.Vector.Unboxed as VU
>>> toVector (makeArrayR S Par (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]

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

Instances
type ARepr Vector Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type ARepr Vector = U
type ARepr Vector Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type ARepr Vector = S
type ARepr Vector Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type ARepr Vector = P
type ARepr Vector Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type ARepr Vector = B

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

Match array representation to a vector type

Instances
type VRepr U Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type VRepr U = Vector
type VRepr S Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type VRepr S = Vector
type VRepr P Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type VRepr P = Vector
type VRepr N Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type VRepr N = Vector
type VRepr B Source # 
Instance details

Defined in Data.Massiv.Array.Manifest.Vector

type VRepr B = Vector