{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
module Numeric.LAPACK.Matrix.Type.Private where

import qualified Numeric.LAPACK.Matrix.Plain.Format as ArrFormat
import qualified Numeric.LAPACK.Output as Output
import qualified Numeric.LAPACK.Permutation.Private as Perm
import qualified Numeric.LAPACK.Matrix.Shape as MatrixShape
import qualified Numeric.LAPACK.Matrix.Shape.Omni as Omni
import qualified Numeric.LAPACK.Matrix.Extent.Strict as ExtentStrict
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import Numeric.LAPACK.Matrix.Layout.Private (Empty, Filled)
import Numeric.LAPACK.Matrix.Extent.Private (Extent, Shape, Small)
import Numeric.LAPACK.Output (Output)

import qualified Numeric.Netlib.Class as Class

import qualified Hyper

import qualified Control.DeepSeq as DeepSeq
import Control.Applicative ((<$>))

import qualified Data.Array.Comfort.Boxed as BoxedArray
import qualified Data.Array.Comfort.Shape as Shape

import qualified Data.Foldable as Fold
import Data.Function.HT (Id)
import Data.Monoid (Monoid, mempty, mappend)
import Data.Semigroup (Semigroup, (<>))
import Data.Foldable (Foldable)
import Data.Maybe (fromMaybe)
import Data.Tuple.HT (mapSnd)

import GHC.Exts (Constraint)



data family
   Matrix typ extraLower extraUpper lower upper meas vert horiz height width a

type Quadratic typ extraLower extraUpper lower upper sh =
      QuadraticMeas typ extraLower extraUpper lower upper Shape sh sh
type QuadraticMeas typ extraLower extraUpper lower upper meas =
      Matrix typ extraLower extraUpper lower upper meas Small Small


asQuadratic ::
   Id (QuadraticMeas typ extraLower extraUpper lower upper meas height width a)
asQuadratic :: Id
  (QuadraticMeas
     typ extraLower extraUpper lower upper meas height width a)
asQuadratic = Id
  (QuadraticMeas
     typ extraLower extraUpper lower upper meas height width a)
forall a. a -> a
id


data Product fuse
data instance
   Matrix (Product fuse) xl xu lower upper meas vert horiz height width a where
      Product ::
         (Omni.MultipliedBands lowerA lowerB ~ lowerC,
          Omni.MultipliedBands lowerB lowerA ~ lowerC,
          Omni.MultipliedBands upperA upperB ~ upperC,
          Omni.MultipliedBands upperB upperA ~ upperC) =>
         Matrix typA xlA xuA lowerA upperA meas vert horiz height fuse a ->
         Matrix typB xlB xuB lowerB upperB meas vert horiz fuse width a ->
         Matrix (Product fuse)
            (typA,xlA,xuA,lowerA,upperA) (typB,xuB,xlB,upperB,lowerB)
            lowerC upperC meas vert horiz height width a

type family ProductType   extra
type family ProductExtraL extra
type family ProductExtraU extra
type family ProductLower  extra
type family ProductUpper  extra
type instance ProductType   (typ,xl,xu,lower,upper) = typ
type instance ProductExtraL (typ,xl,xu,lower,upper) = xl
type instance ProductExtraU (typ,xl,xu,lower,upper) = xu
type instance ProductLower  (typ,xl,xu,lower,upper) = lower
type instance ProductUpper  (typ,xl,xu,lower,upper) = upper


data Scale
data instance
   Matrix Scale xl xu lower upper meas vert horiz height width a where
      Scale :: sh -> a -> Quadratic Scale () () Empty Empty sh a

deriving instance
   (Shape.C height, Show height, Show a) =>
   Show (Matrix Scale xl xu lower upper meas vert horiz height width a)


data Identity
data instance
   Matrix Identity xl xu lower upper meas vert horiz height width a where
      Identity ::
         (Extent.Measure meas) =>
         Extent meas Small Small height width ->
         QuadraticMeas Identity () () Empty Empty meas height width a


data Permutation
data instance
   Matrix Permutation xl xu lower upper meas vert horiz height width a where
   Permutation ::
      Perm.Permutation sh -> Quadratic Permutation () () lower upper sh a

deriving instance
   (Shape.C height, Show height) =>
   Show (Matrix Permutation xl xu lower upper meas vert horiz height width a)

deriving instance
   (Shape.C height, Eq height) =>
   Eq (Matrix Permutation xl xu lower upper meas vert horiz height width a)


instance
   (NFData typ,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    DeepSeq.NFData height, DeepSeq.NFData width, DeepSeq.NFData a) =>
   DeepSeq.NFData (Matrix typ xl xu lower upper meas vert horiz height width a)
      where
   rnf :: Matrix typ xl xu lower upper meas vert horiz height width a -> ()
rnf = Matrix typ xl xu lower upper meas vert horiz height width a -> ()
forall typ meas vert horiz height width a xl xu lower upper.
(NFData typ, Measure meas, C vert, C horiz, NFData height,
 NFData width, NFData a) =>
Matrix typ xl xu lower upper meas vert horiz height width a -> ()
rnf

class NFData typ where
   rnf ::
      (Extent.Measure meas, Extent.C vert, Extent.C horiz,
       DeepSeq.NFData height, DeepSeq.NFData width, DeepSeq.NFData a) =>
      Matrix typ xl xu lower upper meas vert horiz height width a -> ()



instance
   (Format typ, FormatExtra typ xl, FormatExtra typ xu,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
      Hyper.Display
         (Matrix typ xl xu lower upper meas vert horiz height width a) where
   display :: Matrix typ xl xu lower upper meas vert horiz height width a
-> Graphic
display = Html -> Graphic
Output.hyper (Html -> Graphic)
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> Html)
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Graphic
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Config
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Html
forall typ xl xu meas vert horiz height width a out lower upper.
(Format typ, FormatExtra typ xl, FormatExtra typ xu, Measure meas,
 C vert, C horiz, C height, C width, Floating a, Output out) =>
Config
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> out
format Config
ArrFormat.defltConfig


class Format typ where
   type FormatExtra typ extra :: Constraint
   format ::
      (FormatExtra typ xl, FormatExtra typ xu,
       Extent.Measure meas, Extent.C vert, Extent.C horiz,
       Shape.C height, Shape.C width, Class.Floating a, Output out) =>
      ArrFormat.Config ->
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      out

{- |
Default implementation of 'format'.
Some matrices need more than one array for display,
e.g. @Householder@ and @LowerUpper@.
'Layout' class is still needed for @Block@ matrices.
-}
formatWithLayout ::
   (Layout typ, LayoutExtra typ xl, LayoutExtra typ xu,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a, Output out) =>
   ArrFormat.Config ->
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   out
formatWithLayout :: Config
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> out
formatWithLayout Config
fmt =
   [[(Separator, Style, out)]] -> out
forall out. Output out => [[(Separator, Style, out)]] -> out
Output.formatTable ([[(Separator, Style, out)]] -> out)
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> [[(Separator, Style, out)]])
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> out
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(Separator, Array (TupleShape a) (Style, out))]
 -> [(Separator, Style, out)])
