blas-0.7.1: Bindings to the BLAS library

Stabilityexperimental
MaintainerPatrick Perry <patperry@stanford.edu>

Data.Matrix.Dense.Class

Contents

Description

An overloaded interface to mutable dense matrices. For matrix types than can be used with this interface, see Data.Matrix.Dense.IO and Data.Matrix.Dense.ST. Many of these functions can also be used with the immutable type defined in Data.Matrix.Dense.

Synopsis

Dense matrix type classes

class (HasVectorView a, Elem e, MatrixShaped a, BaseVector (VectorView a) e) => BaseMatrix a e whereSource

Common functionality for all dense matrix types.

Methods

ldaMatrix :: a (n, p) e -> IntSource

isHermMatrix :: a (n, p) e -> BoolSource

coerceMatrix :: a np e -> a np' eSource

Cast the shape type of the matrix.

maybeViewMatrixAsVector :: a (n, p) e -> Maybe (VectorView a np e)Source

Possibly create a vector view of a matrix. This will fail if the matrix is hermed or if the lda of the matrix is not equal to the number of rows in the matrix.

maybeViewVectorAsRow :: VectorView a p e -> Maybe (a (one, p) e)Source

Possibly create a matrix view of a row vector. This will fail if the stride of the vector is not 1 or the vector is conjugated.

maybeViewVectorAsCol :: VectorView a n e -> Maybe (a (n, one) e)Source

Possibly create a matrix view of a column vector. This will fail if the stride of the vector is not 1 or the vector is not conjugated.

maybeViewVectorAsMatrix :: (Int, Int) -> VectorView a np e -> Maybe (a (n, p) e)Source

Possible create a matrix view of the vector. This will fail if the stride of the vector is not 1 or the vector is conjugated. An error will be called if the vector does not have the same number of elements as the desired matrix.

unsafeMatrixToIOMatrix :: a (n, p) e -> IOMatrix (n, p) eSource

Unsafe cast from a matrix to an IOMatrix.

Instances

class (BaseMatrix a e, BLAS3 e, ReadTensor a (Int, Int) e m, MMatrix a e m, MMatrix (Herm a) e m, MMatrix (Tri a) e m, MSolve (Tri a) e m, ReadVector (VectorView a) e m) => ReadMatrix a e m whereSource

Dense matrices that can be read in a monad.

Methods

unsafePerformIOWithMatrix :: a (n, p) e -> (IOMatrix (n, p) e -> IO r) -> m rSource

Cast the matrix to an IOMatrix, perform an IO action, and convert the IO action to an action in the monad m. This operation is very unsafe.

freezeMatrix :: a (n, p) e -> m (Matrix (n, p) e)Source

Convert a mutable matrix to an immutable one by taking a complete copy of it.

unsafeFreezeMatrix :: a (n, p) e -> m (Matrix (n, p) e)Source

Instances

class (ReadMatrix a e m, WriteTensor a (Int, Int) e m, WriteVector (VectorView a) e m) => WriteMatrix a e m whereSource

Dense matrices that can be created or modified in a monad.

Methods

newMatrix_ :: (Int, Int) -> m (a (n, p) e)Source

Creates a new matrix of the given shape. The elements will be uninitialized.

unsafeConvertIOMatrix :: IO (IOMatrix (n, p) e) -> m (a (n, p) e)Source

Unsafely convert an IO action that creates an IOMatrix into an action in m that creates a matrix.

thawMatrix :: Matrix (n, p) e -> m (a (n, p) e)Source

Convert an immutable matrix to a mutable one by taking a complete copy of it.

unsafeThawMatrix :: Matrix (n, p) e -> m (a (n, p) e)Source

Instances

Overloaded interface for matrices

Creating matrices

newMatrix :: WriteMatrix a e m => (Int, Int) -> [((Int, Int), e)] -> m (a (n, p) e)Source

Creates a new matrix with the given association list. Unspecified indices will get initialized to zero.

