module Numeric.LAPACK.Orthogonal.Householder (
   Basic.Householder,
   Basic.General,
   Basic.Tall,
   Basic.Wide,
   Basic.Square,
   Basic.mapExtent,
   fromMatrix,
   Basic.determinant,
   Basic.determinantAbsolute,
   leastSquares,
   minimumNorm,

   Mod.Transposition(..),
   Mod.Conjugation(..),
   extractQ,
   extractR,
   multiplyQ,

   tallExtractQ,
   tallExtractR,
   tallMultiplyQ,
   tallMultiplyQAdjoint,
   tallMultiplyR,
   tallSolveR,
   ) where

import qualified Numeric.LAPACK.Orthogonal.Private as Basic
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Extent as Extent
import qualified Numeric.LAPACK.Matrix.Modifier as Mod
import Numeric.LAPACK.Orthogonal.Private (Householder)
import Numeric.LAPACK.Matrix.Array.Triangular (Upper)
import Numeric.LAPACK.Matrix.Array (Full, Square)
import Numeric.LAPACK.Matrix.Modifier (Transposition, Conjugation)

import qualified Numeric.Netlib.Class as Class

import qualified Data.Array.Comfort.Shape as Shape


fromMatrix ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Full vert horiz height width a ->
   Householder vert horiz height width a
fromMatrix :: Full vert horiz height width a
-> Householder vert horiz height width a
fromMatrix = Full vert horiz height width a
-> Householder vert horiz height width a
forall vert horiz height width a.
(C vert, C horiz, C height, C width, Floating a) =>
Full vert horiz height width a
-> Householder vert horiz height width a
Basic.fromMatrix (Full vert horiz height width a
 -> Householder vert horiz height width a)
-> (Full vert horiz height width a
    -> Full vert horiz height width a)
-> Full vert horiz height width a
-> Householder vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full vert horiz height width a -> Full vert horiz height width a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector

leastSquares ::
   (Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Eq width, Shape.C nrhs,
    Class.Floating a) =>
   Householder horiz Extent.Small height width a ->
   Full vert horiz height nrhs a ->
   Full vert horiz width nrhs a
leastSquares :: Householder horiz Small height width a
-> Full vert horiz height nrhs a -> Full vert horiz width nrhs a
leastSquares = (Array (Full vert horiz height nrhs) a
 -> Array (Full vert horiz width nrhs) a)
-> Full vert horiz height nrhs a -> Full vert horiz width nrhs a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Full vert horiz height nrhs) a
  -> Array (Full vert horiz width nrhs) a)
 -> Full vert horiz height nrhs a -> Full vert horiz width nrhs a)
-> (Householder horiz Small height width a
    -> Array (Full vert horiz height nrhs) a
    -> Array (Full vert horiz width nrhs) a)
-> Householder horiz Small height width a
-> Full vert horiz height nrhs a
-> Full vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder horiz Small height width a
-> Array (Full vert horiz height nrhs) a
-> Array (Full vert horiz width nrhs) a
forall vert horiz height width nrhs a.
(C vert, C horiz, C height, Eq height, C width, Eq width, C nrhs,
 Floating a) =>
Householder horiz Small height width a
-> Full vert horiz height nrhs a -> Full vert horiz width nrhs a
Basic.leastSquares

{- |
@
HH.minimumNorm (HH.fromMatrix a) b
==
Ortho.minimumNorm (adjoint a) b
@
-}
minimumNorm ::
   (Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Eq width, Shape.C nrhs,
    Class.Floating a) =>
   Householder vert Extent.Small width height a ->
   Full vert horiz height nrhs a ->
   Full vert horiz width nrhs a
minimumNorm :: Householder vert Small width height a
-> Full vert horiz height nrhs a -> Full vert horiz width nrhs a
minimumNorm = (Array (Full vert horiz height nrhs) a
 -> Array (Full vert horiz width nrhs) a)
-> Full vert horiz height nrhs a -> Full vert horiz width nrhs a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Full vert horiz height nrhs) a
  -> Array (Full vert horiz width nrhs) a)
 -> Full vert horiz height nrhs a -> Full vert horiz width nrhs a)
-> (Householder vert Small width height a
    -> Array (Full vert horiz height nrhs) a
    -> Array (Full vert horiz width nrhs) a)
-> Householder vert Small width height a
-> Full vert horiz height nrhs a
-> Full vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder vert Small width height a
-> Array (Full vert horiz height nrhs) a
-> Array (Full vert horiz width nrhs) a
forall vert horiz height width nrhs a.
(C vert, C horiz, C height, Eq height, C width, Eq width, C nrhs,
 Floating a) =>
Householder vert Small width height a
-> Full vert horiz height nrhs a -> Full vert horiz width nrhs a
Basic.minimumNorm


extractQ ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Householder vert horiz height width a -> Square height a
extractQ :: Householder vert horiz height width a -> Square height a
extractQ = Array (Square height) a -> Square height a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (Square height) a -> Square height a)
-> (Householder vert horiz height width a
    -> Array (Square height) a)
