{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GADTs #-}
module Numeric.LAPACK.Matrix.Class (
   SquareShape(toSquare, takeDiagonal, mapSquareSize, identityFrom),
   MapSize(mapHeight, mapWidth),
   trace,
   Complex(conjugate, fromReal, toComplex),
   adjoint,
   ) where

import qualified Numeric.LAPACK.Matrix.Array.Basic as OmniMatrix
import qualified Numeric.LAPACK.Matrix.Array as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Type 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.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 (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


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) =>
   (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 meas vert horiz width height a xl xu lower upper.
(Transpose typ, Measure meas, C vert, C horiz, C width, C height,
 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
   toSquare ::
      (Shape.C sh, Class.Floating a) =>
      Matrix.Quadratic typ xl xu lower upper sh a -> ArrMatrix.Square sh a
   takeDiagonal ::
      (Shape.C sh, Class.Floating a) =>
      Matrix.Quadratic typ xl xu lower upper sh a -> Vector sh a
   {- |
   The number of rows and columns
   must be maintained by the shape mapping function.
   -}
   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
   identityFrom ::
      (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
   toSquare :: Quadratic (Array pack property) xl xu lower upper sh a
-> Square sh a
toSquare a :: Quadratic (Array pack property) xl xu lower upper sh a
a@(ArrMatrix.Array _) = ArrayMatrix pack property lower upper Shape Small Small sh sh a
-> Square sh 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 Quadratic (Array pack property) xl xu lower upper sh a
ArrayMatrix pack property lower upper Shape Small Small sh sh a
a
   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
   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
   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
   toSquare :: Quadratic Scale xl xu lower upper sh a -> Square sh a
toSquare (Matrix.Scale sh a) =
      PlainArray
  Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> Square sh a
forall pack prop lower upper meas vert horiz height width a.
FromPlain pack prop lower upper meas vert horiz height width =>
PlainArray pack prop lower upper meas vert horiz height width a
-> ArrayMatrix pack prop lower upper meas vert horiz height width a
ArrMatrix.lift0 (PlainArray
   Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
 -> Square sh a)
-> PlainArray
     Unpacked Arbitrary Filled Filled Shape Small Small sh sh a
-> Square sh a
forall a b. (a -> b) -> a -> b
$ Banded U0 U0 Shape Small Small sh sh a
-> Full Shape Small Small sh sh 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 sh sh a
 -> Full Shape Small Small sh sh a)
-> Banded U0 U0 Shape Small Small sh sh a
-> Full Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$
      Order -> Vector sh a -> Banded U0 U0 Shape Small Small sh sh a
forall sh a.
(C sh, Floating a) =>
Order -> Vector sh a -> Diagonal sh a
Banded.diagonal Order
Layout.RowMajor (Vector sh a -> Banded U0 U0 Shape Small Small sh sh a)
-> Vector sh a -> Banded U0 U0 Shape Small Small sh sh a
forall a b. (a -> b) -> a -> b
$ sh -> a -> Vector sh a
forall sh a. (C sh, Floating a) => sh -> a -> Vector sh a
Vector.constant sh
sh a
a
   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
   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
   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
   toSquare :: Quadratic Permutation xl xu lower upper sh a -> Square sh a
toSquare (Matrix.Permutation perm) = Permutation sh -> Square sh a
forall sh a. (C sh, Floating a) => Permutation sh -> Square sh a
PermPub.toMatrix Permutation sh
perm
   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
   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
   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, 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 sh a xl xu lower upper.
(SquareShape typ, C sh, Floating a) =>
Quadratic typ xl xu lower upper sh a -> Vector sh a
takeDiagonal



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