Copyright | (c) Alexey Kuleshevich 2018-2019 |
---|---|

License | BSD3 |

Maintainer | Alexey Kuleshevich <lehins@yandex.ru> |

Stability | experimental |

Portability | non-portable |

Safe Haskell | None |

Language | Haskell2010 |

## Synopsis

- fromVectorM :: (MonadThrow m, Typeable v, Vector v a, Mutable (ARepr v) ix a, Construct r ix a, Mutable r ix a) => Comp -> Sz ix -> v a -> m (Array r ix a)
- fromVector' :: (Typeable v, Vector v a, Mutable (ARepr v) ix a, Construct r ix a, Mutable r ix a) => Comp -> Sz ix -> v a -> Array r ix a
- fromVector :: (Typeable v, Vector v a, Mutable (ARepr v) ix a, Construct r ix a, Mutable r ix a) => Comp -> Sz ix -> v a -> Array r ix a
- castFromVector :: forall v r ix e. (Vector v e, Typeable v, Mutable r ix e, ARepr v ~ r) => Comp -> Sz ix -> v e -> Maybe (Array r ix e)
- 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
- castToVector :: forall v r ix e. (Mutable r ix e, VRepr r ~ v) => Array r ix e -> Maybe (v e)
- type family ARepr (v :: * -> *) :: * where ...
- type family VRepr r :: * -> * where ...

# Documentation

:: (MonadThrow m, Typeable v, Vector v a, Mutable (ARepr v) ix a, Construct r ix a, Mutable 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*

:: (Typeable v, Vector v a, Mutable (ARepr v) ix a, Construct r ix a, Mutable r ix 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*

:: (Typeable v, Vector v a, Mutable (ARepr v) ix a, Construct r ix a, Mutable r ix a) | |

=> Comp | |

-> Sz ix | Resulting size of the array |

-> v a | Source Vector |

-> Array r ix a |

Deprecated: In favor of safer `fromVectorM`

:: (Vector v e, Typeable v, Mutable r ix e, ARepr v ~ r) | |

=> Comp | |

-> Sz 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

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 qualified Data.Vector.Storable as VS`

`>>>`

[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]`toVector (makeArrayR S Par (Sz2 5 6) (\(i :. j) -> i + j)) :: VS.Vector Int`

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`

`>>>`

[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]`toVector (makeArrayR S Par (Sz2 5 6) (\(i :. j) -> i + j)) :: VU.Vector Int`

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