Copyright | (c) Alexey Kuleshevich 2018-2022 |
---|---|
License | BSD3 |
Maintainer | Alexey Kuleshevich <lehins@yandex.ru> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- fromVectorM :: (MonadThrow m, Typeable v, Vector v a, Manifest r a, Load (ARepr v) ix a, Load r ix a) => Comp -> Sz ix -> v a -> m (Array r ix a)
- fromVector' :: (HasCallStack, Typeable v, Vector v a, Load (ARepr v) ix a, Load r ix a, Manifest r a) => Comp -> Sz ix -> v a -> Array r ix a
- castFromVector :: forall v r ix e. (Vector v e, Typeable v, Index ix, ARepr v ~ r) => Comp -> Sz ix -> v e -> Maybe (Array r ix e)
- toVector :: forall r ix e v. (Manifest r e, Load r ix e, Manifest (ARepr v) e, Vector v e, VRepr (ARepr v) ~ v) => Array r ix e -> v e
- castToVector :: forall v r ix e. (Manifest r e, Index ix, VRepr r ~ v) => Array r ix e -> Maybe (v e)
- type family ARepr (v :: Type -> Type) :: Type where ...
- type family VRepr r :: Type -> Type where ...
Documentation
:: (MonadThrow m, Typeable v, Vector v a, Manifest r a, Load (ARepr v) ix a, Load r ix a) | |
=> Comp | |
-> Sz ix | Resulting size of the array |
-> v a | Source Vector |
-> 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.
Since: 0.3.0
:: (HasCallStack, Typeable v, Vector v a, Load (ARepr v) ix a, Load r ix a, Manifest r a) | |
=> Comp | |
-> Sz ix | Resulting size of the array |
-> v a | Source Vector |
-> Array r ix a |
Just like fromVectorM
, but will throw an exception on a mismatched size.
Since: 0.3.0
toVector :: forall r ix e v. (Manifest r e, Load r ix e, Manifest (ARepr v) 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
In this example a S
torable Array is created and then casted into a Storable
Vector
in costant time:
>>>
import Data.Massiv.Array as A
>>>
import Data.Massiv.Array.Manifest.Vector (toVector)
>>>
import qualified Data.Vector.Storable as VS
>>>
toVector (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 S
torable Array will first be converted into U
nboxed
representation in Par
allel and only after that will be coverted into Unboxed
Vector
in constant time.
>>>
import qualified Data.Vector.Unboxed as VU
>>>
toVector (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]
castToVector :: forall v r ix e. (Manifest r e, Index ix, VRepr r ~ v) => Array r ix e -> Maybe (v e) Source #