-> [[(Separator, Array (TupleShape a) (Style, out))]]
-> [[(Separator, Style, out)]]
forall a b. (a -> b) -> [a] -> [b]
map (((Separator, Array (TupleShape a) (Style, out))
 -> [(Separator, Style, out)])
-> [(Separator, Array (TupleShape a) (Style, out))]
-> [(Separator, Style, out)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ((Separator
 -> Array (TupleShape a) (Style, out) -> [(Separator, Style, out)])
-> (Separator, Array (TupleShape a) (Style, out))
-> [(Separator, Style, out)]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Separator
-> Array (TupleShape a) (Style, out) -> [(Separator, Style, out)]
forall (f :: * -> *) style str.
Foldable f =>
Separator -> f (style, str) -> [(Separator, style, str)]
attachSeparators)) ([[(Separator, Array (TupleShape a) (Style, out))]]
 -> [[(Separator, Style, out)]])
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> [[(Separator, Array (TupleShape a) (Style, out))]])
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> [[(Separator, Style, out)]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   Array
  (height, width) (Separator, Array (TupleShape a) (Style, out))
-> [[(Separator, Array (TupleShape a) (Style, out))]]
forall height width a.
(C height, C width) =>
Array (height, width) a -> [[a]]
ArrFormat.toRows (Array
   (height, width) (Separator, Array (TupleShape a) (Style, out))
 -> [[(Separator, Array (TupleShape a) (Style, out))]])
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> Array
         (height, width) (Separator, Array (TupleShape a) (Style, out)))
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> [[(Separator, Array (TupleShape a) (Style, out))]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Separator, Maybe (Style, a))
 -> (Separator, Array (TupleShape a) (Style, out)))
-> Array (height, width) (Separator, Maybe (Style, a))
-> Array
     (height, width) (Separator, Array (TupleShape a) (Style, out))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Maybe (Style, a) -> Array (TupleShape a) (Style, out))
-> (Separator, Maybe (Style, a))
-> (Separator, Array (TupleShape a) (Style, out))
forall b c a. (b -> c) -> (a, b) -> (a, c)
mapSnd (Config -> Maybe (Style, a) -> Array (TupleShape a) (Style, out)
forall a out.
(Floating a, Output out) =>
Config -> Maybe (Style, a) -> Tuple a (Style, out)
formatCell Config
fmt)) (Array (height, width) (Separator, Maybe (Style, a))
 -> Array
      (height, width) (Separator, Array (TupleShape a) (Style, out)))
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> Array (height, width) (Separator, Maybe (Style, a)))
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> Array
     (height, width) (Separator, Array (TupleShape a) (Style, out))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix typ xl xu lower upper meas vert horiz height width a
