Stability | experimental |
---|---|
Maintainer | Patrick Perry <patperry@stanford.edu> |
An overloaded interface to mutable dense vectors. For vector types than can be used with this interface, see Data.Vector.Dense.IO and Data.Vector.Dense.ST. Many of these functions can also be used with the immutable type defined in Data.Vector.Dense.
- class (Shaped x Int, Elem e) => BaseVector x e where
- class (BaseVector x e, BLAS1 e, Monad m, ReadTensor x Int e m) => ReadVector x e m where
- unsafePerformIOWithVector :: x n e -> (IOVector n e -> IO a) -> m a
- freezeVector :: x n e -> m (Vector n e)
- unsafeFreezeVector :: x n e -> m (Vector n e)
- class (ReadVector x e m, WriteTensor x Int e m) => WriteVector x e m where
- unsafeConvertIOVector :: IO (IOVector n e) -> m (x n e)
- newVector_ :: Int -> m (x n e)
- thawVector :: Vector n e -> m (x n e)
- unsafeThawVector :: Vector n e -> m (x n e)
- newVector :: WriteVector x e m => Int -> [(Int, e)] -> m (x n e)
- newListVector :: WriteVector x e m => Int -> [e] -> m (x n e)
- newZeroVector :: WriteVector x e m => Int -> m (x n e)
- newConstantVector :: WriteVector x e m => Int -> e -> m (x n e)
- newBasisVector :: WriteVector x e m => Int -> Int -> m (x n e)
- setZeroVector :: WriteVector x e m => x n e -> m ()
- setConstantVector :: WriteVector x e m => e -> x n e -> m ()
- setBasisVector :: WriteVector x e m => Int -> x n e -> m ()
- newCopyVector :: (ReadVector x e m, WriteVector y e m) => x n e -> m (y n e)
- newCopyVector' :: (ReadVector x e m, WriteVector y e m) => x n e -> m (y n e)
- copyVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()
- swapVector :: (WriteVector x e m, WriteVector y e m) => x n e -> y n e -> m ()
- subvectorView :: BaseVector x e => x n e -> Int -> Int -> x n' e
- subvectorViewWithStride :: BaseVector x e => Int -> x n e -> Int -> Int -> x n' e
- module Data.Tensor.Class.MTensor
- getConjVector :: (ReadVector x e m, WriteVector y e m) => x n e -> m (y n e)
- getScaledVector :: (ReadVector x e m, WriteVector y e m) => e -> x n e -> m (y n e)
- getShiftedVector :: (ReadVector x e m, WriteVector y e m) => e -> x n e -> m (y n e)
- doConjVector :: WriteVector y e m => y n e -> m ()
- scaleByVector :: WriteVector y e m => e -> y n e -> m ()
- shiftByVector :: WriteVector y e m => e -> y n e -> m ()
- getAddVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)
- getSubVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)
- getMulVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)
- getDivVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)
- addVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()
- subVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()
- axpyVector :: (ReadVector x e m, WriteVector y e m) => e -> x n e -> y n e -> m ()
- mulVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()
- divVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()
- getSumAbs :: ReadVector x e m => x n e -> m Double
- getNorm2 :: ReadVector x e m => x n e -> m Double
- getWhichMaxAbs :: ReadVector x e m => x n e -> m (Int, e)
- getDot :: (ReadVector x e m, ReadVector y e m) => x n e -> y n e -> m e
Dense vector type classes
class (Shaped x Int, Elem e) => BaseVector x e whereSource
Common functionality for all vector types.
Get the dimension (length) of the vector.
Get the memory stride (in elements) between consecutive elements.
Indicate whether or not internally the vector stores the complex conjugates of its elements.
conjEnum :: x n e -> ConjEnumSource
Get the storage type.
Get a view into the complex conjugate of a vector.
coerceVector :: x n e -> x n' eSource
Cast the shape type of the vector.
unsafeVectorToIOVector :: x n e -> IOVector n eSource
Unsafe cast from a vector to an IOVector
.
Elem e => BaseVector IOVector e | |
Elem e => BaseVector Vector e | |
Elem e => BaseVector (STVector s) e |
class (BaseVector x e, BLAS1 e, Monad m, ReadTensor x Int e m) => ReadVector x e m whereSource
Vectors that can be read in a monad.
unsafePerformIOWithVector :: x n e -> (IOVector n e -> IO a) -> m aSource
Cast the vector to an IOVector
, perform an IO
action, and
convert the IO
action to an action in the monad m
. This
operation is very unsafe.
freezeVector :: x n e -> m (Vector n e)Source
Convert a mutable vector to an immutable one by taking a complete copy of it.
unsafeFreezeVector :: x n e -> m (Vector n e)Source
BLAS1 e => ReadVector IOVector e IO | |
BLAS1 e => ReadVector Vector e IO | |
BLAS1 e => ReadVector Vector e (ST s) | |
BLAS1 e => ReadVector (STVector s) e (ST s) |
class (ReadVector x e m, WriteTensor x Int e m) => WriteVector x e m whereSource
Vectors that can be created or modified in a monad.
unsafeConvertIOVector :: IO (IOVector n e) -> m (x n e)Source
newVector_ :: Int -> m (x n e)Source
Creates a new vector of the given length. The elements will be uninitialized.
thawVector :: Vector n e -> m (x n e)Source
Convert an immutable vector to a mutable one by taking a complete copy of it.
unsafeThawVector :: Vector n e -> m (x n e)Source
BLAS1 e => WriteVector IOVector e IO | |
BLAS1 e => WriteVector (STVector s) e (ST s) |
Creating new vectors
newVector :: WriteVector x e m => Int -> [(Int, e)] -> m (x n e)Source
Creates a new vector with the given association list. Unspecified indices will get initialized to zero.
newListVector :: WriteVector x e m => Int -> [e] -> m (x n e)Source
Creates a new vector of the given dimension with the given elements. If the list has length less than the passed-in dimenson, the tail of the vector will be uninitialized.
Special vectors
newZeroVector :: WriteVector x e m => Int -> m (x n e)Source
Create a zero vector of the specified length.
newConstantVector :: WriteVector x e m => Int -> e -> m (x n e)Source
Create a vector with every element initialized to the same value.
newBasisVector :: WriteVector x e m => Int -> Int -> m (x n e)Source
newBasisVector n i
creates a vector of length n
that is all zero
except for at position i
, where it equal to one.
setZeroVector :: WriteVector x e m => x n e -> m ()Source
Set every element in the vector to zero.
setConstantVector :: WriteVector x e m => e -> x n e -> m ()Source
Set every element in the vector to a constant.
setBasisVector :: WriteVector x e m => Int -> x n e -> m ()Source
setBasis x i
sets the i
th coordinate of x
to 1
, and all other
coordinates to 0
. If the vector has been scaled, it is possible that
readVector x i
will not return exactly 1
. See setElem
.
Copying vectors
newCopyVector :: (ReadVector x e m, WriteVector y e m) => x n e -> m (y n e)Source
Creates a new vector by copying another one.
newCopyVector' :: (ReadVector x e m, WriteVector y e m) => x n e -> m (y n e)Source
Creates a new vector by copying another one. The returned vector
is gauranteed not to be a view into another vector. That is, the
returned vector will have isConj
to be False
.
copyVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()Source
copyVector dst src
replaces the values in dst
with those in
source. The operands must be the same shape.
swapVector :: (WriteVector x e m, WriteVector y e m) => x n e -> y n e -> m ()Source
Swap the values stored in two vectors.
Vector views
subvectorView :: BaseVector x e => x n e -> Int -> Int -> x n' eSource
subvectorView x o n
creates a subvector view of x
starting at index o
and having length n
.
subvectorViewWithStride :: BaseVector x e => Int -> x n e -> Int -> Int -> x n' eSource
subvectorViewWithStride s x o n
creates a subvector view of x
starting
at index o
, having length n
and stride s
.
Overloaded interface for reading and writing vector elements
module Data.Tensor.Class.MTensor
Vector operations
Unary
getConjVector :: (ReadVector x e m, WriteVector y e m) => x n e -> m (y n e)Source
Get a new vector with elements with the conjugates of the elements of the given vector
getScaledVector :: (ReadVector x e m, WriteVector y e m) => e -> x n e -> m (y n e)Source
Get a new vector by scaling the elements of another vector by a given value.
getShiftedVector :: (ReadVector x e m, WriteVector y e m) => e -> x n e -> m (y n e)Source
Get a new vector by shifting the elements of another vector by a given value.
doConjVector :: WriteVector y e m => y n e -> m ()Source
Conjugate every element of the vector.
scaleByVector :: WriteVector y e m => e -> y n e -> m ()Source
Scale every element by the given value.
shiftByVector :: WriteVector y e m => e -> y n e -> m ()Source
Add the given value to every element.
Binary
getAddVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)Source
getAddVector x y
creates a new vector equal to the sum x+y
. The
operands must have the same dimension.
getSubVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)Source
getSubVector x y
creates a new tensor equal to the difference x-y
.
The operands must have the same dimension.
getMulVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)Source
getMulVector x y
creates a new vector equal to the elementwise product
x*y
. The operands must have the same dimensino
getDivVector :: (ReadVector x e m, ReadVector y e m, WriteVector z e m) => x n e -> y n e -> m (z n e)Source
getDivVector x y
creates a new vector equal to the elementwise
ratio x/y
. The operands must have the same shape.
addVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()Source
addVector y x
replaces y
with y+x
.
subVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()Source
subVector y x
replaces y
with y-x
.
axpyVector :: (ReadVector x e m, WriteVector y e m) => e -> x n e -> y n e -> m ()Source
axpyVector alpha x y
replaces y
with alpha * x + y
.
mulVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()Source
mulVector y x
replaces y
with y*x
.
divVector :: (WriteVector y e m, ReadVector x e m) => y n e -> x n e -> m ()Source
divVector y x
replaces y
with y/x
.
Vector Properties
getSumAbs :: ReadVector x e m => x n e -> m DoubleSource
Gets the sum of the absolute values of the vector entries.
getNorm2 :: ReadVector x e m => x n e -> m DoubleSource
Gets the 2-norm of a vector.
getWhichMaxAbs :: ReadVector x e m => x n e -> m (Int, e)Source
Gets the index and norm of the element with maximum magnitude. This is
undefined if any of the elements are NaN
. It will throw an exception if
the dimension of the vector is 0.
getDot :: (ReadVector x e m, ReadVector y e m) => x n e -> y n e -> m eSource
Computes the dot product of two vectors.