Copyright | (C) 2013 Amgen Inc. 2016 Tweag I/O Limited. |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Data.Vector.SEXP.Mutable
Description
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.
Synopsis
- data MVector s (ty :: SEXPTYPE) a
- fromSEXP :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => SEXP s ty -> MVector s ty a
- toSEXP :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (SEXP (Region m) ty)
- release :: forall s' s (ty :: SEXPTYPE) a. s' <= s => MVector s ty a -> MVector s' ty a
- unsafeRelease :: forall s (ty :: SEXPTYPE) a s'. MVector s ty a -> MVector s' ty a
- length :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> Int
- null :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> Bool
- new :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a)
- unsafeNew :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a)
- replicate :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => Int -> a -> m (MVector (Region m) ty a)
- replicateM :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => Int -> m a -> m (MVector (Region m) ty a)
- clone :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (MVector (Region m) ty a)
- slice :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> Int -> MVector s ty a -> MVector s ty a
- init :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a
- tail :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a
- take :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- drop :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- splitAt :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> (MVector s ty a, MVector s ty a)
- unsafeSlice :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> Int -> MVector s ty a -> MVector s ty a
- unsafeInit :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a
- unsafeTail :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a
- unsafeTake :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- unsafeDrop :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a
- overlaps :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a -> Bool
- clear :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m ()
- read :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a
- write :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m ()
- swap :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m ()
- unsafeRead :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a
- unsafeWrite :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m ()
- unsafeSwap :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m ()
- set :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> a -> m ()
- copy :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
- move :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
- unsafeCopy :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
- unsafeMove :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m ()
Mutable slices of SEXP
vector types
fromSEXP :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => SEXP s ty -> MVector s ty a Source #
O(1) Create a vector from a SEXP
.
toSEXP :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (SEXP (Region m) ty) Source #
Accessors
Length information
length :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> Int Source #
Length of the mutable vector.
null :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> Bool Source #
Check whether the vector is empty.
Construction
Initialisation
new :: forall m (ty :: SEXPTYPE) 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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall s (ty :: SEXPTYPE) a. 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.
take :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a Source #
drop :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a Source #
splitAt :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> (MVector s ty a, MVector s ty a) Source #
Arguments
:: forall s (ty :: SEXPTYPE) a. VECTOR s ty a | |
=> Int | starting index |
-> Int | length of the slice |
-> MVector s ty a | |
-> MVector s ty a |
Yield a part of the mutable vector without copying it. No bounds checks are performed.
unsafeInit :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a Source #
unsafeTail :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a Source #
unsafeTake :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a Source #
unsafeDrop :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a Source #
Overlapping
overlaps :: forall s (ty :: SEXPTYPE) a. VECTOR s ty a => MVector s ty a -> MVector s ty a -> Bool Source #
Check whether two vectors overlap.
Restricting memory usage
clear :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a Source #
Yield the element at the given position.
write :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m () Source #
Replace the element at the given position.
swap :: forall m (ty :: SEXPTYPE) a. (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m () Source #
Swap the elements at the given positions.
unsafeRead :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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 :: forall m (ty :: SEXPTYPE) a. (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.
Arguments
:: forall m (ty :: SEXPTYPE) a. (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.
Arguments
:: forall m (ty :: SEXPTYPE) a. (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.