hblas- Human friendly BLAS and Lapack bindings for Haskell.

Safe HaskellNone



PSA, the matrix data types used in the hBLAS binding should not be regarded as being general purpose matrices.

They are designed to exactly express only the matrices which are valid inputs for BLAS. When applicable, such matrices should be easily mapped to and from other matrix libraries. That said, the BLAS and LAPACK matrix formats capture a rich and very expressive subset of Dense Matrix formats.

The primary and hence default format is Dense Row and Column Major Matrices, but support will be added for other formats that BLAS and LAPACK provide operations for.

A guiding rule of thumb for this package is that there are no generic abstractions provided, merely machinery to ensure all uses of BLAS and LAPACK operations can be used in their full generality in a human friendly type safe fashion. It is the role of a higher level library to provide any generic operations.

One such higher level lib you can interface with easily is Numerical. There is a work in progress binding to help this in the numerical-hblas package (which may not be public yet at the time of this writing)



type Row = RowSource

data MatUpLo Source

For Symmetric, Hermetian or Triangular matrices, which part is modeled.



data MatDiag Source

Many triangular matrix routines expect to know if the matrix is all 1 (unit ) on the diagonal or not. Likewise, Many Factorizations routines can be assumed to return unit triangular matrices



data EquationSide Source

For certain Square matrix product, do you want to Compute A*B or B*A only used as an argument



type family TransposeF x :: OrientationSource

data SVariant whereSource

Variant and SVariant are a bit odd looking, They crop up when needing to talk about eg the row vectors of a packed triangular row major matrix wrt both their logical size and manifest sizes this notion only makes sense in the 1dim case. If you don't understand this parameter, just use SDirect and Direct as they will generally be the correct choice for most users.


SImplicit :: !Int -> !Int -> SVariant Implicit 


_frontPadding :: !Int
_endPadding :: !Int
SDirect :: SVariant Direct 

data DenseVector whereSource


DenseVector :: !(SVariant varnt) -> !Int -> !Int -> !(Vector elem) -> DenseVector varnt elem 

data MDenseVector whereSource


MutableDenseVector :: !(SVariant varnt) -> !Int -> !Int -> !(MVector s elem) -> MDenseVector s varnt elem 

data DenseMatrix whereSource

DenseMatrix is for dense row or column major matrices


DenseMatrix :: SOrientation ornt -> !Int -> !Int -> !Int -> !(Vector elem) -> DenseMatrix ornt elem 


(Show el, Storable el) => Show (DenseMatrix Column el) 
(Show el, Storable el) => Show (DenseMatrix Row el) 

mutableVectorToList :: (PrimMonad m, Storable a) => MVector (PrimState m) a -> m [a]Source

this should never be used in real code, ever ever, but its handy for testing but seriously never use this in real code, it doesn't do what you think because in the case of a matrix slice, the underlying buffer will have additional elements aside from the ones you expect! never use this in real code please. :)

data MDenseMatrix whereSource


MutableDenseMatrix :: SOrientation ornt -> !Int -> !Int -> !Int -> !(MVector s elem) -> MDenseMatrix s ornt elem 

uncheckedDenseMatrixIndexM :: (Monad m, Storable elem) => DenseMatrix or elem -> (Int, Int) -> m elemSource

swap :: (a, b) -> (b, a)Source

mapDenseMatrix :: (Storable a, Storable b) => (a -> b) -> DenseMatrix or a -> DenseMatrix or bSource

`map f matrix`

imapDenseMatrix :: (Storable a, Storable b) => ((Int, Int) -> a -> b) -> DenseMatrix or a -> DenseMatrix or bSource

uncheckedDenseMatrixNextTuple :: DenseMatrix or elem -> (Int, Int) -> Maybe (Int, Int)Source

In Matrix format memory order enumeration of the index tuples, for good locality 2dim map

generateDenseMatrix :: Storable a => SOrientation x -> (Int, Int) -> ((Int, Int) -> a) -> DenseMatrix x aSource

generateDenseMatrix Row (k,k) (i,j)-> if i == j then 1.0 else 0.0 would generate a KxK identity matrix

generateMutableDenseMatrix :: (Storable a, PrimMonad m) => SOrientation x -> (Int, Int) -> ((Int, Int) -> a) -> m (MDenseMatrix (PrimState m) x a)Source

mutable version of generateDenseMatrix

uncheckedDenseMatrixSlice :: Storable elem => DenseMatrix or elem -> (Int, Int) -> (Int, Int) -> DenseMatrix or elemSource

transposeDenseMatrix :: (inor ~ TransposeF outor, outor ~ TransposeF inor) => DenseMatrix inor elem -> DenseMatrix outor elemSource

tranposeMatrix does a shallow transpose that swaps the format and the x y params, but changes nothing in the memory layout. Most applications where transpose is used in a computation need a deep, copying, tranpose operation