{-# LANGUAGE PartialTypeSignatures, ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-orphans -funbox-strict-fields #-}
module Algebra.Matrix.HMatrix (STMatrix) where
import Algebra.Matrix.Generic
import Algebra.Matrix.Generic.Mutable (MMatrix (..))
import Algebra.Prelude.Core
import Control.Monad (forM_)
import Control.Monad.Primitive
import qualified Data.Coerce as DC
import qualified Data.Vector.Storable as SV
import qualified Numeric.LinearAlgebra as LA
import qualified Numeric.LinearAlgebra.Devel as LA
type instance Mutable LA.Matrix = STMatrix
type instance Row LA.Matrix = LA.Vector
type instance Column LA.Matrix = LA.Vector
type instance Row STMatrix = LA.Vector
type instance Column STMatrix = LA.Vector
data STMatrix s a = STMat { STMatrix s a -> Int
stmRows :: !Int
, STMatrix s a -> Int
stmCols :: !Int
, STMatrix s a -> STMatrix s a
unwrapSTM :: LA.STMatrix s a
}
instance (Num a, LA.Container LA.Matrix a) => Matrix LA.Matrix (WrapNum a) where
basicRowCount :: Matrix (WrapNum a) -> Int
basicRowCount = Matrix (WrapNum a) -> Int
forall t. Matrix t -> Int
LA.rows
basicColumnCount :: Matrix (WrapNum a) -> Int
basicColumnCount = Matrix (WrapNum a) -> Int
forall t. Matrix t -> Int
LA.cols
unsafeFromRows :: [Row Matrix (WrapNum a)] -> Matrix (WrapNum a)
unsafeFromRows [Row Matrix (WrapNum a)]
rs = Matrix a -> Matrix (WrapNum a)
DC.coerce (Matrix a -> Matrix (WrapNum a)) -> Matrix a -> Matrix (WrapNum a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows ([Vector (WrapNum a)] -> [Vector a]
DC.coerce [Vector (WrapNum a)]
[Row Matrix (WrapNum a)]
rs :: [LA.Vector a])
unsafeFromColumns :: [Column Matrix (WrapNum a)] -> Matrix (WrapNum a)
unsafeFromColumns [Column Matrix (WrapNum a)]
cs = Matrix a -> Matrix (WrapNum a)
DC.coerce (Matrix a -> Matrix (WrapNum a)) -> Matrix a -> Matrix (WrapNum a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromColumns ([Vector (WrapNum a)] -> [Vector a]
DC.coerce [Vector (WrapNum a)]
[Column Matrix (WrapNum a)]
cs :: [LA.Vector a])
basicUnsafeIndexM :: Matrix (WrapNum a) -> Int -> Int -> m (WrapNum a)
basicUnsafeIndexM Matrix (WrapNum a)
m Int
i Int
j =
WrapNum a -> m (WrapNum a)
forall (m :: * -> *) a. Monad m => a -> m a
return (WrapNum a -> m (WrapNum a)) -> WrapNum a -> m (WrapNum a)
forall a b. (a -> b) -> a -> b
$ a -> WrapNum a
forall a. a -> WrapNum a
WrapNum (a -> WrapNum a) -> a -> WrapNum a
forall a b. (a -> b) -> a -> b
$ (Matrix (WrapNum a) -> Matrix a
DC.coerce Matrix (WrapNum a)
m :: LA.Matrix a) Matrix a -> IndexOf Matrix -> a
forall (c :: * -> *) e. Container c e => c e -> IndexOf c -> e
`LA.atIndex` (Int
i, Int
j)
unsafeFreeze :: Mutable Matrix (PrimState m) (WrapNum a) -> m (Matrix (WrapNum a))
unsafeFreeze = ST (PrimState m) (Matrix (WrapNum a)) -> m (Matrix (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Matrix (WrapNum a)) -> m (Matrix (WrapNum a)))
-> (STMatrix (PrimState m) (WrapNum a)
-> ST (PrimState m) (Matrix (WrapNum a)))
-> STMatrix (PrimState m) (WrapNum a)
-> m (Matrix (WrapNum a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapNum a)
-> ST (PrimState m) (Matrix (WrapNum a))
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapNum a)
-> ST (PrimState m) (Matrix (WrapNum a)))
-> (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> STMatrix (PrimState m) (WrapNum a)
-> ST (PrimState m) (Matrix (WrapNum a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. STMatrix s a -> STMatrix s a
unwrapSTM
unsafeThaw :: Matrix (WrapNum a) -> m (Mutable Matrix (PrimState m) (WrapNum a))
unsafeThaw Matrix (WrapNum a)
m = ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix (WrapNum a) -> Int
forall t. Matrix t -> Int
LA.rows Matrix (WrapNum a)
m) (Matrix (WrapNum a) -> Int
forall t. Matrix t -> Int
LA.cols Matrix (WrapNum a)
m) (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapNum a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix (WrapNum a)
m
basicUnsafeGetRowM :: Matrix (WrapNum a) -> Int -> m (Row Matrix (WrapNum a))
basicUnsafeGetRowM Matrix (WrapNum a)
m Int
i = Vector (WrapNum a) -> m (Vector (WrapNum a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector (WrapNum a) -> m (Vector (WrapNum a)))
-> Vector (WrapNum a) -> m (Vector (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapNum a)
DC.coerce (Vector a -> Vector (WrapNum a)) -> Vector a -> Vector (WrapNum a)
forall a b. (a -> b) -> a -> b
$ Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getRowLA Int
i (Matrix (WrapNum a) -> Matrix a
DC.coerce Matrix (WrapNum a)
m :: LA.Matrix a)
basicUnsafeGetColumnM :: Matrix (WrapNum a) -> Int -> m (Column Matrix (WrapNum a))
basicUnsafeGetColumnM Matrix (WrapNum a)
m Int
i =
Vector (WrapNum a) -> m (Vector (WrapNum a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector (WrapNum a) -> m (Vector (WrapNum a)))
-> Vector (WrapNum a) -> m (Vector (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapNum a)
DC.coerce (Vector a -> Vector (WrapNum a)) -> Vector a -> Vector (WrapNum a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Vector a
forall a. [a] -> a
head ([Vector a] -> Vector a) -> [Vector a] -> Vector a
forall a b. (a -> b) -> a -> b
$ Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toColumns (Matrix (WrapNum a) -> Matrix a
DC.coerce Matrix (WrapNum a)
m Matrix a -> [Int] -> Matrix a
forall t. Element t => Matrix t -> [Int] -> Matrix t
LA.¿ [Int
i] :: LA.Matrix a)
unsafeGenerate :: Int -> Int -> (Int -> Int -> WrapNum a) -> Matrix (WrapNum a)
unsafeGenerate Int
w Int
h Int -> Int -> WrapNum a
f =
Matrix a -> Matrix (WrapNum a)
DC.coerce (Matrix a -> Matrix (WrapNum a)) -> Matrix a -> Matrix (WrapNum a)
forall a b. (a -> b) -> a -> b
$
[Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows [ Int -> (Int -> a) -> Vector a
forall a. Storable a => Int -> (Int -> a) -> Vector a
SV.generate Int
w ((Int -> a) -> Vector a) -> (Int -> a) -> Vector a
forall a b. (a -> b) -> a -> b
$ \Int
j -> WrapNum a -> a
forall a. WrapNum a -> a
unwrapNum (WrapNum a -> a) -> WrapNum a -> a
forall a b. (a -> b) -> a -> b
$ Int -> Int -> WrapNum a
f Int
i Int
j
| Int
i <- [Int
0..Int
h Int -> Int -> Int
forall r. Group r => r -> r -> r
- Int
1]
]
instance (Integral a, LA.Container LA.Matrix a) => Matrix LA.Matrix (WrapIntegral a) where
basicRowCount :: Matrix (WrapIntegral a) -> Int
basicRowCount = Matrix (WrapIntegral a) -> Int
forall t. Matrix t -> Int
LA.rows
basicColumnCount :: Matrix (WrapIntegral a) -> Int
basicColumnCount = Matrix (WrapIntegral a) -> Int
forall t. Matrix t -> Int
LA.cols
unsafeFromRows :: [Row Matrix (WrapIntegral a)] -> Matrix (WrapIntegral a)
unsafeFromRows [Row Matrix (WrapIntegral a)]
rs = Matrix a -> Matrix (WrapIntegral a)
DC.coerce (Matrix a -> Matrix (WrapIntegral a))
-> Matrix a -> Matrix (WrapIntegral a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows ([Vector (WrapIntegral a)] -> [Vector a]
DC.coerce [Vector (WrapIntegral a)]
[Row Matrix (WrapIntegral a)]
rs :: [LA.Vector a])
unsafeFromColumns :: [Column Matrix (WrapIntegral a)] -> Matrix (WrapIntegral a)
unsafeFromColumns [Column Matrix (WrapIntegral a)]
cs = Matrix a -> Matrix (WrapIntegral a)
DC.coerce (Matrix a -> Matrix (WrapIntegral a))
-> Matrix a -> Matrix (WrapIntegral a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromColumns ([Vector (WrapIntegral a)] -> [Vector a]
DC.coerce [Vector (WrapIntegral a)]
[Column Matrix (WrapIntegral a)]
cs :: [LA.Vector a])
basicUnsafeIndexM :: Matrix (WrapIntegral a) -> Int -> Int -> m (WrapIntegral a)
basicUnsafeIndexM Matrix (WrapIntegral a)
m Int
i Int
j =
WrapIntegral a -> m (WrapIntegral a)
forall (m :: * -> *) a. Monad m => a -> m a
return (WrapIntegral a -> m (WrapIntegral a))
-> WrapIntegral a -> m (WrapIntegral a)
forall a b. (a -> b) -> a -> b
$ a -> WrapIntegral a
forall a. a -> WrapIntegral a
WrapIntegral (a -> WrapIntegral a) -> a -> WrapIntegral a
forall a b. (a -> b) -> a -> b
$ (Matrix (WrapIntegral a) -> Matrix a
DC.coerce Matrix (WrapIntegral a)
m :: LA.Matrix a) Matrix a -> IndexOf Matrix -> a
forall (c :: * -> *) e. Container c e => c e -> IndexOf c -> e
`LA.atIndex` (Int
i, Int
j)
unsafeFreeze :: Mutable Matrix (PrimState m) (WrapIntegral a)
-> m (Matrix (WrapIntegral a))
unsafeFreeze = ST (PrimState m) (Matrix (WrapIntegral a))
-> m (Matrix (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Matrix (WrapIntegral a))
-> m (Matrix (WrapIntegral a)))
-> (STMatrix (PrimState m) (WrapIntegral a)
-> ST (PrimState m) (Matrix (WrapIntegral a)))
-> STMatrix (PrimState m) (WrapIntegral a)
-> m (Matrix (WrapIntegral a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapIntegral a)
-> ST (PrimState m) (Matrix (WrapIntegral a))
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapIntegral a)
-> ST (PrimState m) (Matrix (WrapIntegral a)))
-> (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> STMatrix (PrimState m) (WrapIntegral a)
-> ST (PrimState m) (Matrix (WrapIntegral a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. STMatrix s a -> STMatrix s a
unwrapSTM
unsafeThaw :: Matrix (WrapIntegral a)
-> m (Mutable Matrix (PrimState m) (WrapIntegral a))
unsafeThaw Matrix (WrapIntegral a)
m = ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix (WrapIntegral a) -> Int
forall t. Matrix t -> Int
LA.rows Matrix (WrapIntegral a)
m) (Matrix (WrapIntegral a) -> Int
forall t. Matrix t -> Int
LA.cols Matrix (WrapIntegral a)
m) (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapIntegral a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix (WrapIntegral a)
m
basicUnsafeGetRowM :: Matrix (WrapIntegral a) -> Int -> m (Row Matrix (WrapIntegral a))
basicUnsafeGetRowM Matrix (WrapIntegral a)
m Int
i = Vector (WrapIntegral a) -> m (Vector (WrapIntegral a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector (WrapIntegral a) -> m (Vector (WrapIntegral a)))
-> Vector (WrapIntegral a) -> m (Vector (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapIntegral a)
DC.coerce (Vector a -> Vector (WrapIntegral a))
-> Vector a -> Vector (WrapIntegral a)
forall a b. (a -> b) -> a -> b
$ Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getRowLA Int
i (Matrix (WrapIntegral a) -> Matrix a
DC.coerce Matrix (WrapIntegral a)
m :: LA.Matrix a)
basicUnsafeGetColumnM :: Matrix (WrapIntegral a)
-> Int -> m (Column Matrix (WrapIntegral a))
basicUnsafeGetColumnM Matrix (WrapIntegral a)
m Int
i =
Vector (WrapIntegral a) -> m (Vector (WrapIntegral a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector (WrapIntegral a) -> m (Vector (WrapIntegral a)))
-> Vector (WrapIntegral a) -> m (Vector (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapIntegral a)
DC.coerce (Vector a -> Vector (WrapIntegral a))
-> Vector a -> Vector (WrapIntegral a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Vector a
forall a. [a] -> a
head ([Vector a] -> Vector a) -> [Vector a] -> Vector a
forall a b. (a -> b) -> a -> b
$ Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toColumns (Matrix (WrapIntegral a) -> Matrix a
DC.coerce Matrix (WrapIntegral a)
m Matrix a -> [Int] -> Matrix a
forall t. Element t => Matrix t -> [Int] -> Matrix t
LA.¿ [Int
i] :: LA.Matrix a)
unsafeGenerate :: Int
-> Int -> (Int -> Int -> WrapIntegral a) -> Matrix (WrapIntegral a)
unsafeGenerate Int
w Int
h Int -> Int -> WrapIntegral a
f =
Matrix a -> Matrix (WrapIntegral a)
DC.coerce (Matrix a -> Matrix (WrapIntegral a))
-> Matrix a -> Matrix (WrapIntegral a)
forall a b. (a -> b) -> a -> b
$
[Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows [ Int -> (Int -> a) -> Vector a
forall a. Storable a => Int -> (Int -> a) -> Vector a
SV.generate Int
w ((Int -> a) -> Vector a) -> (Int -> a) -> Vector a
forall a b. (a -> b) -> a -> b
$ \Int
j -> WrapIntegral a -> a
forall a. WrapIntegral a -> a
unwrapIntegral (WrapIntegral a -> a) -> WrapIntegral a -> a
forall a b. (a -> b) -> a -> b
$ Int -> Int -> WrapIntegral a
f Int
i Int
j
| Int
i <- [Int
0..Int
h Int -> Int -> Int
forall r. Group r => r -> r -> r
- Int
1]
]
instance (Fractional a, LA.Container LA.Matrix a) => Matrix LA.Matrix (WrapFractional a) where
basicRowCount :: Matrix (WrapFractional a) -> Int
basicRowCount = Matrix (WrapFractional a) -> Int
forall t. Matrix t -> Int
LA.rows
basicColumnCount :: Matrix (WrapFractional a) -> Int
basicColumnCount = Matrix (WrapFractional a) -> Int
forall t. Matrix t -> Int
LA.cols
unsafeFromRows :: [Row Matrix (WrapFractional a)] -> Matrix (WrapFractional a)
unsafeFromRows [Row Matrix (WrapFractional a)]
rs = Matrix a -> Matrix (WrapFractional a)
DC.coerce (Matrix a -> Matrix (WrapFractional a))
-> Matrix a -> Matrix (WrapFractional a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows ([Vector (WrapFractional a)] -> [Vector a]
DC.coerce [Vector (WrapFractional a)]
[Row Matrix (WrapFractional a)]
rs :: [LA.Vector a])
unsafeFromColumns :: [Column Matrix (WrapFractional a)] -> Matrix (WrapFractional a)
unsafeFromColumns [Column Matrix (WrapFractional a)]
cs = Matrix a -> Matrix (WrapFractional a)
DC.coerce (Matrix a -> Matrix (WrapFractional a))
-> Matrix a -> Matrix (WrapFractional a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromColumns ([Vector (WrapFractional a)] -> [Vector a]
DC.coerce [Vector (WrapFractional a)]
[Column Matrix (WrapFractional a)]
cs :: [LA.Vector a])
basicUnsafeIndexM :: Matrix (WrapFractional a) -> Int -> Int -> m (WrapFractional a)
basicUnsafeIndexM Matrix (WrapFractional a)
m Int
i Int
j =
WrapFractional a -> m (WrapFractional a)
forall (m :: * -> *) a. Monad m => a -> m a
return (WrapFractional a -> m (WrapFractional a))
-> WrapFractional a -> m (WrapFractional a)
forall a b. (a -> b) -> a -> b
$ a -> WrapFractional a
forall a. a -> WrapFractional a
WrapFractional (a -> WrapFractional a) -> a -> WrapFractional a
forall a b. (a -> b) -> a -> b
$ (Matrix (WrapFractional a) -> Matrix a
DC.coerce Matrix (WrapFractional a)
m :: LA.Matrix a) Matrix a -> IndexOf Matrix -> a
forall (c :: * -> *) e. Container c e => c e -> IndexOf c -> e
`LA.atIndex` (Int
i, Int
j)
unsafeFreeze :: Mutable Matrix (PrimState m) (WrapFractional a)
-> m (Matrix (WrapFractional a))
unsafeFreeze = ST (PrimState m) (Matrix (WrapFractional a))
-> m (Matrix (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Matrix (WrapFractional a))
-> m (Matrix (WrapFractional a)))
-> (STMatrix (PrimState m) (WrapFractional a)
-> ST (PrimState m) (Matrix (WrapFractional a)))
-> STMatrix (PrimState m) (WrapFractional a)
-> m (Matrix (WrapFractional a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapFractional a)
-> ST (PrimState m) (Matrix (WrapFractional a))
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapFractional a)
-> ST (PrimState m) (Matrix (WrapFractional a)))
-> (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> STMatrix (PrimState m) (WrapFractional a)
-> ST (PrimState m) (Matrix (WrapFractional a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. STMatrix s a -> STMatrix s a
unwrapSTM
unsafeThaw :: Matrix (WrapFractional a)
-> m (Mutable Matrix (PrimState m) (WrapFractional a))
unsafeThaw Matrix (WrapFractional a)
m = ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix (WrapFractional a) -> Int
forall t. Matrix t -> Int
LA.rows Matrix (WrapFractional a)
m) (Matrix (WrapFractional a) -> Int
forall t. Matrix t -> Int
LA.cols Matrix (WrapFractional a)
m) (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapFractional a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix (WrapFractional a)
m
basicUnsafeGetRowM :: Matrix (WrapFractional a)
-> Int -> m (Row Matrix (WrapFractional a))
basicUnsafeGetRowM Matrix (WrapFractional a)
m Int
i = Vector (WrapFractional a) -> m (Vector (WrapFractional a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector (WrapFractional a) -> m (Vector (WrapFractional a)))
-> Vector (WrapFractional a) -> m (Vector (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapFractional a)
DC.coerce (Vector a -> Vector (WrapFractional a))
-> Vector a -> Vector (WrapFractional a)
forall a b. (a -> b) -> a -> b
$ Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getRowLA Int
i (Matrix (WrapFractional a) -> Matrix a
DC.coerce Matrix (WrapFractional a)
m :: LA.Matrix a)
basicUnsafeGetColumnM :: Matrix (WrapFractional a)
-> Int -> m (Column Matrix (WrapFractional a))
basicUnsafeGetColumnM Matrix (WrapFractional a)
m Int
i =
Vector (WrapFractional a) -> m (Vector (WrapFractional a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector (WrapFractional a) -> m (Vector (WrapFractional a)))
-> Vector (WrapFractional a) -> m (Vector (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapFractional a)
DC.coerce (Vector a -> Vector (WrapFractional a))
-> Vector a -> Vector (WrapFractional a)
forall a b. (a -> b) -> a -> b
$ [Vector a] -> Vector a
forall a. [a] -> a
head ([Vector a] -> Vector a) -> [Vector a] -> Vector a
forall a b. (a -> b) -> a -> b
$ Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toColumns (Matrix (WrapFractional a) -> Matrix a
DC.coerce Matrix (WrapFractional a)
m Matrix a -> [Int] -> Matrix a
forall t. Element t => Matrix t -> [Int] -> Matrix t
LA.¿ [Int
i] :: LA.Matrix a)
unsafeGenerate :: Int
-> Int
-> (Int -> Int -> WrapFractional a)
-> Matrix (WrapFractional a)
unsafeGenerate Int
w Int
h Int -> Int -> WrapFractional a
f =
Matrix a -> Matrix (WrapFractional a)
DC.coerce (Matrix a -> Matrix (WrapFractional a))
-> Matrix a -> Matrix (WrapFractional a)
forall a b. (a -> b) -> a -> b
$
[Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows [ Int -> (Int -> a) -> Vector a
forall a. Storable a => Int -> (Int -> a) -> Vector a
SV.generate Int
w ((Int -> a) -> Vector a) -> (Int -> a) -> Vector a
forall a b. (a -> b) -> a -> b
$ \Int
j -> WrapFractional a -> a
forall a. WrapFractional a -> a
unwrapFractional (WrapFractional a -> a) -> WrapFractional a -> a
forall a b. (a -> b) -> a -> b
$ Int -> Int -> WrapFractional a
f Int
i Int
j
| Int
i <- [Int
0..Int
h Int -> Int -> Int
forall r. Group r => r -> r -> r
- Int
1]
]
getRowLA :: LA.Element t => Int -> LA.Matrix t -> LA.Vector t
getRowLA :: Int -> Matrix t -> Vector t
getRowLA Int
i Matrix t
m = [Vector t] -> Vector t
forall a. [a] -> a
head ([Vector t] -> Vector t) -> [Vector t] -> Vector t
forall a b. (a -> b) -> a -> b
$ Matrix t -> [Vector t]
forall t. Element t => Matrix t -> [Vector t]
LA.toRows (Matrix t -> [Vector t]) -> Matrix t -> [Vector t]
forall a b. (a -> b) -> a -> b
$ Matrix t
m Matrix t -> [Int] -> Matrix t
forall t. Element t => Matrix t -> [Int] -> Matrix t
LA.? [Int
i]
getColLA :: LA.Element t => Int -> LA.Matrix t -> LA.Vector t
getColLA :: Int -> Matrix t -> Vector t
getColLA Int
i Matrix t
m = [Vector t] -> Vector t
forall a. [a] -> a
head ([Vector t] -> Vector t) -> [Vector t] -> Vector t
forall a b. (a -> b) -> a -> b
$ Matrix t -> [Vector t]
forall t. Element t => Matrix t -> [Vector t]
LA.toColumns (Matrix t -> [Vector t]) -> Matrix t -> [Vector t]
forall a b. (a -> b) -> a -> b
$ Matrix t
m Matrix t -> [Int] -> Matrix t
forall t. Element t => Matrix t -> [Int] -> Matrix t
LA.¿ [Int
i]
unwrapSTMNum :: STMatrix s (WrapNum a) -> LA.STMatrix s a
unwrapSTMNum :: STMatrix s (WrapNum a) -> STMatrix s a
unwrapSTMNum = STMatrix s (WrapNum a) -> STMatrix s a
DC.coerce (STMatrix s (WrapNum a) -> STMatrix s a)
-> (STMatrix s (WrapNum a) -> STMatrix s (WrapNum a))
-> STMatrix s (WrapNum a)
-> STMatrix s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix s (WrapNum a) -> STMatrix s (WrapNum a)
forall s a. STMatrix s a -> STMatrix s a
unwrapSTM
{-# INLINE unwrapSTMNum #-}
castSTMatrixNum :: LA.STMatrix s (WrapNum a) -> LA.STMatrix s a
castSTMatrixNum :: STMatrix s (WrapNum a) -> STMatrix s a
castSTMatrixNum = STMatrix s (WrapNum a) -> STMatrix s a
DC.coerce
{-# INLINE castSTMatrixNum #-}
instance (Num a, LA.Container LA.Matrix a) => MMatrix STMatrix (WrapNum a) where
basicUnsafeNew :: Int -> Int -> m (STMatrix (PrimState m) (WrapNum a))
basicUnsafeNew Int
n Int
m = ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
n Int
m (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WrapNum a
-> Int
-> Int
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall t s. Storable t => t -> Int -> Int -> ST s (STMatrix s t)
LA.newMatrix WrapNum a
0 Int
n Int
m
basicInitialise :: STMatrix (PrimState m) (WrapNum a) -> m ()
basicInitialise STMatrix (PrimState m) (WrapNum a)
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
basicRowCount :: STMatrix s (WrapNum a) -> Int
basicRowCount = STMatrix s (WrapNum a) -> Int
forall s a. STMatrix s a -> Int
stmRows
basicColumnCount :: STMatrix s (WrapNum a) -> Int
basicColumnCount = STMatrix s (WrapNum a) -> Int
forall s a. STMatrix s a -> Int
stmCols
unsafeGetRow :: Int
-> STMatrix (PrimState m) (WrapNum a)
-> m (Row STMatrix (WrapNum a))
unsafeGetRow Int
i STMatrix (PrimState m) (WrapNum a)
m =
ST (PrimState m) (Vector (WrapNum a)) -> m (Vector (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Vector (WrapNum a)) -> m (Vector (WrapNum a)))
-> ST (PrimState m) (Vector (WrapNum a)) -> m (Vector (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapNum a)
DC.coerce (Vector a -> Vector (WrapNum a))
-> (Matrix a -> Vector a) -> Matrix a -> Vector (WrapNum a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getRowLA Int
i (Matrix a -> Vector (WrapNum a))
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) (Vector (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapNum a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapNum a) -> STMatrix s a
unwrapSTMNum STMatrix (PrimState m) (WrapNum a)
m)
unsafeGetColumn :: Int
-> STMatrix (PrimState m) (WrapNum a)
-> m (Column STMatrix (WrapNum a))
unsafeGetColumn Int
i STMatrix (PrimState m) (WrapNum a)
m = ST (PrimState m) (Vector (WrapNum a)) -> m (Vector (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Vector (WrapNum a)) -> m (Vector (WrapNum a)))
-> ST (PrimState m) (Vector (WrapNum a)) -> m (Vector (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapNum a)
DC.coerce (Vector a -> Vector (WrapNum a))
-> (Matrix a -> Vector a) -> Matrix a -> Vector (WrapNum a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getColLA Int
i (Matrix a -> Vector (WrapNum a))
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) (Vector (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapNum a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapNum a) -> STMatrix s a
unwrapSTMNum STMatrix (PrimState m) (WrapNum a)
m)
unsafeFill :: Int -> Int -> WrapNum a -> m (STMatrix (PrimState m) (WrapNum a))
unsafeFill Int
n Int
m WrapNum a
a = ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
n Int
m (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WrapNum a
-> Int
-> Int
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall t s. Storable t => t -> Int -> Int -> ST s (STMatrix s t)
LA.newMatrix WrapNum a
a Int
n Int
m
unsafeFromRow :: Row STMatrix (WrapNum a) -> m (STMatrix (PrimState m) (WrapNum a))
unsafeFromRow Row STMatrix (WrapNum a)
r = ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
1 (Vector (WrapNum a) -> Int
forall a. Storable a => Vector a -> Int
SV.length Vector (WrapNum a)
Row STMatrix (WrapNum a)
r) (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapNum a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix (Vector (WrapNum a) -> Matrix (WrapNum a)
forall a. Storable a => Vector a -> Matrix a
LA.asRow Vector (WrapNum a)
Row STMatrix (WrapNum a)
r)
unsafeFromRows :: [Row STMatrix (WrapNum a)]
-> m (STMatrix (PrimState m) (WrapNum a))
unsafeFromRows [Row STMatrix (WrapNum a)]
rs = ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall a b. (a -> b) -> a -> b
$ do
let m :: Matrix a
m = [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows ([Vector (WrapNum a)] -> [Vector a]
DC.coerce [Vector (WrapNum a)]
[Row STMatrix (WrapNum a)]
rs :: [LA.Vector a])
Int
-> Int
-> STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix a -> Int
forall t. Matrix t -> Int
LA.rows Matrix a
m) (Matrix a -> Int
forall t. Matrix t -> Int
LA.cols Matrix a
m) (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> (STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapNum a))
-> STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapNum a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapNum a)
DC.coerce (STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix a -> ST (PrimState m) (STMatrix (PrimState m) a)
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix a
m
unsafeFromColumn :: Column STMatrix (WrapNum a)
-> m (STMatrix (PrimState m) (WrapNum a))
unsafeFromColumn Column STMatrix (WrapNum a)
c = ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Vector (WrapNum a) -> Int
forall a. Storable a => Vector a -> Int
SV.length Vector (WrapNum a)
Column STMatrix (WrapNum a)
c) Int
1 (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapNum a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix (Vector (WrapNum a) -> Matrix (WrapNum a)
forall a. Storable a => Vector a -> Matrix a
LA.asColumn Vector (WrapNum a)
Column STMatrix (WrapNum a)
c)
unsafeFromColumns :: [Column STMatrix (WrapNum a)]
-> m (STMatrix (PrimState m) (WrapNum a))
unsafeFromColumns [Column STMatrix (WrapNum a)]
rs = ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
-> m (STMatrix (PrimState m) (WrapNum a))
forall a b. (a -> b) -> a -> b
$ do
let m :: Matrix a
m = [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromColumns ([Vector (WrapNum a)] -> [Vector a]
DC.coerce [Vector (WrapNum a)]
[Column STMatrix (WrapNum a)]
rs :: [LA.Vector a])
Int
-> Int
-> STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix a -> Int
forall t. Matrix t -> Int
LA.rows Matrix a
m) (Matrix a -> Int
forall t. Matrix t -> Int
LA.cols Matrix a
m) (STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a))
-> (STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapNum a))
-> STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapNum a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapNum a)
DC.coerce (STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapNum a))
-> ST (PrimState m) (STMatrix (PrimState m) a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapNum a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix a -> ST (PrimState m) (STMatrix (PrimState m) a)
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix a
m
unsafeCopy :: STMatrix (PrimState m) (WrapNum a)
-> STMatrix (PrimState m) (WrapNum a) -> m ()
unsafeCopy (STMat Int
r Int
c STMatrix (PrimState m) (WrapNum a)
m) (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapNum a)
m') = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Matrix (WrapNum a)
m0 <- STMatrix (PrimState m) (WrapNum a)
-> ST (PrimState m) (Matrix (WrapNum a))
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix STMatrix (PrimState m) (WrapNum a)
m'
STMatrix (PrimState m) a
-> Int -> Int -> Matrix a -> ST (PrimState m) ()
forall t s.
Element t =>
STMatrix s t -> Int -> Int -> Matrix t -> ST s ()
LA.setMatrix (STMatrix (PrimState m) (WrapNum a) -> STMatrix w a
DC.coerce STMatrix (PrimState m) (WrapNum a)
m :: LA.STMatrix w a) Int
r Int
c (Matrix (WrapNum a) -> Matrix a
DC.coerce Matrix (WrapNum a)
m0 :: LA.Matrix a)
unsafeRead :: STMatrix (PrimState m) (WrapNum a) -> Int -> Int -> m (WrapNum a)
unsafeRead (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapNum a)
m) Int
i Int
j = ST (PrimState m) (WrapNum a) -> m (WrapNum a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (WrapNum a) -> m (WrapNum a))
-> ST (PrimState m) (WrapNum a) -> m (WrapNum a)
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapNum a)
-> Int -> Int -> ST (PrimState m) (WrapNum a)
forall t s. Storable t => STMatrix s t -> Int -> Int -> ST s t
LA.readMatrix STMatrix (PrimState m) (WrapNum a)
m Int
i Int
j
unsafeWrite :: STMatrix (PrimState m) (WrapNum a)
-> Int -> Int -> WrapNum a -> m ()
unsafeWrite (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapNum a)
m) Int
i Int
j WrapNum a
x = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapNum a)
-> Int -> Int -> WrapNum a -> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> t -> ST s ()
LA.writeMatrix STMatrix (PrimState m) (WrapNum a)
m Int
i Int
j WrapNum a
x
basicSet :: STMatrix (PrimState m) (WrapNum a) -> WrapNum a -> m ()
basicSet (STMat Int
r Int
c STMatrix (PrimState m) (WrapNum a)
m) WrapNum a
x = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapNum a)
-> Int -> Int -> (WrapNum a -> WrapNum a) -> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> (t -> t) -> ST s ()
LA.modifyMatrix STMatrix (PrimState m) (WrapNum a)
m Int
r Int
c ((WrapNum a -> WrapNum a) -> ST (PrimState m) ())
-> (WrapNum a -> WrapNum a) -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ WrapNum a -> WrapNum a -> WrapNum a
forall a b. a -> b -> a
const WrapNum a
x
basicUnsafeSwapRows :: STMatrix (PrimState m) (WrapNum a) -> Int -> Int -> m ()
basicUnsafeSwapRows (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapNum a)
m) Int
i Int
j =
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ RowOper a -> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall t s.
(Num t, Element t) =>
RowOper t -> STMatrix s t -> ST s ()
LA.rowOper (Int -> Int -> ColRange -> RowOper a
forall t. Int -> Int -> ColRange -> RowOper t
LA.SWAP Int
i Int
j ColRange
LA.AllCols) (STMatrix (PrimState m) a -> ST (PrimState m) ())
-> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapNum a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapNum a) -> STMatrix s a
castSTMatrixNum STMatrix (PrimState m) (WrapNum a)
m
unsafeScaleRow :: STMatrix (PrimState m) (WrapNum a) -> Int -> WrapNum a -> m ()
unsafeScaleRow (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapNum a)
m) Int
i WrapNum a
c =
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ RowOper a -> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall t s.
(Num t, Element t) =>
RowOper t -> STMatrix s t -> ST s ()
LA.rowOper (a -> RowRange -> ColRange -> RowOper a
forall t. t -> RowRange -> ColRange -> RowOper t
LA.SCAL (WrapNum a -> a
forall a. WrapNum a -> a
unwrapNum WrapNum a
c) (Int -> RowRange
LA.Row Int
i) ColRange
LA.AllCols) (STMatrix (PrimState m) a -> ST (PrimState m) ())
-> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapNum a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapNum a) -> STMatrix s a
castSTMatrixNum STMatrix (PrimState m) (WrapNum a)
m
basicUnsafeIMapRowM :: STMatrix (PrimState m) (WrapNum a)
-> Int -> (Int -> WrapNum a -> m (WrapNum a)) -> m ()
basicUnsafeIMapRowM (STMat Int
_ Int
c STMatrix (PrimState m) (WrapNum a)
m) Int
i Int -> WrapNum a -> m (WrapNum a)
f = [Int] -> (Int -> m ()) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0..Int
cInt -> Int -> Int
forall r. Group r => r -> r -> r
-Int
1] ((Int -> m ()) -> m ()) -> (Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
j ->
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ())
-> (WrapNum a -> ST (PrimState m) ()) -> WrapNum a -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapNum a)
-> Int -> Int -> WrapNum a -> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> t -> ST s ()
LA.writeMatrix STMatrix (PrimState m) (WrapNum a)
m Int
i Int
j (WrapNum a -> m ()) -> m (WrapNum a) -> m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int -> WrapNum a -> m (WrapNum a)
f Int
j (WrapNum a -> m (WrapNum a)) -> m (WrapNum a) -> m (WrapNum a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ST (PrimState m) (WrapNum a) -> m (WrapNum a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (STMatrix (PrimState m) (WrapNum a)
-> Int -> Int -> ST (PrimState m) (WrapNum a)
forall t s. Storable t => STMatrix s t -> Int -> Int -> ST s t
LA.readMatrix STMatrix (PrimState m) (WrapNum a)
m Int
i Int
j)
toRows :: STMatrix (PrimState m) (WrapNum a) -> m [Row STMatrix (WrapNum a)]
toRows (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapNum a)
m) =
ST (PrimState m) [Vector (WrapNum a)] -> m [Vector (WrapNum a)]
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) [Vector (WrapNum a)] -> m [Vector (WrapNum a)])
-> ST (PrimState m) [Vector (WrapNum a)] -> m [Vector (WrapNum a)]
forall a b. (a -> b) -> a -> b
$ [Vector a] -> [Vector (WrapNum a)]
DC.coerce ([Vector a] -> [Vector (WrapNum a)])
-> (Matrix a -> [Vector a]) -> Matrix a -> [Vector (WrapNum a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toRows (Matrix a -> [Vector (WrapNum a)])
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) [Vector (WrapNum a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapNum a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapNum a) -> STMatrix s a
castSTMatrixNum STMatrix (PrimState m) (WrapNum a)
m)
toColumns :: STMatrix (PrimState m) (WrapNum a)
-> m [Column STMatrix (WrapNum a)]
toColumns (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapNum a)
m) =
ST (PrimState m) [Vector (WrapNum a)] -> m [Vector (WrapNum a)]
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) [Vector (WrapNum a)] -> m [Vector (WrapNum a)])
-> ST (PrimState m) [Vector (WrapNum a)] -> m [Vector (WrapNum a)]
forall a b. (a -> b) -> a -> b
$ [Vector a] -> [Vector (WrapNum a)]
DC.coerce ([Vector a] -> [Vector (WrapNum a)])
-> (Matrix a -> [Vector a]) -> Matrix a -> [Vector (WrapNum a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toColumns (Matrix a -> [Vector (WrapNum a)])
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) [Vector (WrapNum a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapNum a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapNum a) -> STMatrix s a
castSTMatrixNum STMatrix (PrimState m) (WrapNum a)
m)
unwrapSTMFractional :: STMatrix s (WrapFractional a) -> LA.STMatrix s a
unwrapSTMFractional :: STMatrix s (WrapFractional a) -> STMatrix s a
unwrapSTMFractional = STMatrix s (WrapFractional a) -> STMatrix s a
DC.coerce (STMatrix s (WrapFractional a) -> STMatrix s a)
-> (STMatrix s (WrapFractional a) -> STMatrix s (WrapFractional a))
-> STMatrix s (WrapFractional a)
-> STMatrix s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix s (WrapFractional a) -> STMatrix s (WrapFractional a)
forall s a. STMatrix s a -> STMatrix s a
unwrapSTM
{-# INLINE unwrapSTMFractional #-}
castSTMatrixFractional :: LA.STMatrix s (WrapFractional a) -> LA.STMatrix s a
castSTMatrixFractional :: STMatrix s (WrapFractional a) -> STMatrix s a
castSTMatrixFractional = STMatrix s (WrapFractional a) -> STMatrix s a
DC.coerce
{-# INLINE castSTMatrixFractional #-}
instance (Fractional a, LA.Container LA.Matrix a) => MMatrix STMatrix (WrapFractional a) where
basicUnsafeNew :: Int -> Int -> m (STMatrix (PrimState m) (WrapFractional a))
basicUnsafeNew Int
n Int
m = ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
n Int
m (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WrapFractional a
-> Int
-> Int
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall t s. Storable t => t -> Int -> Int -> ST s (STMatrix s t)
LA.newMatrix WrapFractional a
0 Int
n Int
m
basicInitialise :: STMatrix (PrimState m) (WrapFractional a) -> m ()
basicInitialise STMatrix (PrimState m) (WrapFractional a)
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
basicRowCount :: STMatrix s (WrapFractional a) -> Int
basicRowCount = STMatrix s (WrapFractional a) -> Int
forall s a. STMatrix s a -> Int
stmRows
basicColumnCount :: STMatrix s (WrapFractional a) -> Int
basicColumnCount = STMatrix s (WrapFractional a) -> Int
forall s a. STMatrix s a -> Int
stmCols
unsafeGetRow :: Int
-> STMatrix (PrimState m) (WrapFractional a)
-> m (Row STMatrix (WrapFractional a))
unsafeGetRow Int
i STMatrix (PrimState m) (WrapFractional a)
m =
ST (PrimState m) (Vector (WrapFractional a))
-> m (Vector (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Vector (WrapFractional a))
-> m (Vector (WrapFractional a)))
-> ST (PrimState m) (Vector (WrapFractional a))
-> m (Vector (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapFractional a)
DC.coerce (Vector a -> Vector (WrapFractional a))
-> (Matrix a -> Vector a) -> Matrix a -> Vector (WrapFractional a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getRowLA Int
i (Matrix a -> Vector (WrapFractional a))
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) (Vector (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapFractional a) -> STMatrix s a
unwrapSTMFractional STMatrix (PrimState m) (WrapFractional a)
m)
unsafeGetColumn :: Int
-> STMatrix (PrimState m) (WrapFractional a)
-> m (Column STMatrix (WrapFractional a))
unsafeGetColumn Int
i STMatrix (PrimState m) (WrapFractional a)
m = ST (PrimState m) (Vector (WrapFractional a))
-> m (Vector (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Vector (WrapFractional a))
-> m (Vector (WrapFractional a)))
-> ST (PrimState m) (Vector (WrapFractional a))
-> m (Vector (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapFractional a)
DC.coerce (Vector a -> Vector (WrapFractional a))
-> (Matrix a -> Vector a) -> Matrix a -> Vector (WrapFractional a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getColLA Int
i (Matrix a -> Vector (WrapFractional a))
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) (Vector (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapFractional a) -> STMatrix s a
unwrapSTMFractional STMatrix (PrimState m) (WrapFractional a)
m)
unsafeFill :: Int
-> Int
-> WrapFractional a
-> m (STMatrix (PrimState m) (WrapFractional a))
unsafeFill Int
n Int
m WrapFractional a
a = ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
n Int
m (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WrapFractional a
-> Int
-> Int
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall t s. Storable t => t -> Int -> Int -> ST s (STMatrix s t)
LA.newMatrix WrapFractional a
a Int
n Int
m
unsafeFromRow :: Row STMatrix (WrapFractional a)
-> m (STMatrix (PrimState m) (WrapFractional a))
unsafeFromRow Row STMatrix (WrapFractional a)
r = ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
1 (Vector (WrapFractional a) -> Int
forall a. Storable a => Vector a -> Int
SV.length Vector (WrapFractional a)
Row STMatrix (WrapFractional a)
r) (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapFractional a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix (Vector (WrapFractional a) -> Matrix (WrapFractional a)
forall a. Storable a => Vector a -> Matrix a
LA.asRow Vector (WrapFractional a)
Row STMatrix (WrapFractional a)
r)
unsafeFromRows :: [Row STMatrix (WrapFractional a)]
-> m (STMatrix (PrimState m) (WrapFractional a))
unsafeFromRows [Row STMatrix (WrapFractional a)]
rs = ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ do
let m :: Matrix a
m = [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows ([Vector (WrapFractional a)] -> [Vector a]
DC.coerce [Vector (WrapFractional a)]
[Row STMatrix (WrapFractional a)]
rs :: [LA.Vector a])
Int
-> Int
-> STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix a -> Int
forall t. Matrix t -> Int
LA.rows Matrix a
m) (Matrix a -> Int
forall t. Matrix t -> Int
LA.cols Matrix a
m) (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a))
-> STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a)
DC.coerce (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix a -> ST (PrimState m) (STMatrix (PrimState m) a)
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix a
m
unsafeFromColumn :: Column STMatrix (WrapFractional a)
-> m (STMatrix (PrimState m) (WrapFractional a))
unsafeFromColumn Column STMatrix (WrapFractional a)
c = ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Vector (WrapFractional a) -> Int
forall a. Storable a => Vector a -> Int
SV.length Vector (WrapFractional a)
Column STMatrix (WrapFractional a)
c) Int
1 (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapFractional a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix (Vector (WrapFractional a) -> Matrix (WrapFractional a)
forall a. Storable a => Vector a -> Matrix a
LA.asColumn Vector (WrapFractional a)
Column STMatrix (WrapFractional a)
c)
unsafeFromColumns :: [Column STMatrix (WrapFractional a)]
-> m (STMatrix (PrimState m) (WrapFractional a))
unsafeFromColumns [Column STMatrix (WrapFractional a)]
rs = ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
-> m (STMatrix (PrimState m) (WrapFractional a))
forall a b. (a -> b) -> a -> b
$ do
let m :: Matrix a
m = [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromColumns ([Vector (WrapFractional a)] -> [Vector a]
DC.coerce [Vector (WrapFractional a)]
[Column STMatrix (WrapFractional a)]
rs :: [LA.Vector a])
Int
-> Int
-> STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix a -> Int
forall t. Matrix t -> Int
LA.rows Matrix a
m) (Matrix a -> Int
forall t. Matrix t -> Int
LA.cols Matrix a
m) (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a))
-> (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a))
-> STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a)
DC.coerce (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapFractional a))
-> ST (PrimState m) (STMatrix (PrimState m) a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapFractional a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix a -> ST (PrimState m) (STMatrix (PrimState m) a)
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix a
m
unsafeCopy :: STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) (WrapFractional a) -> m ()
unsafeCopy (STMat Int
r Int
c STMatrix (PrimState m) (WrapFractional a)
m) (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapFractional a)
m') = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Matrix (WrapFractional a)
m0 <- STMatrix (PrimState m) (WrapFractional a)
-> ST (PrimState m) (Matrix (WrapFractional a))
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix STMatrix (PrimState m) (WrapFractional a)
m'
STMatrix (PrimState m) a
-> Int -> Int -> Matrix a -> ST (PrimState m) ()
forall t s.
Element t =>
STMatrix s t -> Int -> Int -> Matrix t -> ST s ()
LA.setMatrix (STMatrix (PrimState m) (WrapFractional a) -> STMatrix w a
DC.coerce STMatrix (PrimState m) (WrapFractional a)
m :: LA.STMatrix w a) Int
r Int
c (Matrix (WrapFractional a) -> Matrix a
DC.coerce Matrix (WrapFractional a)
m0 :: LA.Matrix a)
unsafeRead :: STMatrix (PrimState m) (WrapFractional a)
-> Int -> Int -> m (WrapFractional a)
unsafeRead (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapFractional a)
m) Int
i Int
j = ST (PrimState m) (WrapFractional a) -> m (WrapFractional a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (WrapFractional a) -> m (WrapFractional a))
-> ST (PrimState m) (WrapFractional a) -> m (WrapFractional a)
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapFractional a)
-> Int -> Int -> ST (PrimState m) (WrapFractional a)
forall t s. Storable t => STMatrix s t -> Int -> Int -> ST s t
LA.readMatrix STMatrix (PrimState m) (WrapFractional a)
m Int
i Int
j
unsafeWrite :: STMatrix (PrimState m) (WrapFractional a)
-> Int -> Int -> WrapFractional a -> m ()
unsafeWrite (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapFractional a)
m) Int
i Int
j WrapFractional a
x = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapFractional a)
-> Int -> Int -> WrapFractional a -> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> t -> ST s ()
LA.writeMatrix STMatrix (PrimState m) (WrapFractional a)
m Int
i Int
j WrapFractional a
x
basicSet :: STMatrix (PrimState m) (WrapFractional a)
-> WrapFractional a -> m ()
basicSet (STMat Int
r Int
c STMatrix (PrimState m) (WrapFractional a)
m) WrapFractional a
x = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapFractional a)
-> Int
-> Int
-> (WrapFractional a -> WrapFractional a)
-> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> (t -> t) -> ST s ()
LA.modifyMatrix STMatrix (PrimState m) (WrapFractional a)
m Int
r Int
c ((WrapFractional a -> WrapFractional a) -> ST (PrimState m) ())
-> (WrapFractional a -> WrapFractional a) -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ WrapFractional a -> WrapFractional a -> WrapFractional a
forall a b. a -> b -> a
const WrapFractional a
x
basicUnsafeSwapRows :: STMatrix (PrimState m) (WrapFractional a) -> Int -> Int -> m ()
basicUnsafeSwapRows (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapFractional a)
m) Int
i Int
j =
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ RowOper a -> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall t s.
(Num t, Element t) =>
RowOper t -> STMatrix s t -> ST s ()
LA.rowOper (Int -> Int -> ColRange -> RowOper a
forall t. Int -> Int -> ColRange -> RowOper t
LA.SWAP Int
i Int
j ColRange
LA.AllCols) (STMatrix (PrimState m) a -> ST (PrimState m) ())
-> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapFractional a) -> STMatrix s a
castSTMatrixFractional STMatrix (PrimState m) (WrapFractional a)
m
unsafeScaleRow :: STMatrix (PrimState m) (WrapFractional a)
-> Int -> WrapFractional a -> m ()
unsafeScaleRow (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapFractional a)
m) Int
i WrapFractional a
c =
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ RowOper a -> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall t s.
(Num t, Element t) =>
RowOper t -> STMatrix s t -> ST s ()
LA.rowOper (a -> RowRange -> ColRange -> RowOper a
forall t. t -> RowRange -> ColRange -> RowOper t
LA.SCAL (WrapFractional a -> a
forall a. WrapFractional a -> a
unwrapFractional WrapFractional a
c) (Int -> RowRange
LA.Row Int
i) ColRange
LA.AllCols) (STMatrix (PrimState m) a -> ST (PrimState m) ())
-> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapFractional a) -> STMatrix s a
castSTMatrixFractional STMatrix (PrimState m) (WrapFractional a)
m
basicUnsafeIMapRowM :: STMatrix (PrimState m) (WrapFractional a)
-> Int -> (Int -> WrapFractional a -> m (WrapFractional a)) -> m ()
basicUnsafeIMapRowM (STMat Int
_ Int
c STMatrix (PrimState m) (WrapFractional a)
m) Int
i Int -> WrapFractional a -> m (WrapFractional a)
f = [Int] -> (Int -> m ()) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0..Int
cInt -> Int -> Int
forall r. Group r => r -> r -> r
-Int
1] ((Int -> m ()) -> m ()) -> (Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
j ->
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ())
-> (WrapFractional a -> ST (PrimState m) ())
-> WrapFractional a
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapFractional a)
-> Int -> Int -> WrapFractional a -> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> t -> ST s ()
LA.writeMatrix STMatrix (PrimState m) (WrapFractional a)
m Int
i Int
j (WrapFractional a -> m ()) -> m (WrapFractional a) -> m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int -> WrapFractional a -> m (WrapFractional a)
f Int
j (WrapFractional a -> m (WrapFractional a))
-> m (WrapFractional a) -> m (WrapFractional a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ST (PrimState m) (WrapFractional a) -> m (WrapFractional a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (STMatrix (PrimState m) (WrapFractional a)
-> Int -> Int -> ST (PrimState m) (WrapFractional a)
forall t s. Storable t => STMatrix s t -> Int -> Int -> ST s t
LA.readMatrix STMatrix (PrimState m) (WrapFractional a)
m Int
i Int
j)
toRows :: STMatrix (PrimState m) (WrapFractional a)
-> m [Row STMatrix (WrapFractional a)]
toRows (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapFractional a)
m) =
ST (PrimState m) [Vector (WrapFractional a)]
-> m [Vector (WrapFractional a)]
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) [Vector (WrapFractional a)]
-> m [Vector (WrapFractional a)])
-> ST (PrimState m) [Vector (WrapFractional a)]
-> m [Vector (WrapFractional a)]
forall a b. (a -> b) -> a -> b
$ [Vector a] -> [Vector (WrapFractional a)]
DC.coerce ([Vector a] -> [Vector (WrapFractional a)])
-> (Matrix a -> [Vector a])
-> Matrix a
-> [Vector (WrapFractional a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toRows (Matrix a -> [Vector (WrapFractional a)])
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) [Vector (WrapFractional a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapFractional a) -> STMatrix s a
castSTMatrixFractional STMatrix (PrimState m) (WrapFractional a)
m)
toColumns :: STMatrix (PrimState m) (WrapFractional a)
-> m [Column STMatrix (WrapFractional a)]
toColumns (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapFractional a)
m) =
ST (PrimState m) [Vector (WrapFractional a)]
-> m [Vector (WrapFractional a)]
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) [Vector (WrapFractional a)]
-> m [Vector (WrapFractional a)])
-> ST (PrimState m) [Vector (WrapFractional a)]
-> m [Vector (WrapFractional a)]
forall a b. (a -> b) -> a -> b
$ [Vector a] -> [Vector (WrapFractional a)]
DC.coerce ([Vector a] -> [Vector (WrapFractional a)])
-> (Matrix a -> [Vector a])
-> Matrix a
-> [Vector (WrapFractional a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toColumns (Matrix a -> [Vector (WrapFractional a)])
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) [Vector (WrapFractional a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapFractional a)
-> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapFractional a) -> STMatrix s a
castSTMatrixFractional STMatrix (PrimState m) (WrapFractional a)
m)
unwrapSTMIntegral :: STMatrix s (WrapIntegral a) -> LA.STMatrix s a
unwrapSTMIntegral :: STMatrix s (WrapIntegral a) -> STMatrix s a
unwrapSTMIntegral = STMatrix s (WrapIntegral a) -> STMatrix s a
DC.coerce (STMatrix s (WrapIntegral a) -> STMatrix s a)
-> (STMatrix s (WrapIntegral a) -> STMatrix s (WrapIntegral a))
-> STMatrix s (WrapIntegral a)
-> STMatrix s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix s (WrapIntegral a) -> STMatrix s (WrapIntegral a)
forall s a. STMatrix s a -> STMatrix s a
unwrapSTM
{-# INLINE unwrapSTMIntegral #-}
castSTMatrixIntegral :: LA.STMatrix s (WrapIntegral a) -> LA.STMatrix s a
castSTMatrixIntegral :: STMatrix s (WrapIntegral a) -> STMatrix s a
castSTMatrixIntegral = STMatrix s (WrapIntegral a) -> STMatrix s a
DC.coerce
{-# INLINE castSTMatrixIntegral #-}
instance (Integral a, LA.Container LA.Matrix a) => MMatrix STMatrix (WrapIntegral a) where
basicUnsafeNew :: Int -> Int -> m (STMatrix (PrimState m) (WrapIntegral a))
basicUnsafeNew Int
n Int
m = ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
n Int
m (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WrapIntegral a
-> Int
-> Int
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall t s. Storable t => t -> Int -> Int -> ST s (STMatrix s t)
LA.newMatrix WrapIntegral a
0 Int
n Int
m
basicInitialise :: STMatrix (PrimState m) (WrapIntegral a) -> m ()
basicInitialise STMatrix (PrimState m) (WrapIntegral a)
_ = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
basicRowCount :: STMatrix s (WrapIntegral a) -> Int
basicRowCount = STMatrix s (WrapIntegral a) -> Int
forall s a. STMatrix s a -> Int
stmRows
basicColumnCount :: STMatrix s (WrapIntegral a) -> Int
basicColumnCount = STMatrix s (WrapIntegral a) -> Int
forall s a. STMatrix s a -> Int
stmCols
unsafeGetRow :: Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> m (Row STMatrix (WrapIntegral a))
unsafeGetRow Int
i STMatrix (PrimState m) (WrapIntegral a)
m =
ST (PrimState m) (Vector (WrapIntegral a))
-> m (Vector (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Vector (WrapIntegral a))
-> m (Vector (WrapIntegral a)))
-> ST (PrimState m) (Vector (WrapIntegral a))
-> m (Vector (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapIntegral a)
DC.coerce (Vector a -> Vector (WrapIntegral a))
-> (Matrix a -> Vector a) -> Matrix a -> Vector (WrapIntegral a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getRowLA Int
i (Matrix a -> Vector (WrapIntegral a))
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) (Vector (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapIntegral a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapIntegral a) -> STMatrix s a
unwrapSTMIntegral STMatrix (PrimState m) (WrapIntegral a)
m)
unsafeGetColumn :: Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> m (Column STMatrix (WrapIntegral a))
unsafeGetColumn Int
i STMatrix (PrimState m) (WrapIntegral a)
m = ST (PrimState m) (Vector (WrapIntegral a))
-> m (Vector (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (Vector (WrapIntegral a))
-> m (Vector (WrapIntegral a)))
-> ST (PrimState m) (Vector (WrapIntegral a))
-> m (Vector (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Vector a -> Vector (WrapIntegral a)
DC.coerce (Vector a -> Vector (WrapIntegral a))
-> (Matrix a -> Vector a) -> Matrix a -> Vector (WrapIntegral a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Matrix a -> Vector a
forall t. Element t => Int -> Matrix t -> Vector t
getColLA Int
i (Matrix a -> Vector (WrapIntegral a))
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) (Vector (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapIntegral a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapIntegral a) -> STMatrix s a
unwrapSTMIntegral STMatrix (PrimState m) (WrapIntegral a)
m)
unsafeFill :: Int
-> Int
-> WrapIntegral a
-> m (STMatrix (PrimState m) (WrapIntegral a))
unsafeFill Int
n Int
m WrapIntegral a
a = ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
n Int
m (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WrapIntegral a
-> Int
-> Int
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall t s. Storable t => t -> Int -> Int -> ST s (STMatrix s t)
LA.newMatrix WrapIntegral a
a Int
n Int
m
unsafeFromRow :: Row STMatrix (WrapIntegral a)
-> m (STMatrix (PrimState m) (WrapIntegral a))
unsafeFromRow Row STMatrix (WrapIntegral a)
r = ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat Int
1 (Vector (WrapIntegral a) -> Int
forall a. Storable a => Vector a -> Int
SV.length Vector (WrapIntegral a)
Row STMatrix (WrapIntegral a)
r) (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapIntegral a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix (Vector (WrapIntegral a) -> Matrix (WrapIntegral a)
forall a. Storable a => Vector a -> Matrix a
LA.asRow Vector (WrapIntegral a)
Row STMatrix (WrapIntegral a)
r)
unsafeFromRows :: [Row STMatrix (WrapIntegral a)]
-> m (STMatrix (PrimState m) (WrapIntegral a))
unsafeFromRows [Row STMatrix (WrapIntegral a)]
rs = ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ do
let m :: Matrix a
m = [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromRows ([Vector (WrapIntegral a)] -> [Vector a]
DC.coerce [Vector (WrapIntegral a)]
[Row STMatrix (WrapIntegral a)]
rs :: [LA.Vector a])
Int
-> Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix a -> Int
forall t. Matrix t -> Int
LA.rows Matrix a
m) (Matrix a -> Int
forall t. Matrix t -> Int
LA.cols Matrix a
m) (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapIntegral a))
-> STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapIntegral a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapIntegral a)
DC.coerce (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix a -> ST (PrimState m) (STMatrix (PrimState m) a)
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix a
m
unsafeFromColumn :: Column STMatrix (WrapIntegral a)
-> m (STMatrix (PrimState m) (WrapIntegral a))
unsafeFromColumn Column STMatrix (WrapIntegral a)
c = ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ Int
-> Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Vector (WrapIntegral a) -> Int
forall a. Storable a => Vector a -> Int
SV.length Vector (WrapIntegral a)
Column STMatrix (WrapIntegral a)
c) Int
1 (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix (WrapIntegral a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix (Vector (WrapIntegral a) -> Matrix (WrapIntegral a)
forall a. Storable a => Vector a -> Matrix a
LA.asColumn Vector (WrapIntegral a)
Column STMatrix (WrapIntegral a)
c)
unsafeFromColumns :: [Column STMatrix (WrapIntegral a)]
-> m (STMatrix (PrimState m) (WrapIntegral a))
unsafeFromColumns [Column STMatrix (WrapIntegral a)]
rs = ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a)))
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
-> m (STMatrix (PrimState m) (WrapIntegral a))
forall a b. (a -> b) -> a -> b
$ do
let m :: Matrix a
m = [Vector a] -> Matrix a
forall t. Element t => [Vector t] -> Matrix t
LA.fromColumns ([Vector (WrapIntegral a)] -> [Vector a]
DC.coerce [Vector (WrapIntegral a)]
[Column STMatrix (WrapIntegral a)]
rs :: [LA.Vector a])
Int
-> Int
-> STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a)
forall s a. Int -> Int -> STMatrix s a -> STMatrix s a
STMat (Matrix a -> Int
forall t. Matrix t -> Int
LA.rows Matrix a
m) (Matrix a -> Int
forall t. Matrix t -> Int
LA.cols Matrix a
m) (STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a))
-> (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapIntegral a))
-> STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapIntegral a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) a -> STMatrix (PrimState m) (WrapIntegral a)
DC.coerce (STMatrix (PrimState m) a
-> STMatrix (PrimState m) (WrapIntegral a))
-> ST (PrimState m) (STMatrix (PrimState m) a)
-> ST (PrimState m) (STMatrix (PrimState m) (WrapIntegral a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix a -> ST (PrimState m) (STMatrix (PrimState m) a)
forall t s. Storable t => Matrix t -> ST s (STMatrix s t)
LA.unsafeThawMatrix Matrix a
m
unsafeCopy :: STMatrix (PrimState m) (WrapIntegral a)
-> STMatrix (PrimState m) (WrapIntegral a) -> m ()
unsafeCopy (STMat Int
r Int
c STMatrix (PrimState m) (WrapIntegral a)
m) (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapIntegral a)
m') = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Matrix (WrapIntegral a)
m0 <- STMatrix (PrimState m) (WrapIntegral a)
-> ST (PrimState m) (Matrix (WrapIntegral a))
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix STMatrix (PrimState m) (WrapIntegral a)
m'
STMatrix (PrimState m) a
-> Int -> Int -> Matrix a -> ST (PrimState m) ()
forall t s.
Element t =>
STMatrix s t -> Int -> Int -> Matrix t -> ST s ()
LA.setMatrix (STMatrix (PrimState m) (WrapIntegral a) -> STMatrix w a
DC.coerce STMatrix (PrimState m) (WrapIntegral a)
m :: LA.STMatrix w a) Int
r Int
c (Matrix (WrapIntegral a) -> Matrix a
DC.coerce Matrix (WrapIntegral a)
m0 :: LA.Matrix a)
unsafeRead :: STMatrix (PrimState m) (WrapIntegral a)
-> Int -> Int -> m (WrapIntegral a)
unsafeRead (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapIntegral a)
m) Int
i Int
j = ST (PrimState m) (WrapIntegral a) -> m (WrapIntegral a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) (WrapIntegral a) -> m (WrapIntegral a))
-> ST (PrimState m) (WrapIntegral a) -> m (WrapIntegral a)
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapIntegral a)
-> Int -> Int -> ST (PrimState m) (WrapIntegral a)
forall t s. Storable t => STMatrix s t -> Int -> Int -> ST s t
LA.readMatrix STMatrix (PrimState m) (WrapIntegral a)
m Int
i Int
j
unsafeWrite :: STMatrix (PrimState m) (WrapIntegral a)
-> Int -> Int -> WrapIntegral a -> m ()
unsafeWrite (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapIntegral a)
m) Int
i Int
j WrapIntegral a
x = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapIntegral a)
-> Int -> Int -> WrapIntegral a -> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> t -> ST s ()
LA.writeMatrix STMatrix (PrimState m) (WrapIntegral a)
m Int
i Int
j WrapIntegral a
x
basicSet :: STMatrix (PrimState m) (WrapIntegral a) -> WrapIntegral a -> m ()
basicSet (STMat Int
r Int
c STMatrix (PrimState m) (WrapIntegral a)
m) WrapIntegral a
x = ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapIntegral a)
-> Int
-> Int
-> (WrapIntegral a -> WrapIntegral a)
-> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> (t -> t) -> ST s ()
LA.modifyMatrix STMatrix (PrimState m) (WrapIntegral a)
m Int
r Int
c ((WrapIntegral a -> WrapIntegral a) -> ST (PrimState m) ())
-> (WrapIntegral a -> WrapIntegral a) -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ WrapIntegral a -> WrapIntegral a -> WrapIntegral a
forall a b. a -> b -> a
const WrapIntegral a
x
basicUnsafeSwapRows :: STMatrix (PrimState m) (WrapIntegral a) -> Int -> Int -> m ()
basicUnsafeSwapRows (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapIntegral a)
m) Int
i Int
j =
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ RowOper a -> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall t s.
(Num t, Element t) =>
RowOper t -> STMatrix s t -> ST s ()
LA.rowOper (Int -> Int -> ColRange -> RowOper a
forall t. Int -> Int -> ColRange -> RowOper t
LA.SWAP Int
i Int
j ColRange
LA.AllCols) (STMatrix (PrimState m) a -> ST (PrimState m) ())
-> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapIntegral a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapIntegral a) -> STMatrix s a
castSTMatrixIntegral STMatrix (PrimState m) (WrapIntegral a)
m
unsafeScaleRow :: STMatrix (PrimState m) (WrapIntegral a)
-> Int -> WrapIntegral a -> m ()
unsafeScaleRow (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapIntegral a)
m) Int
i WrapIntegral a
c =
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ()) -> ST (PrimState m) () -> m ()
forall a b. (a -> b) -> a -> b
$ RowOper a -> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall t s.
(Num t, Element t) =>
RowOper t -> STMatrix s t -> ST s ()
LA.rowOper (a -> RowRange -> ColRange -> RowOper a
forall t. t -> RowRange -> ColRange -> RowOper t
LA.SCAL (WrapIntegral a -> a
forall a. WrapIntegral a -> a
unwrapIntegral WrapIntegral a
c) (Int -> RowRange
LA.Row Int
i) ColRange
LA.AllCols) (STMatrix (PrimState m) a -> ST (PrimState m) ())
-> STMatrix (PrimState m) a -> ST (PrimState m) ()
forall a b. (a -> b) -> a -> b
$ STMatrix (PrimState m) (WrapIntegral a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapIntegral a) -> STMatrix s a
castSTMatrixIntegral STMatrix (PrimState m) (WrapIntegral a)
m
basicUnsafeIMapRowM :: STMatrix (PrimState m) (WrapIntegral a)
-> Int -> (Int -> WrapIntegral a -> m (WrapIntegral a)) -> m ()
basicUnsafeIMapRowM (STMat Int
_ Int
c STMatrix (PrimState m) (WrapIntegral a)
m) Int
i Int -> WrapIntegral a -> m (WrapIntegral a)
f = [Int] -> (Int -> m ()) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Int
0..Int
cInt -> Int -> Int
forall r. Group r => r -> r -> r
-Int
1] ((Int -> m ()) -> m ()) -> (Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
j ->
ST (PrimState m) () -> m ()
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) () -> m ())
-> (WrapIntegral a -> ST (PrimState m) ())
-> WrapIntegral a
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. STMatrix (PrimState m) (WrapIntegral a)
-> Int -> Int -> WrapIntegral a -> ST (PrimState m) ()
forall t s.
Storable t =>
STMatrix s t -> Int -> Int -> t -> ST s ()
LA.writeMatrix STMatrix (PrimState m) (WrapIntegral a)
m Int
i Int
j (WrapIntegral a -> m ()) -> m (WrapIntegral a) -> m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int -> WrapIntegral a -> m (WrapIntegral a)
f Int
j (WrapIntegral a -> m (WrapIntegral a))
-> m (WrapIntegral a) -> m (WrapIntegral a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ST (PrimState m) (WrapIntegral a) -> m (WrapIntegral a)
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (STMatrix (PrimState m) (WrapIntegral a)
-> Int -> Int -> ST (PrimState m) (WrapIntegral a)
forall t s. Storable t => STMatrix s t -> Int -> Int -> ST s t
LA.readMatrix STMatrix (PrimState m) (WrapIntegral a)
m Int
i Int
j)
toRows :: STMatrix (PrimState m) (WrapIntegral a)
-> m [Row STMatrix (WrapIntegral a)]
toRows (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapIntegral a)
m) =
ST (PrimState m) [Vector (WrapIntegral a)]
-> m [Vector (WrapIntegral a)]
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) [Vector (WrapIntegral a)]
-> m [Vector (WrapIntegral a)])
-> ST (PrimState m) [Vector (WrapIntegral a)]
-> m [Vector (WrapIntegral a)]
forall a b. (a -> b) -> a -> b
$ [Vector a] -> [Vector (WrapIntegral a)]
DC.coerce ([Vector a] -> [Vector (WrapIntegral a)])
-> (Matrix a -> [Vector a])
-> Matrix a
-> [Vector (WrapIntegral a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toRows (Matrix a -> [Vector (WrapIntegral a)])
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) [Vector (WrapIntegral a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapIntegral a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapIntegral a) -> STMatrix s a
castSTMatrixIntegral STMatrix (PrimState m) (WrapIntegral a)
m)
toColumns :: STMatrix (PrimState m) (WrapIntegral a)
-> m [Column STMatrix (WrapIntegral a)]
toColumns (STMat Int
_ Int
_ STMatrix (PrimState m) (WrapIntegral a)
m) =
ST (PrimState m) [Vector (WrapIntegral a)]
-> m [Vector (WrapIntegral a)]
forall (m :: * -> *) a. PrimMonad m => ST (PrimState m) a -> m a
stToPrim (ST (PrimState m) [Vector (WrapIntegral a)]
-> m [Vector (WrapIntegral a)])
-> ST (PrimState m) [Vector (WrapIntegral a)]
-> m [Vector (WrapIntegral a)]
forall a b. (a -> b) -> a -> b
$ [Vector a] -> [Vector (WrapIntegral a)]
DC.coerce ([Vector a] -> [Vector (WrapIntegral a)])
-> (Matrix a -> [Vector a])
-> Matrix a
-> [Vector (WrapIntegral a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix a -> [Vector a]
forall t. Element t => Matrix t -> [Vector t]
LA.toColumns (Matrix a -> [Vector (WrapIntegral a)])
-> ST (PrimState m) (Matrix a)
-> ST (PrimState m) [Vector (WrapIntegral a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STMatrix (PrimState m) a -> ST (PrimState m) (Matrix a)
forall t s. Storable t => STMatrix s t -> ST s (Matrix t)
LA.unsafeFreezeMatrix (STMatrix (PrimState m) (WrapIntegral a) -> STMatrix (PrimState m) a
forall s a. STMatrix s (WrapIntegral a) -> STMatrix s a
castSTMatrixIntegral STMatrix (PrimState m) (WrapIntegral a)
m)
instance {-# OVERLAPPING #-} (LA.Container LA.Matrix a, Show a) => Show (LA.Matrix (WrapNum a)) where
showsPrec :: Int -> Matrix (WrapNum a) -> ShowS
showsPrec Int
d = Int -> Matrix a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
d (Matrix a -> ShowS)
-> (Matrix (WrapNum a) -> Matrix a) -> Matrix (WrapNum a) -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Matrix (WrapNum a) -> Matrix a
DC.coerce :: LA.Matrix (WrapNum a) -> LA.Matrix a)
instance {-# OVERLAPPING #-} (LA.Container LA.Matrix a, Show a) => Show (LA.Matrix (WrapIntegral a)) where
showsPrec :: Int -> Matrix (WrapIntegral a) -> ShowS
showsPrec Int
d = Int -> Matrix a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
d (Matrix a -> ShowS)
-> (Matrix (WrapIntegral a) -> Matrix a)
-> Matrix (WrapIntegral a)
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Matrix (WrapIntegral a) -> Matrix a
DC.coerce :: LA.Matrix (WrapIntegral a) -> LA.Matrix a)
instance {-# OVERLAPPING #-} (LA.Container LA.Matrix a, Show a) => Show (LA.Matrix (WrapFractional a)) where
showsPrec :: Int -> Matrix (WrapFractional a) -> ShowS
showsPrec Int
d = Int -> Matrix a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
d (Matrix a -> ShowS)
-> (Matrix (WrapFractional a) -> Matrix a)
-> Matrix (WrapFractional a)
-> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Matrix (WrapFractional a) -> Matrix a
DC.coerce :: LA.Matrix (WrapFractional a) -> LA.Matrix a)