blas-0.7.6: Bindings to the BLAS library

Stability experimental Patrick Perry

Data.Vector.Dense

Description

Immutable dense vectors.

Synopsis

# The Vector type

data Vector n e Source

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)

class (Shaped x Int, Elem e) => BaseVector x e whereSource

Common functionality for all vector types.

Methods

dim :: x n e -> IntSource

Get the dimension (length) of the vector.

isConj :: x n e -> BoolSource

Indicate whether or not internally the vector stores the complex conjugates of its elements.

conjEnum :: x n e -> ConjEnumSource

Get the storage type.

conj :: x n e -> x n eSource

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.

# 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.

norm2 :: BLAS1 e => Vector n e -> DoubleSource

Compute the 2-norm of a 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`.

(<.>) :: BLAS1 e => Vector n e -> Vector n e -> eSource

Compute the dot product of two vectors.