-> Householder vert horiz height width a
-> Square height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder vert horiz height width a -> Array (Square height) a
forall vert horiz height width a.
(C vert, C horiz, C height, C width, Floating a) =>
Householder vert horiz height width a -> Square height a
Basic.extractQ

tallExtractQ ::
   (Extent.C vert, Shape.C height, Shape.C width, Class.Floating a) =>
   Householder vert Extent.Small height width a ->
   Full vert Extent.Small height width a
tallExtractQ :: Householder vert Small height width a
-> Full vert Small height width a
tallExtractQ = Array (Full vert Small height width) a
-> Full vert Small height width a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (Full vert Small height width) a
 -> Full vert Small height width a)
-> (Householder vert Small height width a
    -> Array (Full vert Small height width) a)
-> Householder vert Small height width a
-> Full vert Small height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder vert Small height width a
-> Array (Full vert Small height width) a
forall vert height width a.
(C vert, C height, C width, Floating a) =>
Householder vert Small height width a
-> Full vert Small height width a
Basic.tallExtractQ


tallMultiplyQ ::
   (Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Shape.C fuse, Eq fuse,
    Class.Floating a) =>
   Householder vert Extent.Small height fuse a ->
   Full vert horiz fuse width a ->
   Full vert horiz height width a
tallMultiplyQ :: Householder vert Small height fuse a
-> Full vert horiz fuse width a -> Full vert horiz height width a
tallMultiplyQ = (Array (Full vert horiz fuse width) a
 -> Array (Full vert horiz height width) a)
-> Full vert horiz fuse width a -> Full vert horiz height width a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Full vert horiz fuse width) a
  -> Array (Full vert horiz height width) a)
 -> Full vert horiz fuse width a -> Full vert horiz height width a)
-> (Householder vert Small height fuse a
    -> Array (Full vert horiz fuse width) a
    -> Array (Full vert horiz height width) a)
-> Householder vert Small height fuse a
-> Full vert horiz fuse width a
-> Full vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder vert Small height fuse a
-> Array (Full vert horiz fuse width) a
-> Array (Full vert horiz height width) a
forall vert horiz height width fuse a.
(C vert, C horiz, C height, Eq height, C width, C fuse, Eq fuse,
 Floating a) =>
Householder vert Small height fuse a
-> Full vert horiz fuse width a -> Full vert horiz height width a
Basic.tallMultiplyQ

tallMultiplyQAdjoint ::
   (Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Shape.C fuse, Eq fuse, Class.Floating a) =>
   Householder horiz Extent.Small fuse height a ->
   Full vert horiz fuse width a ->
   Full vert horiz height width a
tallMultiplyQAdjoint :: Householder horiz Small fuse height a
-> Full vert horiz fuse width a -> Full vert horiz height width a
tallMultiplyQAdjoint = (Array (Full vert horiz fuse width) a
 -> Array (Full vert horiz height width) a)
-> Full vert horiz fuse width a -> Full vert horiz height width a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Full vert horiz fuse width) a
  -> Array (Full vert horiz height width) a)
 -> Full vert horiz fuse width a -> Full vert horiz height width a)
-> (Householder horiz Small fuse height a
    -> Array (Full vert horiz fuse width) a
    -> Array (Full vert horiz height width) a)
-> Householder horiz Small fuse height a
-> Full vert horiz fuse width a
-> Full vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder horiz Small fuse height a
-> Array (Full vert horiz fuse width) a
-> Array (Full vert horiz height width) a
forall vert horiz height width fuse a.
(C vert, C horiz, C height, C width, C fuse, Eq fuse,
 Floating a) =>
Householder horiz Small fuse height a
-> Full vert horiz fuse width a -> Full vert horiz height width a
Basic.tallMultiplyQAdjoint


multiplyQ ::
   (Extent.C vertA, Extent.C horizA, Shape.C widthA,
    Extent.C vertB, Extent.C horizB, Shape.C widthB,
    Shape.C height, Eq height, Class.Floating a) =>
   Transposition -> Conjugation ->
   Householder vertA horizA height widthA a ->
   Full vertB horizB height widthB a ->
   Full vertB horizB height widthB a
multiplyQ :: Transposition
-> Conjugation
-> Householder vertA horizA height widthA a
-> Full vertB horizB height widthB a
-> Full vertB horizB height widthB a
multiplyQ Transposition
transposed Conjugation
conjugated =
   (Array (Full vertB horizB height widthB) a
 -> Array (Full vertB horizB height widthB) a)
-> Full vertB horizB height widthB a
-> Full vertB horizB height widthB a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Full vertB horizB height widthB) a
  -> Array (Full vertB horizB height widthB) a)
 -> Full vertB horizB height widthB a
 -> Full vertB horizB height widthB a)
-> (Householder vertA horizA height widthA a
    -> Array (Full vertB horizB height widthB) a
    -> Array (Full vertB horizB height widthB) a)
-> Householder vertA horizA height widthA a
-> Full vertB horizB height widthB a
-> Full vertB horizB height widthB a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transposition
-> Conjugation
-> Householder vertA horizA height widthA a
-> Array (Full vertB horizB height widthB) a
-> Array (Full vertB horizB height widthB) a
forall vertA horizA widthA vertB horizB widthB height a.
(C vertA, C horizA, C widthA, C vertB, C horizB, C widthB,
 C height, Eq height, Floating a) =>
