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

License | BSD3 |

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

Stability | experimental |

Portability | non-portable |

Safe Haskell | None |

Language | Haskell2010 |

- fromVector :: (Typeable v, Vector v a, Mutable (ARepr v) ix a, Mutable r ix a) => Comp -> 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 -> 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. (Vector v e, Mutable r ix e, VRepr r ~ v) => Array r ix e -> Maybe (v e)
- type family ARepr (v :: * -> *) :: *
- type family VRepr r :: * -> *

# Documentation

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

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

In this example a `S`

torable Array is created and then casted into a Storable
`Vector`

in costant time:

`>>>`

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