module Data.Matrix.Dense.Class.Special (
newZeroMatrix,
setZeroMatrix,
newConstantMatrix,
setConstantMatrix,
newIdentityMatrix,
setIdentityMatrix,
) where
import BLAS.Elem( Elem )
import BLAS.Tensor( unsafeWriteElem )
import BLAS.Matrix.Base( numRows, numCols )
import Data.Matrix.Dense.Class.Internal
newIdentityMatrix :: (WriteMatrix a x m, Elem e) => (Int,Int) -> m (a mn e)
newIdentityMatrix mn = do
a <- newMatrix_ mn
setIdentityMatrix a
return a
setIdentityMatrix :: (WriteMatrix a x m, Elem e) => a mn e -> m ()
setIdentityMatrix a = do
setZeroMatrix a
mapM_ (\i -> unsafeWriteElem a (i,i) 1) [0..(mn1)]
where
mn = min (numRows a) (numCols a)