| Stability | experimental |
|---|---|
| Maintainer | Patrick Perry <patperry@stanford.edu> |
Data.Vector.Dense
Contents
Description
Immutable dense vectors.
- data Vector n e
- class (Shaped x Int, Elem e) => BaseVector x e where
- vector :: BLAS1 e => Int -> [(Int, e)] -> Vector n e
- listVector :: BLAS1 e => Int -> [e] -> Vector n e
- zeroVector :: BLAS1 e => Int -> Vector n e
- constantVector :: BLAS1 e => Int -> e -> Vector n e
- basisVector :: BLAS1 e => Int -> Int -> Vector n e
- module Data.Tensor.Class.ITensor
- subvector :: BLAS1 e => Vector n e -> Int -> Int -> Vector n' e
- subvectorWithStride :: BLAS1 e => Int -> Vector n e -> Int -> Int -> Vector n' e
- sumAbs :: BLAS1 e => Vector n e -> Double
- norm2 :: BLAS1 e => Vector n e -> Double
- whichMaxAbs :: BLAS1 e => Vector n e -> (Int, e)
- (<.>) :: BLAS1 e => Vector n e -> Vector n e -> e
The Vector type
Immutable dense vectors. The type arguments are as follows:
-
n: a phantom type for the dimension of the vector -
e: the element type of the vector. Only certain element types are supported.
Instances
| Shaped Vector Int | |
| Elem e => BaseVector Vector e | |
| BLAS1 e => ITensor Vector Int e | |
| BLAS1 e => ReadVector Vector e IO | |
| (BLAS1 e, Monad m) => ReadTensor Vector Int e m | |
| BLAS1 e => ReadVector Vector e (ST s) | |
| BLAS1 e => Eq (Vector n e) | |
| (BLAS1 e, Floating e) => Floating (Vector n e) | |
| BLAS1 e => Fractional (Vector n e) | |
| BLAS1 e => Num (Vector n e) | |
| (Elem e, Show e) => Show (Vector n e) | |
| BLAS1 e => AEq (Vector n e) |
Overloaded interface for vectors
class (Shaped x Int, Elem e) => BaseVector x e whereSource
Common functionality for all vector types.
Methods
Get the dimension (length) of the vector.
Indicate whether or not internally the vector stores the complex conjugates of its elements.
Get a view into the complex conjugate of a vector.
coerceVector :: x n e -> x n' eSource
Cast the shape type of the vector.
Instances
| Elem e => BaseVector IOVector e | |
| Elem e => BaseVector Vector e | |
| Elem e => BaseVector (STVector s) e |
Creating new vectors
vector :: BLAS1 e => Int -> [(Int, e)] -> Vector n eSource
Create a vector with the given dimension and elements. The elements given in the association list must all have unique indices, otherwise the result is undefined.
listVector :: BLAS1 e => Int -> [e] -> Vector n eSource
Create a vector of the given dimension with elements initialized
to the values from the list. listVector n es is equivalent to
vector n (zip [0..(n-1)] es), except that the result is undefined
if length es is less than n.
Special vectors
zeroVector :: BLAS1 e => Int -> Vector n eSource
zeroVector n creates a vector of dimension n with all values
set to zero.
constantVector :: BLAS1 e => Int -> e -> Vector n eSource
constantVector n e creates a vector of dimension n with all values
set to e.
basisVector :: BLAS1 e => Int -> Int -> Vector n eSource
basisVector n i creates a vector of dimension n with zeros
everywhere but position i, where there is a one.
Overloaded interface for reading vector elements
module Data.Tensor.Class.ITensor
Vector views
subvector :: BLAS1 e => Vector n e -> Int -> Int -> Vector n' eSource
subvector x o n creates a subvector of x starting at index o
and having length n.
subvectorWithStride :: BLAS1 e => Int -> Vector n e -> Int -> Int -> Vector n' eSource
subvectorWithStride s x o n creates a subvector of x starting
at index o, having length n and stride s.
Vector properties
sumAbs :: BLAS1 e => Vector n e -> DoubleSource
Compute the sum of absolute values of entries in the vector.
whichMaxAbs :: BLAS1 e => Vector n e -> (Int, e)Source
Get the index and norm of the element with absulte value. Not valid
if any of the vector entries are NaN. Raises an exception if the
vector has length 0.