newListMatrix :: WriteMatrix a e m => (Int, Int) -> [e] -> m (a (n, p) e)Source

Create a new matrix with the given elements in column-major order.

newRowsMatrix :: (ReadVector x e m, WriteMatrix a e m) => (Int, Int) -> [x p e] -> m (a (n, p) e)Source

Form a matrix from a list of row vectors.

newColsMatrix :: (ReadVector x e m, WriteMatrix a e m) => (Int, Int) -> [x n e] -> m (a (n, p) e)Source

Form a matrix from a list of column vectors.

newRowMatrix :: (ReadVector x e m, WriteMatrix a e m) => x p e -> m (a (one, p) e)Source

Create a new matrix from a row vector.

newColMatrix :: (ReadVector x e m, WriteMatrix a e m) => x n e -> m (a (n, one) e)Source

Create a new matrix from a column vector.

Special matrices

newZeroMatrix :: WriteMatrix a e m => (Int, Int) -> m (a (n, p) e)Source

Create a zero matrix of the specified shape.

setZeroMatrix :: WriteMatrix a e m => a (n, p) e -> m ()Source

Set every element in the matrix to zero.

newConstantMatrix :: WriteMatrix a e m => (Int, Int) -> e -> m (a (n, p) e)Source

Create a constant matrix of the specified shape.

setConstantMatrix :: WriteMatrix a e m => e -> a (n, p) e -> m ()Source

Set every element in the matrix to the given constant.

newIdentityMatrix :: WriteMatrix a e m => (Int, Int) -> m (a (n, p) e)Source

Create a new matrix of the given shape with ones along the diagonal, and zeros everywhere else.

setIdentityMatrix :: WriteMatrix a e m => a (n, p) e -> m ()Source

Set diagonal elements to one and all other elements to zero.

Copying matrices

newCopyMatrix :: (ReadMatrix a e m, WriteMatrix b e m) => a (n, p) e -> m (b (n, p) e)Source

Get a copy of a matrix.

newCopyMatrix' :: (ReadMatrix a e m, WriteMatrix b e m) => a (n, p) e -> m (b (n, p) e)Source

Get a copy of a matrix and make sure the returned matrix is not a view. Specififially, the returned matrix will have isHermMatrix equal to False.

copyMatrix :: (WriteMatrix b e m, ReadMatrix a e m) => b (n, p) e -> a (n, p) e -> m ()Source

copyMatrix dst src replaces the values in dst with those in source. The operands must be the same shape.

swapMatrix :: (WriteMatrix a e m, WriteMatrix b e m) => a (n, p) e -> b (n, p) e -> m ()Source

swapMatrix x y swaps the values stored in two matrices.

Swapping rows and columns

swapRows :: WriteMatrix a e m => a (n, p) e -> Int -> Int -> m ()Source

Swap the elements in two rows of a matrix.

swapCols :: WriteMatrix a e m => a (n, p) e -> Int -> Int -> m ()Source

Swap the elements in two columns of a matrix.

Matrix views

submatrixView :: BaseMatrix a e => a (n, p) e -> (Int, Int) -> (Int, Int) -> a (n', p') eSource

submatrixView a ij mn returns a view of the submatrix of a with element (0,0) being element ij in a, and having shape mn.

splitRowsAt :: BaseMatrix a e => Int -> a (n, p) e -> (a (n1, p) e, a (n2, p) e)Source

Divide the rows of a matrix into two blocks and return views into the blocks. The integer argument indicates how many rows should be in the first block.

splitColsAt :: BaseMatrix a e => Int -> a (n, p) e -> (a (n, p1) e, a (n, p2) e)Source

Divide the columns of a matrix into two blocks and return views into the blocks. The integer argument indicates how many columns should be in the first block.

Row and column views

rowViews :: BaseMatrix a e => a (n, p) e -> [VectorView a p e]Source

Get a list of vector views of the rows of the matrix.

colViews :: BaseMatrix a e => a (n, p) e -> [VectorView a n e]Source

Get a list of vector views of the columns of the matrix.

