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

import qualified Numeric.LAPACK.Matrix.BandedHermitianPositiveDefinite.Linear
                                                                  as Linear
import qualified Numeric.LAPACK.Matrix.Array.Banded as Banded
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Extent as Extent
import Numeric.LAPACK.Matrix.Array (Full)
import Numeric.LAPACK.Scalar (RealOf)

import qualified Numeric.Netlib.Class as Class

import qualified Type.Data.Num.Unary as Unary

import qualified Data.Array.Comfort.Shape as Shape


solve ::
   (Unary.Natural offDiag, Shape.C size, Eq size,
    Extent.C vert, Extent.C horiz, Shape.C nrhs, Class.Floating a) =>
   Banded.Hermitian offDiag size a ->
   Full vert horiz size nrhs a -> Full vert horiz size nrhs a
solve :: Hermitian offDiag size a
-> Full vert horiz size nrhs a -> Full vert horiz size nrhs a
solve = (Array (BandedHermitian offDiag size) a
 -> Array (Full vert horiz size nrhs) a
 -> Array (Full vert horiz size nrhs) a)
-> Hermitian offDiag size a
-> Full vert horiz size nrhs a
-> Full vert horiz size 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 (BandedHermitian offDiag size) a
-> Array (Full vert horiz size nrhs) a
-> Array (Full vert horiz size nrhs) a
forall offDiag size vert horiz nrhs a.
(Natural offDiag, C size, Eq size, C vert, C horiz, C nrhs,
 Floating a) =>
BandedHermitian offDiag size a
-> Full vert horiz size nrhs a -> Full vert horiz size nrhs a
Linear.solve

{- |
> solve a b == solveDecomposed (decompose a) b
> solve (gramian u) b == solveDecomposed u b
-}
solveDecomposed ::
   (Unary.Natural offDiag, Shape.C size, Eq size,
    Extent.C vert, Extent.C horiz, Shape.C nrhs, Class.Floating a) =>
   Banded.Upper offDiag size a ->
   Full vert horiz size nrhs a -> Full vert horiz size nrhs a
solveDecomposed :: Upper offDiag size a
-> Full vert horiz size nrhs a -> Full vert horiz size nrhs a
solveDecomposed = (Array (BandedSquare U0 offDiag size) a
 -> Array (Full vert horiz size nrhs) a
 -> Array (Full vert horiz size nrhs) a)
-> Upper offDiag size a
-> Full vert horiz size nrhs a
-> Full vert horiz size 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 (BandedSquare U0 offDiag size) a
-> Array (Full vert horiz size nrhs) a
-> Array (Full vert horiz size nrhs) a
forall offDiag size vert horiz nrhs a.
(Natural offDiag, C size, Eq size, C vert, C horiz, C nrhs,
 Floating a) =>
Upper offDiag size a
-> Full vert horiz size nrhs a -> Full vert horiz size nrhs a
Linear.solveDecomposed

{- |
Cholesky decomposition
-}
decompose ::
   (Unary.Natural offDiag, Shape.C size, Class.Floating a) =>
   Banded.Hermitian offDiag size a -> Banded.Upper offDiag size a
decompose :: Hermitian offDiag size a -> Upper offDiag size a
decompose = (Array (BandedHermitian offDiag size) a
 -> Array (BandedSquare U0 offDiag size) a)
-> Hermitian offDiag size a -> Upper offDiag size a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (BandedHermitian offDiag size) a
-> Array (BandedSquare U0 offDiag size) a
forall offDiag size a.
(Natural offDiag, C size, Floating a) =>
BandedHermitian offDiag size a -> Upper offDiag size a
Linear.decompose

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