Safe Haskell | None |
---|---|
Language | Haskell2010 |
Storable Vector
unsafe functions. These perform no bounds
checking, and may cause segmentation faults etc.! Import as:
import qualified RIO.Vector.Storable.Unsafe as VS'
Synopsis
- unsafeIndex :: Storable a => Vector a -> Int -> a
- unsafeHead :: Storable a => Vector a -> a
- unsafeLast :: Storable a => Vector a -> a
- unsafeIndexM :: (Storable a, Monad m) => Vector a -> Int -> m a
- unsafeHeadM :: (Storable a, Monad m) => Vector a -> m a
- unsafeLastM :: (Storable a, Monad m) => Vector a -> m a
- unsafeSlice :: Storable a => Int -> Int -> Vector a -> Vector a
- unsafeInit :: Storable a => Vector a -> Vector a
- unsafeTail :: Storable a => Vector a -> Vector a
- unsafeTake :: Storable a => Int -> Vector a -> Vector a
- unsafeDrop :: Storable a => Int -> Vector a -> Vector a
- unsafeUpd :: Storable a => Vector a -> [(Int, a)] -> Vector a
- unsafeUpdate_ :: Storable a => Vector a -> Vector Int -> Vector a -> Vector a
- unsafeAccum :: Storable a => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a
- unsafeAccumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a
- unsafeBackpermute :: Storable a => Vector a -> Vector Int -> Vector a
- unsafeFreeze :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> m (Vector a)
- unsafeThaw :: (Storable a, PrimMonad m) => Vector a -> m (MVector (PrimState m) a)
- unsafeCopy :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
- unsafeFromForeignPtr :: Storable a => ForeignPtr a -> Int -> Int -> Vector a
- unsafeFromForeignPtr0 :: Storable a => ForeignPtr a -> Int -> Vector a
- unsafeToForeignPtr :: Storable a => Vector a -> (ForeignPtr a, Int, Int)
- unsafeToForeignPtr0 :: Storable a => Vector a -> (ForeignPtr a, Int)
- unsafeWith :: (MonadUnliftIO m, Storable a) => Vector a -> (Ptr a -> m b) -> m b
Accessors
Indexing
unsafeIndex :: Storable a => Vector a -> Int -> a #
O(1) Unsafe indexing without bounds checking
unsafeHead :: Storable a => Vector a -> a #
O(1) First element without checking if the vector is empty
unsafeLast :: Storable a => Vector a -> a #
O(1) Last element without checking if the vector is empty
Monadic indexing
unsafeIndexM :: (Storable a, Monad m) => Vector a -> Int -> m a #
O(1) Indexing in a monad without bounds checks. See indexM
for an
explanation of why this is useful.
unsafeHeadM :: (Storable a, Monad m) => Vector a -> m a #
O(1) First element in a monad without checking for empty vectors.
See indexM
for an explanation of why this is useful.
unsafeLastM :: (Storable a, Monad m) => Vector a -> m a #
O(1) Last element in a monad without checking for empty vectors.
See indexM
for an explanation of why this is useful.
Extracting subvectors
O(1) Yield a slice of the vector without copying. The vector must
contain at least i+n
elements but this is not checked.
unsafeInit :: Storable a => Vector a -> Vector a #
O(1) Yield all but the last element without copying. The vector may not be empty but this is not checked.
unsafeTail :: Storable a => Vector a -> Vector a #
O(1) Yield all but the first element without copying. The vector may not be empty but this is not checked.
unsafeTake :: Storable a => Int -> Vector a -> Vector a #
O(1) Yield the first n
elements without copying. The vector must
contain at least n
elements but this is not checked.
unsafeDrop :: Storable a => Int -> Vector a -> Vector a #
O(1) Yield all but the first n
elements without copying. The vector
must contain at least n
elements but this is not checked.
Modifying vectors
Bulk updates
unsafeUpd :: Storable a => Vector a -> [(Int, a)] -> Vector a #
Same as (//
) but without bounds checking.
unsafeUpdate_ :: Storable a => Vector a -> Vector Int -> Vector a -> Vector a #
Same as update_
but without bounds checking.
Accumulations
unsafeAccum :: Storable a => (a -> b -> a) -> Vector a -> [(Int, b)] -> Vector a #
Same as accum
but without bounds checking.
unsafeAccumulate_ :: (Storable a, Storable b) => (a -> b -> a) -> Vector a -> Vector Int -> Vector b -> Vector a #
Same as accumulate_
but without bounds checking.
Permutations
unsafeBackpermute :: Storable a => Vector a -> Vector Int -> Vector a #
Same as backpermute
but without bounds checking.
Conversions
Mutable vectors
unsafeFreeze :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> m (Vector a) #
O(1) Unsafe convert a mutable vector to an immutable one without copying. The mutable vector may not be used after this operation.
unsafeThaw :: (Storable a, PrimMonad m) => Vector a -> m (MVector (PrimState m) a) #
O(1) Unsafely convert an immutable vector to a mutable one without copying. The immutable vector may not be used after this operation.
unsafeCopy :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () #
O(n) Copy an immutable vector into a mutable one. The two vectors must have the same length. This is not checked.
Raw pointers
:: Storable a | |
=> ForeignPtr a | pointer |
-> Int | offset |
-> Int | length |
-> Vector a |
O(1) Create a vector from a ForeignPtr
with an offset and a length.
The data may not be modified through the ForeignPtr
afterwards.
If your offset is 0 it is more efficient to use unsafeFromForeignPtr0
.
:: Storable a | |
=> ForeignPtr a | pointer |
-> Int | length |
-> Vector a |
O(1) Create a vector from a ForeignPtr
and a length.
It is assumed the pointer points directly to the data (no offset).
Use unsafeFromForeignPtr
if you need to specify an offset.
The data may not be modified through the ForeignPtr
afterwards.
unsafeToForeignPtr :: Storable a => Vector a -> (ForeignPtr a, Int, Int) #
O(1) Yield the underlying ForeignPtr
together with the offset to the
data and its length. The data may not be modified through the ForeignPtr
.
unsafeToForeignPtr0 :: Storable a => Vector a -> (ForeignPtr a, Int) #
O(1) Yield the underlying ForeignPtr
together with its length.
You can assume the pointer points directly to the data (no offset).
The data may not be modified through the ForeignPtr
.
unsafeWith :: (MonadUnliftIO m, Storable a) => Vector a -> (Ptr a -> m b) -> m b Source #
Lifted version of unsafeWith