Copyright | (C) 2013 Amgen Inc. 2016 Tweag I/O Limited. |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Vectors that can be passed to and from R with no copying at all. These
vectors are wrappers over SEXP vectors used by R. Memory for vectors is
allocated from the R heap, and in such way that they can be converted to
a SEXP
by simple pointer arithmetic (see toSEXP
).
Like Data.Vector.Storable.Mutable vectors, the vector type in this module
adds one extra level of indirection and a small amount of storage overhead
for maintainging lengths and slice offsets. If you're keeping a very large
number of tiny vectors in memory, you're better off keeping them as SEXP
s
and calling fromSEXP
on-the-fly.
- data MVector s ty a
- fromSEXP :: VECTOR s ty a => SEXP s ty -> MVector s ty a
- toSEXP :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (SEXP (Region m) ty)
- release :: s' <= s => MVector s ty a -> MVector s' ty a
- unsafeRelease :: MVector s ty a -> MVector s' ty a
- length :: VECTOR s ty a => MVector s ty a -> Int
- null :: VECTOR s ty a => MVector s ty a -> Bool
- new :: forall m ty a. (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a)
- unsafeNew :: (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a)
- replicate :: (MonadR m, VECTOR (Region m) ty a) => Int -> a -> m (MVector (Region m) ty a)
- replicateM :: (MonadR m, VECTOR (Region m) ty a) => Int -> m a -> m (MVector (Region m) ty a)
- clone :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (MVector (Region m) ty a)
- slice :: VECTOR s ty a => Int -> Int -> MVector s ty a -> MVector s ty a
- init :: VECTOR s ty a => MVector s ty a -> MVector s ty a
- tail :: VECTOR s ty a => MVector s ty a -> MVector s ty a
- take :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- drop :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- splitAt :: VECTOR s ty a => Int -> MVector s ty a -> (MVector s ty a, MVector s ty a)
- unsafeSlice :: VECTOR s ty a => Int -> Int -> MVector s ty a -> MVector s ty a
- unsafeInit :: VECTOR s ty a => MVector s ty a -> MVector s ty a
- unsafeTail :: VECTOR s ty a => MVector s ty a -> MVector s ty a
- unsafeTake :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- unsafeDrop :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- overlaps :: VECTOR s ty a => MVector s ty a -> MVector s ty a -> Bool
- clear :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m ()
- read :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a
- write :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m ()
- swap :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m ()
- unsafeRead :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a
- unsafeWrite :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m ()
- unsafeSwap :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m ()
- set :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> a -> m ()
- copy :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
- move :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
- unsafeCopy :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
- unsafeMove :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
Mutable slices of SEXP
vector types
toSEXP :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (SEXP (Region m) ty) Source #
unsafeRelease :: MVector s ty a -> MVector s' ty a Source #
Accessors
Length information
Construction
Initialisation
new :: forall m ty a. (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a) Source #
Create a mutable vector of the given length.
unsafeNew :: (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a) Source #
Create a mutable vector of the given length. The length is not checked.
replicate :: (MonadR m, VECTOR (Region m) ty a) => Int -> a -> m (MVector (Region m) ty a) Source #
Create a mutable vector of the given length (0 if the length is negative) and fill it with an initial value.
replicateM :: (MonadR m, VECTOR (Region m) ty a) => Int -> m a -> m (MVector (Region m) ty a) Source #
Create a mutable vector of the given length (0 if the length is negative) and fill it with values produced by repeatedly executing the monadic action.
clone :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (MVector (Region m) ty a) Source #
Create a copy of a mutable vector.
Extracting subvectors
slice :: VECTOR s ty a => Int -> Int -> MVector s ty a -> MVector s ty a Source #
Yield a part of the mutable vector without copying it.
Yield a part of the mutable vector without copying it. No bounds checks are performed.
Overlapping
overlaps :: VECTOR s ty a => MVector s ty a -> MVector s ty a -> Bool Source #
Check whether two vectors overlap.
Restricting memory usage
clear :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m () Source #
Reset all elements of the vector to some undefined value, clearing all references to external objects. This is usually a noop for unboxed vectors.
Accessing individual elements
read :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a Source #
Yield the element at the given position.
write :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m () Source #
Replace the element at the given position.
swap :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m () Source #
Swap the elements at the given positions.
unsafeRead :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a Source #
Yield the element at the given position. No bounds checks are performed.
unsafeWrite :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m () Source #
Replace the element at the given position. No bounds checks are performed.
unsafeSwap :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m () Source #
Swap the elements at the given positions. No bounds checks are performed.
Modifying vectors
Filling and copying
set :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> a -> m () Source #
Set all elements of the vector to the given value.
copy :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m () Source #
Copy a vector. The two vectors must have the same length and may not overlap.
move :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m () Source #
Move the contents of a vector. The two vectors must have the same length.
If the vectors do not overlap, then this is equivalent to copy
.
Otherwise, the copying is performed as if the source vector were
copied to a temporary vector and then the temporary vector was copied
to the target vector.
:: (MonadR m, VECTOR (Region m) ty a) | |
=> MVector (Region m) ty a | target |
-> MVector (Region m) ty a | source |
-> m () |
Copy a vector. The two vectors must have the same length and may not overlap. This is not checked.
:: (MonadR m, VECTOR (Region m) ty a) | |
=> MVector (Region m) ty a | target |
-> MVector (Region m) ty a | source |
-> m () |
Move the contents of a vector. The two vectors must have the same length, but this is not checked.
If the vectors do not overlap, then this is equivalent to unsafeCopy
.
Otherwise, the copying is performed as if the source vector were
copied to a temporary vector and then the temporary vector was copied
to the target vector.