module Data.Matrix.Dense (
Matrix,
module BLAS.Matrix.Base,
module BLAS.Matrix.Immutable,
module BLAS.Tensor.Base,
module BLAS.Tensor.Dense.Immutable,
module BLAS.Tensor.Immutable,
module BLAS.Tensor.Scalable,
matrix,
listMatrix,
fromCols,
fromRows,
identity,
row,
col,
rows,
cols,
diag,
submatrix,
apply,
applyMat,
sapply,
sapplyMat,
shift,
scale,
invScale,
coerceMatrix,
fromRow,
fromCol,
unsafeMatrix,
unsafeRow,
unsafeCol,
unsafeDiag,
unsafeSubmatrix,
) where
import Data.Maybe ( fromJust )
import System.IO.Unsafe ( unsafePerformIO )
import BLAS.Access
import BLAS.Elem ( BLAS1, BLAS2 )
import BLAS.Matrix.Base hiding ( Matrix )
import BLAS.Matrix.Immutable
import BLAS.Tensor.Base
import BLAS.Tensor.Dense.Immutable
import BLAS.Tensor.Immutable
import BLAS.Tensor.Scalable
import Data.Matrix.Dense.Internal
import qualified Data.Matrix.Dense.Internal as M
import Data.Matrix.Dense.Operations ( apply, applyMat, sapply, sapplyMat,
shift, scale, invScale, plus, minus, times, divide )
import Data.Vector.Dense hiding ( scale, invScale, shift )
matrix :: (BLAS1 e) => (Int,Int) -> [((Int,Int), e)] -> Matrix (m,n) e
matrix mn ies = unsafePerformIO $ newMatrix mn ies
unsafeMatrix :: (BLAS1 e) => (Int,Int) -> [((Int,Int), e)] -> Matrix (m,n) e
unsafeMatrix mn ies = unsafePerformIO $ unsafeNewMatrix mn ies
fromCols :: (BLAS1 e) => (Int,Int) -> [Vector m e] -> Matrix (m,n) e
fromCols mn cs = unsafePerformIO $ newColsMatrix mn cs
fromRows :: (BLAS1 e) => (Int,Int) -> [Vector n e] -> Matrix (m,n) e
fromRows mn rs = unsafePerformIO $ newRowsMatrix mn rs
identity :: (BLAS1 e) => (Int,Int) -> Matrix (m,n) e
identity mn = unsafePerformIO $ newIdentity mn
fromRow :: (BLAS1 e) => Vector n e -> Matrix (one,n) e
fromRow x =
case maybeFromRow x of
Just x' -> x'
Nothing -> fromJust $ maybeFromRow $ unsafePerformIO $ newCopy x
fromCol :: (BLAS1 e) => Vector m e -> Matrix (m,one) e
fromCol x =
case maybeFromCol x of
Just x' -> x'
Nothing -> fromJust $ maybeFromCol $ unsafePerformIO $ newCopy x
instance (BLAS1 e) => Scalable (DMatrix Imm (m,n)) e where
(*>) = scale
instance (BLAS2 e) => Num (DMatrix Imm (m,n) e) where
(+) = plus
() = minus
(*) = times
negate = scale (1)
abs = amap abs
signum = amap signum
fromInteger n = constant (1,1) (fromInteger n)
instance (BLAS2 e) => Fractional (DMatrix Imm (m,n) e) where
(/) a b = divide a b
recip = amap recip
fromRational q = constant (1,1) (fromRational q)
instance (BLAS2 e, Floating e) => Floating (DMatrix Imm (m,n) e) where
pi = constant (1,1) pi
exp = amap exp
sqrt = amap sqrt
log = amap log
(**) = azipWith (**)
sin = amap sin
cos = amap cos
tan = amap tan
asin = amap asin
acos = amap acos
atan = amap atan
sinh = amap sinh
cosh = amap cosh
tanh = amap tanh
asinh = amap asinh
acosh = amap acosh
atanh = amap atanh