Transposition
-> Conjugation
-> Householder vertA horizA height widthA a
-> Full vertB horizB height widthB a
-> Full vertB horizB height widthB a
Basic.multiplyQ Transposition
transposed Conjugation
conjugated


extractR ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Householder vert horiz height width a ->
   Full vert horiz height width a
extractR :: Householder vert horiz height width a
-> Full vert horiz height width a
extractR = Array (Full vert horiz height width) a
-> Full vert horiz height width a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (Full vert horiz height width) a
 -> Full vert horiz height width a)
-> (Householder vert horiz height width a
    -> Array (Full vert horiz height width) a)
-> Householder vert horiz height width a
-> Full vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder vert horiz height width a
-> Array (Full vert horiz height width) a
forall vert horiz height width a.
(C vert, C horiz, C height, C width, Floating a) =>
Householder vert horiz height width a
-> Full vert horiz height width a
Basic.extractR

tallExtractR ::
   (Extent.C vert, Shape.C height, Shape.C width, Class.Floating a) =>
   Householder vert Extent.Small height width a -> Upper width a
tallExtractR :: Householder vert Small height width a -> Upper width a
tallExtractR = Array (UpperTriangular NonUnit width) a -> Upper width a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (UpperTriangular NonUnit width) a -> Upper width a)
-> (Householder vert Small height width a
    -> Array (UpperTriangular NonUnit width) a)
-> Householder vert Small height width a
-> Upper width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder vert Small height width a
-> Array (UpperTriangular NonUnit width) a
forall vert height width a.
(C vert, C height, C width, Floating a) =>
Householder vert Small height width a -> Upper width a
Basic.tallExtractR

tallMultiplyR ::
   (Extent.C vertA, Extent.C vert, Extent.C horiz, Shape.C height, Eq height,
    Shape.C heightA, Shape.C widthB, Class.Floating a) =>
   Transposition ->
   Householder vertA Extent.Small heightA height a ->
   Full vert horiz height widthB a ->
   Full vert horiz height widthB a
tallMultiplyR :: Transposition
-> Householder vertA Small heightA height a
-> Full vert horiz height widthB a
-> Full vert horiz height widthB a
tallMultiplyR Transposition
transposed = (Array (Full vert horiz height widthB) a
 -> Array (Full vert horiz height widthB) a)
-> Full vert horiz height widthB a
-> Full vert horiz height widthB a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Full vert horiz height widthB) a
  -> Array (Full vert horiz height widthB) a)
 -> Full vert horiz height widthB a
 -> Full vert horiz height widthB a)
-> (Householder vertA Small heightA height a
    -> Array (Full vert horiz height widthB) a
    -> Array (Full vert horiz height widthB) a)
-> Householder vertA Small heightA height a
-> Full vert horiz height widthB a
-> Full vert horiz height widthB a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transposition
-> Householder vertA Small heightA height a
-> Array (Full vert horiz height widthB) a
-> Array (Full vert horiz height widthB) a
forall vertA vert horiz height heightA widthB a.
(C vertA, C vert, C horiz, C height, Eq height, C heightA,
 C widthB, Floating a) =>
Transposition
-> Householder vertA Small heightA height a
-> Full vert horiz height widthB a
-> Full vert horiz height widthB a
Basic.tallMultiplyR Transposition
transposed

tallSolveR ::
   (Extent.C vertA, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Shape.C nrhs, Class.Floating a) =>
   Transposition -> Conjugation ->
   Householder vertA Extent.Small height width a ->
   Full vert horiz width nrhs a -> Full vert horiz width nrhs a
tallSolveR :: Transposition
-> Conjugation
-> Householder vertA Small height width a
-> Full vert horiz width nrhs a
-> Full vert horiz width nrhs a
tallSolveR Transposition
transposed Conjugation
conjugated =
   (Array (Full vert horiz width nrhs) a
 -> Array (Full vert horiz width nrhs) a)
-> Full vert horiz width nrhs a -> Full vert horiz width nrhs a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 ((Array (Full vert horiz width nrhs) a
  -> Array (Full vert horiz width nrhs) a)
 -> Full vert horiz width nrhs a -> Full vert horiz width nrhs a)
-> (Householder vertA Small height width a
    -> Array (Full vert horiz width nrhs) a
    -> Array (Full vert horiz width nrhs) a)
-> Householder vertA Small height width a
-> Full vert horiz width nrhs a
-> Full vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transposition
-> Conjugation
-> Householder vertA Small height width a
-> Array (Full vert horiz width nrhs) a
-> Array (Full vert horiz width nrhs) a
forall vertA vert horiz height width nrhs a.
(C vertA, C vert, C horiz, C height, C width, Eq width, C nrhs,
 Floating a) =>
Transposition
-> Conjugation
-> Householder vertA Small height width a
-> Full vert horiz width nrhs a
-> Full vert horiz width nrhs a
Basic.tallSolveR Transposition
transposed Conjugation
conjugated