{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
module Numeric.LAPACK.Matrix.Class (
   SquareShape(takeDiagonal, identityFrom), SquareShapeExtra, toSquare,
   MapSquareSize(mapSquareSize),
   MapSize(mapHeight, mapWidth),
   trace,
   Complex(conjugate, fromReal, toComplex),
   adjoint,
   Unpack(unpack), UnpackExtra, toFull,

   Homogeneous, HomogeneousExtra, Scale, ScaleExtra,
   zeroFrom, negate, scaleReal, scale, scaleRealReal, (.*#),
   Additive, AdditiveExtra, add, (#+#),
   Subtractive, SubtractiveExtra, sub, (#-#),
   ) where

import qualified Numeric.LAPACK.Matrix.Array.Basic as OmniMatrix
import qualified Numeric.LAPACK.Matrix.Array.Private as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Type.Private as Matrix
import qualified Numeric.LAPACK.Matrix.Banded.Basic as Banded
import qualified Numeric.LAPACK.Matrix.Layout.Private as Layout
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import qualified Numeric.LAPACK.Matrix.Permutation as Permutation
import qualified Numeric.LAPACK.Matrix.Shape.Omni as Omni
import qualified Numeric.LAPACK.Permutation.Private as Perm
import qualified Numeric.LAPACK.Permutation as PermPub
import qualified Numeric.LAPACK.Vector as Vector
import qualified Numeric.LAPACK.Scalar as Scalar
import Numeric.LAPACK.Matrix.Type.Private (Matrix)
import Numeric.LAPACK.Vector (Vector)
import Numeric.LAPACK.Scalar (RealOf, ComplexOf)

import qualified Numeric.Netlib.Class as Class

import qualified Data.Array.Comfort.Shape as Shape

import Prelude hiding (negate)

import GHC.Exts (Constraint)


class Complex typ where
   conjugate ::
      (Matrix typ xl xu lower upper meas vert horiz height width ~ matrix,
       Extent.Measure meas, Extent.C vert, Extent.C horiz,
       Shape.C height, Shape.C width, Class.Floating a) =>
      matrix a -> matrix a
   fromReal ::
      (Matrix typ xl xu lower upper meas vert horiz height width ~ matrix,
       Extent.Measure meas, Extent.C vert, Extent.C horiz,
       Shape.C height, Shape.C width, Class.Floating a) =>
      matrix (RealOf a) -> matrix a
   toComplex ::
      (Matrix typ xl xu lower upper meas vert horiz height width ~ matrix,
       Extent.Measure meas, Extent.C vert, Extent.C horiz,
       Shape.C height, Shape.C width, Class.Floating a) =>
      matrix a -> matrix (ComplexOf a)

instance Complex (ArrMatrix.Array pack property) where
   conjugate :: matrix a -> matrix a
conjugate (ArrMatrix.Array a) = OmniArray pack property lower upper meas vert horiz height width a
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall pack prop lower upper meas vert horiz height width a.
OmniArray pack prop lower upper meas vert horiz height width a
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
ArrMatrix.Array (OmniArray pack property lower upper meas vert horiz height width a
 -> Matrix
      (Array pack property)
      ()
      ()
      lower
      upper
      meas
      vert
      horiz
      height
      width
      a)
-> OmniArray
     pack property lower upper meas vert horiz height width a
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall a b. (a -> b) -> a -> b
$ OmniArray pack property lower upper meas vert horiz height width a
-> OmniArray
     pack property lower upper meas vert horiz height width a
forall sh a. (C sh, Floating a) => Vector sh a -> Vector sh a
Vector.conjugate OmniArray pack property lower upper meas vert horiz height width a
a
   fromReal :: matrix (RealOf a) -> matrix a
fromReal  (ArrMatrix.Array a) = OmniArray pack property lower upper meas vert horiz height width a
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall pack prop lower upper meas vert horiz height width a.
OmniArray pack prop lower upper meas vert horiz height width a
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
ArrMatrix.Array (OmniArray pack property lower upper meas vert horiz height width a
 -> Matrix
      (Array pack property)
      ()
      ()
      lower
      upper
      meas
      vert
      horiz
      height
      width
      a)
-> OmniArray
     pack property lower upper meas vert horiz height width a
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall a b. (a -> b) -> a -> b
$ Vector
  (Omni pack property lower upper meas vert horiz height width)
  (RealOf a)
-> OmniArray
     pack property lower upper meas vert horiz height width a
forall sh a.
(C sh, Floating a) =>
Vector sh (RealOf a) -> Vector sh a
Vector.fromReal  Vector
  (Omni pack property lower upper meas vert horiz height width)
  (RealOf a)
a
   toComplex :: matrix a -> matrix (ComplexOf a)
toComplex (ArrMatrix.Array a) = OmniArray
  pack
  property
  lower
  upper
  meas
  vert
  horiz
  height
  width
  (ComplexOf a)
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     (ComplexOf a)
forall pack prop lower upper meas vert horiz height width a.
OmniArray pack prop lower upper meas vert horiz height width a
-> Matrix
     (Array pack prop) () () lower upper meas vert horiz height width a
ArrMatrix.Array (OmniArray
   pack
   property
   lower
   upper
   meas
   vert
   horiz
   height
   width
   (ComplexOf a)
 -> Matrix
      (Array pack property)
      ()
      ()
      lower
      upper
      meas
      vert
      horiz
      height
      width
      (ComplexOf a))
-> OmniArray
     pack
     property
     lower
     upper
     meas
     vert
     horiz
     height
     width
     (ComplexOf a)
-> Matrix
     (Array pack property)
     ()
     ()
     lower
     upper
     meas
     vert
     horiz
     height
     width
     (ComplexOf a)
forall a b. (a -> b) -> a -> b
$ Vector
  (Omni pack property lower upper meas vert horiz height width) a
-> OmniArray
     pack
     property
     lower
     upper
     meas
     vert
     horiz
     height
     width
     (ComplexOf a)
forall sh a.
(C sh, Floating a) =>
Vector sh a -> Vector sh (ComplexOf a)
Vector.toComplex Vector
  (Omni pack property lower upper meas vert horiz height width) a
a

instance Complex Matrix.Scale where
   conjugate :: matrix a -> matrix a
conjugate (Matrix.Scale sh m) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sh (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. Floating a => a -> a
Scalar.conjugate a
m
   fromReal :: matrix (RealOf a) -> matrix a
fromReal (Matrix.Scale sh m) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sh (a -> Quadratic Scale () () Empty Empty height a)
-> a -> Quadratic Scale () () Empty Empty height a
forall a b. (a -> b) -> a -> b
$ RealOf a -> a
forall a. Floating a => RealOf a -> a
Scalar.fromReal RealOf a
m
   toComplex :: matrix a -> matrix (ComplexOf a)
toComplex (Matrix.Scale sh m) = height
-> ComplexOf a
-> Quadratic Scale () () Empty Empty height (ComplexOf a)
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sh (ComplexOf a
 -> Quadratic Scale () () Empty Empty height (ComplexOf a))
-> ComplexOf a
-> Quadratic Scale () () Empty Empty height (ComplexOf a)
forall a b. (a -> b) -> a -> b
$ a -> ComplexOf a
forall a. Floating a => a -> ComplexOf a
Scalar.toComplex a
m

instance Complex Matrix.Permutation where
   conjugate :: matrix a -> matrix a
conjugate = matrix a -> matrix a
forall a. a -> a
id
   fromReal :: matrix (RealOf a) -> matrix a
fromReal (Matrix.Permutation p) = Permutation height
-> Quadratic Permutation () () lower upper height a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Matrix.Permutation Permutation height
p
   toComplex :: matrix a -> matrix (ComplexOf a)
toComplex (Matrix.Permutation p) = Permutation height
-> Quadratic Permutation () () lower upper height (ComplexOf a)
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Matrix.Permutation Permutation height
p

adjoint ::
   (Matrix.Transpose typ, Complex typ) =>
   (Matrix.TransposeExtra typ xl, Matrix.TransposeExtra typ xu) =>
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Shape.C height, Shape.C width, Class.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
adjoint :: Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xu xl upper lower meas horiz vert width height a
adjoint = Matrix typ xu xl upper lower meas horiz vert width height a
-> Matrix typ xu xl upper lower meas horiz vert width height a
forall typ xl xu lower upper meas vert horiz height width
       (matrix :: * -> *) a.
(Complex typ,
 Matrix typ xl xu lower upper meas vert horiz height width ~ matrix,
 Measure meas, C vert, C horiz, C height, C width, Floating a) =>
matrix a -> matrix a
conjugate (Matrix typ xu xl upper lower meas horiz vert width height a
 -> Matrix typ xu xl upper lower meas horiz vert width height 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 typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xu xl upper lower meas horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xu xl upper lower meas horiz vert 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


class (Matrix.Box typ) => SquareShape typ where
   type SquareShapeExtra typ extra :: Constraint
   takeDiagonal ::
      (SquareShapeExtra typ xl, SquareShapeExtra typ xu) =>
      (Shape.C sh, Class.Floating a) =>
      Matrix.Quadratic typ xl xu lower upper sh a -> Vector sh a
   identityFrom ::
      (SquareShapeExtra typ xl, SquareShapeExtra typ xu) =>
      (Shape.C sh, Class.Floating a) =>
      Matrix.Quadratic typ xl xu lower upper sh a ->
      Matrix.Quadratic typ xl xu lower upper sh a

instance SquareShape (ArrMatrix.Array pack property) where
   type SquareShapeExtra (ArrMatrix.Array pack property) extra = ()
   takeDiagonal :: Quadratic (Array pack property) xl xu lower upper sh a
-> Vector sh a
takeDiagonal a :: Quadratic (Array pack property) xl xu lower upper sh a
a@(ArrMatrix.Array _) = Quadratic pack property lower upper sh a -> Vector sh a
forall sh a pack property lower upper.
(C sh, Floating a) =>
Quadratic pack property lower upper sh a -> Vector sh a
OmniMatrix.takeDiagonal Quadratic (Array pack property) xl xu lower upper sh a
Quadratic pack property lower upper sh a
a
   identityFrom :: Quadratic (Array pack property) xl xu lower upper sh a
-> Quadratic (Array pack property) xl xu lower upper sh a
identityFrom a :: Quadratic (Array pack property) xl xu lower upper sh a
a@(ArrMatrix.Array _) = Quadratic pack property lower upper sh a
-> Quadratic pack property lower upper sh a
forall sh a pack property lower upper.
(C sh, Floating a) =>
Quadratic pack property lower upper sh a
-> Quadratic pack property lower upper sh a
OmniMatrix.identityFrom Quadratic (Array pack property) xl xu lower upper sh a
Quadratic pack property lower upper sh a
a

instance SquareShape Matrix.Scale where
   type SquareShapeExtra Matrix.Scale extra = ()
   takeDiagonal :: Quadratic Scale xl xu lower upper sh a -> Vector sh a
takeDiagonal (Matrix.Scale sh a) = sh -> a -> Vector sh a
forall sh a. (C sh, Floating a) => sh -> a -> Vector sh a
Vector.constant sh
sh a
a
   identityFrom :: Quadratic Scale xl xu lower upper sh a
-> Quadratic Scale xl xu lower upper sh a
identityFrom (Matrix.Scale sh _a) = sh -> a -> Quadratic Scale () () Empty Empty sh a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale sh
sh a
forall a. Floating a => a
Scalar.one

instance SquareShape Matrix.Permutation where
   type SquareShapeExtra Matrix.Permutation extra = ()
   takeDiagonal :: Quadratic Permutation xl xu lower upper sh a -> Vector sh a
takeDiagonal a :: Quadratic Permutation xl xu lower upper sh a
a@(Matrix.Permutation _) =
      Permutation sh -> Vector sh a
forall sh a. (C sh, Floating a) => Permutation sh -> Vector sh a
Perm.takeDiagonal (Permutation sh -> Vector sh a)
-> (FlexPermutation lower upper sh a -> Permutation sh)
-> FlexPermutation lower upper sh a
-> Vector sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FlexPermutation lower upper sh a -> Permutation sh
forall sh lower upper a.
C sh =>
FlexPermutation lower upper sh a -> Permutation sh
Permutation.toPermutation (FlexPermutation lower upper sh a -> Vector sh a)
-> FlexPermutation lower upper sh a -> Vector sh a
forall a b. (a -> b) -> a -> b
$ Quadratic Permutation xl xu lower upper sh a
FlexPermutation lower upper sh a
a
   identityFrom :: Quadratic Permutation xl xu lower upper sh a
-> Quadratic Permutation xl xu lower upper sh a
identityFrom (Matrix.Permutation perm) =
      Permutation sh -> Quadratic Permutation () () lower upper sh a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Matrix.Permutation (Permutation sh -> Quadratic Permutation () () lower upper sh a)
-> Permutation sh -> Quadratic Permutation () () lower upper sh a
forall a b. (a -> b) -> a -> b
$ sh -> Permutation sh
forall sh. C sh => sh -> Permutation sh
Perm.identity (sh -> Permutation sh) -> sh -> Permutation sh
forall a b. (a -> b) -> a -> b
$ Permutation sh -> sh
forall sh. Permutation sh -> sh
Perm.size Permutation sh
perm


trace ::
   (SquareShape typ, SquareShapeExtra typ xl, SquareShapeExtra typ xu) =>
   (Shape.C sh, Class.Floating a) =>
   Matrix.Quadratic typ xl xu lower upper sh a -> a
trace :: Quadratic typ xl xu lower upper sh a -> a
trace = Vector sh a -> a
forall sh a. (C sh, Floating a) => Vector sh a -> a
Vector.sum (Vector sh a -> a)
-> (Quadratic typ xl xu lower upper sh a -> Vector sh a)
-> Quadratic typ xl xu lower upper sh a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Quadratic typ xl xu lower upper sh a -> Vector sh a
forall typ xl xu sh a lower upper.
(SquareShape typ, SquareShapeExtra typ xl, SquareShapeExtra typ xu,
 C sh, Floating a) =>
Quadratic typ xl xu lower upper sh a -> Vector sh a
takeDiagonal



class (SquareShape typ) => MapSquareSize typ where
   {- |
   The number of rows and columns
   must be maintained by the shape mapping function.

   Not available for `Block` matrices.
   -}
   mapSquareSize ::
      (Shape.C shA, Shape.C shB) =>
      (shA -> shB) ->
      Matrix.Quadratic typ xl xu lower upper shA a ->
      Matrix.Quadratic typ xl xu lower upper shB a

instance MapSquareSize (ArrMatrix.Array pack property) where
   mapSquareSize :: (shA -> shB)
-> Quadratic (Array pack property) xl xu lower upper shA a
-> Quadratic (Array pack property) xl xu lower upper shB a
mapSquareSize shA -> shB
f a :: Quadratic (Array pack property) xl xu lower upper shA a
a@(ArrMatrix.Array _) = (shA -> shB)
-> Quadratic pack property lower upper shA a
-> Quadratic pack property lower upper shB a
forall shA shB pack property lower upper a.
(C shA, C shB) =>
(shA -> shB)
-> Quadratic pack property lower upper shA a
-> Quadratic pack property lower upper shB a
OmniMatrix.mapSquareSize shA -> shB
f Quadratic (Array pack property) xl xu lower upper shA a
Quadratic pack property lower upper shA a
a

instance MapSquareSize Matrix.Scale where
   mapSquareSize :: (shA -> shB)
-> Quadratic Scale xl xu lower upper shA a
-> Quadratic Scale xl xu lower upper shB a
mapSquareSize shA -> shB
f (Matrix.Scale sh a) =
      shB -> a -> Quadratic Scale () () Empty Empty shB a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale (String -> (shA -> shB) -> shA -> shB
forall sha shb.
(C sha, C shb) =>
String -> (sha -> shb) -> sha -> shb
Layout.mapChecked String
"Scale.mapSquareSize" shA -> shB
f shA
sh) a
a

instance MapSquareSize Matrix.Permutation where
   mapSquareSize :: (shA -> shB)
-> Quadratic Permutation xl xu lower upper shA a
-> Quadratic Permutation xl xu lower upper shB a
mapSquareSize shA -> shB
f (Matrix.Permutation perm) =
      Permutation shB -> Quadratic Permutation () () lower upper shB a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Matrix.Permutation (Permutation shB -> Quadratic Permutation () () lower upper shB a)
-> Permutation shB -> Quadratic Permutation () () lower upper shB a
forall a b. (a -> b) -> a -> b
$ (shA -> shB) -> Permutation shA -> Permutation shB
forall shA shB.
(C shA, C shB) =>
(shA -> shB) -> Permutation shA -> Permutation shB
Perm.mapSize shA -> shB
f Permutation shA
perm


class (Matrix.Box typ) => MapSize typ where
   {- |
   The number of rows and columns
   must be maintained by the shape mapping function.
   -}
   mapHeight ::
      (Extent.C vert, Extent.C horiz,
       Shape.C heightA, Shape.C heightB, Shape.C width) =>
      (heightA -> heightB) ->
      Matrix typ extraLower extraUpper lower upper
         Extent.Size vert horiz heightA width a ->
      Matrix typ extraLower extraUpper lower upper
         Extent.Size vert horiz heightB width a
   mapWidth ::
      (Extent.C vert, Extent.C horiz,
       Shape.C height, Shape.C widthA, Shape.C widthB) =>
      (widthA -> widthB) ->
      Matrix typ extraLower extraUpper lower upper
         Extent.Size vert horiz height widthA a ->
      Matrix typ extraLower extraUpper lower upper
         Extent.Size vert horiz height widthB a

instance MapSize (ArrMatrix.Array pack property) where
   mapHeight :: (heightA -> heightB)
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     heightA
     width
     a
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     heightB
     width
     a
mapHeight heightA -> heightB
f a :: Matrix
  (Array pack property)
  extraLower
  extraUpper
  lower
  upper
  Size
  vert
  horiz
  heightA
  width
  a
a@(ArrMatrix.Array _) = (heightA -> heightB)
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     heightA
     width
     a
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     heightB
     width
     a
forall pack property lower upper vert horiz
       (matrix :: * -> * -> * -> *) heightA heightB width a.
(ArrayMatrix pack property lower upper Size vert horiz ~ matrix,
 C vert, C horiz, C heightA, C heightB, C width) =>
(heightA -> heightB)
-> matrix heightA width a -> matrix heightB width a
OmniMatrix.mapHeight heightA -> heightB
f Matrix
  (Array pack property)
  extraLower
  extraUpper
  lower
  upper
  Size
  vert
  horiz
  heightA
  width
  a
a
   mapWidth :: (widthA -> widthB)
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     height
     widthA
     a
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     height
     widthB
     a
mapWidth widthA -> widthB
f a :: Matrix
  (Array pack property)
  extraLower
  extraUpper
  lower
  upper
  Size
  vert
  horiz
  height
  widthA
  a
a@(ArrMatrix.Array _) = (widthA -> widthB)
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     height
     widthA
     a
-> Matrix
     (Array pack property)
     extraLower
     extraUpper
     lower
     upper
     Size
     vert
     horiz
     height
     widthB
     a
forall pack property lower upper vert horiz
       (matrix :: * -> * -> * -> *) widthA widthB height a.
(ArrayMatrix pack property lower upper Size vert horiz ~ matrix,
 C vert, C horiz, C widthA, C widthB, C height) =>
(widthA -> widthB)
-> matrix height widthA a -> matrix height widthB a
OmniMatrix.mapWidth widthA -> widthB
f Matrix
  (Array pack property)
  extraLower
  extraUpper
  lower
  upper
  Size
  vert
  horiz
  height
  widthA
  a
a


class Unpack typ where
   type UnpackExtra typ extra :: Constraint
   -- In contrast to OmniMatrix.unpack it cannot maintain the matrix property.
   unpack ::
      (UnpackExtra typ xl, UnpackExtra typ xu) =>
      (Omni.Strip lower, Omni.Strip upper) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Class.Floating a) =>
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      ArrMatrix.ArrayMatrix Layout.Unpacked Omni.Arbitrary
         lower upper meas vert horiz height width a

instance (Omni.Property prop) => Unpack (ArrMatrix.Array pack prop) where
   type UnpackExtra (ArrMatrix.Array pack prop) extra = extra ~ ()
   unpack :: Matrix
  (Array pack prop) xl xu lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked Arbitrary lower upper meas vert horiz height width a
unpack a :: Matrix
  (Array pack prop) xl xu lower upper meas vert horiz height width a
a@(ArrMatrix.Array _) =
      (FullArray meas vert horiz height width a
 -> FullArray meas vert horiz height width a)
-> UnpackedMatrix prop lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked Arbitrary lower upper meas vert horiz height width a
forall propertyA lowerA upperA propertyB lowerB upperB measA vertA
       horizA heightA widthA a measB vertB horizB heightB widthB b.
(Property propertyA, Strip lowerA, Strip upperA,
 Property propertyB, Strip lowerB, Strip upperB) =>
(FullArray measA vertA horizA heightA widthA a
 -> FullArray measB vertB horizB heightB widthB b)
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.liftUnpacked1 FullArray meas vert horiz height width a
-> FullArray meas vert horiz height width a
forall a. a -> a
id (UnpackedMatrix prop lower upper meas vert horiz height width a
 -> ArrayMatrix
      Unpacked Arbitrary lower upper meas vert horiz height width a)
-> UnpackedMatrix prop lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked Arbitrary lower upper meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ ArrayMatrix pack prop lower upper meas vert horiz height width a
-> UnpackedMatrix prop lower upper meas vert horiz height width a
forall meas vert horiz height width a pack property lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked property lower upper meas vert horiz height width a
OmniMatrix.unpack Matrix
  (Array pack prop) xl xu lower upper meas vert horiz height width a
ArrayMatrix pack prop lower upper meas vert horiz height width a
a

instance Unpack Matrix.Scale where
   type UnpackExtra Matrix.Scale extra = extra ~ ()
   unpack :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked Arbitrary lower upper meas vert horiz height width a
unpack (Matrix.Scale sh a) =
      FullArray Shape Small Small height height a
-> UnpackedMatrix
     Arbitrary lower upper Shape Small Small height height a
forall propertyA lowerA upperA measA vertA horizA heightA widthA a.
(Property propertyA, Strip lowerA, Strip upperA) =>
FullArray measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
ArrMatrix.liftUnpacked0 (FullArray Shape Small Small height height a
 -> UnpackedMatrix
      Arbitrary lower upper Shape Small Small height height a)
-> FullArray Shape Small Small height height a
-> UnpackedMatrix
     Arbitrary lower upper Shape Small Small height height a
forall a b. (a -> b) -> a -> b
$ Banded U0 U0 Shape Small Small height height a
-> FullArray Shape Small Small height height a
forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Floating a) =>
Banded sub super meas vert horiz height width a
-> Full meas vert horiz height width a
Banded.toFull (Banded U0 U0 Shape Small Small height height a
 -> FullArray Shape Small Small height height a)
-> Banded U0 U0 Shape Small Small height height a
-> FullArray Shape Small Small height height a
forall a b. (a -> b) -> a -> b
$
      Order
-> Vector height a
-> Banded U0 U0 Shape Small Small height height a
forall sh a.
(C sh, Floating a) =>
Order -> Vector sh a -> Diagonal sh a
Banded.diagonal Order
Layout.RowMajor (Vector height a -> Banded U0 U0 Shape Small Small height height a)
-> Vector height a
-> Banded U0 U0 Shape Small Small height height a
forall a b. (a -> b) -> a -> b
$ height -> a -> Vector height a
forall sh a. (C sh, Floating a) => sh -> a -> Vector sh a
Vector.constant height
sh a
a

instance Unpack Matrix.Permutation where
   type UnpackExtra Matrix.Permutation extra = extra ~ ()
   unpack :: Matrix Permutation xl xu lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked Arbitrary lower upper meas vert horiz height width a
unpack (Matrix.Permutation perm) =
      (FullArray Shape Small Small height height a
 -> FullArray Shape Small Small height height a)
-> UnpackedMatrix
     Arbitrary Filled Filled Shape Small Small height height a
-> UnpackedMatrix
     Arbitrary lower upper Shape Small Small height height a
forall propertyA lowerA upperA propertyB lowerB upperB measA vertA
       horizA heightA widthA a measB vertB horizB heightB widthB b.
(Property propertyA, Strip lowerA, Strip upperA,
 Property propertyB, Strip lowerB, Strip upperB) =>
(FullArray measA vertA horizA heightA widthA a
 -> FullArray measB vertB horizB heightB widthB b)
-> UnpackedMatrix
     propertyA lowerA upperA measA vertA horizA heightA widthA a
-> UnpackedMatrix
     propertyB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.liftUnpacked1 FullArray Shape Small Small height height a
-> FullArray Shape Small Small height height a
forall a. a -> a
id (UnpackedMatrix
   Arbitrary Filled Filled Shape Small Small height height a
 -> UnpackedMatrix
      Arbitrary lower upper Shape Small Small height height a)
-> UnpackedMatrix
     Arbitrary Filled Filled Shape Small Small height height a
-> UnpackedMatrix
     Arbitrary lower upper Shape Small Small height height a
forall a b. (a -> b) -> a -> b
$ Permutation height
-> UnpackedMatrix
     Arbitrary Filled Filled Shape Small Small height height a
forall sh a. (C sh, Floating a) => Permutation sh -> Square sh a
PermPub.toMatrix Permutation height
perm

toFull ::
   (Unpack typ, UnpackExtra typ xl, UnpackExtra typ xu) =>
   (Omni.Strip lower, Omni.Strip upper) =>
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Shape.C height, Shape.C width, Class.Floating a) =>
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   ArrMatrix.Full meas vert horiz height width a
toFull :: Matrix typ xl xu lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
toFull = ArrayMatrix
  Unpacked Arbitrary lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
forall meas vert horiz height width a pack property lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
OmniMatrix.toFull (ArrayMatrix
   Unpacked Arbitrary lower upper meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> ArrayMatrix
         Unpacked Arbitrary lower upper meas vert horiz height width a)
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix typ xl xu lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked Arbitrary lower upper meas vert horiz height width a
forall typ xl xu lower upper meas vert horiz height width a.
(Unpack typ, UnpackExtra typ xl, UnpackExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> ArrayMatrix
     Unpacked Arbitrary lower upper meas vert horiz height width a
unpack

toSquare ::
   (Unpack typ, UnpackExtra typ xl, UnpackExtra typ xu) =>
   (Omni.Strip lower, Omni.Strip upper) =>
   (Shape.C sh, Class.Floating a) =>
   Matrix.Quadratic typ xl xu lower upper sh a -> ArrMatrix.Square sh a
toSquare :: Quadratic typ xl xu lower upper sh a -> Square sh a
toSquare = Quadratic typ xl xu lower upper sh a -> Square sh a
forall typ xl xu lower upper meas vert horiz height width a.
(Unpack typ, UnpackExtra typ xl, UnpackExtra typ xu, Strip lower,
 Strip upper, Measure meas, C vert, C horiz, C height, C width,
 Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
toFull



class Homogeneous typ where
   type HomogeneousExtra typ extra :: Constraint
   zeroFrom ::
      (HomogeneousExtra typ xl, HomogeneousExtra typ xu) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Class.Floating a) =>
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a
   negate ::
      (HomogeneousExtra typ xl, HomogeneousExtra typ xu) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Class.Floating a) =>
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a
   scaleReal ::
      (HomogeneousExtra typ xl, HomogeneousExtra typ xu) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Class.Floating a) =>
      RealOf a ->
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a

instance
   (ArrMatrix.Homogeneous property) =>
      Homogeneous (ArrMatrix.Array pack property) where
   type HomogeneousExtra (ArrMatrix.Array pack property) extra = extra ~ ()
   zeroFrom :: Matrix
  (Array pack property)
  xl
  xu
  lower
  upper
  meas
  vert
  horiz
  height
  width
  a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
zeroFrom = Omni pack property lower upper meas vert horiz height width
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
Omni pack property lower upper meas vert horiz height width
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.zero (Omni pack property lower upper meas vert horiz height width
 -> ArrayMatrix
      pack property lower upper meas vert horiz height width a)
-> (ArrayMatrix
      pack property lower upper meas vert horiz height width a
    -> Omni pack property lower upper meas vert horiz height width)
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Omni pack property lower upper meas vert horiz height width
forall pack property lower upper meas vert horiz height width a.
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> Omni pack property lower upper meas vert horiz height width
ArrMatrix.shape
   negate :: Matrix
  (Array pack property)
  xl
  xu
  lower
  upper
  meas
  vert
  horiz
  height
  width
  a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
negate = Matrix
  (Array pack property)
  xl
  xu
  lower
  upper
  meas
  vert
  horiz
  height
  width
  a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.negate
   scaleReal :: RealOf a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
scaleReal = RealOf a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall property meas vert horiz height width a pack lower upper.
(Homogeneous property, Measure meas, C vert, C horiz, C height,
 C width, Floating a) =>
RealOf a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.scaleReal

instance Homogeneous Matrix.Scale where
   type HomogeneousExtra Matrix.Scale extra = extra ~ ()
   zeroFrom :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
zeroFrom (Matrix.Scale sh _a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sh a
forall a. Floating a => a
Scalar.zero
   negate :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
negate (Matrix.Scale sh a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sh (-a
a)
   scaleReal :: RealOf a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
scaleReal RealOf a
c (Matrix.Scale sh a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sh (RealOf a -> a
forall a. Floating a => RealOf a -> a
Scalar.fromReal RealOf a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
a)

newtype ScaleReal f a = ScaleReal {ScaleReal f a -> a -> f a -> f a
getScaleReal :: a -> f a -> f a}

scaleRealReal ::
   (Homogeneous typ, HomogeneousExtra typ xl, HomogeneousExtra typ xu) =>
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Shape.C height, Shape.C width, Class.Real a) =>
   a ->
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   Matrix typ xl xu lower upper meas vert horiz height width a
scaleRealReal :: a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
scaleRealReal =
   ScaleReal
  (Matrix typ xl xu lower upper meas vert horiz height width) a
-> a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
forall (f :: * -> *) a. ScaleReal f a -> a -> f a -> f a
getScaleReal (ScaleReal
   (Matrix typ xl xu lower upper meas vert horiz height width) a
 -> a
 -> Matrix typ xl xu lower upper meas vert horiz height width a
 -> Matrix typ xl xu lower upper meas vert horiz height width a)
-> ScaleReal
     (Matrix typ xl xu lower upper meas vert horiz height width) a
-> a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ ScaleReal
  (Matrix typ xl xu lower upper meas vert horiz height width) Float
-> ScaleReal
     (Matrix typ xl xu lower upper meas vert horiz height width) Double
-> ScaleReal
     (Matrix typ xl xu lower upper meas vert horiz height width) a
forall a (f :: * -> *). Real a => f Float -> f Double -> f a
Class.switchReal ((Float
 -> Matrix typ xl xu lower upper meas vert horiz height width Float
 -> Matrix typ xl xu lower upper meas vert horiz height width Float)
-> ScaleReal
     (Matrix typ xl xu lower upper meas vert horiz height width) Float
forall (f :: * -> *) a. (a -> f a -> f a) -> ScaleReal f a
ScaleReal Float
-> Matrix typ xl xu lower upper meas vert horiz height width Float
-> Matrix typ xl xu lower upper meas vert horiz height width Float
forall typ xl xu meas vert horiz height width a lower upper.
(Homogeneous typ, HomogeneousExtra typ xl, HomogeneousExtra typ xu,
 Measure meas, C vert, C horiz, C height, C width, Floating a) =>
RealOf a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
scaleReal) ((Double
 -> Matrix typ xl xu lower upper meas vert horiz height width Double
 -> Matrix
      typ xl xu lower upper meas vert horiz height width Double)
-> ScaleReal
     (Matrix typ xl xu lower upper meas vert horiz height width) Double
forall (f :: * -> *) a. (a -> f a -> f a) -> ScaleReal f a
ScaleReal Double
-> Matrix typ xl xu lower upper meas vert horiz height width Double
-> Matrix typ xl xu lower upper meas vert horiz height width Double
forall typ xl xu meas vert horiz height width a lower upper.
(Homogeneous typ, HomogeneousExtra typ xl, HomogeneousExtra typ xu,
 Measure meas, C vert, C horiz, C height, C width, Floating a) =>
RealOf a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
scaleReal)


class (Homogeneous typ) => Scale typ where
   type ScaleExtra typ extra :: Constraint
   scale ::
      (ScaleExtra typ xl, ScaleExtra typ xu) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (Shape.C height, Shape.C width, Class.Floating a) =>
      a ->
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a

instance
   (ArrMatrix.Scale property) =>
      Scale (ArrMatrix.Array pack property) where
   type ScaleExtra (ArrMatrix.Array pack property) extra = extra ~ ()
   scale :: a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
scale = a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Scale property, C height, C width,
 Floating a) =>
a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.scale

instance Scale Matrix.Scale where
   type ScaleExtra Matrix.Scale extra = extra ~ ()
   scale :: a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
scale a
c (Matrix.Scale sh a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sh (a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
a)

(.*#) ::
   (Scale typ, ScaleExtra typ xl, ScaleExtra typ xu) =>
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Shape.C height, Shape.C width, Class.Floating a) =>
   a ->
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   Matrix typ xl xu lower upper meas vert horiz height width a
.*# :: a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
(.*#) = a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
forall typ xl xu meas vert horiz height width a lower upper.
(Scale typ, ScaleExtra typ xl, ScaleExtra typ xu, Measure meas,
 C vert, C horiz, C height, C width, Floating a) =>
a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
scale

infixl 7 .*#


class Additive typ where
   type AdditiveExtra typ extra :: Constraint
   add ::
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (AdditiveExtra typ xl, AdditiveExtra typ xu,
       Shape.C height, Eq height, Shape.C width, Eq width, Class.Floating a) =>
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a

instance
   (ArrMatrix.Additive property) =>
      Additive (ArrMatrix.Array pack property) where
   type AdditiveExtra (ArrMatrix.Array pack property) extra = extra ~ ()
   add :: Matrix
  (Array pack property)
  xl
  xu
  lower
  upper
  meas
  vert
  horiz
  height
  width
  a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
add = Matrix
  (Array pack property)
  xl
  xu
  lower
  upper
  meas
  vert
  horiz
  height
  width
  a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Additive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.add

instance Additive Matrix.Scale where
   type AdditiveExtra Matrix.Scale extra = extra ~ ()
   add :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
add (Matrix.Scale sha a) (Matrix.Scale shb b) =
      if height
sha height -> height -> Bool
forall a. Eq a => a -> a -> Bool
== height
shb
         then height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sha (a
aa -> a -> a
forall a. Num a => a -> a -> a
+a
b)
         else String
-> Matrix Scale xl xu lower upper meas vert horiz height width a
forall a. HasCallStack => String -> a
error String
"Matrix.add Scale: dimensions mismatch"

class (Additive typ) => Subtractive typ where
   type SubtractiveExtra typ extra :: Constraint
   sub ::
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      (SubtractiveExtra typ xl, SubtractiveExtra typ xu,
       Shape.C height, Eq height, Shape.C width, Eq width, Class.Floating a) =>
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Matrix typ xl xu lower upper meas vert horiz height width a

instance
   (ArrMatrix.Subtractive property) =>
      Subtractive (ArrMatrix.Array pack property) where
   type SubtractiveExtra (ArrMatrix.Array pack property) extra = extra ~ ()
   sub :: Matrix
  (Array pack property)
  xl
  xu
  lower
  upper
  meas
  vert
  horiz
  height
  width
  a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
sub = Matrix
  (Array pack property)
  xl
  xu
  lower
  upper
  meas
  vert
  horiz
  height
  width
  a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
-> Matrix
     (Array pack property)
     xl
     xu
     lower
     upper
     meas
     vert
     horiz
     height
     width
     a
forall meas vert horiz property height width a pack lower upper.
(Measure meas, C vert, C horiz, Subtractive property, C height,
 Eq height, C width, Eq width, Floating a) =>
ArrayMatrix
  pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
-> ArrayMatrix
     pack property lower upper meas vert horiz height width a
ArrMatrix.sub

instance Subtractive Matrix.Scale where
   type SubtractiveExtra Matrix.Scale extra = extra ~ ()
   sub :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xl xu lower upper meas vert horiz height width a
sub (Matrix.Scale sha a) (Matrix.Scale shb b) =
      if height
sha height -> height -> Bool
forall a. Eq a => a -> a -> Bool
== height
shb
         then height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Matrix.Scale height
sha (a
aa -> a -> a
forall a. Num a => a -> a -> a
-a
b)
         else String
-> Matrix Scale xl xu lower upper meas vert horiz height width a
forall a. HasCallStack => String -> a
error String
"Matrix.sub Scale: dimensions mismatch"

infixl 6 #+#, #-#, `add`, `sub`

(#+#) ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Additive typ, AdditiveExtra typ xl, AdditiveExtra typ xu,
    Shape.C height, Eq height, Shape.C width, Eq width, Class.Floating a) =>
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   Matrix typ xl xu lower upper meas vert horiz height width a
#+# :: Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
(#+#) = Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
forall typ meas vert horiz xl xu height width a lower upper.
(Additive typ, Measure meas, C vert, C horiz, AdditiveExtra typ xl,
 AdditiveExtra typ xu, C height, Eq height, C width, Eq width,
 Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
add

(#-#) ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Subtractive typ, SubtractiveExtra typ xl, SubtractiveExtra typ xu,
    Shape.C height, Eq height, Shape.C width, Eq width, Class.Floating a) =>
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   Matrix typ xl xu lower upper meas vert horiz height width a
#-# :: Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
(#-#) = Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
forall typ meas vert horiz xl xu height width a lower upper.
(Subtractive typ, Measure meas, C vert, C horiz,
 SubtractiveExtra typ xl, SubtractiveExtra typ xu, C height,
 Eq height, C width, Eq width, Floating a) =>
Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Matrix typ xl xu lower upper meas vert horiz height width a
sub