module Data.Matrix.Banded.Base
where
import Control.Monad
import Control.Monad.ST
import Data.AEq
import Data.Ix
import System.IO.Unsafe
import Unsafe.Coerce
import BLAS.Internal( clearArray, checkedRow, checkedCol, checkedDiag,
diagLen, inlinePerformIO )
import Data.Elem.BLAS( Elem, BLAS1, BLAS2, BLAS3 )
import Data.Tensor.Class
import Data.Tensor.Class.ITensor
import Data.Tensor.Class.MTensor
import Data.Matrix.Class
import Data.Matrix.Class.IMatrixBase
import Data.Matrix.Class.MMatrixBase
import Data.Matrix.Class.ISolveBase
import Data.Matrix.Class.MSolveBase
import Data.Matrix.Herm
import Data.Matrix.Tri
import Data.Vector.Dense.ST( runSTVector )
import Data.Vector.Dense.Base( BaseVector, ReadVector, WriteVector, Vector(..),
dim, unsafeVectorToIOVector, unsafePerformIOWithVector,
unsafeConvertIOVector, newZeroVector, newCopyVector )
import Data.Matrix.Dense.ST( runSTMatrix )
import Data.Matrix.Dense.Base( BaseMatrix, ReadMatrix, WriteMatrix, Matrix(..),
unsafeMatrixToIOMatrix, unsafePerformIOWithMatrix )
import Data.Matrix.Banded.IOBase( IOBanded )
import qualified Data.Matrix.Banded.IOBase as IO
newtype Banded np e = Banded (IOBanded np e)
freezeIOBanded :: (BLAS1 e) => IOBanded np e -> IO (Banded np e)
freezeIOBanded x = do
y <- IO.newCopyIOBanded x
return (Banded y)
thawIOBanded :: (BLAS1 e) => Banded np e -> IO (IOBanded np e)
thawIOBanded (Banded x) =
IO.newCopyIOBanded x
unsafeFreezeIOBanded :: IOBanded np e -> IO (Banded np e)
unsafeFreezeIOBanded = return . Banded
unsafeThawIOBanded :: Banded np e -> IO (IOBanded np e)
unsafeThawIOBanded (Banded x) = return x
class ( MatrixShaped a, HasVectorView a, HasMatrixStorage a, Elem e
, BaseVector (VectorView a) e, BaseMatrix (MatrixStorage a) e
) => BaseBanded a e where
numLower :: a (n,p) e -> Int
numUpper :: a (n,p) e -> Int
bandwidths :: a (n,p) e -> (Int,Int)
ldaBanded :: a (n,p) e -> Int
transEnumBanded :: a (n,p) e -> TransEnum
isHermBanded :: a (n,p) e -> Bool
isHermBanded = (ConjTrans ==) . transEnumBanded
coerceBanded :: a np e -> a np' e
coerceBanded = unsafeCoerce
maybeMatrixStorageFromBanded :: a (n,p) e -> Maybe (MatrixStorage a (k,p) e)
maybeBandedFromMatrixStorage :: (Int,Int)
-> (Int,Int)
-> MatrixStorage a (k,p) e
-> Maybe (a (n,p) e)
viewVectorAsBanded :: (Int,Int) -> VectorView a k e -> a (n,p) e
viewVectorAsDiagBanded :: VectorView a n e -> a (n,n) e
viewVectorAsDiagBanded x = let
n = dim x
in viewVectorAsBanded (n,n) x
maybeViewBandedAsVector :: a (n,p) e -> Maybe (VectorView a k e)
unsafeDiagViewBanded :: a (n,p) e -> Int -> VectorView a k e
unsafeRowViewBanded :: a (n,p) e -> Int -> (Int, VectorView a k e, Int)
unsafeColViewBanded :: a (n,p) e -> Int -> (Int, VectorView a k e, Int)
unsafeBandedToIOBanded :: a (n,p) e -> IOBanded (n,p) e
unsafeIOBandedToBanded :: IOBanded (n,p) e -> a (n,p) e
class ( BaseBanded a e, BLAS2 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 (MatrixStorage a) e m
) => ReadBanded a e m where
unsafePerformIOWithBanded :: a (n,p) e -> (IOBanded (n,p) e -> IO r) -> m r
freezeBanded :: a (n,p) e -> m (Banded (n,p) e)
unsafeFreezeBanded :: a (n,p) e -> m (Banded (n,p) e)
class ( ReadBanded a e m, WriteTensor a (Int,Int) e m
, WriteVector (VectorView a) e m
, WriteMatrix (MatrixStorage a) e m
) => WriteBanded a e m where
newBanded_ :: (Int,Int) -> (Int,Int) -> m (a (n,p) e)
unsafeConvertIOBanded :: IO (IOBanded (n,p) e) -> m (a (n,p) e)
thawBanded :: Banded (n,p) e -> m (a (n,p) e)
unsafeThawBanded :: Banded (n,p) e -> m (a (n,p) e)
newBanded :: (WriteBanded a e m) =>
(Int,Int) -> (Int,Int) -> [((Int,Int), e)] -> m (a (n,p) e)
newBanded = newBandedHelp writeElem
unsafeNewBanded :: (WriteBanded a e m) =>
(Int,Int) -> (Int,Int) -> [((Int,Int), e)] -> m (a (n,p) e)
unsafeNewBanded = newBandedHelp unsafeWriteElem
newBandedHelp :: (WriteBanded a e m) =>
(IOBanded (n,p) e -> (Int,Int) -> e -> IO ())
-> (Int,Int) -> (Int,Int) -> [((Int,Int),e)] -> m (a (n,p) e)
newBandedHelp set (m,n) (kl,ku) ijes =
unsafeConvertIOBanded $ do
x <- newBanded_ (m,n) (kl,ku)
IO.withIOBanded x $ flip clearArray ((kl+1+ku)*n)
mapM_ (uncurry $ set x) ijes
return x
newListsBanded :: (WriteBanded a e m) =>
(Int,Int) -> (Int,Int) -> [[e]] -> m (a (n,p) e)
newListsBanded (m,n) (kl,ku) xs = do
a <- newBanded_ (m,n) (kl,ku)
zipWithM_ (writeDiagElems a) [(negate kl)..ku] xs
return a
where
writeDiagElems :: (WriteBanded a e m) => a (n,p) e -> Int -> [e] -> m ()
writeDiagElems a i es =
let d = unsafeDiagViewBanded a i
nb = max 0 (negate i)
es' = drop nb es
in zipWithM_ (unsafeWriteElem d) [0..(dim d 1)] es'
newZeroBanded :: (WriteBanded a e m) => (Int,Int) -> (Int,Int) -> m (a (n,p) e)
newZeroBanded mn bw = unsafeConvertIOBanded $
IO.newZeroIOBanded mn bw
newConstantBanded :: (WriteBanded a e m)
=> (Int,Int) -> (Int,Int) -> e -> m (a (n,p) e)
newConstantBanded mn bw e = unsafeConvertIOBanded $
IO.newConstantIOBanded mn bw e
setZeroBanded :: (WriteBanded a e m) => a (n,p) e -> m ()
setZeroBanded a =
unsafePerformIOWithBanded a $ IO.setZeroIOBanded
setConstantBanded :: (WriteBanded a e m) => e -> a (n,p) e -> m ()
setConstantBanded e a =
unsafePerformIOWithBanded a $ IO.setConstantIOBanded e
newCopyBanded :: (ReadBanded a e m, WriteBanded b e m)
=> a (n,p) e -> m (b (n,p) e)
newCopyBanded a = unsafeConvertIOBanded $
IO.newCopyIOBanded (unsafeBandedToIOBanded a)
copyBanded :: (WriteBanded b e m, ReadBanded a e m) =>
b (n,p) e -> a (n,p) e -> m ()
copyBanded dst src
| shape dst /= shape src =
error "Shape mismatch in copyBanded."
| bandwidths dst /= bandwidths src =
error "Bandwidth mismatch in copyBanded."
| otherwise =
unsafeCopyBanded dst src
unsafeCopyBanded :: (WriteBanded b e m, ReadBanded a e m)
=> b (n,p) e -> a (n,p) e -> m ()
unsafeCopyBanded dst src =
unsafePerformIOWithBanded dst $ \dst' ->
IO.unsafeCopyIOBanded dst' (unsafeBandedToIOBanded src)
diagViewBanded :: (BaseBanded a e)
=> a (n,p) e -> Int -> VectorView a k e
diagViewBanded a i
| i < (numLower a) || i > numUpper a =
error $ "Tried to get a diagonal view outside of the bandwidth."
| otherwise =
unsafeDiagViewBanded a i
rowViewBanded :: (BaseBanded a e) =>
a (n,p) e -> Int -> (Int, VectorView a k e, Int)
rowViewBanded a = checkedRow (shape a) (unsafeRowViewBanded a)
colViewBanded :: (BaseBanded a e) =>
a (n,p) e -> Int -> (Int, VectorView a k e, Int)
colViewBanded a = checkedCol (shape a) (unsafeColViewBanded a)
getDiagBanded :: (ReadBanded a e m, WriteVector y e m) =>
a (n,p) e -> Int -> m (y k e)
getDiagBanded a i | i >= kl && i <= ku =
newCopyVector $ diagViewBanded a i
| otherwise =
newZeroVector $ diagLen (m,n) i
where
(m,n) = shape a
(kl,ku) = bandwidths a
unsafeGetDiagBanded :: (ReadBanded a e m, WriteVector y e m) =>
a (n,p) e -> Int -> m (y k e)
unsafeGetDiagBanded a i =
newCopyVector $ unsafeDiagViewBanded a i
unsafeGetRowBanded :: (ReadBanded a e m, WriteVector y e m) =>
a (n,p) e -> Int -> m (y p e)
unsafeGetRowBanded a i = unsafeConvertIOVector $
IO.unsafeGetRowIOBanded (unsafeBandedToIOBanded a) i
unsafeGetColBanded :: (ReadBanded a e m, WriteVector y e m) =>
a (n,p) e -> Int -> m (y n e)
unsafeGetColBanded a i = unsafeConvertIOVector $
IO.unsafeGetColIOBanded (unsafeBandedToIOBanded a) i
gbmv :: (ReadBanded a e m, ReadVector x e m, WriteVector y e m) =>
e -> a (k,l) e -> x l e -> e -> y k e -> m ()
gbmv alpha a x beta y =
unsafePerformIOWithVector y $
IO.gbmv alpha (unsafeBandedToIOBanded a) (unsafeVectorToIOVector x) beta
gbmm :: (ReadBanded a e m, ReadMatrix b e m, WriteMatrix c e m) =>
e -> a (r,s) e -> b (s,t) e -> e -> c (r,t) e -> m ()
gbmm alpha a b beta c =
unsafePerformIOWithMatrix c $
IO.gbmm alpha (unsafeBandedToIOBanded a) (unsafeMatrixToIOMatrix b) beta
hbmv :: (ReadBanded a e m, ReadVector x e m, WriteVector y e m) =>
e -> Herm a (k,l) e -> x l e -> e -> y k e -> m ()
hbmv alpha a x beta y =
unsafePerformIOWithVector y $
IO.hbmv alpha (mapHerm unsafeBandedToIOBanded a) (unsafeVectorToIOVector x) beta
hbmm :: (ReadBanded a e m, ReadMatrix b e m, WriteMatrix c e m) =>
e -> Herm a (r,s) e -> b (s,t) e -> e -> c (r,t) e -> m ()
hbmm alpha a b beta c =
unsafePerformIOWithMatrix c $
IO.hbmm alpha (mapHerm unsafeBandedToIOBanded a) (unsafeMatrixToIOMatrix b) beta
tbmv :: (ReadBanded a e m, WriteVector y e m) =>
e -> Tri a (k,k) e -> y k e -> m ()
tbmv alpha a x =
unsafePerformIOWithVector x $
IO.tbmv alpha (mapTri unsafeBandedToIOBanded a)
tbmm :: (ReadBanded a e m, WriteMatrix b e m) =>
e -> Tri a (k,k) e -> b (k,l) e -> m ()
tbmm alpha a b =
unsafePerformIOWithMatrix b $
IO.tbmm alpha (mapTri unsafeBandedToIOBanded a)
tbmv' :: (ReadBanded a e m, ReadVector x e m, WriteVector y e m) =>
e -> Tri a (k,l) e -> x l e -> e -> y k e -> m ()
tbmv' alpha a x beta y =
unsafePerformIOWithVector y $
IO.tbmv' alpha (mapTri unsafeBandedToIOBanded a) (unsafeVectorToIOVector x) beta
tbmm' :: (ReadBanded a e m, ReadMatrix b e m, WriteMatrix c e m) =>
e -> Tri a (r,s) e -> b (s,t) e -> e -> c (r,t) e -> m ()
tbmm' alpha a b beta c =
unsafePerformIOWithMatrix c $
IO.tbmm' alpha (mapTri unsafeBandedToIOBanded a) (unsafeMatrixToIOMatrix b) beta
tbsv :: (ReadBanded a e m, WriteVector y e m) =>
e -> Tri a (k,k) e -> y k e -> m ()
tbsv alpha a x =
unsafePerformIOWithVector x $
IO.tbmv alpha (mapTri unsafeBandedToIOBanded a)
tbsm :: (ReadBanded a e m, WriteMatrix b e m) =>
e -> Tri a (k,k) e -> b (k,l) e -> m ()
tbsm alpha a b =
unsafePerformIOWithMatrix b $
IO.tbsm alpha (mapTri unsafeBandedToIOBanded a)
tbsv' :: (ReadBanded a e m, ReadVector y e m, WriteVector x e m)
=> e -> Tri a (k,l) e -> y k e -> x l e -> m ()
tbsv' alpha a y x =
unsafePerformIOWithVector x $
IO.tbsv' alpha (mapTri unsafeBandedToIOBanded a) (unsafeVectorToIOVector y)
tbsm' :: (ReadBanded a e m, ReadMatrix c e m, WriteMatrix b e m)
=> e -> Tri a (r,s) e -> c (r,t) e -> b (s,t) e -> m ()
tbsm' alpha a c b =
unsafePerformIOWithMatrix b $
IO.tbsm' alpha (mapTri unsafeBandedToIOBanded a) (unsafeMatrixToIOMatrix c)
instance (Elem e) => BaseBanded IOBanded e where
numLower = IO.numLowerIOBanded
numUpper = IO.numUpperIOBanded
bandwidths = IO.bandwidthsIOBanded
ldaBanded = IO.ldaIOBanded
transEnumBanded = IO.transEnumIOBanded
maybeMatrixStorageFromBanded = IO.maybeMatrixStorageFromIOBanded
maybeBandedFromMatrixStorage = IO.maybeIOBandedFromMatrixStorage
viewVectorAsBanded = IO.viewVectorAsIOBanded
maybeViewBandedAsVector = IO.maybeViewIOBandedAsVector
unsafeDiagViewBanded = IO.unsafeDiagViewIOBanded
unsafeRowViewBanded = IO.unsafeRowViewIOBanded
unsafeColViewBanded = IO.unsafeColViewIOBanded
unsafeIOBandedToBanded = id
unsafeBandedToIOBanded = id
instance (BLAS3 e) => ReadBanded IOBanded e IO where
unsafePerformIOWithBanded a f = f a
freezeBanded = freezeIOBanded
unsafeFreezeBanded = unsafeFreezeIOBanded
instance (BLAS3 e) => WriteBanded IOBanded e IO where
newBanded_ = IO.newIOBanded_
unsafeConvertIOBanded = id
thawBanded = thawIOBanded
unsafeThawBanded = unsafeThawIOBanded
banded :: (BLAS3 e) => (Int,Int) -> (Int,Int) -> [((Int,Int), e)] -> Banded (n,p) e
banded mn kl ies = unsafePerformIO $
unsafeFreezeIOBanded =<< newBanded mn kl ies
unsafeBanded :: (BLAS3 e) => (Int,Int) -> (Int,Int) -> [((Int,Int), e)] -> Banded (n,p) e
unsafeBanded mn kl ies = unsafePerformIO $
unsafeFreezeIOBanded =<< unsafeNewBanded mn kl ies
listsBanded :: (BLAS3 e) => (Int,Int) -> (Int,Int) -> [[e]] -> Banded (n,p) e
listsBanded mn kl xs = unsafePerformIO $
unsafeFreezeIOBanded =<< newListsBanded mn kl xs
zeroBanded :: (BLAS3 e) => (Int,Int) -> (Int,Int) -> Banded (n,p) e
zeroBanded mn kl = unsafePerformIO $
unsafeFreezeIOBanded =<< newZeroBanded mn kl
constantBanded :: (BLAS3 e) => (Int,Int) -> (Int,Int) -> e -> Banded (n,p) e
constantBanded mn kl e = unsafePerformIO $
unsafeFreezeIOBanded =<< newConstantBanded mn kl e
bandedFromVector :: (Elem e) => (Int,Int) -> Vector k e -> Banded (n,p) e
bandedFromVector = viewVectorAsBanded
diagBandedFromVector :: (Elem e) => Vector n e -> Banded (n,n) e
diagBandedFromVector = viewVectorAsDiagBanded
maybeVectorFromBanded :: (Elem e) => Banded (n,p) e -> Maybe (Vector k e)
maybeVectorFromBanded = maybeViewBandedAsVector
diagBanded :: (BLAS1 e) => Banded (n,p) e -> Int -> Vector k e
diagBanded a = checkedDiag (shape a) (unsafeDiagBanded a)
unsafeDiagBanded :: (BLAS1 e) => Banded (n,p) e -> Int -> Vector k e
unsafeDiagBanded a i | i >= kl && i <= ku = unsafeDiagViewBanded a i
| otherwise = runSTVector $
newZeroVector $ diagLen (shape a) i
where
(kl,ku) = bandwidths a
listsFromBanded :: (BLAS1 e) => Banded np e -> ((Int,Int), (Int,Int),[[e]])
listsFromBanded a = ( (m,n)
, (kl,ku)
, map paddedDiag [(kl)..ku]
)
where
(m,n) = shape a
(kl,ku) = bandwidths (coerceBanded a)
padBegin i = replicate (max (i) 0) 0
padEnd i = replicate (max (mn+i) 0) 0
paddedDiag i = ( padBegin i
++ elems (unsafeDiagViewBanded (coerceBanded a) i)
++ padEnd i
)
instance (BLAS3 e) => Show (Banded (n,p) e) where
show a
| isHermBanded a =
"herm (" ++ show (herm a) ++ ")"
| otherwise =
let (mn,kl,es) = listsFromBanded a
in "listsBanded " ++ show mn ++ " " ++ show kl ++ " " ++ show es
compareBandedHelp :: (BLAS3 e) =>
(e -> e -> Bool) -> Banded (n,p) e -> Banded (n,p) e -> Bool
compareBandedHelp cmp a b
| shape a /= shape b =
False
| isHermBanded a == isHermBanded b && bandwidths a == bandwidths b =
let elems' = if isHermBanded a then elems . herm
else elems
in
and $ zipWith cmp (elems' a) (elems' b)
| otherwise =
let l = max (numLower a) (numLower b)
u = max (numUpper a) (numUpper b)
in
and $ zipWith cmp (diagElems (l,u) a) (diagElems (l,u) b)
where
diagElems bw c = concatMap elems [ diagBanded c i | i <- range bw ]
instance (BLAS3 e, Eq e) => Eq (Banded (n,p) e) where
(==) = compareBandedHelp (==)
instance (BLAS3 e, AEq e) => AEq (Banded (n,p) e) where
(===) = compareBandedHelp (===)
(~==) = compareBandedHelp (~==)
replaceBandedHelp :: (BLAS3 e) =>
(forall n. IOBanded n e -> (Int,Int) -> e -> IO ())
-> Banded mn e -> [((Int,Int), e)] -> Banded mn e
replaceBandedHelp set x ies = unsafePerformIO $ do
y <- newCopyBanded =<< unsafeThawIOBanded (coerceBanded x)
mapM_ (uncurry $ set y) ies
unsafeFreezeIOBanded (coerceBanded y)
instance (BLAS3 e) => ITensor Banded (Int,Int) e where
(//) = replaceBandedHelp writeElem
unsafeReplace = replaceBandedHelp unsafeWriteElem
unsafeAt (Banded a) i = inlinePerformIO (unsafeReadElem a i)
size (Banded a) = IO.sizeIOBanded a
elems (Banded a) = inlinePerformIO $ getElems a
indices (Banded a) = IO.indicesIOBanded a
assocs (Banded a) = inlinePerformIO $ getAssocs a
tmap f a = coerceBanded $ listsBanded mn bw (map (map f) es)
where (mn,bw,es) = listsFromBanded a
instance (BLAS3 e, Monad m) => ReadTensor Banded (Int,Int) e m where
getSize = return . size
getAssocs = return . assocs
getIndices = return . indices
getElems = return . elems
getAssocs' = return . assocs
getIndices' = return . indices
getElems' = return . elems
unsafeReadElem x i = return (unsafeAt x i)
instance HasVectorView Banded where
type VectorView Banded = Vector
instance HasMatrixStorage Banded where
type MatrixStorage Banded = Matrix
instance Shaped Banded (Int,Int) where
shape (Banded a) = IO.shapeIOBanded a
bounds (Banded a) = IO.boundsIOBanded a
instance MatrixShaped Banded where
herm (Banded a) = Banded $ IO.hermIOBanded a
instance (Elem e) => BaseBanded Banded e where
numLower (Banded a) = IO.numLowerIOBanded a
numUpper (Banded a) = IO.numUpperIOBanded a
bandwidths (Banded a) = IO.bandwidthsIOBanded a
ldaBanded (Banded a) = IO.ldaIOBanded a
transEnumBanded (Banded a) = IO.transEnumIOBanded a
maybeMatrixStorageFromBanded (Banded a) = liftM Matrix $ IO.maybeMatrixStorageFromIOBanded a
maybeBandedFromMatrixStorage mn kl (Matrix a) =
liftM Banded $ IO.maybeIOBandedFromMatrixStorage mn kl a
viewVectorAsBanded mn (Vector x) = Banded $ IO.viewVectorAsIOBanded mn x
maybeViewBandedAsVector (Banded a) =
liftM Vector $ IO.maybeViewIOBandedAsVector a
unsafeDiagViewBanded (Banded a) i = Vector $ IO.unsafeDiagViewIOBanded a i
unsafeRowViewBanded (Banded a) i =
case IO.unsafeRowViewIOBanded a i of (nb,x,na) -> (nb, Vector x, na)
unsafeColViewBanded (Banded a) j =
case IO.unsafeColViewIOBanded a j of (nb,x,na) -> (nb, Vector x, na)
unsafeIOBandedToBanded = Banded
unsafeBandedToIOBanded (Banded a) = a
instance (BLAS3 e) => ReadBanded Banded e IO where
unsafePerformIOWithBanded (Banded a) f = f a
freezeBanded (Banded a) = freezeIOBanded a
unsafeFreezeBanded (Banded a) = unsafeFreezeIOBanded a
instance (BLAS3 e) => MMatrix Banded e IO where
unsafeDoSApplyAdd = gbmv
unsafeDoSApplyAddMat = gbmm
unsafeGetRow = unsafeGetRowBanded
unsafeGetCol = unsafeGetColBanded
getRows = getRowsIO
getCols = getColsIO
instance (BLAS3 e) => MMatrix (Herm Banded) e IO where
unsafeDoSApplyAdd = hbmv
unsafeDoSApplyAddMat = hbmm
getRows = getRowsIO
getCols = getColsIO
instance (BLAS3 e) => MMatrix (Tri Banded) e IO where
unsafeDoSApply_ = tbmv
unsafeDoSApplyMat_ = tbmm
unsafeDoSApplyAdd = tbmv'
unsafeDoSApplyAddMat = tbmm'
getRows = getRowsIO
getCols = getColsIO
instance (BLAS3 e) => MSolve (Tri Banded) e IO where
unsafeDoSSolve_ = tbsv
unsafeDoSSolveMat_ = tbsm
unsafeDoSSolve = tbsv'
unsafeDoSSolveMat = tbsm'
instance (BLAS3 e) => ReadBanded Banded e (ST s) where
unsafePerformIOWithBanded (Banded a) f = unsafeIOToST $ f a
freezeBanded (Banded a) = unsafeIOToST $ freezeIOBanded a
unsafeFreezeBanded (Banded a) = unsafeIOToST $ unsafeFreezeIOBanded a
instance (BLAS3 e) => MMatrix Banded e (ST s) where
unsafeDoSApplyAdd = gbmv
unsafeDoSApplyAddMat = gbmm
unsafeGetRow = unsafeGetRowBanded
unsafeGetCol = unsafeGetColBanded
getRows = getRowsST
getCols = getColsST
instance (BLAS3 e) => MMatrix (Herm Banded) e (ST s) where
unsafeDoSApplyAdd = hbmv
unsafeDoSApplyAddMat = hbmm
getRows = getRowsST
getCols = getColsST
instance (BLAS3 e) => MMatrix (Tri Banded) e (ST s) where
unsafeDoSApply_ = tbmv
unsafeDoSApplyMat_ = tbmm
unsafeDoSApplyAdd = tbmv'
unsafeDoSApplyAddMat = tbmm'
getRows = getRowsST
getCols = getColsST
instance (BLAS3 e) => MSolve (Tri Banded) e (ST s) where
unsafeDoSSolve_ = tbsv
unsafeDoSSolveMat_ = tbsm
unsafeDoSSolve = tbsv'
unsafeDoSSolveMat = tbsm'
instance (BLAS3 e) => IMatrix Banded e where
unsafeSApply alpha a x = runSTVector $ unsafeGetSApply alpha a x
unsafeSApplyMat alpha a b = runSTMatrix $ unsafeGetSApplyMat alpha a b
unsafeRow a i = runSTVector $ unsafeGetRow a i
unsafeCol a j = runSTVector $ unsafeGetCol a j
instance (BLAS3 e) => IMatrix (Herm Banded) e where
unsafeSApply alpha a x = runSTVector $ unsafeGetSApply alpha a x
unsafeSApplyMat alpha a b = runSTMatrix $ unsafeGetSApplyMat alpha a b
instance (BLAS3 e) => IMatrix (Tri Banded) e where
unsafeSApply alpha a x = runSTVector $ unsafeGetSApply alpha a x
unsafeSApplyMat alpha a b = runSTMatrix $ unsafeGetSApplyMat alpha a b
instance (BLAS3 e) => ISolve (Tri Banded) e where
unsafeSSolve alpha a y = runSTVector $ unsafeGetSSolve alpha a y
unsafeSSolveMat alpha a c = runSTMatrix $ unsafeGetSSolveMat alpha a c