-> Array (height, width) (Separator, Maybe (Style, a))
forall typ xl xu meas vert horiz height width a lower upper.
(Layout typ, LayoutExtra typ xl, LayoutExtra 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
-> Array (height, width) (Separator, Maybe (Style, a))
layout

attachSeparators :: (Foldable f) =>
   Output.Separator -> f (style,str) -> [(Output.Separator, style, str)]
attachSeparators :: Separator -> f (style, str) -> [(Separator, style, str)]
attachSeparators Separator
sep0 =
   ((Separator, (style, str)) -> (Separator, style, str))
-> [(Separator, (style, str))] -> [(Separator, style, str)]
forall a b. (a -> b) -> [a] -> [b]
map (\(Separator
sep,(style
style,str
x)) -> (Separator
sep,style
style,str
x)) ([(Separator, (style, str))] -> [(Separator, style, str)])
-> (f (style, str) -> [(Separator, (style, str))])
-> f (style, str)
-> [(Separator, style, str)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   [Separator] -> [(style, str)] -> [(Separator, (style, str))]
forall a b. [a] -> [b] -> [(a, b)]
zip (Separator
sep0 Separator -> [Separator] -> [Separator]
forall a. a -> [a] -> [a]
: Separator -> [Separator]
forall a. a -> [a]
repeat Separator
Output.Empty) ([(style, str)] -> [(Separator, (style, str))])
-> (f (style, str) -> [(style, str)])
-> f (style, str)
-> [(Separator, (style, str))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. f (style, str) -> [(style, str)]
forall (t :: * -> *) a. Foldable t => t a -> [a]
Fold.toList

formatCell ::
   (Class.Floating a, Output out) =>
   ArrFormat.Config -> Maybe (Output.Style, a) ->
   ArrFormat.Tuple a (Output.Style, out)
formatCell :: Config -> Maybe (Style, a) -> Tuple a (Style, out)
formatCell Config
fmt =
   Tuple a (Style, out)
-> ((Style, a) -> Tuple a (Style, out))
-> Maybe (Style, a)
-> Tuple a (Style, out)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      ((Style, out) -> Tuple a (Style, out)
forall a b. Floating a => b -> Tuple a b
ArrFormat.fillTuple
         (Style
Output.Stored, String -> out
forall out. Output out => String -> out
Output.text (String -> out) -> String -> out
forall a b. (a -> b) -> a -> b
$ Config -> String
ArrFormat.configEmpty Config
fmt))
      (\(Style
style,a
a) ->
         (,) Style
style (out -> (Style, out)) -> (String -> out) -> String -> (Style, out)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> out
forall out. Output out => String -> out
Output.text (String -> (Style, out))
-> Array (TupleShape a) String -> Tuple a (Style, out)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Config -> a -> Array (TupleShape a) String
forall a. Floating a => Config -> a -> Tuple a String
ArrFormat.printfFloating Config
fmt a
a)


instance Format Scale where
   type FormatExtra Scale extra = ()
   format :: Config
-> Matrix Scale xl xu lower upper meas vert horiz height width a
-> out
format = Config
-> Matrix Scale xl xu lower upper meas vert horiz height width a
-> out
forall typ xl xu meas vert horiz height width a out lower upper.
(Layout typ, LayoutExtra typ xl, LayoutExtra typ xu, Measure meas,
 C vert, C horiz, C height, C width, Floating a, Output out) =>
Config
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> out
formatWithLayout

instance Format Permutation where
   type FormatExtra Permutation extra = ()
   format :: Config
-> Matrix
     Permutation xl xu lower upper meas vert horiz height width a
-> out
format Config
_fmt (Permutation perm) = Permutation height -> out
forall sh out. (C sh, Output out) => Permutation sh -> out
Perm.format Permutation height
perm


{- |
Layout matrix elements for use in formatting a block matrix.
Optimally its implementation is reused in 'format' via 'formatWithLayout',
but sometimes that is not possible.
-}
class (Box typ) => Layout typ where
   type LayoutExtra typ extra :: Constraint
   {-
   We use constraint @(Class.Floating a)@ and not @(Format a)@
   because it allows us to align the components of complex numbers.

   We use a BoxedArray instead of a nested list,
   although both the underlying formatters
   and the frontend use a nested list.
   This gives us a little more type safety for block matrices.
   -}
   layout ::
      (LayoutExtra typ xl, LayoutExtra 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 ->
      BoxedArray.Array (height, width)
         (Output.Separator, Maybe (Output.Style, a))

instance Layout Scale where
   type LayoutExtra Scale extra = ()
   layout :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> Array (height, width) (Separator, Maybe (Style, a))
layout (Scale shape a) =
      let n :: Int
n = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
shape in
      -- ToDo: 'take' no longer needed when BoxedArray.fromList includes it
      (height, height)
-> [(Separator, Maybe (Style, a))]
-> Array (height, height) (Separator, Maybe (Style, a))
forall sh a. C sh => sh -> [a] -> Array sh a
BoxedArray.fromList (height
shape,height
shape) ([(Separator, Maybe (Style, a))]
 -> Array (height, height) (Separator, Maybe (Style, a)))
-> [(Separator, Maybe (Style, a))]
-> Array (height, height) (Separator, Maybe (Style, a))
forall a b. (a -> b) -> a -> b
$ Int
-> [(Separator, Maybe (Style, a))]
-> [(Separator, Maybe (Style, a))]
forall a. Int -> [a] -> [a]
take (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n) ([(Separator, Maybe (Style, a))]
 -> [(Separator, Maybe (Style, a))])
-> [(Separator, Maybe (Style, a))]
-> [(Separator, Maybe (Style, a))]
forall a b. (a -> b) -> a -> b
$
      [(Separator, Maybe (Style, a))] -> [(Separator, Maybe (Style, a))]
forall a. [a] -> [a]
cycle ([(Separator, Maybe (Style, a))]
 -> [(Separator, Maybe (Style, a))])
-> [(Separator, Maybe (Style, a))]
-> [(Separator, Maybe (Style, a))]
forall a b. (a -> b) -> a -> b
$
      (Separator
Output.Space, (Style, a) -> Maybe (Style, a)
forall a. a -> Maybe a
Just (Style
Output.Stored, a
a))
      (Separator, Maybe (Style, a))
-> [(Separator, Maybe (Style, a))]
-> [(Separator, Maybe (Style, a))]
forall a. a -> [a] -> [a]
:
      Int
-> (Separator, Maybe (Style, a)) -> [(Separator, Maybe (Style, a))]
forall a. Int -> a -> [a]
replicate Int
n (Separator
Output.Space, Maybe (Style, a)
forall a. Maybe a
Nothing)

instance Layout Permutation where
   type LayoutExtra Permutation extra = ()
   layout :: Matrix Permutation xl xu lower upper meas vert horiz height width a
-> Array (height, width) (Separator, Maybe (Style, a))
layout (Permutation perm) =
      let sh :: height
sh = Permutation height -> height
forall sh. Permutation sh -> sh
Perm.size Permutation height
perm in
      (height, height)
-> [(Separator, Maybe (Style, a))]
-> Array (height, height) (Separator, Maybe (Style, a))
forall sh a. C sh => sh -> [a] -> Array sh a
BoxedArray.fromList (height
sh,height
sh) ([(Separator, Maybe (Style, a))]
 -> Array (height, height) (Separator, Maybe (Style, a)))
-> [(Separator, Maybe (Style, a))]
-> Array (height, height) (Separator, Maybe (Style, a))
forall a b. (a -> b) -> a -> b
$ [[(Separator, Maybe (Style, a))]]
-> [(Separator, Maybe (Style, a))]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[(Separator, Maybe (Style, a))]]
 -> [(Separator, Maybe (Style, a))])
-> [[(Separator, Maybe (Style, a))]]
-> [(Separator, Maybe (Style, a))]
forall a b. (a -> b) -> a -> b
$
      ([Maybe a] -> [(Separator, Maybe (Style, a))])
-> [[Maybe a]] -> [[(Separator, Maybe (Style, a))]]
forall a b. (a -> b) -> [a] -> [b]
map ((Maybe a -> (Separator, Maybe (Style, a)))
-> [Maybe a] -> [(Separator, Maybe (Style, a))]
forall a b. (a -> b) -> [a] -> [b]
map ((,) Separator
Output.Space (Maybe (Style, a) -> (Separator, Maybe (Style, a)))
-> (Maybe a -> Maybe (Style, a))
-> Maybe a
-> (Separator, Maybe (Style, a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> (Style, a)) -> Maybe a -> Maybe (Style, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((,) Style
Output.Stored))) ([[Maybe a]] -> [[(Separator, Maybe (Style, a))]])
-> [[Maybe a]] -> [[(Separator, Maybe (Style, a))]]
forall a b. (a -> b) -> a -> b
$
      Permutation height -> [[Maybe a]]
forall sh a. (C sh, Floating a) => Permutation sh -> [[Maybe a]]
Perm.layout Permutation height
perm



instance
   (MultiplySame typ, MultiplySameExtra typ xl, MultiplySameExtra typ xu,
    MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, height ~ width, Class.Floating a) =>
      Semigroup (Matrix typ xl xu lower upper meas vert horiz height width a)
         where
   <> :: 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 matrix xl xu lower upper meas vert horiz sh a.
(MultiplySame typ,
 matrix ~ Matrix typ xl xu lower upper meas vert horiz sh sh a,
 MultiplySameExtra typ xl, MultiplySameExtra typ xu,
 PowerStrip lower, PowerStrip upper, Measure meas, C vert, C horiz,
 C sh, Eq sh, Floating a) =>
matrix -> matrix -> matrix
multiplySame

class (Box typ) => MultiplySame typ where
   type MultiplySameExtra typ extra :: Constraint
   multiplySame ::
      (matrix ~ Matrix typ xl xu lower upper meas vert horiz sh sh a,
       MultiplySameExtra typ xl, MultiplySameExtra typ xu,
       MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
       Extent.Measure meas, Extent.C vert, Extent.C horiz,
       Shape.C sh, Eq sh, Class.Floating a) =>
      matrix -> matrix -> matrix

instance MultiplySame Scale where
   type MultiplySameExtra Scale extra = extra ~ ()
   multiplySame :: matrix -> matrix -> matrix
multiplySame =
      String
-> (Matrix Scale () () lower upper meas vert horiz sh sh a -> sh)
-> (a
    -> Matrix Scale () () lower upper meas vert horiz sh sh a
    -> matrix)
-> Matrix Scale () () lower upper meas vert horiz sh sh a
-> Matrix Scale () () lower upper meas vert horiz sh sh a
-> matrix
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
"Scale.multiplySame" Matrix Scale () () lower upper meas vert horiz sh sh a -> sh
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
height
         (\a
a (Scale shape b) -> sh -> a -> Quadratic Scale () () Empty Empty sh a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Scale sh
shape (a -> Quadratic Scale () () Empty Empty sh a)
-> a -> Quadratic Scale () () Empty Empty sh a
forall a b. (a -> b) -> a -> b
$ a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
b)

instance MultiplySame Permutation where
   type MultiplySameExtra Permutation extra = extra ~ ()
   multiplySame :: matrix -> matrix -> matrix
multiplySame (Permutation a) (Permutation b) =
      Permutation sh -> Quadratic Permutation () () lower upper sh a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Permutation (Permutation sh -> Quadratic Permutation () () lower upper sh a)
-> Permutation sh -> Quadratic Permutation () () lower upper sh a
forall a b. (a -> b) -> a -> b
$ Permutation sh -> Permutation sh -> Permutation sh
forall sh.
(C sh, Eq sh) =>
Permutation sh -> Permutation sh -> Permutation sh
Perm.multiply Permutation sh
b Permutation sh
a


instance
   (MultiplySame typ, StaticIdentity typ,
    MultiplySameExtra typ xl, MultiplySameExtra typ xu,
    StaticIdentityExtra typ xl, StaticIdentityStrip typ lower,
    StaticIdentityExtra typ xu, StaticIdentityStrip typ upper,
    MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper,
    meas ~ Shape, vert ~ Small, horiz ~ Small,
    Shape.Static height, Eq height, height ~ width, Class.Floating a) =>
      Monoid (Matrix typ xl xu lower upper meas vert horiz height width a) where
   mappend :: 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
mappend = 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 a. Semigroup a => a -> a -> a
(<>)
   mempty :: Matrix typ xl xu lower upper meas vert horiz height width a
mempty = Matrix typ xl xu lower upper meas vert horiz height width a
forall typ xl lower xu upper sh a.
(StaticIdentity typ, StaticIdentityExtra typ xl,
 StaticIdentityStrip typ lower, StaticIdentityExtra typ xu,
 StaticIdentityStrip typ upper, Static sh, Floating a) =>
Quadratic typ xl xu lower upper sh a
staticIdentity

class StaticIdentity typ where
   type StaticIdentityExtra typ extra :: Constraint
   type StaticIdentityStrip typ strip :: Constraint
   staticIdentity ::
      (StaticIdentityExtra typ xl, StaticIdentityStrip typ lower) =>
      (StaticIdentityExtra typ xu, StaticIdentityStrip typ upper) =>
      (Shape.Static sh, Class.Floating a) =>
      Quadratic typ xl xu lower upper sh a

instance StaticIdentity Scale where
   type StaticIdentityExtra Scale extra = extra ~ ()
   type StaticIdentityStrip Scale strip = strip ~ Empty
   staticIdentity :: Quadratic Scale xl xu lower upper sh a
staticIdentity = sh -> a -> Quadratic Scale () () Empty Empty sh a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Scale sh
forall sh. Static sh => sh
Shape.static a
1

instance StaticIdentity Permutation where
   type StaticIdentityExtra Permutation extra = extra ~ ()
   type StaticIdentityStrip Permutation strip = strip ~ Filled
   staticIdentity :: Quadratic Permutation xl xu lower upper sh a
staticIdentity = Permutation sh -> Quadratic Permutation () () lower upper sh a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
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
forall sh. Static sh => sh
Shape.static


scaleWithCheck :: (Eq shape) =>
   String -> (b -> shape) ->
   (a -> b -> c) ->
   Matrix Scale xl xu lower upper meas vert horiz shape shape a ->
   b -> c
scaleWithCheck :: String
-> (b -> shape)
-> (a -> b -> c)
-> Matrix Scale xl xu lower upper meas vert horiz shape shape a
-> b
-> c
scaleWithCheck String
name b -> shape
getSize a -> b -> c
f (Scale shape a) b
b =
   if shape
shape shape -> shape -> Bool
forall a. Eq a => a -> a -> Bool
== b -> shape
getSize b
b
      then a -> b -> c
f a
a b
b
      else String -> c
forall a. HasCallStack => String -> a
error (String -> c) -> String -> c
forall a b. (a -> b) -> a -> b
$ String
name String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
": dimensions mismatch"


class Box typ where
   type BoxExtra typ extra :: Constraint
   extent ::
      (BoxExtra typ xl, BoxExtra typ xu) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      Matrix typ xl xu lower upper meas vert horiz height width a ->
      Extent.Extent meas vert horiz height width
   height ::
      (BoxExtra typ xl, BoxExtra typ xu) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      Matrix typ xl xu lower upper meas vert horiz height width a -> height
   height = Extent meas vert horiz 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 vert horiz height width -> height)
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> Extent meas vert horiz height width)
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> height
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix typ xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
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
-> Extent meas vert horiz height width
extent
   width ::
      (BoxExtra typ xl, BoxExtra typ xu) =>
      (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
      Matrix typ xl xu lower upper meas vert horiz height width a -> width
   width = Extent meas vert horiz height width -> width
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> width
Extent.width (Extent meas vert horiz height width -> width)
-> (Matrix typ xl xu lower upper meas vert horiz height width a
    -> Extent meas vert horiz height width)
-> Matrix typ xl xu lower upper meas vert horiz height width a
-> width
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix typ xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
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
-> Extent meas vert horiz height width
extent

instance Box Scale where
   type BoxExtra Scale extra = ()
   extent :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
extent (Scale shape _) = height -> Square height
forall sh. sh -> Square sh
Extent.square height
shape
   height :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> height
height (Scale shape _) = height
shape
   width :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> width
width (Scale shape _) = height
width
shape

instance Box Identity where
   type BoxExtra Identity extra = ()
   extent :: Matrix Identity xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
extent (Identity extent_) = Extent meas vert horiz height width
Extent meas Small Small height width
extent_

instance Box Permutation where
   type BoxExtra Permutation extra = ()
   extent :: Matrix Permutation xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
extent (Permutation perm) = height -> Square height
forall sh. sh -> Square sh
Extent.square (height -> Square height) -> height -> Square height
forall a b. (a -> b) -> a -> b
$ Permutation height -> height
forall sh. Permutation sh -> sh
Perm.size Permutation height
perm
   height :: Matrix Permutation xl xu lower upper meas vert horiz height width a
-> height
height (Permutation perm) = Permutation height -> height
forall sh. Permutation sh -> sh
Perm.size Permutation height
perm
   width :: Matrix Permutation xl xu lower upper meas vert horiz height width a
-> width
width (Permutation perm) = Permutation height -> height
forall sh. Permutation sh -> sh
Perm.size Permutation height
perm

instance (Eq fuse) => Box (Product fuse) where
   type BoxExtra (Product fuse) extra =
         (Box (ProductType extra),
          BoxExtra (ProductType extra) (ProductExtraL extra),
          BoxExtra (ProductType extra) (ProductExtraU extra))
   extent :: Matrix
  (Product fuse) xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
extent (Product a b) =
      Extent meas vert horiz height width
-> Maybe (Extent meas vert horiz height width)
-> Extent meas vert horiz height width
forall a. a -> Maybe a -> a
fromMaybe (String -> Extent meas vert horiz height width
forall a. HasCallStack => String -> a
error String
"Matrix.Product: shapes mismatch") (Maybe (Extent meas vert horiz height width)
 -> Extent meas vert horiz height width)
-> Maybe (Extent meas vert horiz height width)
-> Extent meas vert horiz height width
forall a b. (a -> b) -> a -> b
$
      Extent meas vert horiz height fuse
-> Extent meas vert horiz fuse width
-> Maybe (Extent meas vert horiz height width)
forall meas vert horiz fuse height width.
(Measure meas, C vert, C horiz, Eq fuse) =>
Extent meas vert horiz height fuse
-> Extent meas vert horiz fuse width
-> Maybe (Extent meas vert horiz height width)
Extent.fuse (Matrix typA xlA xuA lowerA upperA meas vert horiz height fuse a
-> Extent meas vert horiz height fuse
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
-> Extent meas vert horiz height width
extent Matrix typA xlA xuA lowerA upperA meas vert horiz height fuse a
a) (Matrix typB xlB xuB lowerB upperB meas vert horiz fuse width a
-> Extent meas vert horiz fuse width
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
-> Extent meas vert horiz height width
extent Matrix typB xlB xuB lowerB upperB meas vert horiz fuse width a
b)

squareSize ::
   (Box typ, BoxExtra typ xl, BoxExtra typ xu) =>
   Quadratic typ xl xu lower upper sh a -> sh
squareSize :: Quadratic typ xl xu lower upper sh a -> sh
squareSize = Quadratic typ xl xu lower upper sh a -> sh
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
height

indices ::
   (Box typ, BoxExtra typ xl, BoxExtra typ xu,
    Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Shape.Indexed height, Shape.Indexed width) =>
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   [(Shape.Index height, Shape.Index width)]
indices :: Matrix typ xl xu lower upper meas vert horiz height width a
-> [(Index height, Index width)]
indices Matrix typ xl xu lower upper meas vert horiz height width a
sh = (height, width) -> [Index (height, width)]
forall sh. Indexed sh => sh -> [Index sh]
Shape.indices (Matrix typ xl xu lower upper 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
height Matrix typ xl xu lower upper meas vert horiz height width a
sh, Matrix typ xl xu lower upper meas vert horiz height width a
-> width
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
-> width
width Matrix typ xl xu lower upper meas vert horiz height width a
sh)


class (Box typ) => ToQuadratic typ where
   heightToQuadratic ::
      (Extent.Measure meas) =>
      QuadraticMeas typ xl xu lower upper meas height width a ->
      Quadratic typ xl xu lower upper height a
   widthToQuadratic ::
      (Extent.Measure meas) =>
      QuadraticMeas typ xl xu lower upper meas height width a ->
      Quadratic typ xl xu lower upper width a

instance ToQuadratic Scale where
   heightToQuadratic :: QuadraticMeas Scale xl xu lower upper meas height width a
-> Quadratic Scale xl xu lower upper height a
heightToQuadratic (Scale shape a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Scale height
shape a
a
   widthToQuadratic :: QuadraticMeas Scale xl xu lower upper meas height width a
-> Quadratic Scale xl xu lower upper width a
widthToQuadratic (Scale shape a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Scale height
shape a
a

instance ToQuadratic Identity where
   heightToQuadratic :: QuadraticMeas Identity xl xu lower upper meas height width a
-> Quadratic Identity xl xu lower upper height a
heightToQuadratic (Identity extent_) =
      Extent Shape Small Small height height
-> QuadraticMeas Identity () () Empty Empty Shape height height a
forall meas height width a.
Measure meas =>
Extent meas Small Small height width
-> QuadraticMeas Identity () () Empty Empty meas height width a
Identity (Extent Shape Small Small height height
 -> QuadraticMeas Identity () () Empty Empty Shape height height a)
-> Extent Shape Small Small height height
-> QuadraticMeas Identity () () Empty Empty Shape height height a
forall a b. (a -> b) -> a -> b
$ height -> Extent Shape Small Small height height
forall sh. sh -> Square sh
Extent.square (height -> Extent Shape Small Small height height)
-> height -> Extent Shape Small Small height height
forall a b. (a -> b) -> a -> b
$ 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_
   widthToQuadratic :: QuadraticMeas Identity xl xu lower upper meas height width a
-> Quadratic Identity xl xu lower upper width a
widthToQuadratic (Identity extent_) =
      Extent Shape Small Small width width
-> QuadraticMeas Identity () () Empty Empty Shape width width a
forall meas height width a.
Measure meas =>
Extent meas Small Small height width
-> QuadraticMeas Identity () () Empty Empty meas height width a
Identity (Extent Shape Small Small width width
 -> QuadraticMeas Identity () () Empty Empty Shape width width a)
-> Extent Shape Small Small width width
-> QuadraticMeas Identity () () Empty Empty Shape width width a
forall a b. (a -> b) -> a -> b
$ width -> Extent Shape Small Small width width
forall sh. sh -> Square sh
Extent.square (width -> Extent Shape Small Small width width)
-> width -> Extent Shape Small Small width width
forall a b. (a -> b) -> a -> b
$ Extent meas Small Small height width -> width
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> width
Extent.width Extent meas Small Small height width
extent_

instance ToQuadratic Permutation where
   heightToQuadratic :: QuadraticMeas Permutation xl xu lower upper meas height width a
-> Quadratic Permutation xl xu lower upper height a
heightToQuadratic (Permutation perm) = Permutation height
-> Quadratic Permutation () () lower upper height a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Permutation Permutation height
perm
   widthToQuadratic :: QuadraticMeas Permutation xl xu lower upper meas height width a
-> Quadratic Permutation xl xu lower upper width a
widthToQuadratic (Permutation perm) = Permutation height
-> Quadratic Permutation () () lower upper height a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Permutation Permutation height
perm


class (Box typ) => MapExtent typ where
   type MapExtentExtra typ extra :: Constraint
   type MapExtentStrip typ strip :: Constraint
   mapExtent ::
      (MapExtentExtra typ xl, MapExtentStrip typ lower) =>
      (MapExtentExtra typ xu, MapExtentStrip typ upper) =>
      (Extent.Measure measA, Extent.C vertA, Extent.C horizA) =>
      (Extent.Measure measB, Extent.C vertB, Extent.C horizB) =>
      ExtentStrict.Map measA vertA horizA measB vertB horizB height width ->
      Matrix typ xl xu lower upper measA vertA horizA height width a ->
      Matrix typ xl xu lower upper measB vertB horizB height width a


class (Box typ) => Transpose typ where
   type TransposeExtra typ extra :: Constraint
   transpose ::
      (TransposeExtra typ xl, 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

instance Transpose Scale where
   type TransposeExtra Scale extra = ()
   transpose :: Matrix Scale xl xu lower upper meas vert horiz height width a
-> Matrix Scale xu xl upper lower meas horiz vert width height a
transpose (Scale shape a) = height -> a -> Quadratic Scale () () Empty Empty height a
forall sh a. sh -> a -> Quadratic Scale () () Empty Empty sh a
Scale height
shape a
a

instance Transpose Identity where
   type TransposeExtra Identity extra = ()
   transpose :: Matrix Identity xl xu lower upper meas vert horiz height width a
-> Matrix Identity xu xl upper lower meas horiz vert width height a
transpose (Identity extent_) = Extent meas Small Small width height
-> QuadraticMeas Identity () () Empty Empty meas width height a
forall meas height width a.
Measure meas =>
Extent meas Small Small height width
-> QuadraticMeas Identity () () Empty Empty meas height width a
Identity (Extent meas Small Small width height
 -> QuadraticMeas Identity () () Empty Empty meas width height a)
-> Extent meas Small Small width height
-> QuadraticMeas Identity () () Empty Empty meas width height a
forall a b. (a -> b) -> a -> b
$ Extent meas Small Small height width
-> Extent meas Small Small width height
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width
-> Extent meas horiz vert width height
Extent.transpose Extent meas Small Small height width
extent_

instance Transpose Permutation where
   type TransposeExtra Permutation extra = ()
   transpose :: Matrix Permutation xl xu lower upper meas vert horiz height width a
-> Matrix
     Permutation xu xl upper lower meas horiz vert width height a
transpose (Permutation perm) = Permutation height
-> Quadratic Permutation () () upper lower height a
forall sh lower upper a.
Permutation sh -> Quadratic Permutation () () lower upper sh a
Permutation (Permutation height
 -> Quadratic Permutation () () upper lower height a)
-> Permutation height
-> Quadratic Permutation () () upper lower height a
forall a b. (a -> b) -> a -> b
$ Permutation height -> Permutation height
forall sh. C sh => Permutation sh -> Permutation sh
Perm.transpose Permutation height
perm

instance (Shape.C fuse, Eq fuse) => Transpose (Product fuse) where
   type TransposeExtra (Product fuse) extra =
         (Transpose (ProductType extra),
          TransposeExtra (ProductType extra) (ProductExtraL extra),
          TransposeExtra (ProductType extra) (ProductExtraU extra))
   transpose :: Matrix
  (Product fuse) xl xu lower upper meas vert horiz height width a
-> Matrix
     (Product fuse) xu xl upper lower meas horiz vert width height a
transpose (Product a b) = Matrix typB xuB xlB upperB lowerB meas horiz vert width fuse a
-> Matrix typA xuA xlA upperA lowerA meas horiz vert fuse height a
-> Matrix
     (Product fuse)
     (typB, xuB, xlB, upperB, lowerB)
     (typA, xlA, xuA, lowerA, upperA)
     upper
     lower
     meas
     horiz
     vert
     width
     height
     a
forall lowerA lowerB lowerC upperA upperB upperC typA xlA xuA meas
       vert horiz height fuse a typB xlB xuB width.
(MultipliedBands lowerA lowerB ~ lowerC,
 MultipliedBands lowerB lowerA ~ lowerC,
 MultipliedBands upperA upperB ~ upperC,
 MultipliedBands upperB upperA ~ upperC) =>
Matrix typA xlA xuA lowerA upperA meas vert horiz height fuse a
-> Matrix typB xlB xuB lowerB upperB meas vert horiz fuse width a
-> Matrix
     (Product fuse)
     (typA, xlA, xuA, lowerA, upperA)
     (typB, xuB, xlB, upperB, lowerB)
     lowerC
     upperC
     meas
     vert
     horiz
     height
     width
     a
Product (Matrix typB xlB xuB lowerB upperB meas vert horiz fuse width a
-> Matrix typB xuB xlB upperB lowerB meas horiz vert width fuse 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
transpose Matrix typB xlB xuB lowerB upperB meas vert horiz fuse width a
b) (Matrix typA xlA xuA lowerA upperA meas vert horiz height fuse a
-> Matrix typA xuA xlA upperA lowerA meas horiz vert fuse 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
transpose Matrix typA xlA xuA lowerA upperA meas vert horiz height fuse a
a)


swapMultiply ::
   (Transpose typA, Transpose typB) =>
   (TransposeExtra typA xlA, TransposeExtra typA xuA) =>
   (TransposeExtra typB xlB, TransposeExtra typB xuB) =>
   (Extent.Measure measA, Extent.C vertA, Extent.C horizA) =>
   (Extent.Measure measB, Extent.C vertB, Extent.C horizB) =>
   (Shape.C heightA, Shape.C widthA) =>
   (Shape.C heightB, Shape.C widthB) =>
   (Class.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
swapMultiply :: (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
swapMultiply 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
multiplyTrans Matrix
  typA xlA xuA lowerA upperA measA vertA horizA heightA widthA a
a matrix
b =
   Matrix
  typB xuB xlB upperB lowerB measB horizB vertB widthB heightB a
-> Matrix
     typB xlB xuB lowerB upperB measB vertB horizB heightB widthB 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
transpose (Matrix
   typB xuB xlB upperB lowerB measB horizB vertB widthB heightB a
 -> Matrix
      typB xlB xuB lowerB upperB measB vertB horizB heightB widthB a)
-> Matrix
     typB xuB xlB upperB lowerB measB horizB vertB widthB heightB a
-> Matrix
     typB xlB xuB lowerB upperB measB vertB horizB heightB widthB a
forall a b. (a -> b) -> a -> b
$ 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
multiplyTrans matrix
b (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 xuA xlA upperA lowerA measA horizA vertA widthA heightA a
-> Matrix
     typB xuB xlB upperB lowerB measB horizB vertB widthB heightB a
forall a b. (a -> b) -> a -> b
$ Matrix
  typA xlA xuA lowerA upperA measA vertA horizA heightA widthA a
-> Matrix
     typA xuA xlA upperA lowerA measA horizA vertA widthA heightA 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
transpose Matrix
  typA xlA xuA lowerA upperA measA vertA horizA heightA widthA a
a

powerStrips ::
   (MatrixShape.PowerStrip lower, MatrixShape.PowerStrip upper) =>
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   (MatrixShape.PowerStripSingleton lower,
    MatrixShape.PowerStripSingleton upper)
powerStrips :: Matrix typ xl xu lower upper meas vert horiz height width a
-> (PowerStripSingleton lower, PowerStripSingleton upper)
powerStrips Matrix typ xl xu lower upper meas vert horiz height width a
_ =
   (PowerStripSingleton lower
forall c. PowerStrip c => PowerStripSingleton c
MatrixShape.powerStripSingleton, PowerStripSingleton upper
forall c. PowerStrip c => PowerStripSingleton c
MatrixShape.powerStripSingleton)

strips ::
   (MatrixShape.Strip lower, MatrixShape.Strip upper) =>
   Matrix typ xl xu lower upper meas vert horiz height width a ->
   (MatrixShape.StripSingleton lower, MatrixShape.StripSingleton upper)
strips :: Matrix typ xl xu lower upper meas vert horiz height width a
-> (StripSingleton lower, StripSingleton upper)
strips Matrix typ xl xu lower upper meas vert horiz height width a
_ = (StripSingleton lower
forall c. Strip c => StripSingleton c
MatrixShape.stripSingleton, StripSingleton upper
forall c. Strip c => StripSingleton c
MatrixShape.stripSingleton)