module Numeric.LAPACK.Matrix.HermitianPositiveDefinite (
   solve,
   solveDecomposed,
   inverse,
   decompose,
   determinant,
   ) where

import qualified Numeric.LAPACK.Matrix.HermitianPositiveDefinite.Linear
                                                                  as Linear
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Extent as Extent
import Numeric.LAPACK.Matrix.Array.Triangular (Hermitian, Upper)
import Numeric.LAPACK.Matrix.Array (Full)
import Numeric.LAPACK.Scalar (RealOf)

import qualified Numeric.Netlib.Class as Class

import qualified Data.Array.Comfort.Shape as Shape


solve ::
   (Extent.C vert, Extent.C horiz,
    Shape.C sh, Eq sh, Shape.C nrhs, Class.Floating a) =>
   Hermitian sh a -> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
solve :: Hermitian sh a
-> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
solve = (Array (Hermitian sh) a
 -> Array (Full vert horiz sh nrhs) a
 -> Array (Full vert horiz sh nrhs) a)
-> Hermitian sh a
-> Full vert horiz sh nrhs a
-> Full vert horiz sh nrhs a
forall shA a shB b shC c.
(Array shA a -> Array shB b -> Array shC c)
-> ArrayMatrix shA a -> ArrayMatrix shB b -> ArrayMatrix shC c
ArrMatrix.lift2 Array (Hermitian sh) a
-> Array (Full vert horiz sh nrhs) a
-> Array (Full vert horiz sh nrhs) a
forall vert horiz sh nrhs a.
(C vert, C horiz, C sh, Eq sh, C nrhs, Floating a) =>
Hermitian sh a
-> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
Linear.solve

{- |
> solve a b == solveDecomposed (decompose a) b
> solve (gramian u) b == solveDecomposed u b
-}
solveDecomposed ::
   (Extent.C vert, Extent.C horiz,
    Shape.C sh, Eq sh, Shape.C nrhs, Class.Floating a) =>
   Upper sh a -> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
solveDecomposed :: Upper sh a
-> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
solveDecomposed = (Array (UpperTriangular NonUnit sh) a
 -> Array (Full vert horiz sh nrhs) a
 -> Array (Full vert horiz sh nrhs) a)
-> Upper sh a
-> Full vert horiz sh nrhs a
-> Full vert horiz sh nrhs a
forall shA a shB b shC c.
(Array shA a -> Array shB b -> Array shC c)
-> ArrayMatrix shA a -> ArrayMatrix shB b -> ArrayMatrix shC c
ArrMatrix.lift2 Array (UpperTriangular NonUnit sh) a
-> Array (Full vert horiz sh nrhs) a
-> Array (Full vert horiz sh nrhs) a
forall vert horiz sh nrhs a.
(C vert, C horiz, C sh, Eq sh, C nrhs, Floating a) =>
Upper sh a
-> Full vert horiz sh nrhs a -> Full vert horiz sh nrhs a
Linear.solveDecomposed

inverse :: (Shape.C sh, Class.Floating a) => Hermitian sh a -> Hermitian sh a
inverse :: Hermitian sh a -> Hermitian sh a
inverse = (Array (Hermitian sh) a -> Array (Hermitian sh) a)
-> Hermitian sh a -> Hermitian sh a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (Hermitian sh) a -> Array (Hermitian sh) a
forall sh a. (C sh, Floating a) => Hermitian sh a -> Hermitian sh a
Linear.inverse

{- |
Cholesky decomposition
-}
decompose :: (Shape.C sh, Class.Floating a) => Hermitian sh a -> Upper sh a
decompose :: Hermitian sh a -> Upper sh a
decompose = (Array (Hermitian sh) a -> Array (UpperTriangular NonUnit sh) a)
-> Hermitian sh a -> Upper sh a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (Hermitian sh) a -> Array (UpperTriangular NonUnit sh) a
forall sh a. (C sh, Floating a) => Hermitian sh a -> Upper sh a
Linear.decompose

determinant :: (Shape.C sh, Class.Floating a) => Hermitian sh a -> RealOf a
determinant :: Hermitian sh a -> RealOf a
determinant = Hermitian sh a -> RealOf a
forall sh a. (C sh, Floating a) => Hermitian sh a -> RealOf a
Linear.determinant (Hermitian sh a -> RealOf a)
-> (Hermitian sh a -> Hermitian sh a) -> Hermitian sh a -> RealOf a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hermitian sh a -> Hermitian sh a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector