{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE UndecidableInstances #-}
module Numeric.LAPACK.Matrix.Divide where

import qualified Numeric.LAPACK.Matrix.Multiply as Multiply
import qualified Numeric.LAPACK.Matrix.Array.Divide as ArrDivide
import qualified Numeric.LAPACK.Matrix.Array.Unpacked as Unpacked
import qualified Numeric.LAPACK.Matrix.Array.Private as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Permutation as PermMatrix
import qualified Numeric.LAPACK.Matrix.Type.Private as Matrix
import qualified Numeric.LAPACK.Matrix.Shape as MatrixShape
import qualified Numeric.LAPACK.Matrix.Shape.Omni as Omni
import qualified Numeric.LAPACK.Matrix.Layout.Private as Layout
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import qualified Numeric.LAPACK.Vector as Vector
import Numeric.LAPACK.Matrix.Array.Private (Full)
import Numeric.LAPACK.Matrix.Type.Private (scaleWithCheck)
import Numeric.LAPACK.Matrix.Modifier
         (Transposition(NonTransposed,Transposed),
          Inversion(Inverted))
import Numeric.LAPACK.Vector (Vector)

import qualified Numeric.Netlib.Class as Class

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

import Data.Semigroup ((<>))

import GHC.Exts (Constraint)


class (Matrix.Box typ) => Determinant typ where
   type DeterminantExtra typ extra :: Constraint
   determinant ::
      (DeterminantExtra typ xl, DeterminantExtra typ xu) =>
      (Omni.Strip lower, Omni.Strip upper) =>
      (Shape.C sh, Class.Floating a) =>
      Matrix.Quadratic typ xl xu lower upper sh a -> a

class (Matrix.Box typ) => Solve typ where
   type SolveExtra typ extra :: Constraint
   {-# MINIMAL solve | solveLeft,solveRight #-}
   solve ::
      (SolveExtra typ xl, SolveExtra typ xu) =>
      (Omni.Strip lower, Omni.Strip upper) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Eq height, Class.Floating a) =>
      Transposition ->
      Matrix.Quadratic typ xl xu lower upper height a ->
      Full meas vert horiz height width a ->
      Full meas vert horiz height width a
   solve Transposition
NonTransposed Quadratic typ xl xu lower upper height a
a Full meas vert horiz height width a
b = Quadratic typ xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall typ xl xu lower upper meas vert horiz height width a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Eq height, Floating a) =>
Quadratic typ xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solveRight Quadratic typ xl xu lower upper height a
a Full meas vert horiz height width a
b
   solve Transposition
Transposed Quadratic typ xl xu lower upper height a
a Full meas vert horiz height width a
b =
      Unpacked Arbitrary Filled Filled meas horiz vert width height a
-> Full meas vert horiz height width a
forall property lower upper meas vert horiz height width a.
(Property property, Strip lower, Strip upper, Measure meas, C vert,
 C horiz) =>
Unpacked property lower upper meas vert horiz height width a
-> Unpacked property upper lower meas horiz vert width height a
Unpacked.transpose (Unpacked Arbitrary Filled Filled meas horiz vert width height a
 -> Full meas vert horiz height width a)
-> Unpacked Arbitrary Filled Filled meas horiz vert width height a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ Unpacked Arbitrary Filled Filled meas horiz vert width height a
-> Quadratic typ xl xu lower upper height a
-> Unpacked Arbitrary Filled Filled meas horiz vert width height a
forall typ xl xu lower upper meas vert horiz height width a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Eq width, Floating a) =>
Full meas vert horiz height width a
-> Quadratic typ xl xu lower upper width a
-> Full meas vert horiz height width a
solveLeft (Full meas vert horiz height width a
-> Unpacked Arbitrary Filled Filled meas horiz vert width height a
forall property lower upper meas vert horiz height width a.
(Property property, Strip lower, Strip upper, Measure meas, C vert,
 C horiz) =>
Unpacked property lower upper meas vert horiz height width a
-> Unpacked property upper lower meas horiz vert width height a
Unpacked.transpose Full meas vert horiz height width a
b) Quadratic typ xl xu lower upper height a
a

   solveRight ::
      (SolveExtra typ xl, SolveExtra typ xu) =>
      (Omni.Strip lower, Omni.Strip upper) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Eq height, Class.Floating a) =>
      Matrix.Quadratic typ xl xu lower upper height a ->
      Full meas vert horiz height width a ->
      Full meas vert horiz height width a
   solveRight = Transposition
-> Quadratic typ xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall typ xl xu lower upper meas vert horiz height width a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Eq height, Floating a) =>
Transposition
-> Quadratic typ xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solve Transposition
NonTransposed

   solveLeft ::
      (SolveExtra typ xl, SolveExtra typ xu) =>
      (Omni.Strip lower, Omni.Strip upper) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
      Full meas vert horiz height width a ->
      Matrix.Quadratic typ xl xu lower upper width a ->
      Full meas vert horiz height width a
   solveLeft = (Quadratic typ xl xu lower upper width a
 -> Unpacked Arbitrary Filled Filled meas horiz vert width height a
 -> Unpacked Arbitrary Filled Filled meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Quadratic typ xl xu lower upper width a
-> Full meas vert horiz height width a
forall propertyA lowerA upperA propertyB lowerB upperB measA vertA
       horizA measB vertB horizB matrix widthA heightA a widthB heightB.
(Property propertyA, Strip lowerA, Strip upperA,
 Property propertyB, Strip lowerB, Strip upperB, Measure measA,
 C vertA, C horizA, Measure measB, C vertB, C horizB) =>
(matrix
 -> Unpacked
      propertyA upperA lowerA measA horizA vertA widthA heightA a
 -> Unpacked
      propertyB upperB lowerB measB horizB vertB widthB heightB a)
-> Unpacked
     propertyA lowerA upperA measA vertA horizA heightA widthA a
-> matrix
-> Unpacked
     propertyB lowerB upperB measB vertB horizB heightB widthB a
Unpacked.swapMultiply ((Quadratic typ xl xu lower upper width a
  -> Unpacked Arbitrary Filled Filled meas horiz vert width height a
  -> Unpacked Arbitrary Filled Filled meas horiz vert width height a)
 -> Full meas vert horiz height width a
 -> Quadratic typ xl xu lower upper width a
 -> Full meas vert horiz height width a)
-> (Quadratic typ xl xu lower upper width a
    -> Unpacked Arbitrary Filled Filled meas horiz vert width height a
    -> Unpacked Arbitrary Filled Filled meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Quadratic typ xl xu lower upper width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ Transposition
-> Quadratic typ xl xu lower upper width a
-> Unpacked Arbitrary Filled Filled meas horiz vert width height a
-> Unpacked Arbitrary Filled Filled meas horiz vert width height a
forall typ xl xu lower upper meas vert horiz height width a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Eq height, Floating a) =>
Transposition
-> Quadratic typ xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solve Transposition
Transposed

class (Solve typ) => Inverse typ where
   type InverseExtra typ extra :: Constraint
   inverse ::
      (InverseExtra typ xl, InverseExtra typ xu) =>
      (MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
       Extent.Measure meas, Shape.C height, Shape.C width, Class.Floating a) =>
      Matrix.QuadraticMeas typ xl xu lower upper meas height width a ->
      Matrix.QuadraticMeas typ xl xu lower upper meas width height a

infixl 7 ##/#
infixr 7 #\##

(#\##) ::
   (Solve typ, Matrix.ToQuadratic typ,
    SolveExtra typ xl, SolveExtra typ xu,
    Matrix.BoxExtra typ xl, Matrix.BoxExtra typ xu,
    Omni.Strip lower, Omni.Strip upper,
    Shape.C height, Eq height, Shape.C width, Shape.C nrhs,
    Extent.Measure measA, Extent.Measure measB, Extent.Measure measC,
    Extent.MultiplyMeasure measA measB ~ measC,
    Extent.C vert, Extent.C horiz, Class.Floating a) =>
   Matrix.QuadraticMeas typ xl xu lower upper measA height width a ->
   Full measB vert horiz height nrhs a -> Full measC vert horiz width nrhs a
QuadraticMeas typ xl xu lower upper measA height width a
a#\## :: QuadraticMeas typ xl xu lower upper measA height width a
-> Full measB vert horiz height nrhs a
-> Full measC vert horiz width nrhs a
#\##Full measB vert horiz height nrhs a
b =
   case QuadraticMeas typ xl xu lower upper measA height width a
-> (Quadratic typ xl xu lower upper height a,
    IdentityMaes measA height width a)
forall typ meas xl xu lower upper height width a.
(ToQuadratic typ, Measure meas, BoxExtra typ xl,
 BoxExtra typ xu) =>
QuadraticMeas typ xl xu lower upper meas height width a
-> (Quadratic typ xl xu lower upper height a,
    IdentityMaes meas height width a)
Multiply.factorIdentityRight QuadraticMeas typ xl xu lower upper measA height width a
a of
      (Quadratic typ xl xu lower upper height a
q, IdentityMaes measA height width a
ident) ->
         IdentityMaes measA width height a
-> Full measB vert horiz height nrhs a
-> Full measC vert horiz width nrhs a
forall measA measB measC vert horiz fuse height a width.
(Measure measA, Measure measB, Measure measC,
 MultiplyMeasure measA measB ~ measC, C vert, C horiz, Eq fuse) =>
IdentityMaes measA height fuse a
-> Full measB vert horiz fuse width a
-> Full measC vert horiz height width a
Multiply.reshapeHeight (IdentityMaes measA height width a
-> IdentityMaes measA width height a
forall typ xl xu meas vert horiz height width a lower upper.
(Transpose typ, TransposeExtra typ xl, TransposeExtra typ xu,
 Measure meas, C vert, C horiz, C height, C width, Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xu xl upper lower meas horiz vert width height a
Matrix.transpose IdentityMaes measA height width a
ident) (Quadratic typ xl xu lower upper height a
-> Full measB vert horiz height nrhs a
-> Full measB vert horiz height nrhs a
forall typ xl xu lower upper meas vert horiz height width a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Eq height, Floating a) =>
Quadratic typ xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solveRight Quadratic typ xl xu lower upper height a
q Full measB vert horiz height nrhs a
b)

(##/#) ::
   (Solve typ, Matrix.ToQuadratic typ,
    SolveExtra typ xl, SolveExtra typ xu,
    Matrix.BoxExtra typ xl, Matrix.BoxExtra typ xu,
    Omni.Strip lower, Omni.Strip upper,
    Shape.C height, Shape.C width, Eq width, Shape.C nrhs,
    Extent.Measure measA, Extent.Measure measB, Extent.Measure measC,
    Extent.MultiplyMeasure measA measB ~ measC,
    Extent.C vert, Extent.C horiz, Class.Floating a) =>
   Full measB vert horiz nrhs width a ->
   Matrix.QuadraticMeas typ xl xu lower upper measA height width a ->
   Full measC vert horiz nrhs height a
Full measB vert horiz nrhs width a
b##/# :: Full measB vert horiz nrhs width a
-> QuadraticMeas typ xl xu lower upper measA height width a
-> Full measC vert horiz nrhs height a
##/#QuadraticMeas typ xl xu lower upper measA height width a
a =
   case QuadraticMeas typ xl xu lower upper measA height width a
-> (IdentityMaes measA height width a,
    Quadratic typ xl xu lower upper width a)
forall typ meas xl xu lower upper height width a.
(ToQuadratic typ, Measure meas, BoxExtra typ xl,
 BoxExtra typ xu) =>
QuadraticMeas typ xl xu lower upper meas height width a
-> (IdentityMaes meas height width a,
    Quadratic typ xl xu lower upper width a)
Multiply.factorIdentityLeft QuadraticMeas typ xl xu lower upper measA height width a
a of
      (IdentityMaes measA height width a
ident, Quadratic typ xl xu lower upper width a
q) ->
         Full measB vert horiz nrhs width a
-> IdentityMaes measA width height a
-> Full measC vert horiz nrhs height a
forall measA measB measC vert horiz fuse height a width.
(Measure measA, Measure measB, Measure measC,
 MultiplyMeasure measA measB ~ measC, C vert, C horiz, Eq fuse) =>
Full measB vert horiz height fuse a
-> IdentityMaes measA fuse width a
-> Full measC vert horiz height width a
Multiply.reshapeWidth (Full measB vert horiz nrhs width a
-> Quadratic typ xl xu lower upper width a
-> Full measB vert horiz nrhs width a
forall typ xl xu lower upper meas vert horiz height width a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Eq width, Floating a) =>
Full meas vert horiz height width a
-> Quadratic typ xl xu lower upper width a
-> Full meas vert horiz height width a
solveLeft Full measB vert horiz nrhs width a
b Quadratic typ xl xu lower upper width a
q) (IdentityMaes measA height width a
-> IdentityMaes measA width height a
forall typ xl xu meas vert horiz height width a lower upper.
(Transpose typ, TransposeExtra typ xl, TransposeExtra typ xu,
 Measure meas, C vert, C horiz, C height, C width, Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xu xl upper lower meas horiz vert width height a
Matrix.transpose IdentityMaes measA height width a
ident)


solveVector ::
   (Solve typ, SolveExtra typ xl, SolveExtra typ xu,
    Omni.Strip lower, Omni.Strip upper,
    Shape.C sh, Eq sh, Class.Floating a) =>
   Transposition ->
   Matrix.Quadratic typ xl xu lower upper sh a ->
   Vector sh a -> Vector sh a
solveVector :: Transposition
-> Quadratic typ xl xu lower upper sh a
-> Vector sh a
-> Vector sh a
solveVector Transposition
trans =
   Order
-> (General sh () a -> General sh () a)
-> Vector sh a
-> Vector sh a
forall height0 a height1 b.
Order
-> (General height0 () a -> General height1 () b)
-> Vector height0 a
-> Vector height1 b
ArrMatrix.unliftColumn Order
Layout.ColumnMajor ((General sh () a -> General sh () a)
 -> Vector sh a -> Vector sh a)
-> (Quadratic typ xl xu lower upper sh a
    -> General sh () a -> General sh () a)
-> Quadratic typ xl xu lower upper sh a
-> Vector sh a
-> Vector sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transposition
-> Quadratic typ xl xu lower upper sh a
-> General sh () a
-> General sh () a
forall typ xl xu lower upper meas vert horiz height width a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Eq height, Floating a) =>
Transposition
-> Quadratic typ xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solve Transposition
trans


infixl 7 -/#
infixr 7 #\|

(#\|) ::
   (Solve typ, Matrix.ToQuadratic typ,
    SolveExtra typ xl, SolveExtra typ xu,
    Matrix.BoxExtra typ xl, Matrix.BoxExtra typ xu,
    Omni.Strip lower, Omni.Strip upper, Extent.Measure meas,
    Shape.C height, Shape.C width, Eq height, Class.Floating a) =>
   Matrix.QuadraticMeas typ xl xu lower upper meas height width a ->
   Vector height a -> Vector width a
#\| :: QuadraticMeas typ xl xu lower upper meas height width a
-> Vector height a -> Vector width a
(#\|) QuadraticMeas typ xl xu lower upper meas height width a
a =
   case QuadraticMeas typ xl xu lower upper meas height width a
-> (Quadratic typ xl xu lower upper height a,
    IdentityMaes meas height width a)
forall typ meas xl xu lower upper height width a.
(ToQuadratic typ, Measure meas, BoxExtra typ xl,
 BoxExtra typ xu) =>
QuadraticMeas typ xl xu lower upper meas height width a
-> (Quadratic typ xl xu lower upper height a,
    IdentityMaes meas height width a)
Multiply.factorIdentityRight QuadraticMeas typ xl xu lower upper meas height width a
a of
      (Quadratic typ xl xu lower upper height a
q, IdentityMaes meas height width a
ident) ->
         IdentityMaes meas width height a
-> Vector height a -> Vector width a
forall meas height width a.
(Measure meas, C height, C width) =>
IdentityMaes meas height width a
-> Vector width a -> Vector height a
reshapeVector (IdentityMaes meas height width a
-> IdentityMaes meas width height a
forall typ xl xu meas vert horiz height width a lower upper.
(Transpose typ, TransposeExtra typ xl, TransposeExtra typ xu,
 Measure meas, C vert, C horiz, C height, C width, Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xu xl upper lower meas horiz vert width height a
Matrix.transpose IdentityMaes meas height width a
ident) (Vector height a -> Vector width a)
-> (Vector height a -> Vector height a)
-> Vector height a
-> Vector width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transposition
-> Quadratic typ xl xu lower upper height a
-> Vector height a
-> Vector height a
forall typ xl xu lower upper sh a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, C sh, Eq sh, Floating a) =>
Transposition
-> Quadratic typ xl xu lower upper sh a
-> Vector sh a
-> Vector sh a
solveVector Transposition
NonTransposed Quadratic typ xl xu lower upper height a
q

(-/#) ::
   (Solve typ, Matrix.ToQuadratic typ,
    SolveExtra typ xl, SolveExtra typ xu,
    Matrix.BoxExtra typ xl, Matrix.BoxExtra typ xu,
    Omni.Strip lower, Omni.Strip upper, Extent.Measure meas,
    Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
   Vector width a ->
   Matrix.QuadraticMeas typ xl xu lower upper meas height width a ->
   Vector height a
-/# :: Vector width a
-> QuadraticMeas typ xl xu lower upper meas height width a
-> Vector height a
(-/#) = (QuadraticMeas typ xl xu lower upper meas height width a
 -> Vector width a -> Vector height a)
-> Vector width a
-> QuadraticMeas typ xl xu lower upper meas height width a
-> Vector height a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((QuadraticMeas typ xl xu lower upper meas height width a
  -> Vector width a -> Vector height a)
 -> Vector width a
 -> QuadraticMeas typ xl xu lower upper meas height width a
 -> Vector height a)
-> (QuadraticMeas typ xl xu lower upper meas height width a
    -> Vector width a -> Vector height a)
-> Vector width a
-> QuadraticMeas typ xl xu lower upper meas height width a
-> Vector height a
forall a b. (a -> b) -> a -> b
$ \QuadraticMeas typ xl xu lower upper meas height width a
a ->
   case QuadraticMeas typ xl xu lower upper meas height width a
-> (IdentityMaes meas height width a,
    Quadratic typ xl xu lower upper width a)
forall typ meas xl xu lower upper height width a.
(ToQuadratic typ, Measure meas, BoxExtra typ xl,
 BoxExtra typ xu) =>
QuadraticMeas typ xl xu lower upper meas height width a
-> (IdentityMaes meas height width a,
    Quadratic typ xl xu lower upper width a)
Multiply.factorIdentityLeft QuadraticMeas typ xl xu lower upper meas height width a
a of
      (IdentityMaes meas height width a
ident, Quadratic typ xl xu lower upper width a
q) -> IdentityMaes meas height width a
-> Vector width a -> Vector height a
forall meas height width a.
(Measure meas, C height, C width) =>
IdentityMaes meas height width a
-> Vector width a -> Vector height a
reshapeVector IdentityMaes meas height width a
ident (Vector width a -> Vector height a)
-> (Vector width a -> Vector width a)
-> Vector width a
-> Vector height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transposition
-> Quadratic typ xl xu lower upper width a
-> Vector width a
-> Vector width a
forall typ xl xu lower upper sh a.
(Solve typ, SolveExtra typ xl, SolveExtra typ xu, Strip lower,
 Strip upper, C sh, Eq sh, Floating a) =>
Transposition
-> Quadratic typ xl xu lower upper sh a
-> Vector sh a
-> Vector sh a
solveVector Transposition
Transposed Quadratic typ xl xu lower upper width a
q


reshapeVector ::
   (Extent.Measure meas, Shape.C height, Shape.C width) =>
   Multiply.IdentityMaes meas height width a ->
   Vector width a -> Vector height a
reshapeVector :: IdentityMaes meas height width a
-> Vector width a -> Vector height a
reshapeVector (Matrix.Identity extent) = height -> Vector width a -> Vector height a
forall sh0 sh1 a.
(C sh0, C sh1) =>
sh1 -> Array sh0 a -> Array sh1 a
Array.reshape (Extent meas Small Small height width -> height
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> height
Extent.height Extent meas Small Small height width
extent)


instance Determinant Matrix.Scale where
   type DeterminantExtra Matrix.Scale extra = extra ~ ()
   determinant :: Quadratic Scale xl xu lower upper sh a -> a
determinant (Matrix.Scale sh a) = a
a a -> Int -> a
forall a b. (Num a, Integral b) => a -> b -> a
^ sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
sh

instance Solve Matrix.Scale where
   type SolveExtra Matrix.Scale extra = extra ~ ()
   solve :: Transposition
-> Quadratic Scale xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solve Transposition
_trans =
      String
-> (Full meas vert horiz height width a -> height)
-> (a
    -> Full meas vert horiz height width a
    -> Full meas vert horiz height width a)
-> Quadratic Scale xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall shape b a c xl xu lower upper meas vert horiz.
Eq shape =>
String
-> (b -> shape)
-> (a -> b -> c)
-> Matrix Scale xl xu lower upper meas vert horiz shape shape a
-> b
-> c
scaleWithCheck String
"Matrix.Scale.solve" Full meas vert horiz height width a -> height
forall typ xl xu meas vert horiz lower upper height width a.
(Box typ, BoxExtra typ xl, BoxExtra typ xu, Measure meas, C vert,
 C horiz) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> height
Matrix.height ((a
  -> Full meas vert horiz height width a
  -> Full meas vert horiz height width a)
 -> Quadratic Scale xl xu lower upper height a
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (a
    -> Full meas vert horiz height width a
    -> Full meas vert horiz height width a)
-> Quadratic Scale xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
         (Array (Full meas vert horiz height width) a
 -> Array (Full meas vert horiz height width) a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 ((Array (Full meas vert horiz height width) a
  -> Array (Full meas vert horiz height width) a)
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (a
    -> Array (Full meas vert horiz height width) a
    -> Array (Full meas vert horiz height width) a)
-> a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a
-> Array (Full meas vert horiz height width) a
-> Array (Full meas vert horiz height width) a
forall sh a. (C sh, Floating a) => a -> Vector sh a -> Vector sh a
Vector.scale (a
 -> Array (Full meas vert horiz height width) a
 -> Array (Full meas vert horiz height width) a)
-> (a -> a)
-> a
-> Array (Full meas vert horiz height width) a
-> Array (Full meas vert horiz height width) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
forall a. Fractional a => a -> a
recip

instance Inverse Matrix.Scale where
   type InverseExtra Matrix.Scale extra = extra ~ ()
   inverse :: QuadraticMeas Scale xl xu lower upper meas height width a
-> QuadraticMeas Scale xl xu lower upper meas width height a
inverse (Matrix.Scale shape a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
shape (a -> Quadratic Scale () () Empty Empty height a)
-> a -> Quadratic Scale () () Empty Empty height a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a. Fractional a => a -> a
recip a
a


instance Determinant Matrix.Permutation where
   type DeterminantExtra Matrix.Permutation extra = extra ~ ()
   determinant :: Quadratic Permutation xl xu lower upper sh a -> a
determinant = Quadratic Permutation xl xu lower upper sh a -> a
forall sh a lower upper.
(C sh, Floating a) =>
FlexPermutation lower upper sh a -> a
PermMatrix.determinant

instance Solve Matrix.Permutation where
   type SolveExtra Matrix.Permutation extra = extra ~ ()
   solve :: Transposition
-> Quadratic Permutation xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solve Transposition
trans =
      Inversion
-> FlexPermutation lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall meas vert horiz height width a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Floating a) =>
Inversion
-> FlexPermutation lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
PermMatrix.multiplyFull
         (Inversion
Inverted Inversion -> Inversion -> Inversion
forall a. Semigroup a => a -> a -> a
<> Transposition -> Inversion
PermMatrix.inversionFromTransposition Transposition
trans)

instance Inverse Matrix.Permutation where
   type InverseExtra Matrix.Permutation extra = extra ~ ()
   inverse :: QuadraticMeas Permutation xl xu lower upper meas height width a
-> QuadraticMeas Permutation xl xu lower upper meas width height a
inverse a :: QuadraticMeas Permutation xl xu lower upper meas height width a
a@(Matrix.Permutation _) =
      case QuadraticMeas Permutation xl xu lower upper meas height width a
-> (PowerStripSingleton lower, PowerStripSingleton upper)
forall lower upper typ xl xu meas vert horiz height width a.
(PowerStrip lower, PowerStrip upper) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> (PowerStripSingleton lower, PowerStripSingleton upper)
Matrix.powerStrips QuadraticMeas Permutation xl xu lower upper meas height width a
a of
         (PowerStripSingleton lower
MatrixShape.Filled, PowerStripSingleton upper
MatrixShape.Filled) -> FlexPermutation lower upper height a
-> FlexPermutation upper lower height a
forall sh lower upper a.
C sh =>
FlexPermutation lower upper sh a
-> FlexPermutation upper lower sh a
PermMatrix.transpose QuadraticMeas Permutation xl xu lower upper meas height width a
FlexPermutation lower upper height a
a
         (PowerStripSingleton lower, PowerStripSingleton upper)
_ -> QuadraticMeas Permutation xl xu lower upper meas height width a
QuadraticMeas Permutation xl xu lower upper meas width height a
a -- identity matrix

instance
   (Layout.Packing pack, Omni.Property property) =>
      Determinant (ArrMatrix.Array pack property) where
   type DeterminantExtra (ArrMatrix.Array pack property) extra = extra ~ ()
   determinant :: Quadratic (Array pack property) xl xu lower upper sh a -> a
determinant = Quadratic (Array pack property) xl xu lower upper sh a -> a
forall pack property lower upper sh a.
(Packing pack, Property property, Strip lower, Strip upper, C sh,
 Floating a) =>
Quadratic pack property lower upper sh a -> a
ArrDivide.determinant

instance
   (Layout.Packing pack, Omni.Property property) =>
      Solve (ArrMatrix.Array pack property) where
   type SolveExtra (ArrMatrix.Array pack property) extra = extra ~ ()
   solveRight :: Quadratic (Array pack property) xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solveRight = Quadratic (Array pack property) xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall pack property lower upper meas vert horiz sh nrhs a.
(Packing pack, Property property, Strip lower, Strip upper,
 Measure meas, C vert, C horiz, C sh, Eq sh, C nrhs, Floating a) =>
Quadratic pack property lower upper sh a
-> Full meas vert horiz sh nrhs a -> Full meas vert horiz sh nrhs a
ArrDivide.solve
   solveLeft :: Full meas vert horiz height width a
-> Quadratic (Array pack property) xl xu lower upper width a
-> Full meas vert horiz height width a
solveLeft = (Matrix
   (Array pack property)
   ()
   ()
   lower
   upper
   Shape
   Small
   Small
   width
   width
   a
 -> Matrix
      (Array Unpacked Arbitrary)
      ()
      ()
      Filled
      Filled
      meas
      horiz
      vert
      width
      height
      a
 -> Matrix
      (Array Unpacked Arbitrary)
      ()
      ()
      Filled
      Filled
      meas
      horiz
      vert
      width
      height
      a)
-> Full meas vert horiz height width a
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     Shape
     Small
     Small
     width
     width
     a
-> Full meas vert horiz height width a
forall typA typB xlA xuA xlB xuB measA vertA horizA measB vertB
       horizB heightA widthA heightB widthB a matrix upperA lowerA upperB
       lowerB.
(Transpose typA, Transpose typB, TransposeExtra typA xlA,
 TransposeExtra typA xuA, TransposeExtra typB xlB,
 TransposeExtra typB xuB, Measure measA, C vertA, C horizA,
 Measure measB, C vertB, C horizB, C heightA, C widthA, C heightB,
 C widthB, Floating a) =>
(matrix
 -> Matrix
      typA xuA xlA upperA lowerA measA horizA vertA widthA heightA a
 -> Matrix
      typB xuB xlB upperB lowerB measB horizB vertB widthB heightB a)
-> Matrix
     typA xlA xuA lowerA upperA measA vertA horizA heightA widthA a
-> matrix
-> Matrix
     typB xlB xuB lowerB upperB measB vertB horizB heightB widthB a
Matrix.swapMultiply ((Matrix
    (Array pack property)
    ()
    ()
    lower
    upper
    Shape
    Small
    Small
    width
    width
    a
  -> Matrix
       (Array Unpacked Arbitrary)
       ()
       ()
       Filled
       Filled
       meas
       horiz
       vert
       width
       height
       a
  -> Matrix
       (Array Unpacked Arbitrary)
       ()
       ()
       Filled
       Filled
       meas
       horiz
       vert
       width
       height
       a)
 -> Full meas vert horiz height width a
 -> Matrix
      (Array pack property)
      ()
      ()
      lower
      upper
      Shape
      Small
      Small
      width
      width
      a
 -> Full meas vert horiz height width a)
-> (Matrix
      (Array pack property)
      ()
      ()
      lower
      upper
      Shape
      Small
      Small
      width
      width
      a
    -> Matrix
         (Array Unpacked Arbitrary)
         ()
         ()
         Filled
         Filled
         meas
         horiz
         vert
         width
         height
         a
    -> Matrix
         (Array Unpacked Arbitrary)
         ()
         ()
         Filled
         Filled
         meas
         horiz
         vert
         width
         height
         a)
-> Full meas vert horiz height width a
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     Shape
     Small
     Small
     width
     width
     a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$  Quadratic pack property upper lower width a
-> Matrix
     (Array Unpacked Arbitrary)
     ()
     ()
     Filled
     Filled
     meas
     horiz
     vert
     width
     height
     a
-> Matrix
     (Array Unpacked Arbitrary)
     ()
     ()
     Filled
     Filled
     meas
     horiz
     vert
     width
     height
     a
forall pack property lower upper meas vert horiz sh nrhs a.
(Packing pack, Property property, Strip lower, Strip upper,
 Measure meas, C vert, C horiz, C sh, Eq sh, C nrhs, Floating a) =>
Quadratic pack property lower upper sh a
-> Full meas vert horiz sh nrhs a -> Full meas vert horiz sh nrhs a
ArrDivide.solve (Quadratic pack property upper lower width a
 -> Matrix
      (Array Unpacked Arbitrary)
      ()
      ()
      Filled
      Filled
      meas
      horiz
      vert
      width
      height
      a
 -> Matrix
      (Array Unpacked Arbitrary)
      ()
      ()
      Filled
      Filled
      meas
      horiz
      vert
      width
      height
      a)
-> (Matrix
      (Array pack property)
      ()
      ()
      lower
      upper
      Shape
      Small
      Small
      width
      width
      a
    -> Quadratic pack property upper lower width a)
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     Shape
     Small
     Small
     width
     width
     a
-> Matrix
     (Array Unpacked Arbitrary)
     ()
     ()
     Filled
     Filled
     meas
     horiz
     vert
     width
     height
     a
-> Matrix
     (Array Unpacked Arbitrary)
     ()
     ()
     Filled
     Filled
     meas
     horiz
     vert
     width
     height
     a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix
  (Array pack property)
  ()
  ()
  lower
  upper
  Shape
  Small
  Small
  width
  width
  a
-> Quadratic pack property upper lower width a
forall typ xl xu meas vert horiz height width a lower upper.
(Transpose typ, TransposeExtra typ xl, TransposeExtra typ xu,
 Measure meas, C vert, C horiz, C height, C width, Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xu xl upper lower meas horiz vert width height a
Matrix.transpose

instance
   (Layout.Packing pack, Omni.Property property) =>
      Inverse (ArrMatrix.Array pack property) where
   type InverseExtra (ArrMatrix.Array pack property) extra = extra ~ ()
   inverse :: QuadraticMeas
  (Array pack property) xl xu lower upper meas height width a
-> QuadraticMeas
     (Array pack property) xl xu lower upper meas width height a
inverse = QuadraticMeas
  (Array pack property) xl xu lower upper meas height width a
-> QuadraticMeas
     (Array pack property) xl xu lower upper meas width height a
forall pack property lower upper meas height width a.
(Packing pack, Property property, PowerStrip lower,
 PowerStrip upper, Measure meas, C height, C width, Floating a) =>
QuadraticMeas pack property lower upper meas height width a
-> QuadraticMeas pack property lower upper meas width height a
ArrDivide.inverse