{-# LANGUAGE TypeFamilies #-}
module Numeric.LAPACK.Singular (
   values,
   valuesTall,
   valuesWide,
   decompose,
   decomposeTall,
   decomposeWide,
   determinantAbsolute,
   leastSquaresMinimumNormRCond,
   pseudoInverseRCond,
   decomposePolar,
   RealOf,
   ) where

import qualified Numeric.LAPACK.Singular.Plain as Plain

import qualified Numeric.LAPACK.Matrix.Hermitian.Basic as HermitianBasic
import qualified Numeric.LAPACK.Matrix.Hermitian as Hermitian
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import qualified Numeric.LAPACK.Matrix.Basic as Basic
import qualified Numeric.LAPACK.Matrix as Matrix
import qualified Numeric.LAPACK.Shape as ExtShape
import Numeric.LAPACK.Matrix.Array (ArrayMatrix, Full, General, Square)
import Numeric.LAPACK.Matrix.Multiply ((##*#), (#*##))
import Numeric.LAPACK.Vector (Vector)
import Numeric.LAPACK.Scalar (RealOf)

import qualified Numeric.Netlib.Class as Class

import qualified Data.Array.Comfort.Shape as Shape
import Data.Array.Comfort.Storable (Array)

import Data.Tuple.HT (mapFst, mapSnd, mapPair, mapTriple)


values ::
   (Shape.C height, Shape.C width, Class.Floating a) =>
   General height width a -> Vector (ExtShape.Min height width) (RealOf a)
values :: General height width a -> Vector (Min height width) (RealOf a)
values = General height width a -> Vector (Min height width) (RealOf a)
forall height width a.
(C height, C width, Floating a) =>
General height width a -> Vector (Min height width) (RealOf a)
Plain.values (General height width a -> Vector (Min height width) (RealOf a))
-> (General height width a -> General height width a)
-> General height width a
-> Vector (Min height width) (RealOf a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. General height width a -> General height width a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector

valuesTall ::
   (Extent.C vert, Shape.C height, Shape.C width, Class.Floating a) =>
   Full vert Extent.Small height width a -> Vector width (RealOf a)
valuesTall :: Full vert Small height width a -> Vector width (RealOf a)
valuesTall = Full vert Small height width a -> Vector width (RealOf a)
forall vert height width a.
(C vert, C height, C width, Floating a) =>
Full vert Small height width a -> Vector width (RealOf a)
Plain.valuesTall (Full vert Small height width a -> Vector width (RealOf a))
-> (Full vert Small height width a
    -> Full vert Small height width a)
-> Full vert Small height width a
-> Vector width (RealOf a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full vert Small height width a -> Full vert Small height width a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector

valuesWide ::
   (Extent.C horiz, Shape.C height, Shape.C width, Class.Floating a) =>
   Full Extent.Small horiz height width a -> Vector height (RealOf a)
valuesWide :: Full Small horiz height width a -> Vector height (RealOf a)
valuesWide = Full Small horiz height width a -> Vector height (RealOf a)
forall horiz height width a.
(C horiz, C height, C width, Floating a) =>
Full Small horiz height width a -> Vector height (RealOf a)
Plain.valuesWide (Full Small horiz height width a -> Vector height (RealOf a))
-> (Full Small horiz height width a
    -> Full Small horiz height width a)
-> Full Small horiz height width a
-> Vector height (RealOf a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Small horiz height width a -> Full Small horiz height width a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector


determinantAbsolute ::
   (Shape.C height, Shape.C width, Class.Floating a) =>
   General height width a -> RealOf a
determinantAbsolute :: General height width a -> RealOf a
determinantAbsolute = General height width a -> RealOf a
forall height width a.
(C height, C width, Floating a) =>
General height width a -> RealOf a
Plain.determinantAbsolute (General height width a -> RealOf a)
-> (General height width a -> General height width a)
-> General height width a
-> RealOf a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. General height width a -> General height width a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector


decompose ::
   (Shape.C height, Shape.C width, Class.Floating a) =>
   General height width a ->
   (Square height a,
    Vector (ExtShape.Min height width) (RealOf a),
    Square width a)
decompose :: General height width a
-> (Square height a, Vector (Min height width) (RealOf a),
    Square width a)
decompose = (Array (General height width) a
 -> (Array (Square height) a, Vector (Min height width) (RealOf a),
     Array (Square width) a))
-> General height width a
-> (Square height a, Vector (Min height width) (RealOf a),
    Square width a)
forall sha a shb b f shc c.
(Array sha a -> (Array shb b, f, Array shc c))
-> ArrayMatrix sha a -> (ArrayMatrix shb b, f, ArrayMatrix shc c)
liftDecompose Array (General height width) a
-> (Array (Square height) a, Vector (Min height width) (RealOf a),
    Array (Square width) a)
forall height width a.
(C height, C width, Floating a) =>
General height width a
-> (Square height a, Vector (Min height width) (RealOf a),
    Square width a)
Plain.decompose

{- |
> let (u,s,vt) = Singular.decomposeWide a
> in a  ==  u #*## Matrix.scaleRowsReal s vt
-}
decomposeWide ::
   (Extent.C horiz, Shape.C height, Shape.C width, Class.Floating a) =>
   Full Extent.Small horiz height width a ->
   (Square height a, Vector height (RealOf a),
      Full Extent.Small horiz height width a)
decomposeWide :: Full Small horiz height width a
-> (Square height a, Vector height (RealOf a),
    Full Small horiz height width a)
decomposeWide = (Array (Full Small horiz height width) a
 -> (Array (Square height) a, Vector height (RealOf a),
     Array (Full Small horiz height width) a))
-> Full Small horiz height width a
-> (Square height a, Vector height (RealOf a),
    Full Small horiz height width a)
forall sha a shb b f shc c.
(Array sha a -> (Array shb b, f, Array shc c))
-> ArrayMatrix sha a -> (ArrayMatrix shb b, f, ArrayMatrix shc c)
liftDecompose Array (Full Small horiz height width) a
-> (Array (Square height) a, Vector height (RealOf a),
    Array (Full Small horiz height width) a)
forall horiz height width a.
(C horiz, C height, C width, Floating a) =>
Full Small horiz height width a
-> (Square height a, Vector height (RealOf a),
    Full Small horiz height width a)
Plain.decomposeWide

{- |
> let (u,s,vt) = Singular.decomposeTall a
> in a  ==  u ##*# Matrix.scaleRowsReal s vt
-}
decomposeTall ::
   (Extent.C vert, Shape.C height, Shape.C width, Class.Floating a) =>
   Full vert Extent.Small height width a ->
   (Full vert Extent.Small height width a,
      Vector width (RealOf a), Square width a)
decomposeTall :: Full vert Small height width a
-> (Full vert Small height width a, Vector width (RealOf a),
    Square width a)
decomposeTall = (Array (Full vert Small height width) a
 -> (Array (Full vert Small height width) a,
     Vector width (RealOf a), Array (Square width) a))
-> Full vert Small height width a
-> (Full vert Small height width a, Vector width (RealOf a),
    Square width a)
forall sha a shb b f shc c.
(Array sha a -> (Array shb b, f, Array shc c))
-> ArrayMatrix sha a -> (ArrayMatrix shb b, f, ArrayMatrix shc c)
liftDecompose Array (Full vert Small height width) a
-> (Array (Full vert Small height width) a,
    Vector width (RealOf a), Array (Square width) a)
forall vert height width a.
(C vert, C height, C width, Floating a) =>
Full vert Small height width a
-> (Full vert Small height width a, Vector width (RealOf a),
    Square width a)
Plain.decomposeTall

liftDecompose ::
   (Array sha a -> (Array shb b, f, Array shc c)) ->
   ArrayMatrix sha a -> (ArrayMatrix shb b, f, ArrayMatrix shc c)
liftDecompose :: (Array sha a -> (Array shb b, f, Array shc c))
-> ArrayMatrix sha a -> (ArrayMatrix shb b, f, ArrayMatrix shc c)
liftDecompose Array sha a -> (Array shb b, f, Array shc c)
f =
   (Array shb b -> ArrayMatrix shb b, f -> f,
 Array shc c -> ArrayMatrix shc c)
-> (Array shb b, f, Array shc c)
-> (ArrayMatrix shb b, f, ArrayMatrix shc c)
forall a d b e c f.
(a -> d, b -> e, c -> f) -> (a, b, c) -> (d, e, f)
mapTriple (Array shb b -> ArrayMatrix shb b
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0, f -> f
forall a. a -> a
id, Array shc c -> ArrayMatrix shc c
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0) ((Array shb b, f, Array shc c)
 -> (ArrayMatrix shb b, f, ArrayMatrix shc c))
-> (ArrayMatrix sha a -> (Array shb b, f, Array shc c))
-> ArrayMatrix sha a
-> (ArrayMatrix shb b, f, ArrayMatrix shc c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array sha a -> (Array shb b, f, Array shc c)
f (Array sha a -> (Array shb b, f, Array shc c))
-> (ArrayMatrix sha a -> Array sha a)
-> ArrayMatrix sha a
-> (Array shb b, f, Array shc c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayMatrix sha a -> Array sha a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector



leastSquaresMinimumNormRCond ::
   (Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Shape.C nrhs, Class.Floating a) =>
   RealOf a ->
   Full horiz vert height width a ->
   Full vert horiz height nrhs a ->
   (Int, Full vert horiz width nrhs a)
leastSquaresMinimumNormRCond :: RealOf a
-> Full horiz vert height width a
-> Full vert horiz height nrhs a
-> (Int, Full vert horiz width nrhs a)
leastSquaresMinimumNormRCond RealOf a
rcond Full horiz vert height width a
a Full vert horiz height nrhs a
b =
   (Array (Full vert horiz width nrhs) a
 -> Full vert horiz width nrhs a)
-> (Int, Array (Full vert horiz width nrhs) a)
-> (Int, Full vert horiz width nrhs a)
forall b c a. (b -> c) -> (a, b) -> (a, c)
mapSnd Array (Full vert horiz width nrhs) a
-> Full vert horiz width nrhs a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 ((Int, Array (Full vert horiz width nrhs) a)
 -> (Int, Full vert horiz width nrhs a))
-> (Int, Array (Full vert horiz width nrhs) a)
-> (Int, Full vert horiz width nrhs a)
forall a b. (a -> b) -> a -> b
$
   RealOf a
-> Full horiz vert height width a
-> Full vert horiz height nrhs a
-> (Int, Array (Full vert horiz width nrhs) a)
forall vert horiz height width nrhs a.
(C vert, C horiz, C height, Eq height, C width, C nrhs,
 Floating a) =>
RealOf a
-> Full horiz vert height width a
-> Full vert horiz height nrhs a
-> (Int, Full vert horiz width nrhs a)
Plain.leastSquaresMinimumNormRCond
      RealOf a
rcond (Full horiz vert height width a -> Full horiz vert height width a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector Full horiz vert height width a
a) (Full vert horiz height nrhs a -> Full vert horiz height nrhs a
forall sh a. ArrayMatrix sh a -> Array sh a
ArrMatrix.toVector Full vert horiz height nrhs a
b)

pseudoInverseRCond ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   RealOf a ->
   Full vert horiz height width a ->
   (Int, Full horiz vert width height a)
pseudoInverseRCond :: RealOf a
-> Full vert horiz height width a
-> (Int, Full horiz vert width height a)
pseudoInverseRCond RealOf a
rcond =
   (Full horiz vert (Unchecked width) (Unchecked height) a
 -> Full horiz vert width height a)
-> (Int, Full horiz vert (Unchecked width) (Unchecked height) a)
-> (Int, Full horiz vert width height a)
forall b c a. (b -> c) -> (a, b) -> (a, c)
mapSnd (Array (Full horiz vert width height) a
-> Full horiz vert width height a
forall shA a. Array shA a -> ArrayMatrix shA a
ArrMatrix.lift0 (Array (Full horiz vert width height) a
 -> Full horiz vert width height a)
-> (Full horiz vert (Unchecked width) (Unchecked height) a
    -> Array (Full horiz vert width height) a)
-> Full horiz vert (Unchecked width) (Unchecked height) a
-> Full horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full horiz vert (Unchecked width) (Unchecked height) a
-> Array (Full horiz vert width height) a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz (Unchecked height) (Unchecked width) a
-> Full vert horiz height width a
Basic.recheck) ((Int, Full horiz vert (Unchecked width) (Unchecked height) a)
 -> (Int, Full horiz vert width height a))
-> (Full vert horiz height width a
    -> (Int, Full horiz vert (Unchecked width) (Unchecked height) a))
-> Full vert horiz height width a
-> (Int, Full horiz vert width height a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   RealOf a
-> Full vert horiz (Unchecked height) (Unchecked width) a
-> (Int, Full horiz vert (Unchecked width) (Unchecked height) a)
forall vert horiz height width a.
(C vert, C horiz, C height, Eq height, C width, Eq width,
 Floating a) =>
RealOf a
-> Full vert horiz height width a
-> (Int, Full horiz vert width height a)
Plain.pseudoInverseRCond RealOf a
rcond (Full vert horiz (Unchecked height) (Unchecked width) a
 -> (Int, Full horiz vert (Unchecked width) (Unchecked height) a))
-> (Full vert horiz height width a
    -> Full vert horiz (Unchecked height) (Unchecked width) a)
-> Full vert horiz height width a
-> (Int, Full horiz vert (Unchecked width) (Unchecked height) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   Full vert horiz height width a
-> Full vert horiz (Unchecked height) (Unchecked width) a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a
-> Full vert horiz (Unchecked height) (Unchecked width) a
Basic.uncheck (Full vert horiz height width a
 -> Full vert horiz (Unchecked height) (Unchecked width) a)
-> (Full vert horiz height width a
    -> Full vert horiz height width a)
-> Full vert horiz height width a
-> Full vert horiz (Unchecked height) (Unchecked 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



decomposePolar ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Full vert horiz height width a ->
   (Full vert horiz height width a, Matrix.Hermitian width a)
decomposePolar :: Full vert horiz height width a
-> (Full vert horiz height width a, Hermitian width a)
decomposePolar =
   (ArrayMatrix
   (Full vert horiz (Unchecked height) (Unchecked width)) a
 -> Full vert horiz height width a,
 ArrayMatrix (Hermitian (Unchecked width)) a -> Hermitian width a)
-> (ArrayMatrix
      (Full vert horiz (Unchecked height) (Unchecked width)) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
-> (Full vert horiz height width a, Hermitian width a)
forall a c b d. (a -> c, b -> d) -> (a, b) -> (c, d)
mapPair
      ((Array (Full vert horiz (Unchecked height) (Unchecked width)) a
 -> Array (Full vert horiz height width) a)
-> ArrayMatrix
     (Full vert horiz (Unchecked height) (Unchecked 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 (Unchecked height) (Unchecked width)) a
-> Array (Full vert horiz height width) a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz (Unchecked height) (Unchecked width) a
-> Full vert horiz height width a
Basic.recheck,
       (Array (Hermitian (Unchecked width)) a
 -> Array (Hermitian width) a)
-> ArrayMatrix (Hermitian (Unchecked width)) a -> Hermitian width a
forall shA a shB b.
(Array shA a -> Array shB b)
-> ArrayMatrix shA a -> ArrayMatrix shB b
ArrMatrix.lift1 Array (Hermitian (Unchecked width)) a -> Array (Hermitian width) a
forall sh a. Hermitian (Unchecked sh) a -> Hermitian sh a
HermitianBasic.recheck)
   ((ArrayMatrix
    (Full vert horiz (Unchecked height) (Unchecked width)) a,
  ArrayMatrix (Hermitian (Unchecked width)) a)
 -> (Full vert horiz height width a, Hermitian width a))
-> (Full vert horiz height width a
    -> (ArrayMatrix
          (Full vert horiz (Unchecked height) (Unchecked width)) a,
        ArrayMatrix (Hermitian (Unchecked width)) a))
-> Full vert horiz height width a
-> (Full vert horiz height width a, Hermitian width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   DecomposePolar (Unchecked height) (Unchecked width) a vert horiz
-> ArrayMatrix
     (Full vert horiz (Unchecked height) (Unchecked width)) a
-> (ArrayMatrix
      (Full vert horiz (Unchecked height) (Unchecked width)) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall height width a vert horiz.
DecomposePolar height width a vert horiz
-> Full vert horiz height width a
-> (Full vert horiz height width a, Hermitian width a)
getDecomposePolar
      (DecomposePolar (Unchecked height) (Unchecked width) a Small Small
-> DecomposePolar (Unchecked height) (Unchecked width) a Small Big
-> DecomposePolar (Unchecked height) (Unchecked width) a Big Small
-> DecomposePolar (Unchecked height) (Unchecked width) a Big Big
-> DecomposePolar (Unchecked height) (Unchecked width) a vert horiz
forall vert horiz (f :: * -> * -> *).
(C vert, C horiz) =>
f Small Small
-> f Small Big -> f Big Small -> f Big Big -> f vert horiz
Extent.switchTagPair
         ((Full Small Small (Unchecked height) (Unchecked width) a
 -> (Full Small Small (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> DecomposePolar
     (Unchecked height) (Unchecked width) a Small Small
forall height width a vert horiz.
(Full vert horiz height width a
 -> (Full vert horiz height width a, Hermitian width a))
-> DecomposePolar height width a vert horiz
DecomposePolar Full Small Small (Unchecked height) (Unchecked width) a
-> (Full Small Small (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall horiz height width a.
(C horiz, C height, Eq height, C width, Eq width, Floating a) =>
Full Small horiz height width a
-> (Full Small horiz height width a, Hermitian width a)
decomposePolarWide)
         ((Full Small Big (Unchecked height) (Unchecked width) a
 -> (Full Small Big (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> DecomposePolar (Unchecked height) (Unchecked width) a Small Big
forall height width a vert horiz.
(Full vert horiz height width a
 -> (Full vert horiz height width a, Hermitian width a))
-> DecomposePolar height width a vert horiz
DecomposePolar Full Small Big (Unchecked height) (Unchecked width) a
-> (Full Small Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall horiz height width a.
(C horiz, C height, Eq height, C width, Eq width, Floating a) =>
Full Small horiz height width a
-> (Full Small horiz height width a, Hermitian width a)
decomposePolarWide)
         ((Full Big Small (Unchecked height) (Unchecked width) a
 -> (Full Big Small (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> DecomposePolar (Unchecked height) (Unchecked width) a Big Small
forall height width a vert horiz.
(Full vert horiz height width a
 -> (Full vert horiz height width a, Hermitian width a))
-> DecomposePolar height width a vert horiz
DecomposePolar Full Big Small (Unchecked height) (Unchecked width) a
-> (Full Big Small (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall vert height width a.
(C vert, C height, C width, Eq width, Floating a) =>
Full vert Small height width a
-> (Full vert Small height width a, Hermitian width a)
decomposePolarTall)
         ((Full Big Big (Unchecked height) (Unchecked width) a
 -> (Full Big Big (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> DecomposePolar (Unchecked height) (Unchecked width) a Big Big
forall height width a vert horiz.
(Full vert horiz height width a
 -> (Full vert horiz height width a, Hermitian width a))
-> DecomposePolar height width a vert horiz
DecomposePolar ((Full Big Big (Unchecked height) (Unchecked width) a
  -> (Full Big Big (Unchecked height) (Unchecked width) a,
      ArrayMatrix (Hermitian (Unchecked width)) a))
 -> DecomposePolar (Unchecked height) (Unchecked width) a Big Big)
-> (Full Big Big (Unchecked height) (Unchecked width) a
    -> (Full Big Big (Unchecked height) (Unchecked width) a,
        ArrayMatrix (Hermitian (Unchecked width)) a))
-> DecomposePolar (Unchecked height) (Unchecked width) a Big Big
forall a b. (a -> b) -> a -> b
$
            (Full Big Small (Unchecked height) (Unchecked width) a
 -> (Full Big Big (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> (Full Small Big (Unchecked height) (Unchecked width) a
    -> (Full Big Big (Unchecked height) (Unchecked width) a,
        ArrayMatrix (Hermitian (Unchecked width)) a))
-> Either
     (Full Big Small (Unchecked height) (Unchecked width) a)
     (Full Small Big (Unchecked height) (Unchecked width) a)
-> (Full Big Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
               ((Full Big Small (Unchecked height) (Unchecked width) a
 -> Full Big Big (Unchecked height) (Unchecked width) a)
-> (Full Big Small (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
-> (Full Big Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst Full Big Small (Unchecked height) (Unchecked width) a
-> Full Big Big (Unchecked height) (Unchecked width) a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> General height width a
Matrix.fromFull ((Full Big Small (Unchecked height) (Unchecked width) a,
  ArrayMatrix (Hermitian (Unchecked width)) a)
 -> (Full Big Big (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> (Full Big Small (Unchecked height) (Unchecked width) a
    -> (Full Big Small (Unchecked height) (Unchecked width) a,
        ArrayMatrix (Hermitian (Unchecked width)) a))
-> Full Big Small (Unchecked height) (Unchecked width) a
-> (Full Big Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Big Small (Unchecked height) (Unchecked width) a
-> (Full Big Small (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall vert height width a.
(C vert, C height, C width, Eq width, Floating a) =>
Full vert Small height width a
-> (Full vert Small height width a, Hermitian width a)
decomposePolarTall)
               ((Full Small Big (Unchecked height) (Unchecked width) a
 -> Full Big Big (Unchecked height) (Unchecked width) a)
-> (Full Small Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
-> (Full Big Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst Full Small Big (Unchecked height) (Unchecked width) a
-> Full Big Big (Unchecked height) (Unchecked width) a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> General height width a
Matrix.fromFull ((Full Small Big (Unchecked height) (Unchecked width) a,
  ArrayMatrix (Hermitian (Unchecked width)) a)
 -> (Full Big Big (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> (Full Small Big (Unchecked height) (Unchecked width) a
    -> (Full Small Big (Unchecked height) (Unchecked width) a,
        ArrayMatrix (Hermitian (Unchecked width)) a))
-> Full Small Big (Unchecked height) (Unchecked width) a
-> (Full Big Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Small Big (Unchecked height) (Unchecked width) a
-> (Full Small Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall horiz height width a.
(C horiz, C height, Eq height, C width, Eq width, Floating a) =>
Full Small horiz height width a
-> (Full Small horiz height width a, Hermitian width a)
decomposePolarWide)
            (Either
   (Full Big Small (Unchecked height) (Unchecked width) a)
   (Full Small Big (Unchecked height) (Unchecked width) a)
 -> (Full Big Big (Unchecked height) (Unchecked width) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> (Full Big Big (Unchecked height) (Unchecked width) a
    -> Either
         (Full Big Small (Unchecked height) (Unchecked width) a)
         (Full Small Big (Unchecked height) (Unchecked width) a))
-> Full Big Big (Unchecked height) (Unchecked width) a
-> (Full Big Big (Unchecked height) (Unchecked width) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
            Full Big Big (Unchecked height) (Unchecked width) a
-> Either
     (Full Big Small (Unchecked height) (Unchecked width) a)
     (Full Small Big (Unchecked height) (Unchecked width) a)
forall vert horiz height width a.
(C vert, C horiz, C height, C width) =>
Full vert horiz height width a
-> Either (Tall height width a) (Wide height width a)
Matrix.caseTallWide))
   (ArrayMatrix
   (Full vert horiz (Unchecked height) (Unchecked width)) a
 -> (ArrayMatrix
       (Full vert horiz (Unchecked height) (Unchecked width)) a,
     ArrayMatrix (Hermitian (Unchecked width)) a))
-> (Full vert horiz height width a
    -> ArrayMatrix
         (Full vert horiz (Unchecked height) (Unchecked width)) a)
-> Full vert horiz height width a
-> (ArrayMatrix
      (Full vert horiz (Unchecked height) (Unchecked width)) a,
    ArrayMatrix (Hermitian (Unchecked width)) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   (Array (Full vert horiz height width) a
 -> Array (Full vert horiz (Unchecked height) (Unchecked width)) a)
-> Full vert horiz height width a
-> ArrayMatrix
     (Full vert horiz (Unchecked height) (Unchecked 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 height width) a
-> Array (Full vert horiz (Unchecked height) (Unchecked width)) a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a
-> Full vert horiz (Unchecked height) (Unchecked width) a
Basic.uncheck

newtype DecomposePolar height width a vert horiz =
   DecomposePolar {
      DecomposePolar height width a vert horiz
-> Full vert horiz height width a
-> (Full vert horiz height width a, Hermitian width a)
getDecomposePolar ::
         Full vert horiz height width a ->
         (Full vert horiz height width a, Matrix.Hermitian width a)
   }

decomposePolarTall ::
   (Extent.C vert, Shape.C height, Shape.C width, Eq width,
    Class.Floating a) =>
   Full vert Extent.Small height width a ->
   (Full vert Extent.Small height width a, Matrix.Hermitian width a)
decomposePolarTall :: Full vert Small height width a
-> (Full vert Small height width a, Hermitian width a)
decomposePolarTall Full vert Small height width a
a =
   let (Full vert Small height width a
u,Vector width (RealOf a)
s,Square width a
vt) = Full vert Small height width a
-> (Full vert Small height width a, Vector width (RealOf a),
    Square width a)
forall vert height width a.
(C vert, C height, C width, Floating a) =>
Full vert Small height width a
-> (Full vert Small height width a, Vector width (RealOf a),
    Square width a)
decomposeTall Full vert Small height width a
a
   in (Full vert Small height width a
u Full vert Small height width a
-> Square width a -> Full vert Small height width a
forall typ width height vert horiz a.
(MultiplySquare typ, WidthOf typ ~ width, Eq width, C height,
 C vert, C horiz, Floating a) =>
Full vert horiz height width a
-> Matrix typ a -> Full vert horiz height width a
##*# Square width a
vt, Vector width (RealOf a)
-> General width width a -> Hermitian width a
forall height width a.
(C height, Eq height, C width, Floating a) =>
Vector height (RealOf a)
-> General height width a -> Hermitian width a
Hermitian.congruenceDiagonal Vector width (RealOf a)
s (General width width a -> Hermitian width a)
-> General width width a -> Hermitian width a
forall a b. (a -> b) -> a -> b
$ Square width a -> General width width a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> General height width a
Matrix.fromFull Square width a
vt)

decomposePolarWide ::
   (Extent.C horiz, Shape.C height, Eq height, Shape.C width, Eq width,
    Class.Floating a) =>
   Full Extent.Small horiz height width a ->
   (Full Extent.Small horiz height width a, Matrix.Hermitian width a)
decomposePolarWide :: Full Small horiz height width a
-> (Full Small horiz height width a, Hermitian width a)
decomposePolarWide Full Small horiz height width a
a =
   let (Square height a
u,Vector height (RealOf a)
s,Full Small horiz height width a
vt) = Full Small horiz height width a
-> (Square height a, Vector height (RealOf a),
    Full Small horiz height width a)
forall horiz height width a.
(C horiz, C height, C width, Floating a) =>
Full Small horiz height width a
-> (Square height a, Vector height (RealOf a),
    Full Small horiz height width a)
decomposeWide Full Small horiz height width a
a
   in (Square height a
u Square height a
-> Full Small horiz height width a
-> Full Small horiz height width a
forall typ height width vert horiz a.
(MultiplySquare typ, HeightOf typ ~ height, Eq height, C width,
 C vert, C horiz, Floating a) =>
Matrix typ a
-> Full vert horiz height width a -> Full vert horiz height width a
#*## Full Small horiz height width a
vt, Vector height (RealOf a)
-> General height width a -> Hermitian width a
forall height width a.
(C height, Eq height, C width, Floating a) =>
Vector height (RealOf a)
-> General height width a -> Hermitian width a
Hermitian.congruenceDiagonal Vector height (RealOf a)
s (General height width a -> Hermitian width a)
-> General height width a -> Hermitian width a
forall a b. (a -> b) -> a -> b
$ Full Small horiz height width a -> General height width a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> General height width a
Matrix.fromFull Full Small horiz height width a
vt)