blas-0.7.1: Bindings to the BLAS library

Stabilityexperimental
MaintainerPatrick Perry <patperry@stanford.edu>

Data.Vector.Dense.Class

Contents

Description

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.

Synopsis

Dense vector type classes

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.

stride :: x n e -> IntSource

Get the memory stride (in elements) between consecutive elements.

isConj :: x n e -> BoolSource

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

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.

unsafeVectorToIOVector :: x n e -> IOVector n eSource

Unsafe cast from a vector to an IOVector.

Instances

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.

Methods

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

Instances

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.

Methods

unsafeConvertIOVector :: IO (IOVector n e) -> m (x n e)Source

Unsafely convert an IO action that creates an IOVector into an action in m that creates a vector.

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

Instances

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 ith 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

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.

Conversions between mutable and immutable vectors

Conversions from IOVectors