module LAPACK.Common where
import Common (Reactant)
import qualified Numeric.LAPACK.Matrix.Shape as MatrixShape
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix as Matrix
import qualified Data.Array.Comfort.Storable as Array
import qualified Data.Array.Comfort.Boxed as BoxedArray
import qualified Data.Array.Comfort.Shape as Shape
import qualified Data.Map as Map
import Data.Set (Set)
toSquare :: (Shape.C sh) => Matrix.General sh sh a -> Matrix.Square sh a
toSquare a =
ArrMatrix.liftOmni1
(Array.reshape (MatrixShape.square (ArrMatrix.order a) (Matrix.height a)))
a
matrixFromReactantSet ::
Set Reactant -> Matrix.General (Set String) (Set Reactant) Double
matrixFromReactantSet reactantSet =
let elements = foldMap Map.keysSet reactantSet
in Matrix.fromColumnArray elements $
fmap (Array.fromAssociations 0 elements . Map.toList . fmap fromInteger) $
BoxedArray.indices reactantSet