rowView :: BaseMatrix a e => a (n, p) e -> Int -> VectorView a p eSource

Get a vector view of the given row in a matrix.

colView :: BaseMatrix a e => a (n, p) e -> Int -> VectorView a n eSource

Get a vector view of the given column in a matrix.

diagView :: BaseMatrix a e => a (n, p) e -> Int -> VectorView a k eSource

Get a vector view of the given diagonal in a matrix.

Conversions between matrices and vectors

Getting diagonals

getDiag :: (ReadMatrix a e m, WriteVector y e m) => a (n, p) e -> Int -> m (y k e)Source

Get the given diagonal in a matrix. Negative indices correspond to sub-diagonals.

Overloaded interface for reading and writing matrix elements

Matrix operations

Unary

getConjMatrix :: (ReadMatrix a e m, WriteMatrix b e m) => a (n, p) e -> m (b (n, p) e)Source

Get a new matrix with elements with the conjugates of the elements of the given matrix.

getScaledMatrix :: (ReadMatrix a e m, WriteMatrix b e m) => e -> a (n, p) e -> m (b (n, p) e)Source

Get a new matrix by scaling the elements of another matrix by a given value.

getShiftedMatrix :: (ReadMatrix a e m, WriteMatrix b e m) => e -> a (n, p) e -> m (b (n, p) e)Source

Get a new matrix by shifting the elements of another matrix by a given value.

doConjMatrix :: WriteMatrix a e m => a (n, p) e -> m ()Source

Conjugate every element of a matrix.

scaleByMatrix :: WriteMatrix a e m => e -> a (n, p) e -> m ()Source

Scale every element of a matrix by the given value.

shiftByMatrix :: WriteMatrix a e m => e -> a (n, p) e -> m ()Source

Add a constant to every element in a matrix.

Binary

getAddMatrix :: (ReadMatrix a e m, ReadMatrix b e m, WriteMatrix c e m) => a (n, p) e -> b (n, p) e -> m (c (n, p) e)Source

getAddMatrix a b creates a new matrix equal to the sum a+b. The operands must have the same shape.

getSubMatrix :: (ReadMatrix a e m, ReadMatrix b e m, WriteMatrix c e m) => a (n, p) e -> b (n, p) e -> m (c (n, p) e)Source

getSubMatrix a b creates a new matrix equal to the difference a-b. The operands must have the same shape.

getMulMatrix :: (ReadMatrix a e m, ReadMatrix b e m, WriteMatrix c e m) => a (n, p) e -> b (n, p) e -> m (c (n, p) e)Source

getMulMatrix a b creates a new matrix equal to the elementwise product a*b. The operands must have the same shape.

getDivMatrix :: (ReadMatrix a e m, ReadMatrix b e m, WriteMatrix c e m) => a (n, p) e -> b (n, p) e -> m (c (n, p) e)Source

getDivMatrix a b creates a new matrix equal to the elementwise ratio a/b. The operands must have the same shape.

addMatrix :: (WriteMatrix b e m, ReadMatrix a e m) => b (n, p) e -> a (n, p) e -> m ()Source

Replace the first argument with the elementwise sum.

subMatrix :: (WriteMatrix b e m, ReadMatrix a e m) => b (n, p) e -> a (n, p) e -> m ()Source

Replace the first argument with the elementwise sum.

axpyMatrix :: (ReadMatrix a e m, WriteMatrix b e m) => e -> a (n, p) e -> b (n, p) e -> m ()Source

axpyMatrix a x y replaces y := a x + y.

mulMatrix :: (WriteMatrix b e m, ReadMatrix a e m) => b (n, p) e -> a (n, p) e -> m ()Source

Replace the first argument with the elementwise product.

divMatrix :: (WriteMatrix b e m, ReadMatrix a e m) => b (n, p) e -> a (n, p) e -> m ()Source

Replace the first argument with the elementwise quotient.

Conversions between mutable and immutable matrices

Conversions from IOMatrixs