{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
module Numeric.LAPACK.Orthogonal.Plain where

import qualified Numeric.LAPACK.Matrix.Divide as Divide
import qualified Numeric.LAPACK.Matrix.Multiply as Multiply
import qualified Numeric.LAPACK.Matrix.Type.Private as Matrix
import qualified Numeric.LAPACK.Matrix.Array.Private as ArrMatrix
import qualified Numeric.LAPACK.Matrix.Banded.Basic as Banded
import qualified Numeric.LAPACK.Matrix.Basic as Basic
import qualified Numeric.LAPACK.Matrix.Private as MatrixPriv
import qualified Numeric.LAPACK.Matrix.Plain.Format as ArrFormat
import qualified Numeric.LAPACK.Matrix.Layout as LayoutPub
import qualified Numeric.LAPACK.Matrix.Layout.Private as Layout
import qualified Numeric.LAPACK.Matrix.Extent.Strict as ExtentStrict
import qualified Numeric.LAPACK.Matrix.Extent.Private as ExtentPriv
import qualified Numeric.LAPACK.Matrix.Extent as Extent
import qualified Numeric.LAPACK.Split as Split
import Numeric.LAPACK.Output ((/+/))
import Numeric.LAPACK.Matrix.Plain.Format (formatArray)
import Numeric.LAPACK.Matrix.Type.Private (Matrix)
import Numeric.LAPACK.Matrix.Triangular.Basic (Upper)
import Numeric.LAPACK.Matrix.Layout.Private
         (Order(RowMajor, ColumnMajor), sideSwapFromOrder)
import Numeric.LAPACK.Matrix.Extent.Private (Extent)
import Numeric.LAPACK.Matrix.Modifier
         (Transposition(NonTransposed, Transposed),
          Conjugation(NonConjugated, Conjugated))
import Numeric.LAPACK.Matrix.Private (Full)
import Numeric.LAPACK.Scalar (RealOf, zero, isZero, absolute, conjugate)
import Numeric.LAPACK.Shape.Private (Unchecked(Unchecked), deconsUnchecked)
import Numeric.LAPACK.Private
         (fill, copySubMatrix, copyBlock, conjugateToTemp, caseRealComplexFunc,
          withAutoWorkspaceInfo, errorCodeMsg)

import qualified Numeric.LAPACK.FFI.Generic as LapackGen
import qualified Numeric.Netlib.Utility as Call
import qualified Numeric.Netlib.Class as Class

import qualified Data.Array.Comfort.Storable.Unchecked.Monadic as ArrayIO
import qualified Data.Array.Comfort.Storable.Unchecked as Array
import qualified Data.Array.Comfort.Shape as Shape
import Data.Array.Comfort.Storable.Unchecked (Array(Array))

import Foreign.Marshal.Array (advancePtr)
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Storable (Storable)

import Control.Monad.Trans.Cont (ContT(ContT), evalContT)
import Control.Monad.IO.Class (liftIO)
import Control.Monad (when)
import Control.Applicative (liftA2)

import qualified Data.List as List
import Data.Monoid ((<>))


data Hh

data instance Matrix Hh xl xu lower upper meas vert horiz height width a where
   Householder ::
      Banded.RectangularDiagonal meas vert horiz height width a ->
      SplitArray meas vert horiz height width a ->
      HouseholderFlex lower upper meas vert horiz height width a

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

type SplitArray meas vert horiz height width a =
         Split.Split Layout.Reflector meas vert horiz height width a

split_ ::
   Matrix Hh xl xu lower upper meas vert horiz height width a ->
   SplitArray meas vert horiz height width a
split_ :: Matrix Hh xl xu lower upper meas vert horiz height width a
-> SplitArray meas vert horiz height width a
split_ (Householder _tau split) = SplitArray meas vert horiz height width a
split

type HouseholderFlex = Matrix Hh () ()
type Householder = HouseholderFlex Layout.Filled Layout.Filled
type General height width =
         Householder Extent.Size Extent.Big Extent.Big height width
type Tall height width =
         Householder Extent.Size Extent.Big Extent.Small height width
type Wide height width =
         Householder Extent.Size Extent.Small Extent.Big height width
type LiberalSquare height width = SquareMeas Extent.Size height width
type Square sh = SquareMeas Extent.Shape sh sh
type SquareMeas meas height width =
         Householder meas Extent.Small Extent.Small height width


mapExtent ::
   (Extent.Measure measA, Extent.C vertA, Extent.C horizA) =>
   (Extent.Measure measB, Extent.C vertB, Extent.C horizB) =>
   ExtentPriv.Map measA vertA horizA measB vertB horizB height width ->
   HouseholderFlex lower upper measA vertA horizA height width a ->
   HouseholderFlex lower upper measB vertB horizB height width a
mapExtent :: Map measA vertA horizA measB vertB horizB height width
-> HouseholderFlex lower upper measA vertA horizA height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
mapExtent Map measA vertA horizA measB vertB horizB height width
f (Householder tau split) =
   RectangularDiagonal measB vertB horizB height width a
-> SplitArray measB vertB horizB height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder (Map measA vertA horizA measB vertB horizB height width
-> Banded U0 U0 measA vertA horizA height width a
-> RectangularDiagonal measB vertB horizB height width a
forall vertA horizA vertB horizB measA measB height width sub super
       a.
(C vertA, C horizA, C vertB, C horizB) =>
Map measA vertA horizA measB vertB horizB height width
-> Banded sub super measA vertA horizA height width a
-> Banded sub super measB vertB horizB height width a
Banded.mapExtent Map measA vertA horizA measB vertB horizB height width
f Banded U0 U0 measA vertA horizA height width a
tau) (SplitArray measB vertB horizB height width a
 -> HouseholderFlex lower upper measB vertB horizB height width a)
-> SplitArray measB vertB horizB height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
forall a b. (a -> b) -> a -> b
$ Map measA vertA horizA measB vertB horizB height width
-> Split Reflector measA vertA horizA height width a
-> SplitArray measB vertB horizB height width a
forall measA vertA horizA measB vertB horizB height width lower a.
(Measure measA, C vertA, C horizA, Measure measB, C vertB,
 C horizB) =>
Map measA vertA horizA measB vertB horizB height width
-> Split lower measA vertA horizA height width a
-> Split lower measB vertB horizB height width a
Split.mapExtent Map measA vertA horizA measB vertB horizB height width
f Split Reflector measA vertA horizA height width a
split

mapHeight ::
   (Extent.C vert, Extent.C horiz) =>
   (heightA -> heightB) ->
   HouseholderFlex lower upper Extent.Size vert horiz heightA width a ->
   HouseholderFlex lower upper Extent.Size vert horiz heightB width a
mapHeight :: (heightA -> heightB)
-> HouseholderFlex lower upper Size vert horiz heightA width a
-> HouseholderFlex lower upper Size vert horiz heightB width a
mapHeight heightA -> heightB
f (Householder tau split) =
   RectangularDiagonal Size vert horiz heightB width a
-> SplitArray Size vert horiz heightB width a
-> HouseholderFlex lower upper Size vert horiz heightB width a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder ((heightA -> heightB)
-> Banded U0 U0 Size vert horiz heightA width a
-> RectangularDiagonal Size vert horiz heightB width a
forall vert horiz heightA heightB sub super width a.
(C vert, C horiz) =>
(heightA -> heightB)
-> Banded sub super Size vert horiz heightA width a
-> Banded sub super Size vert horiz heightB width a
Banded.mapHeight heightA -> heightB
f Banded U0 U0 Size vert horiz heightA width a
tau) ((heightA -> heightB)
-> Split Reflector Size vert horiz heightA width a
-> SplitArray Size vert horiz heightB width a
forall vert horiz heightA heightB lower width a.
(C vert, C horiz) =>
(heightA -> heightB)
-> Split lower Size vert horiz heightA width a
-> Split lower Size vert horiz heightB width a
Split.mapHeight heightA -> heightB
f Split Reflector Size vert horiz heightA width a
split)

mapWidth ::
   (Extent.C vert, Extent.C horiz) =>
   (widthA -> widthB) ->
   HouseholderFlex lower upper Extent.Size vert horiz height widthA a ->
   HouseholderFlex lower upper Extent.Size vert horiz height widthB a
mapWidth :: (widthA -> widthB)
-> HouseholderFlex lower upper Size vert horiz height widthA a
-> HouseholderFlex lower upper Size vert horiz height widthB a
mapWidth widthA -> widthB
f (Householder tau split) =
   RectangularDiagonal Size vert horiz height widthB a
-> SplitArray Size vert horiz height widthB a
-> HouseholderFlex lower upper Size vert horiz height widthB a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder ((widthA -> widthB)
-> Banded U0 U0 Size vert horiz height widthA a
-> RectangularDiagonal Size vert horiz height widthB a
forall vert horiz widthA widthB sub super height a.
(C vert, C horiz) =>
(widthA -> widthB)
-> Banded sub super Size vert horiz height widthA a
-> Banded sub super Size vert horiz height widthB a
Banded.mapWidth widthA -> widthB
f Banded U0 U0 Size vert horiz height widthA a
tau) ((widthA -> widthB)
-> Split Reflector Size vert horiz height widthA a
-> SplitArray Size vert horiz height widthB a
forall vert horiz widthA widthB lower height a.
(C vert, C horiz) =>
(widthA -> widthB)
-> Split lower Size vert horiz height widthA a
-> Split lower Size vert horiz height widthB a
Split.mapWidth widthA -> widthB
f Split Reflector Size vert horiz height widthA a
split)

uncheck ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   HouseholderFlex lower upper meas vert horiz height width a ->
   HouseholderFlex lower upper meas vert horiz
                                    (Unchecked height) (Unchecked width) a
uncheck :: HouseholderFlex lower upper meas vert horiz height width a
-> HouseholderFlex
     lower upper meas vert horiz (Unchecked height) (Unchecked width) a
uncheck (Householder tau split) =
   RectangularDiagonal
  meas vert horiz (Unchecked height) (Unchecked width) a
-> SplitArray
     meas vert horiz (Unchecked height) (Unchecked width) a
-> HouseholderFlex
     lower upper meas vert horiz (Unchecked height) (Unchecked width) a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder
      ((Extent meas vert horiz height width
 -> Extent meas vert horiz (Unchecked height) (Unchecked width))
-> Banded U0 U0 meas vert horiz height width a
-> RectangularDiagonal
     meas vert horiz (Unchecked height) (Unchecked width) a
forall vertA horizA vertB horizB measA heightA widthA measB heightB
       widthB sub super a.
(C vertA, C horizA, C vertB, C horizB) =>
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Banded sub super measA vertA horizA heightA widthA a
-> Banded sub super measB vertB horizB heightB widthB a
Banded.mapExtentSizes ((height -> Unchecked height)
-> (width -> Unchecked width)
-> Extent meas vert horiz height width
-> Extent meas vert horiz (Unchecked height) (Unchecked width)
forall meas vert horiz height (f :: * -> *) width.
(Measure meas, C vert, C horiz) =>
(height -> f height)
-> (width -> f width)
-> Extent meas vert horiz height width
-> Extent meas vert horiz (f height) (f width)
ExtentPriv.mapWrap height -> Unchecked height
forall sh. sh -> Unchecked sh
Unchecked width -> Unchecked width
forall sh. sh -> Unchecked sh
Unchecked) Banded U0 U0 meas vert horiz height width a
tau)
      (Split Reflector meas vert horiz height width a
-> SplitArray
     meas vert horiz (Unchecked height) (Unchecked width) a
forall meas vert horiz lower height width a.
(Measure meas, C vert, C horiz) =>
Split lower meas vert horiz height width a
-> Split
     lower meas vert horiz (Unchecked height) (Unchecked width) a
Split.uncheck Split Reflector meas vert horiz height width a
split)


caseTallWide ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width) =>
   Householder meas vert horiz height width a ->
   Either (Tall height width a) (Wide height width a)
caseTallWide :: Householder meas vert horiz height width a
-> Either (Tall height width a) (Wide height width a)
caseTallWide (Householder tau (Array shape a)) =
   let consHouse :: Array (Banded U0 U0 meas vert horiz height width) a
-> ForeignPtr a
-> Split Reflector meas vert horiz height width
-> HouseholderFlex lower upper meas vert horiz height width a
consHouse Array (Banded U0 U0 meas vert horiz height width) a
taub ForeignPtr a
b Split Reflector meas vert horiz height width
newShape =
         RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder
            ((Banded U0 U0 meas vert horiz height width
 -> Banded U0 U0 meas vert horiz height width)
-> Array (Banded U0 U0 meas vert horiz height width) a
-> RectangularDiagonal meas vert horiz height width a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
               (\Banded U0 U0 meas vert horiz height width
bandShape ->
                  Banded U0 U0 meas vert horiz height width
bandShape{bandedExtent :: Extent meas vert horiz height width
Layout.bandedExtent = Split Reflector meas vert horiz height width
-> Extent meas vert horiz height width
forall lower meas vert horiz height width.
Split lower meas vert horiz height width
-> Extent meas vert horiz height width
Layout.splitExtent Split Reflector meas vert horiz height width
newShape})
               Array (Banded U0 U0 meas vert horiz height width) a
taub) (SplitArray meas vert horiz height width a
 -> HouseholderFlex lower upper meas vert horiz height width a)
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
         Split Reflector meas vert horiz height width
-> ForeignPtr a -> SplitArray meas vert horiz height width a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array Split Reflector meas vert horiz height width
newShape ForeignPtr a
b
   in (Split Reflector Size Big Small height width
 -> Either (Tall height width a) (Wide height width a))
-> (Split Reflector Size Small Big height width
    -> Either (Tall height width a) (Wide height width a))
-> Either
     (Split Reflector Size Big Small height width)
     (Split Reflector Size Small Big height width)
-> Either (Tall height width a) (Wide height width a)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Tall height width a
-> Either (Tall height width a) (Wide height width a)
forall a b. a -> Either a b
Left (Tall height width a
 -> Either (Tall height width a) (Wide height width a))
-> (Split Reflector Size Big Small height width
    -> Tall height width a)
-> Split Reflector Size Big Small height width
-> Either (Tall height width a) (Wide height width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array (Banded U0 U0 meas vert horiz height width) a
-> ForeignPtr a
-> Split Reflector Size Big Small height width
-> Tall height width a
forall meas vert horiz height width a meas vert horiz height width
       lower upper.
Array (Banded U0 U0 meas vert horiz height width) a
-> ForeignPtr a
-> Split Reflector meas vert horiz height width
-> HouseholderFlex lower upper meas vert horiz height width a
consHouse Array (Banded U0 U0 meas vert horiz height width) a
tau ForeignPtr a
a) (Wide height width a
-> Either (Tall height width a) (Wide height width a)
forall a b. b -> Either a b
Right (Wide height width a
 -> Either (Tall height width a) (Wide height width a))
-> (Split Reflector Size Small Big height width
    -> Wide height width a)
-> Split Reflector Size Small Big height width
-> Either (Tall height width a) (Wide height width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array (Banded U0 U0 meas vert horiz height width) a
-> ForeignPtr a
-> Split Reflector Size Small Big height width
-> Wide height width a
forall meas vert horiz height width a meas vert horiz height width
       lower upper.
Array (Banded U0 U0 meas vert horiz height width) a
-> ForeignPtr a
-> Split Reflector meas vert horiz height width
-> HouseholderFlex lower upper meas vert horiz height width a
consHouse Array (Banded U0 U0 meas vert horiz height width) a
tau ForeignPtr a
a) (Either
   (Split Reflector Size Big Small height width)
   (Split Reflector Size Small Big height width)
 -> Either (Tall height width a) (Wide height width a))
-> Either
     (Split Reflector Size Big Small height width)
     (Split Reflector Size Small Big height width)
-> Either (Tall height width a) (Wide height width a)
forall a b. (a -> b) -> a -> b
$
      Split Reflector meas vert horiz height width
-> Either
     (Split Reflector Size Big Small height width)
     (Split Reflector Size Small Big height width)
forall meas vert horiz height width lower.
(Measure meas, C vert, C horiz, C height, C width) =>
Split lower meas vert horiz height width
-> Either
     (Split lower Size Big Small height width)
     (Split lower Size Small Big height width)
Layout.caseTallWideSplit Split Reflector meas vert horiz height width
shape


instance Matrix.Format Hh where
   type FormatExtra Hh extra = extra ~ ()
   format :: Config
-> Matrix Hh xl xu lower upper meas vert horiz height width a
-> out
format Config
fmt (Householder tau m) =
      Config -> Array (ZeroBased Int) a -> out
forall sh a out.
(FormatArray sh, Floating a, Output out) =>
Config -> Array sh a -> out
formatArray Config
fmt ((Banded U0 U0 meas vert horiz height width -> ZeroBased Int)
-> Array (Banded U0 U0 meas vert horiz height width) a
-> Array (ZeroBased Int) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (Int -> ZeroBased Int
forall n. n -> ZeroBased n
Shape.ZeroBased (Int -> ZeroBased Int)
-> (Banded U0 U0 meas vert horiz height width -> Int)
-> Banded U0 U0 meas vert horiz height width
-> ZeroBased Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Banded U0 U0 meas vert horiz height width -> Int
forall sh. C sh => sh -> Int
Shape.size) Array (Banded U0 U0 meas vert horiz height width) a
tau)
      out -> out -> out
forall out. Output out => out -> out -> out
/+/
      Config
-> Array (Split Reflector meas vert horiz height width) a -> out
forall sh a out.
(FormatArray sh, Floating a, Output out) =>
Config -> Array sh a -> out
formatArray Config
fmt Array (Split Reflector meas vert horiz height width) a
m

instance Matrix.Layout Hh where
   type LayoutExtra Hh extra = extra ~ ()
   layout :: Matrix Hh xl xu lower upper meas vert horiz height width a
-> Array (height, width) (Separator, Maybe (Style, a))
layout (Householder _tau m) =
      Extent meas vert horiz height width
-> [[a]] -> Array (height, width) (Separator, Maybe (Style, a))
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width) =>
Extent meas vert horiz height width
-> [[a]] -> Array (height, width) (Separator, Maybe (Style, a))
ArrFormat.splitArrayFromList2 (Split Reflector meas vert horiz height width
-> Extent meas vert horiz height width
forall lower meas vert horiz height width.
Split lower meas vert horiz height width
-> Extent meas vert horiz height width
Layout.splitExtent (Split Reflector meas vert horiz height width
 -> Extent meas vert horiz height width)
-> Split Reflector meas vert horiz height width
-> Extent meas vert horiz height width
forall a b. (a -> b) -> a -> b
$ Array (Split Reflector meas vert horiz height width) a
-> Split Reflector meas vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Array (Split Reflector meas vert horiz height width) a
m) ([[a]] -> Array (height, width) (Separator, Maybe (Style, a)))
-> [[a]] -> Array (height, width) (Separator, Maybe (Style, a))
forall a b. (a -> b) -> a -> b
$
      Array (Split Reflector meas vert horiz height width) a -> [[a]]
forall lower meas vert horiz height width a.
(Eq lower, Measure meas, C vert, C horiz, C height, C width,
 Floating a) =>
Array (Split lower meas vert horiz height width) a -> [[a]]
ArrFormat.layoutSplit Array (Split Reflector meas vert horiz height width) a
m

fromMatrix ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Full meas vert horiz height width a ->
   Householder meas vert horiz height width a
fromMatrix :: Full meas vert horiz height width a
-> Householder meas vert horiz height width a
fromMatrix (Array shape :: Full meas vert horiz height width
shape@(Layout.Full Order
order Extent meas vert horiz height width
extent) ForeignPtr a
a) =
   (RectangularDiagonal meas vert horiz height width a
 -> SplitArray meas vert horiz height width a
 -> Householder meas vert horiz height width a)
-> (RectangularDiagonal meas vert horiz height width a,
    SplitArray meas vert horiz height width a)
-> Householder meas vert horiz height width a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> Householder meas vert horiz height width a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder ((RectangularDiagonal meas vert horiz height width a,
  SplitArray meas vert horiz height width a)
 -> Householder meas vert horiz height width a)
-> (RectangularDiagonal meas vert horiz height width a,
    SplitArray meas vert horiz height width a)
-> Householder meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
   RectangularDiagonal meas vert horiz height width
-> (Int -> Ptr a -> IO (SplitArray meas vert horiz height width a))
-> (RectangularDiagonal meas vert horiz height width a,
    SplitArray meas vert horiz height width a)
forall sh a b.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO b) -> (Array sh a, b)
Array.unsafeCreateWithSizeAndResult
      ((Int, RectangularDiagonal meas vert horiz height width)
-> RectangularDiagonal meas vert horiz height width
forall a b. (a, b) -> b
snd ((Int, RectangularDiagonal meas vert horiz height width)
 -> RectangularDiagonal meas vert horiz height width)
-> (Int, RectangularDiagonal meas vert horiz height width)
-> RectangularDiagonal meas vert horiz height width
forall a b. (a -> b) -> a -> b
$ Extent meas vert horiz height width
-> (Int, RectangularDiagonal meas vert horiz height width)
forall meas vert horiz height width.
(Measure meas, C vert, C horiz, C height, C width) =>
Extent meas vert horiz height width
-> (Int, RectangularDiagonal meas vert horiz height width)
Layout.rectangularDiagonal Extent meas vert horiz height width
extent) ((Int -> Ptr a -> IO (SplitArray meas vert horiz height width a))
 -> (RectangularDiagonal meas vert horiz height width a,
     SplitArray meas vert horiz height width a))
-> (Int -> Ptr a -> IO (SplitArray meas vert horiz height width a))
-> (RectangularDiagonal meas vert horiz height width a,
    SplitArray meas vert horiz height width a)
forall a b. (a -> b) -> a -> b
$ \Int
_ Ptr a
tauPtr ->
   Split Reflector meas vert horiz height width
-> (Ptr a -> IO ())
-> IO (SplitArray meas vert horiz height width a)
forall (m :: * -> *) sh a.
(PrimMonad m, C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> m (Array sh a)
ArrayIO.unsafeCreate
      (Reflector
-> Order
-> Extent meas vert horiz height width
-> Split Reflector meas vert horiz height width
forall lower meas vert horiz height width.
lower
-> Order
-> Extent meas vert horiz height width
-> Split lower meas vert horiz height width
Layout.Split Reflector
Layout.Reflector Order
order Extent meas vert horiz height width
extent) ((Ptr a -> IO ())
 -> IO (SplitArray meas vert horiz height width a))
-> (Ptr a -> IO ())
-> IO (SplitArray meas vert horiz height width a)
forall a b. (a -> b) -> a -> b
$ \Ptr a
qrPtr ->

   ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
      let (Int
m,Int
n) = Full meas vert horiz height width -> (Int, Int)
forall meas vert horiz height width.
(Measure meas, C vert, C horiz, C height, C width) =>
Full meas vert horiz height width -> (Int, Int)
Layout.dimensions Full meas vert horiz height width
shape
      Ptr CInt
mPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
m
      Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
      Ptr a
aPtr <- ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
a
      Ptr CInt
ldaPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
m
      IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ do
         Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock (Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n) Ptr a
aPtr Ptr a
qrPtr
         case Order
order of
            Order
RowMajor ->
               String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a.
Floating a =>
String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
withAutoWorkspaceInfo String
errorCodeMsg String
"gelqf" ((Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ())
-> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
                  Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
LapackGen.gelqf Ptr CInt
mPtr Ptr CInt
nPtr Ptr a
qrPtr Ptr CInt
ldaPtr Ptr a
tauPtr
            Order
ColumnMajor ->
               String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a.
Floating a =>
String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
withAutoWorkspaceInfo String
errorCodeMsg String
"geqrf" ((Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ())
-> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
                  Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
LapackGen.geqrf Ptr CInt
mPtr Ptr CInt
nPtr Ptr a
qrPtr Ptr CInt
ldaPtr Ptr a
tauPtr

determinantR ::
   (Extent.Measure meas, Extent.C vert,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Householder meas vert Extent.Small height width a -> a
determinantR :: Householder meas vert Small height width a -> a
determinantR = Split Reflector meas vert Small height width a -> a
forall meas vert height width a lower.
(Measure meas, C vert, C height, C width, Floating a) =>
Split lower meas vert Small height width a -> a
Split.determinantR (Split Reflector meas vert Small height width a -> a)
-> (Householder meas vert Small height width a
    -> Split Reflector meas vert Small height width a)
-> Householder meas vert Small height width a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder meas vert Small height width a
-> Split Reflector meas vert Small height width a
forall xl xu lower upper meas vert horiz height width a.
Matrix Hh xl xu lower upper meas vert horiz height width a
-> SplitArray meas vert horiz height width a
split_

{-
For complex numbers LAPACK uses not exactly reflections,
i.e. the determinants of the primitive transformations are not necessarily -1.

It holds: det(I-tau*v*v^H) = 1-tau*v^H*v
   because of https://en.wikipedia.org/wiki/Sylvester's_determinant_theorem
   simple proof from: https://en.wikipedia.org/wiki/Matrix_determinant_lemma
   I  0 . I+u*vt u .  I  0  =  I+u*vt     u      .  I  0 = I u
   vt 1     0    1   -vt 1     vt+vt*u*vt vt*u+1   -vt 1   0 vt*u+1

We already know:
   v^H*v is real and greater or equal to 1, because v[i] = 1,
   and determinant has absolute value 1.

Let k = v^H*v.
For which real k lies 1-tau*k on the unit circle?

   (1-taur*k)^2 + (taui*k)^2 = 1
   1-2*taur*k+(taur^2+taui^2)*k^2 = 1
   (taur^2 + taui^2)*k^2 - 2*taur*k = 0   (k/=0)
   (taur^2 + taui^2)*k - 2*taur = 0
   k = 2*taur / (taur^2 + taui^2)

   1-tau*k
      = (taur^2 + taui^2 - tau*2*taur) / (taur^2 + taui^2)
      = (taur^2 + taui^2 - 2*(taur+i*taui)*taur) / (taur^2 + taui^2)
      = (-taur^2 + taui^2 - 2*(i*taui)*taur) / (taur^2 + taui^2)
      = -(taur + i*taui)^2 / (taur^2 + taui^2)
-}
determinant ::
   (Shape.C sh, Class.Floating a) =>
   HouseholderFlex lower upper Extent.Shape Extent.Small Extent.Small sh sh a ->
   a
determinant :: HouseholderFlex lower upper Shape Small Small sh sh a -> a
determinant (Householder tau split) =
   (a -> a -> a) -> a -> [a] -> a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' a -> a -> a
forall a. Num a => a -> a -> a
(*) (Split Reflector Shape Small Small sh sh a -> a
forall meas vert height width a lower.
(Measure meas, C vert, C height, C width, Floating a) =>
Split lower meas vert Small height width a -> a
Split.determinantR Split Reflector Shape Small Small sh sh a
split) ([a] -> a) -> [a] -> a
forall a b. (a -> b) -> a -> b
$
   (case Split Reflector Shape Small Small sh sh -> Order
forall lower meas vert horiz height width.
Split lower meas vert horiz height width -> Order
Layout.splitOrder (Split Reflector Shape Small Small sh sh -> Order)
-> Split Reflector Shape Small Small sh sh -> Order
forall a b. (a -> b) -> a -> b
$ Split Reflector Shape Small Small sh sh a
-> Split Reflector Shape Small Small sh sh
forall sh a. Array sh a -> sh
Array.shape Split Reflector Shape Small Small sh sh a
split of
      Order
RowMajor -> (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map a -> a
forall a. Floating a => a -> a
conjugate
      Order
ColumnMajor -> [a] -> [a]
forall a. a -> a
id) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$
   (a -> a) -> [a] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (a -> a
forall a. Num a => a -> a
negate(a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(a -> Int -> a
forall a b. (Num a, Integral b) => a -> b -> a
^(Int
2::Int))(a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.a -> a
forall a. Num a => a -> a
signum) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$
   (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Bool
forall a. Floating a => a -> Bool
isZero) ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ Array (Banded U0 U0 Shape Small Small sh sh) a -> [a]
forall sh a. (C sh, Storable a) => Array sh a -> [a]
Array.toList Array (Banded U0 U0 Shape Small Small sh sh) a
tau

determinantAbsolute ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width,
    Class.Floating a) =>
   Householder meas vert horiz height width a -> RealOf a
determinantAbsolute :: Householder meas vert horiz height width a -> RealOf a
determinantAbsolute =
   a -> RealOf a
forall a. Floating a => a -> RealOf a
absolute (a -> RealOf a)
-> (Householder meas vert horiz height width a -> a)
-> Householder meas vert horiz height width a
-> RealOf a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Householder Size Big Small height width a -> a)
-> (Wide height width a -> a)
-> Either
     (Householder Size Big Small height width a) (Wide height width a)
-> a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Householder Size Big Small height width a -> a
forall meas vert height width a.
(Measure meas, C vert, C height, C width, Floating a) =>
Householder meas vert Small height width a -> a
determinantR (a -> Wide height width a -> a
forall a b. a -> b -> a
const a
forall a. Floating a => a
zero) (Either
   (Householder Size Big Small height width a) (Wide height width a)
 -> a)
-> (Householder meas vert horiz height width a
    -> Either
         (Householder Size Big Small height width a) (Wide height width a))
-> Householder meas vert horiz height width a
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder meas vert horiz height width a
-> Either
     (Householder Size Big Small height width a) (Wide height width a)
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width) =>
Householder meas vert horiz height width a
-> Either (Tall height width a) (Wide height width a)
caseTallWide


leastSquares ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Shape.C nrhs,
    Class.Floating a) =>
   HouseholderFlex lower upper meas horiz Extent.Small height width a ->
   Full meas vert horiz height nrhs a ->
   Full meas vert horiz width nrhs a
leastSquares :: HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
leastSquares HouseholderFlex lower upper meas horiz Small height width a
qr =
   case HouseholderFlex lower upper meas horiz Small height width a
-> Extent meas horiz Small 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
Matrix.extent HouseholderFlex lower upper meas horiz Small height width a
qr of
      ExtentPriv.Square height
_ -> HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
forall meas vert horiz height width nrhs a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Eq width, C nrhs, Floating a) =>
HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
leastSquaresAux HouseholderFlex lower upper meas horiz Small height width a
qr
      ExtentPriv.Separate height
_ width
_ ->
         (Unchecked width -> width)
-> Full Size vert horiz (Unchecked width) nrhs a
-> Full Size vert horiz width nrhs a
forall vert horiz heightA heightB width a.
(C vert, C horiz) =>
(heightA -> heightB)
-> Full Size vert horiz heightA width a
-> Full Size vert horiz heightB width a
Basic.mapHeight Unchecked width -> width
forall sh. Unchecked sh -> sh
deconsUnchecked (Full Size vert horiz (Unchecked width) nrhs a
 -> Full Size vert horiz width nrhs a)
-> (Full Size vert horiz height nrhs a
    -> Full Size vert horiz (Unchecked width) nrhs a)
-> Full Size vert horiz height nrhs a
-> Full Size vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         HouseholderFlex
  lower upper Size horiz Small height (Unchecked width) a
-> Full Size vert horiz height nrhs a
-> Full Size vert horiz (Unchecked width) nrhs a
forall meas vert horiz height width nrhs a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Eq width, C nrhs, Floating a) =>
HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
leastSquaresAux ((width -> Unchecked width)
-> HouseholderFlex lower upper Size horiz Small height width a
-> HouseholderFlex
     lower upper Size horiz Small height (Unchecked width) a
forall vert horiz widthA widthB lower upper height a.
(C vert, C horiz) =>
(widthA -> widthB)
-> HouseholderFlex lower upper Size vert horiz height widthA a
-> HouseholderFlex lower upper Size vert horiz height widthB a
mapWidth width -> Unchecked width
forall sh. sh -> Unchecked sh
Unchecked HouseholderFlex lower upper meas horiz Small height width a
HouseholderFlex lower upper Size horiz Small height width a
qr)

leastSquaresAux ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Eq width, Shape.C nrhs,
    Class.Floating a) =>
   HouseholderFlex lower upper meas horiz Extent.Small height width a ->
   Full meas vert horiz height nrhs a ->
   Full meas vert horiz width nrhs a
leastSquaresAux :: HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
leastSquaresAux HouseholderFlex lower upper meas horiz Small height width a
qr =
   Transposition
-> Conjugation
-> HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz width nrhs a
-> Full meas vert horiz width nrhs a
forall measA vertA meas vert horiz height width nrhs a lower upper.
(Measure measA, C vertA, Measure meas, C vert, C horiz, C height,
 C width, Eq width, C nrhs, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA Small height width a
-> Full meas vert horiz width nrhs a
-> Full meas vert horiz width nrhs a
tallSolveR Transposition
NonTransposed Conjugation
NonConjugated HouseholderFlex lower upper meas horiz Small height width a
qr (Full meas vert horiz width nrhs a
 -> Full meas vert horiz width nrhs a)
-> (Full meas vert horiz height nrhs a
    -> Full meas vert horiz width nrhs a)
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
forall meas vert horiz height width fuse a lower upper.
(Measure meas, C vert, C horiz, C height, C width, C fuse, Eq fuse,
 Floating a) =>
HouseholderFlex lower upper meas horiz Small fuse height a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
tallMultiplyQAdjoint HouseholderFlex lower upper meas horiz Small height width a
qr

minimumNorm ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Shape.C nrhs,
    Class.Floating a) =>
   HouseholderFlex lower upper meas vert Extent.Small width height a ->
   Full meas vert horiz height nrhs a ->
   Full meas vert horiz width nrhs a
minimumNorm :: HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
minimumNorm HouseholderFlex lower upper meas vert Small width height a
qr =
   case HouseholderFlex lower upper meas vert Small width height a
-> Extent meas vert Small width 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
-> Extent meas vert horiz height width
Matrix.extent HouseholderFlex lower upper meas vert Small width height a
qr of
      ExtentPriv.Square width
_ -> HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
forall meas vert horiz height width nrhs a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Eq width, C nrhs, Floating a) =>
HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
minimumNormAux HouseholderFlex lower upper meas vert Small width height a
qr
      ExtentPriv.Separate width
_ height
_ ->
         (Unchecked width -> width)
-> Full Size vert horiz (Unchecked width) nrhs a
-> Full Size vert horiz width nrhs a
forall vert horiz heightA heightB width a.
(C vert, C horiz) =>
(heightA -> heightB)
-> Full Size vert horiz heightA width a
-> Full Size vert horiz heightB width a
Basic.mapHeight Unchecked width -> width
forall sh. Unchecked sh -> sh
deconsUnchecked (Full Size vert horiz (Unchecked width) nrhs a
 -> Full Size vert horiz width nrhs a)
-> (Full Size vert horiz height nrhs a
    -> Full Size vert horiz (Unchecked width) nrhs a)
-> Full Size vert horiz height nrhs a
-> Full Size vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         HouseholderFlex
  lower upper Size vert Small (Unchecked width) height a
-> Full Size vert horiz height nrhs a
-> Full Size vert horiz (Unchecked width) nrhs a
forall meas vert horiz height width nrhs a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Eq width, C nrhs, Floating a) =>
HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
minimumNormAux ((width -> Unchecked width)
-> HouseholderFlex lower upper Size vert Small width height a
-> HouseholderFlex
     lower upper Size vert Small (Unchecked width) height a
forall vert horiz heightA heightB lower upper width a.
(C vert, C horiz) =>
(heightA -> heightB)
-> HouseholderFlex lower upper Size vert horiz heightA width a
-> HouseholderFlex lower upper Size vert horiz heightB width a
mapHeight width -> Unchecked width
forall sh. sh -> Unchecked sh
Unchecked HouseholderFlex lower upper meas vert Small width height a
HouseholderFlex lower upper Size vert Small width height a
qr)

minimumNormAux ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Eq width, Shape.C nrhs,
    Class.Floating a) =>
   HouseholderFlex lower upper meas vert Extent.Small width height a ->
   Full meas vert horiz height nrhs a ->
   Full meas vert horiz width nrhs a
minimumNormAux :: HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
minimumNormAux HouseholderFlex lower upper meas vert Small width height a
qr = HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
forall meas vert horiz height width fuse a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 C fuse, Eq fuse, Floating a) =>
HouseholderFlex lower upper meas vert Small height fuse a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
tallMultiplyQ HouseholderFlex lower upper meas vert Small width height a
qr (Full meas vert horiz height nrhs a
 -> Full meas vert horiz width nrhs a)
-> (Full meas vert horiz height nrhs a
    -> Full meas vert horiz height nrhs a)
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Transposition
-> Conjugation
-> HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz height nrhs a
forall measA vertA meas vert horiz height width nrhs a lower upper.
(Measure measA, C vertA, Measure meas, C vert, C horiz, C height,
 C width, Eq width, C nrhs, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA Small height width a
-> Full meas vert horiz width nrhs a
-> Full meas vert horiz width nrhs a
tallSolveR Transposition
Transposed Conjugation
Conjugated HouseholderFlex lower upper meas vert Small width height a
qr

takeRows ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Eq fuse, Shape.C fuse, Shape.C height, Shape.C width, Class.Floating a) =>
   Extent meas Extent.Small horiz height fuse ->
   Full meas vert horiz fuse width a ->
   Full meas vert horiz height width a
takeRows :: Extent meas Small horiz height fuse
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
takeRows Extent meas Small horiz height fuse
extentA (Array (Layout.Full Order
order Extent meas vert horiz fuse width
extentB) ForeignPtr a
b) =
   case 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 (Extent meas Small horiz height fuse
-> Extent meas vert horiz height fuse
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas Small horiz height width
-> Extent meas vert horiz height width
ExtentPriv.weakenWide Extent meas Small horiz height fuse
extentA) Extent meas vert horiz fuse width
extentB of
      Maybe (Extent meas vert horiz height width)
Nothing -> String -> Full meas vert horiz height width a
forall a. HasCallStack => String -> a
error String
"Householder.takeRows: heights mismatch"
      Just Extent meas vert horiz height width
extentC ->
         fuse
-> Int
-> ForeignPtr a
-> Full meas vert horiz height width
-> Full meas vert horiz height width a
forall meas vert horiz heightA height width a.
(Measure meas, C vert, C horiz, C heightA, C height, C width,
 Floating a) =>
heightA
-> Int
-> ForeignPtr a
-> Full meas vert horiz height width
-> Full meas vert horiz height width a
Basic.takeSub
            (Extent meas vert horiz fuse width -> fuse
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 fuse width
extentB) Int
0 ForeignPtr a
b (Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
order Extent meas vert horiz height width
extentC)

addRows ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Eq fuse, Shape.C fuse, Shape.C height, Shape.C width, Class.Floating a) =>
   Extent meas vert Extent.Small height fuse ->
   Full meas vert horiz fuse width a ->
   Full meas vert horiz height width a
addRows :: Extent meas vert Small height fuse
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
addRows Extent meas vert Small height fuse
extentA (Array shapeB :: Full meas vert horiz fuse width
shapeB@(Layout.Full Order
order Extent meas vert horiz fuse width
extentB) ForeignPtr a
b) =
   case 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 (Extent meas vert Small height fuse
-> Extent meas vert horiz height fuse
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert Small height width
-> Extent meas vert horiz height width
ExtentPriv.weakenTall Extent meas vert Small height fuse
extentA) Extent meas vert horiz fuse width
extentB of
      Maybe (Extent meas vert horiz height width)
Nothing -> String -> Full meas vert horiz height width a
forall a. HasCallStack => String -> a
error String
"Householder.addRows: heights mismatch"
      Just Extent meas vert horiz height width
extentC ->
         Full meas vert horiz height width
-> (Int -> Ptr a -> IO ()) -> Full meas vert horiz height width a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize (Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
order Extent meas vert horiz height width
extentC) ((Int -> Ptr a -> IO ()) -> Full meas vert horiz height width a)
-> (Int -> Ptr a -> IO ()) -> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
            \Int
cSize Ptr a
cPtr ->
         ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
b ((Ptr a -> IO ()) -> IO ()) -> (Ptr a -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr a
bPtr ->
         case Order
order of
            Order
RowMajor -> do
               let bSize :: Int
bSize = Full meas vert horiz fuse width -> Int
forall sh. C sh => sh -> Int
Shape.size Full meas vert horiz fuse width
shapeB
               Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
bSize Ptr a
bPtr Ptr a
cPtr
               a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero (Int
cSize Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
bSize) (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
cPtr Int
bSize)
            Order
ColumnMajor -> do
               let n :: Int
n  = width -> Int
forall sh. C sh => sh -> Int
Shape.size (width -> Int) -> width -> Int
forall a b. (a -> b) -> a -> b
$ Extent meas vert horiz fuse 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 fuse width
extentB
                   mb :: Int
mb = fuse -> Int
forall sh. C sh => sh -> Int
Shape.size (fuse -> Int) -> fuse -> Int
forall a b. (a -> b) -> a -> b
$ Extent meas vert horiz fuse width -> fuse
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 fuse width
extentB
                   mc :: Int
mc = height -> Int
forall sh. C sh => sh -> Int
Shape.size (height -> Int) -> height -> Int
forall a b. (a -> b) -> a -> b
$ 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
extentC
               Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubMatrix Int
mb Int
n Int
mb Ptr a
bPtr Int
mc Ptr a
cPtr
               ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
                  Ptr CChar
uploPtr <- Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char Char
'A'
                  Ptr CInt
mPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint (Int
mcInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
mb)
                  Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
                  Ptr CInt
ldcPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
mc
                  Ptr a
zPtr <- a -> FortranIO () (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
zero
                  IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
                     Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
LapackGen.laset Ptr CChar
uploPtr Ptr CInt
mPtr Ptr CInt
nPtr Ptr a
zPtr Ptr a
zPtr
                        (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
cPtr Int
mb) Ptr CInt
ldcPtr


extractQ ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Householder meas vert horiz height width a -> MatrixPriv.Square height a
extractQ :: Householder meas vert horiz height width a -> Square height a
extractQ
   (Householder tau (Array (Layout.Split _ order extent) qr)) =
      RectangularDiagonal meas vert horiz height width a
-> width
-> Order
-> Extent Shape Small Small height height
-> ForeignPtr a
-> Square height a
forall meas vert horiz measA vertA horizA height width widthQR a.
(Measure meas, C vert, C horiz, Measure measA, C vertA, C horizA,
 C height, C width, C widthQR, Floating a) =>
RectangularDiagonal measA vertA horizA height widthQR a
-> widthQR
-> Order
-> Extent meas vert horiz height width
-> ForeignPtr a
-> Full meas vert horiz height width a
extractQAux RectangularDiagonal meas vert horiz height width a
tau (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
extent) Order
order
         (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 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
extent) ForeignPtr a
qr

tallExtractQ ::
   (Extent.Measure meas, Extent.C vert,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Householder meas vert Extent.Small height width a ->
   Full meas vert Extent.Small height width a
tallExtractQ :: Householder meas vert Small height width a
-> Full meas vert Small height width a
tallExtractQ
   (Householder tau (Array (Layout.Split _ order extent) qr)) =
      RectangularDiagonal meas vert Small height width a
-> width
-> Order
-> Extent meas vert Small height width
-> ForeignPtr a
-> Full meas vert Small height width a
forall meas vert horiz measA vertA horizA height width widthQR a.
(Measure meas, C vert, C horiz, Measure measA, C vertA, C horizA,
 C height, C width, C widthQR, Floating a) =>
RectangularDiagonal measA vertA horizA height widthQR a
-> widthQR
-> Order
-> Extent meas vert horiz height width
-> ForeignPtr a
-> Full meas vert horiz height width a
extractQAux RectangularDiagonal meas vert Small height width a
tau (Extent meas vert 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 vert Small height width
extent) Order
order Extent meas vert Small height width
extent ForeignPtr a
qr


extractQAux ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Extent.Measure measA, Extent.C vertA, Extent.C horizA,
    Shape.C height, Shape.C width, Shape.C widthQR,
    Class.Floating a) =>
   Banded.RectangularDiagonal measA vertA horizA height widthQR a ->
   widthQR ->
   Order -> Extent meas vert horiz height width -> ForeignPtr a ->
   Full meas vert horiz height width a
extractQAux :: RectangularDiagonal measA vertA horizA height widthQR a
-> widthQR
-> Order
-> Extent meas vert horiz height width
-> ForeignPtr a
-> Full meas vert horiz height width a
extractQAux (Array Banded U0 U0 measA vertA horizA height widthQR
widthTau ForeignPtr a
tau) widthQR
widthQR Order
order Extent meas vert horiz height width
extent ForeignPtr a
qr =
   Full meas vert horiz height width
-> (Ptr a -> IO ()) -> Full meas vert horiz height width a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate (Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
order Extent meas vert horiz height width
extent) ((Ptr a -> IO ()) -> Full meas vert horiz height width a)
-> (Ptr a -> IO ()) -> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ \Ptr a
qPtr -> do

   let (height
height,width
width) = Extent meas vert horiz height width -> (height, width)
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> (height, width)
Extent.dimensions Extent meas vert horiz height width
extent
   let m :: Int
m = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
   let n :: Int
n = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
   let k :: Int
k = Banded U0 U0 measA vertA horizA height widthQR -> Int
forall sh. C sh => sh -> Int
Shape.size Banded U0 U0 measA vertA horizA height widthQR
widthTau
   ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
      Ptr CInt
mPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
m
      Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
      Ptr CInt
kPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
k
      Ptr a
qrPtr <- ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
qr
      Ptr a
tauPtr <- ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
tau
      case Order
order of
         Order
RowMajor -> do
            Ptr CInt
ldaPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
n
            IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ do
               Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubMatrix Int
k Int
m (widthQR -> Int
forall sh. C sh => sh -> Int
Shape.size widthQR
widthQR) Ptr a
qrPtr Int
n Ptr a
qPtr
               String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a.
Floating a =>
String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
withAutoWorkspaceInfo String
errorCodeMsg String
"unglq" ((Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ())
-> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
                  Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
LapackGen.unglq Ptr CInt
nPtr Ptr CInt
mPtr Ptr CInt
kPtr Ptr a
qPtr Ptr CInt
ldaPtr Ptr a
tauPtr
         Order
ColumnMajor -> do
            Ptr CInt
ldaPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
m
            IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ do
               Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock (Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
k) Ptr a
qrPtr Ptr a
qPtr
               String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a.
Floating a =>
String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
withAutoWorkspaceInfo String
errorCodeMsg String
"ungqr" ((Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ())
-> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
                  Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
LapackGen.ungqr Ptr CInt
mPtr Ptr CInt
nPtr Ptr CInt
kPtr Ptr a
qPtr Ptr CInt
ldaPtr Ptr a
tauPtr


tallMultiplyQ ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Shape.C fuse, Eq fuse,
    Class.Floating a) =>
   HouseholderFlex lower upper meas vert Extent.Small height fuse a ->
   Full meas vert horiz fuse width a ->
   Full meas vert horiz height width a
tallMultiplyQ :: HouseholderFlex lower upper meas vert Small height fuse a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
tallMultiplyQ HouseholderFlex lower upper meas vert Small height fuse a
qr =
   Transposition
-> Conjugation
-> HouseholderFlex lower upper meas vert Small height fuse a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall measA vertA horizA widthA measB vertB horizB widthB height a
       lower upper.
(Measure measA, C vertA, C horizA, C widthA, Measure measB,
 C vertB, C horizB, C widthB, C height, Eq height, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA horizA height widthA a
-> Full measB vertB horizB height widthB a
-> Full measB vertB horizB height widthB a
multiplyQ Transposition
NonTransposed Conjugation
NonConjugated HouseholderFlex lower upper meas vert Small height fuse a
qr (Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (Full meas vert horiz fuse width a
    -> Full meas vert horiz height width a)
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Extent meas vert Small height fuse
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
forall meas vert horiz fuse height width a.
(Measure meas, C vert, C horiz, Eq fuse, C fuse, C height, C width,
 Floating a) =>
Extent meas vert Small height fuse
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
addRows (HouseholderFlex lower upper meas vert Small height fuse a
-> Extent meas vert Small 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
Matrix.extent HouseholderFlex lower upper meas vert Small height fuse a
qr)

tallMultiplyQAdjoint ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Shape.C fuse, Eq fuse, Class.Floating a) =>
   HouseholderFlex lower upper meas horiz Extent.Small fuse height a ->
   Full meas vert horiz fuse width a ->
   Full meas vert horiz height width a
tallMultiplyQAdjoint :: HouseholderFlex lower upper meas horiz Small fuse height a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
tallMultiplyQAdjoint HouseholderFlex lower upper meas horiz Small fuse height a
qr =
   Extent meas Small horiz height fuse
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
forall meas vert horiz fuse height width a.
(Measure meas, C vert, C horiz, Eq fuse, C fuse, C height, C width,
 Floating a) =>
Extent meas Small horiz height fuse
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
takeRows (Extent meas horiz Small fuse height
-> Extent meas Small horiz height fuse
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 horiz Small fuse height
 -> Extent meas Small horiz height fuse)
-> Extent meas horiz Small fuse height
-> Extent meas Small horiz height fuse
forall a b. (a -> b) -> a -> b
$ HouseholderFlex lower upper meas horiz Small fuse height a
-> Extent meas horiz Small fuse 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
-> Extent meas vert horiz height width
Matrix.extent HouseholderFlex lower upper meas horiz Small fuse height a
qr) (Full meas vert horiz fuse width a
 -> Full meas vert horiz height width a)
-> (Full meas vert horiz fuse width a
    -> Full meas vert horiz fuse width a)
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
   Transposition
-> Conjugation
-> HouseholderFlex lower upper meas horiz Small fuse height a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz fuse width a
forall measA vertA horizA widthA measB vertB horizB widthB height a
       lower upper.
(Measure measA, C vertA, C horizA, C widthA, Measure measB,
 C vertB, C horizB, C widthB, C height, Eq height, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA horizA height widthA a
-> Full measB vertB horizB height widthB a
-> Full measB vertB horizB height widthB a
multiplyQ Transposition
Transposed Conjugation
Conjugated HouseholderFlex lower upper meas horiz Small fuse height a
qr


multiplyQ ::
   (Extent.Measure measA, Extent.C vertA, Extent.C horizA, Shape.C widthA,
    Extent.Measure measB, Extent.C vertB, Extent.C horizB, Shape.C widthB,
    Shape.C height, Eq height, Class.Floating a) =>
   Transposition -> Conjugation ->
   HouseholderFlex lower upper measA vertA horizA height widthA a ->
   Full measB vertB horizB height widthB a ->
   Full measB vertB horizB height widthB a
multiplyQ :: Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA horizA height widthA a
-> Full measB vertB horizB height widthB a
-> Full measB vertB horizB height widthB a
multiplyQ Transposition
transposed Conjugation
conjugated
   (Householder
      (Array widthTau tau)
      (Array shapeA@(Layout.Split _ orderA extentA) qr))
   (Array shapeB :: Full measB vertB horizB height widthB
shapeB@(Layout.Full Order
orderB Extent measB vertB horizB height widthB
extentB) ForeignPtr a
b) =

   Full measB vertB horizB height widthB
-> (Int -> Ptr a -> IO ())
-> Full measB vertB horizB height widthB a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize Full measB vertB horizB height widthB
shapeB ((Int -> Ptr a -> IO ())
 -> Full measB vertB horizB height widthB a)
-> (Int -> Ptr a -> IO ())
-> Full measB vertB horizB height widthB a
forall a b. (a -> b) -> a -> b
$ \Int
cSize Ptr a
cPtr -> do

   let (height
heightA,widthA
widthA) = Extent measA vertA horizA height widthA -> (height, widthA)
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> (height, width)
Extent.dimensions Extent measA vertA horizA height widthA
extentA
   let (height
height,widthB
width) = Extent measB vertB horizB height widthB -> (height, widthB)
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> (height, width)
Extent.dimensions Extent measB vertB horizB height widthB
extentB
   String -> Bool -> IO ()
Call.assert String
"Householder.multiplyQ: height shapes mismatch"
      (height
heightA height -> height -> Bool
forall a. Eq a => a -> a -> Bool
== height
height)

   let (Char
side,(Int
m,Int
n)) =
         Order -> (Int, Int) -> (Char, (Int, Int))
forall a. Order -> (a, a) -> (Char, (a, a))
sideSwapFromOrder Order
orderB (height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height, widthB -> Int
forall sh. C sh => sh -> Int
Shape.size widthB
width)

   ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
      Ptr CChar
sidePtr <- Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char Char
side
      Ptr CInt
mPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
m
      Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
      let k :: Int
k = Banded U0 U0 measA vertA horizA height widthA -> Int
forall sh. C sh => sh -> Int
Shape.size Banded U0 U0 measA vertA horizA height widthA
widthTau
      Ptr CInt
kPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
k
      Ptr CChar
transPtr <-
         Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char (Char -> FortranIO () (Ptr CChar))
-> Char -> FortranIO () (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> Transposition -> Char
forall a (f :: * -> *). Floating a => f a -> Transposition -> Char
adjointFromTranspose ForeignPtr a
qr (Transposition -> Char) -> Transposition -> Char
forall a b. (a -> b) -> a -> b
$
         Transposition
transposed Transposition -> Transposition -> Transposition
forall a. Semigroup a => a -> a -> a
<> if Order
orderAOrder -> Order -> Bool
forall a. Eq a => a -> a -> Bool
==Order
orderB then Transposition
NonTransposed else Transposition
Transposed
      (Ptr a
qrPtr,Ptr a
tauPtr) <-
         if (Order
orderAOrder -> Order -> Bool
forall a. Eq a => a -> a -> Bool
==Order
orderB)
            Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
==
            (Transposition
transposedTransposition -> Transposition -> Bool
forall a. Eq a => a -> a -> Bool
==Transposition
NonTransposed Bool -> Bool -> Bool
&& Conjugation
conjugatedConjugation -> Conjugation -> Bool
forall a. Eq a => a -> a -> Bool
==Conjugation
NonConjugated
             Bool -> Bool -> Bool
||
             Transposition
transposedTransposition -> Transposition -> Bool
forall a. Eq a => a -> a -> Bool
==Transposition
Transposed Bool -> Bool -> Bool
&& Conjugation
conjugatedConjugation -> Conjugation -> Bool
forall a. Eq a => a -> a -> Bool
==Conjugation
Conjugated)
            then
               (Ptr a -> Ptr a -> (Ptr a, Ptr a))
-> ContT () IO (Ptr a)
-> ContT () IO (Ptr a)
-> ContT () IO (Ptr a, Ptr a)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,)
                  (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
qr)
                  (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
tau)
            else
               (Ptr a -> Ptr a -> (Ptr a, Ptr a))
-> ContT () IO (Ptr a)
-> ContT () IO (Ptr a)
-> ContT () IO (Ptr a, Ptr a)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,)
                  (Int -> ForeignPtr a -> ContT () IO (Ptr a)
forall a r. Floating a => Int -> ForeignPtr a -> ContT r IO (Ptr a)
conjugateToTemp (Split Reflector measA vertA horizA height widthA -> Int
forall sh. C sh => sh -> Int
Shape.size Split Reflector measA vertA horizA height widthA
shapeA) ForeignPtr a
qr)
                  (Int -> ForeignPtr a -> ContT () IO (Ptr a)
forall a r. Floating a => Int -> ForeignPtr a -> ContT r IO (Ptr a)
conjugateToTemp Int
k ForeignPtr a
tau)
      Ptr a
bPtr <- ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
b
      Ptr CInt
ldcPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
m
      IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
cSize Ptr a
bPtr Ptr a
cPtr
      case Order
orderA of
         Order
ColumnMajor -> do
            Ptr CInt
ldaPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim (Int -> FortranIO () (Ptr CInt)) -> Int -> FortranIO () (Ptr CInt)
forall a b. (a -> b) -> a -> b
$ height -> Int
forall sh. C sh => sh -> Int
Shape.size height
heightA
            IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a.
Floating a =>
String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
withAutoWorkspaceInfo String
errorCodeMsg String
"unmqr" ((Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ())
-> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
               Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
LapackGen.unmqr Ptr CChar
sidePtr Ptr CChar
transPtr
                  Ptr CInt
mPtr Ptr CInt
nPtr Ptr CInt
kPtr Ptr a
qrPtr Ptr CInt
ldaPtr Ptr a
tauPtr Ptr a
cPtr Ptr CInt
ldcPtr
         Order
RowMajor -> do
            Ptr CInt
ldaPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim (Int -> FortranIO () (Ptr CInt)) -> Int -> FortranIO () (Ptr CInt)
forall a b. (a -> b) -> a -> b
$ widthA -> Int
forall sh. C sh => sh -> Int
Shape.size widthA
widthA
            -- work-around for https://github.com/Reference-LAPACK/lapack/issues/260
            IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
kInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>Int
0) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
               String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a.
Floating a =>
String
-> String -> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
withAutoWorkspaceInfo String
errorCodeMsg String
"unmlq" ((Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ())
-> (Ptr a -> Ptr CInt -> Ptr CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
               Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr CInt
-> IO ()
LapackGen.unmlq Ptr CChar
sidePtr Ptr CChar
transPtr
                  Ptr CInt
mPtr Ptr CInt
nPtr Ptr CInt
kPtr Ptr a
qrPtr Ptr CInt
ldaPtr Ptr a
tauPtr Ptr a
cPtr Ptr CInt
ldcPtr

adjointFromTranspose :: (Class.Floating a) => f a -> Transposition -> Char
adjointFromTranspose :: f a -> Transposition -> Char
adjointFromTranspose f a
qr Transposition
Transposed = f a -> Char
forall a (f :: * -> *). Floating a => f a -> Char
invChar f a
qr
adjointFromTranspose f a
_ Transposition
NonTransposed = Char
'N'

invChar :: (Class.Floating a) => f a -> Char
invChar :: f a -> Char
invChar f a
f = f a -> Char -> Char -> Char
forall a (f :: * -> *) b. Floating a => f a -> b -> b -> b
caseRealComplexFunc f a
f Char
'T' Char
'C'


extractR ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   HouseholderFlex lower upper meas vert horiz height width a ->
   Full meas vert horiz height width a
extractR :: HouseholderFlex lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
extractR = Either Reflector Triangle
-> Split Reflector meas vert horiz height width a
-> Full meas vert horiz height width a
forall meas vert horiz height width a lower.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
Either lower Triangle
-> Split lower meas vert horiz height width a
-> Full meas vert horiz height width a
Split.extractTriangle (Triangle -> Either Reflector Triangle
forall a b. b -> Either a b
Right Triangle
Layout.Triangle) (Split Reflector meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (HouseholderFlex lower upper meas vert horiz height width a
    -> Split Reflector meas vert horiz height width a)
-> HouseholderFlex 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
. HouseholderFlex lower upper meas vert horiz height width a
-> Split Reflector meas vert horiz height width a
forall xl xu lower upper meas vert horiz height width a.
Matrix Hh xl xu lower upper meas vert horiz height width a
-> SplitArray meas vert horiz height width a
split_

tallExtractR ::
   (Extent.Measure meas, Extent.C vert,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Householder meas vert Extent.Small height width a -> Upper width a
tallExtractR :: Householder meas vert Small height width a -> Upper width a
tallExtractR = Split Reflector meas vert Small height width a -> Upper width a
forall meas vert height width a lower.
(Measure meas, C vert, C height, C width, Floating a) =>
Split lower meas vert Small height width a -> Upper width a
Split.tallExtractR (Split Reflector meas vert Small height width a -> Upper width a)
-> (Householder meas vert Small height width a
    -> Split Reflector meas vert Small height width a)
-> Householder meas vert Small height width a
-> Upper width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Householder meas vert Small height width a
-> Split Reflector meas vert Small height width a
forall xl xu lower upper meas vert horiz height width a.
Matrix Hh xl xu lower upper meas vert horiz height width a
-> SplitArray meas vert horiz height width a
split_

tallMultiplyR ::
   (Extent.Measure measA, Extent.C vertA,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height,
    Shape.C heightA, Shape.C widthB, Class.Floating a) =>
   Transposition ->
   HouseholderFlex lower upper measA vertA Extent.Small heightA height a ->
   Full meas vert horiz height widthB a ->
   Full meas vert horiz height widthB a
tallMultiplyR :: Transposition
-> HouseholderFlex lower upper measA vertA Small heightA height a
-> Full meas vert horiz height widthB a
-> Full meas vert horiz height widthB a
tallMultiplyR Transposition
transposed = Transposition
-> Split Reflector measA vertA Small heightA height a
-> Full meas vert horiz height widthB a
-> Full meas vert horiz height widthB a
forall measA vertA meas vert horiz height heightA widthB a lower.
(Measure measA, C vertA, Measure meas, C vert, C horiz, C height,
 Eq height, C heightA, C widthB, Floating a) =>
Transposition
-> Split lower measA vertA Small heightA height a
-> Full meas vert horiz height widthB a
-> Full meas vert horiz height widthB a
Split.tallMultiplyR Transposition
transposed (Split Reflector measA vertA Small heightA height a
 -> Full meas vert horiz height widthB a
 -> Full meas vert horiz height widthB a)
-> (HouseholderFlex lower upper measA vertA Small heightA height a
    -> Split Reflector measA vertA Small heightA height a)
-> HouseholderFlex lower upper measA vertA Small heightA height a
-> Full meas vert horiz height widthB a
-> Full meas vert horiz height widthB a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HouseholderFlex lower upper measA vertA Small heightA height a
-> Split Reflector measA vertA Small heightA height a
forall xl xu lower upper meas vert horiz height width a.
Matrix Hh xl xu lower upper meas vert horiz height width a
-> SplitArray meas vert horiz height width a
split_

tallSolveR ::
   (Extent.Measure measA, Extent.C vertA,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Shape.C nrhs, Class.Floating a) =>
   Transposition -> Conjugation ->
   HouseholderFlex lower upper measA vertA Extent.Small height width a ->
   Full meas vert horiz width nrhs a -> Full meas vert horiz width nrhs a
tallSolveR :: Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA Small height width a
-> Full meas vert horiz width nrhs a
-> Full meas vert horiz width nrhs a
tallSolveR Transposition
transposed Conjugation
conjugated =
   Transposition
-> Conjugation
-> Split Reflector measA vertA Small height width a
-> Full meas vert horiz width nrhs a
-> Full meas vert horiz width nrhs a
forall measA vertA meas vert horiz height width nrhs a lower.
(Measure measA, C vertA, Measure meas, C vert, C horiz, C height,
 C width, Eq width, C nrhs, Floating a) =>
Transposition
-> Conjugation
-> Split lower measA vertA Small height width a
-> Full meas vert horiz width nrhs a
-> Full meas vert horiz width nrhs a
Split.tallSolveR Transposition
transposed Conjugation
conjugated (Split Reflector measA vertA Small height width a
 -> Full meas vert horiz width nrhs a
 -> Full meas vert horiz width nrhs a)
-> (HouseholderFlex lower upper measA vertA Small height width a
    -> Split Reflector measA vertA Small height width a)
-> HouseholderFlex lower upper measA vertA Small height width a
-> Full meas vert horiz width nrhs a
-> Full meas vert horiz width nrhs a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HouseholderFlex lower upper measA vertA Small height width a
-> Split Reflector measA vertA Small height width a
forall xl xu lower upper meas vert horiz height width a.
Matrix Hh xl xu lower upper meas vert horiz height width a
-> SplitArray meas vert horiz height width a
split_


instance Matrix.Box Hh where
   type BoxExtra Hh extra = extra ~ ()
   extent :: Matrix Hh xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
extent = Split Reflector meas vert horiz height width
-> Extent meas vert horiz height width
forall lower meas vert horiz height width.
Split lower meas vert horiz height width
-> Extent meas vert horiz height width
Layout.splitExtent (Split Reflector meas vert horiz height width
 -> Extent meas vert horiz height width)
-> (Matrix Hh xl xu lower upper meas vert horiz height width a
    -> Split Reflector meas vert horiz height width)
-> Matrix Hh xl xu lower upper meas vert horiz height width a
-> Extent meas vert horiz height width
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array (Split Reflector meas vert horiz height width) a
-> Split Reflector meas vert horiz height width
forall sh a. Array sh a -> sh
Array.shape (Array (Split Reflector meas vert horiz height width) a
 -> Split Reflector meas vert horiz height width)
-> (Matrix Hh xl xu lower upper meas vert horiz height width a
    -> Array (Split Reflector meas vert horiz height width) a)
-> Matrix Hh xl xu lower upper meas vert horiz height width a
-> Split Reflector meas vert horiz height width
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Matrix Hh xl xu lower upper meas vert horiz height width a
-> Array (Split Reflector meas vert horiz height width) a
forall xl xu lower upper meas vert horiz height width a.
Matrix Hh xl xu lower upper meas vert horiz height width a
-> SplitArray meas vert horiz height width a
split_

instance Matrix.ToQuadratic Hh where
   heightToQuadratic :: QuadraticMeas Hh xl xu lower upper meas height width a
-> Quadratic Hh xl xu lower upper height a
heightToQuadratic (Householder tau split) =
      RectangularDiagonal Shape Small Small height height a
-> SplitArray Shape Small Small height height a
-> HouseholderFlex lower upper Shape Small Small height height a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder
         ((Banded U0 U0 meas Small Small height width -> Diagonal height)
-> Array (Banded U0 U0 meas Small Small height width) a
-> RectangularDiagonal Shape Small Small height height a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (height -> Diagonal height
forall sh. sh -> Diagonal sh
layoutTauSquare (height -> Diagonal height)
-> (Banded U0 U0 meas Small Small height width -> height)
-> Banded U0 U0 meas Small Small height width
-> Diagonal height
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Banded U0 U0 meas Small Small height width -> height
forall meas vert horiz sub super height width.
(Measure meas, C vert, C horiz) =>
Banded sub super meas vert horiz height width -> height
Layout.bandedHeight) Array (Banded U0 U0 meas Small Small height width) a
tau)
         (Split Reflector meas Small Small height width a
-> SplitArray Shape Small Small height height a
forall meas lower height width a.
Measure meas =>
Split lower meas Small Small height width a
-> Square lower height a
Split.heightToQuadratic Split Reflector meas Small Small height width a
split)
   widthToQuadratic :: QuadraticMeas Hh xl xu lower upper meas height width a
-> Quadratic Hh xl xu lower upper width a
widthToQuadratic (Householder tau split) =
      RectangularDiagonal Shape Small Small width width a
-> SplitArray Shape Small Small width width a
-> HouseholderFlex lower upper Shape Small Small width width a
forall meas vert horiz height width a lower upper.
RectangularDiagonal meas vert horiz height width a
-> SplitArray meas vert horiz height width a
-> HouseholderFlex lower upper meas vert horiz height width a
Householder
         ((Banded U0 U0 meas Small Small height width -> Diagonal width)
-> Array (Banded U0 U0 meas Small Small height width) a
-> RectangularDiagonal Shape Small Small width width a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (width -> Diagonal width
forall sh. sh -> Diagonal sh
layoutTauSquare (width -> Diagonal width)
-> (Banded U0 U0 meas Small Small height width -> width)
-> Banded U0 U0 meas Small Small height width
-> Diagonal width
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Banded U0 U0 meas Small Small height width -> width
forall meas vert horiz sub super height width.
(Measure meas, C vert, C horiz) =>
Banded sub super meas vert horiz height width -> width
Layout.bandedWidth) Array (Banded U0 U0 meas Small Small height width) a
tau)
         (Split Reflector meas Small Small height width a
-> SplitArray Shape Small Small width width a
forall meas lower height width a.
Measure meas =>
Split lower meas Small Small height width a -> Square lower width a
Split.widthToQuadratic Split Reflector meas Small Small height width a
split)

layoutTauSquare :: sh -> Layout.Diagonal sh
layoutTauSquare :: sh -> Diagonal sh
layoutTauSquare = Order -> sh -> Diagonal sh
forall size. Order -> size -> Diagonal size
LayoutPub.diagonal Order
Layout.ColumnMajor

instance Matrix.MapExtent Hh where
   type MapExtentExtra Hh extra = extra ~ ()
   type MapExtentStrip Hh strip = ()
   mapExtent :: Map measA vertA horizA measB vertB horizB height width
-> Matrix Hh xl xu lower upper measA vertA horizA height width a
-> Matrix Hh xl xu lower upper measB vertB horizB height width a
mapExtent = Map measA vertA horizA measB vertB horizB height width
-> HouseholderFlex lower upper measA vertA horizA height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
forall measA vertA horizA measB vertB horizB height width lower
       upper a.
(Measure measA, C vertA, C horizA, Measure measB, C vertB,
 C horizB) =>
Map measA vertA horizA measB vertB horizB height width
-> HouseholderFlex lower upper measA vertA horizA height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
mapExtent (Map measA vertA horizA measB vertB horizB height width
 -> HouseholderFlex lower upper measA vertA horizA height width a
 -> HouseholderFlex lower upper measB vertB horizB height width a)
-> (Map measA vertA horizA measB vertB horizB height width
    -> Map measA vertA horizA measB vertB horizB height width)
-> Map measA vertA horizA measB vertB horizB height width
-> HouseholderFlex lower upper measA vertA horizA height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map measA vertA horizA measB vertB horizB height width
-> Map measA vertA horizA measB vertB horizB height width
forall measA vertA horizA measB vertB horizB height width.
Map measA vertA horizA measB vertB horizB height width
-> Map measA vertA horizA measB vertB horizB height width
ExtentStrict.apply

instance Multiply.MultiplyVector Hh where
   type MultiplyVectorExtra Hh extra = extra ~ ()
   matrixVector :: Matrix Hh xl xu lower upper meas vert horiz height width a
-> Vector width a -> Vector height a
matrixVector Matrix Hh xl xu lower upper meas vert horiz height width a
qr Vector width a
x =
      (Unchecked height -> height)
-> Array (Unchecked height) a -> Vector height a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape Unchecked height -> height
forall sh. Unchecked sh -> sh
deconsUnchecked (Array (Unchecked height) a -> Vector height a)
-> Array (Unchecked height) a -> Vector height a
forall a b. (a -> b) -> a -> b
$
      Order
-> (General (Unchecked height) () a
    -> General (Unchecked height) () a)
-> Array (Unchecked height) a
-> Array (Unchecked height) a
forall height0 a height1 b.
Order
-> (General height0 () a -> General height1 () b)
-> Vector height0 a
-> Vector height1 b
Basic.unliftColumn Order
Layout.ColumnMajor
         (Transposition
-> Conjugation
-> HouseholderFlex
     lower upper meas vert horiz (Unchecked height) (Unchecked width) a
-> General (Unchecked height) () a
-> General (Unchecked height) () a
forall measA vertA horizA widthA measB vertB horizB widthB height a
       lower upper.
(Measure measA, C vertA, C horizA, C widthA, Measure measB,
 C vertB, C horizB, C widthB, C height, Eq height, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA horizA height widthA a
-> Full measB vertB horizB height widthB a
-> Full measB vertB horizB height widthB a
multiplyQ Transposition
NonTransposed Conjugation
NonConjugated (HouseholderFlex
   lower upper meas vert horiz (Unchecked height) (Unchecked width) a
 -> General (Unchecked height) () a
 -> General (Unchecked height) () a)
-> HouseholderFlex
     lower upper meas vert horiz (Unchecked height) (Unchecked width) a
-> General (Unchecked height) () a
-> General (Unchecked height) () a
forall a b. (a -> b) -> a -> b
$ HouseholderFlex lower upper meas vert horiz height width a
-> HouseholderFlex
     lower upper meas vert horiz (Unchecked height) (Unchecked width) a
forall meas vert horiz lower upper height width a.
(Measure meas, C vert, C horiz) =>
HouseholderFlex lower upper meas vert horiz height width a
-> HouseholderFlex
     lower upper meas vert horiz (Unchecked height) (Unchecked width) a
uncheck Matrix Hh xl xu lower upper meas vert horiz height width a
HouseholderFlex lower upper meas vert horiz height width a
qr) (Array (Unchecked height) a -> Array (Unchecked height) a)
-> Array (Unchecked height) a -> Array (Unchecked height) a
forall a b. (a -> b) -> a -> b
$
      (height -> Unchecked height)
-> Vector height a -> Array (Unchecked height) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape height -> Unchecked height
forall sh. sh -> Unchecked sh
Unchecked (Vector height a -> Array (Unchecked height) a)
-> Vector height a -> Array (Unchecked height) a
forall a b. (a -> b) -> a -> b
$
      Full meas vert horiz height width a
-> Vector width a -> Vector height a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width, Eq width,
 Floating a) =>
Full meas vert horiz height width a
-> Vector width a -> Vector height a
Basic.multiplyVector (HouseholderFlex lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
forall meas vert horiz height width a lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
HouseholderFlex lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
extractR Matrix Hh xl xu lower upper meas vert horiz height width a
HouseholderFlex lower upper meas vert horiz height width a
qr) Vector width a
x
   vectorMatrix :: Vector height a
-> Matrix Hh xl xu lower upper meas vert horiz height width a
-> Vector width a
vectorMatrix Vector height a
x Matrix Hh xl xu lower upper meas vert horiz height width a
qr =
      Full meas horiz vert width height a
-> Vector height a -> Vector width a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width, Eq width,
 Floating a) =>
Full meas vert horiz height width a
-> Vector width a -> Vector height a
Basic.multiplyVector (Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width a
-> Full meas horiz vert width height a
Basic.transpose (Full meas vert horiz height width a
 -> Full meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall a b. (a -> b) -> a -> b
$ HouseholderFlex lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
forall meas vert horiz height width a lower upper.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
HouseholderFlex lower upper meas vert horiz height width a
-> Full meas vert horiz height width a
extractR Matrix Hh xl xu lower upper meas vert horiz height width a
HouseholderFlex lower upper meas vert horiz height width a
qr) (Vector height a -> Vector width a)
-> Vector height a -> Vector width a
forall a b. (a -> b) -> a -> b
$
      Order
-> (General height () a -> General height () a)
-> Vector height a
-> Vector height a
forall height0 a height1 b.
Order
-> (General height0 () a -> General height1 () b)
-> Vector height0 a
-> Vector height1 b
Basic.unliftColumn Order
Layout.ColumnMajor
         (Transposition
-> Conjugation
-> HouseholderFlex lower upper meas vert horiz height width a
-> General height () a
-> General height () a
forall measA vertA horizA widthA measB vertB horizB widthB height a
       lower upper.
(Measure measA, C vertA, C horizA, C widthA, Measure measB,
 C vertB, C horizB, C widthB, C height, Eq height, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA horizA height widthA a
-> Full measB vertB horizB height widthB a
-> Full measB vertB horizB height widthB a
multiplyQ Transposition
Transposed Conjugation
NonConjugated Matrix Hh xl xu lower upper meas vert horiz height width a
HouseholderFlex lower upper meas vert horiz height width a
qr) Vector height a
x

instance Multiply.MultiplySquare Hh where
   type MultiplySquareExtra Hh extra = extra ~ ()
   squareFull :: Quadratic Hh xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
squareFull Quadratic Hh xl xu lower upper height a
qr =
      (PlainArray
   Unpacked Arbitrary Filled Filled meas vert horiz height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz height width a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 ((PlainArray
    Unpacked Arbitrary Filled Filled meas vert horiz height width a
  -> PlainArray
       Unpacked Arbitrary Filled Filled meas vert horiz height width a)
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz height width a
    -> PlainArray
         Unpacked Arbitrary Filled Filled meas vert horiz height width a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
         Transposition
-> Conjugation
-> HouseholderFlex lower upper Shape Small Small height height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall measA vertA horizA widthA measB vertB horizB widthB height a
       lower upper.
(Measure measA, C vertA, C horizA, C widthA, Measure measB,
 C vertB, C horizB, C widthB, C height, Eq height, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA horizA height widthA a
-> Full measB vertB horizB height widthB a
-> Full measB vertB horizB height widthB a
multiplyQ Transposition
NonTransposed Conjugation
NonConjugated Quadratic Hh xl xu lower upper height a
HouseholderFlex lower upper Shape Small Small height height a
qr (Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (Full meas vert horiz height width a
    -> Full meas vert horiz height width a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         Transposition
-> HouseholderFlex lower upper Shape Small Small height height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall measA vertA meas vert horiz height heightA widthB a lower
       upper.
(Measure measA, C vertA, Measure meas, C vert, C horiz, C height,
 Eq height, C heightA, C widthB, Floating a) =>
Transposition
-> HouseholderFlex lower upper measA vertA Small heightA height a
-> Full meas vert horiz height widthB a
-> Full meas vert horiz height widthB a
tallMultiplyR Transposition
NonTransposed Quadratic Hh xl xu lower upper height a
HouseholderFlex lower upper Shape Small Small height height a
qr

   fullSquare :: Full meas vert horiz height width a
-> Quadratic Hh xl xu lower upper width a
-> Full meas vert horiz height width a
fullSquare = (HouseholderFlex lower upper Shape Small Small width width a
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> Full meas vert horiz height width a
-> HouseholderFlex lower upper Shape Small Small width width a
-> Full meas vert horiz height width a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((HouseholderFlex lower upper Shape Small Small width width a
  -> Full meas vert horiz height width a
  -> Full meas vert horiz height width a)
 -> Full meas vert horiz height width a
 -> HouseholderFlex lower upper Shape Small Small width width a
 -> Full meas vert horiz height width a)
-> (HouseholderFlex lower upper Shape Small Small width width a
    -> Full meas vert horiz height width a
    -> Full meas vert horiz height width a)
-> Full meas vert horiz height width a
-> HouseholderFlex lower upper Shape Small Small width width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ \HouseholderFlex lower upper Shape Small Small width width a
qr ->
      (PlainArray
   Unpacked Arbitrary Filled Filled meas vert horiz height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz height width a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 ((PlainArray
    Unpacked Arbitrary Filled Filled meas vert horiz height width a
  -> PlainArray
       Unpacked Arbitrary Filled Filled meas vert horiz height width a)
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz height width a
    -> PlainArray
         Unpacked Arbitrary Filled Filled meas vert horiz height width a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
         Full meas horiz vert width height a
-> Full meas vert horiz height width a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width a
-> Full meas horiz vert width height a
Basic.transpose (Full meas horiz vert width height a
 -> Full meas vert horiz height width a)
-> (Full meas vert horiz height width a
    -> Full meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         Transposition
-> HouseholderFlex lower upper Shape Small Small width width a
-> Full meas horiz vert width height a
-> Full meas horiz vert width height a
forall measA vertA meas vert horiz height heightA widthB a lower
       upper.
(Measure measA, C vertA, Measure meas, C vert, C horiz, C height,
 Eq height, C heightA, C widthB, Floating a) =>
Transposition
-> HouseholderFlex lower upper measA vertA Small heightA height a
-> Full meas vert horiz height widthB a
-> Full meas vert horiz height widthB a
tallMultiplyR Transposition
Transposed HouseholderFlex lower upper Shape Small Small width width a
qr (Full meas horiz vert width height a
 -> Full meas horiz vert width height a)
-> (Full meas vert horiz height width a
    -> Full meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         Transposition
-> Conjugation
-> HouseholderFlex lower upper Shape Small Small width width a
-> Full meas horiz vert width height a
-> Full meas horiz vert width height a
forall measA vertA horizA widthA measB vertB horizB widthB height a
       lower upper.
(Measure measA, C vertA, C horizA, C widthA, Measure measB,
 C vertB, C horizB, C widthB, C height, Eq height, Floating a) =>
Transposition
-> Conjugation
-> HouseholderFlex lower upper measA vertA horizA height widthA a
-> Full measB vertB horizB height widthB a
-> Full measB vertB horizB height widthB a
multiplyQ Transposition
Transposed Conjugation
NonConjugated HouseholderFlex lower upper Shape Small Small width width a
qr (Full meas horiz vert width height a
 -> Full meas horiz vert width height a)
-> (Full meas vert horiz height width a
    -> Full meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width a
-> Full meas horiz vert width height a
Basic.transpose

instance Divide.Determinant Hh where
   type DeterminantExtra Hh extra = extra ~ ()
   determinant :: Quadratic Hh xl xu lower upper sh a -> a
determinant = Quadratic Hh xl xu lower upper sh a -> a
forall sh a lower upper.
(C sh, Floating a) =>
HouseholderFlex lower upper Shape Small Small sh sh a -> a
determinant

instance Divide.Solve Hh where
   type SolveExtra Hh extra = extra ~ ()
   solveRight :: Quadratic Hh xl xu lower upper height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
solveRight = (Array (Full meas vert horiz height width) a
 -> Array (Full meas vert horiz height width) a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 ((Array (Full meas vert horiz height width) a
  -> Array (Full meas vert horiz height width) a)
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (HouseholderFlex lower upper Shape Small Small height height a
    -> Array (Full meas vert horiz height width) a
    -> Array (Full meas vert horiz height width) a)
-> HouseholderFlex lower upper Shape Small Small height height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HouseholderFlex lower upper meas horiz Small height height a
-> Array (Full meas vert horiz height width) a
-> Array (Full meas vert horiz height width) a
forall meas vert horiz height width nrhs a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 C nrhs, Floating a) =>
HouseholderFlex lower upper meas horiz Small height width a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
leastSquares (HouseholderFlex lower upper meas horiz Small height height a
 -> Array (Full meas vert horiz height width) a
 -> Array (Full meas vert horiz height width) a)
-> (HouseholderFlex lower upper Shape Small Small height height a
    -> HouseholderFlex lower upper meas horiz Small height height a)
-> HouseholderFlex lower upper Shape Small Small height height a
-> Array (Full meas vert horiz height width) a
-> Array (Full meas vert horiz height width) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map Shape Small Small meas horiz Small height height
-> HouseholderFlex lower upper Shape Small Small height height a
-> HouseholderFlex lower upper meas horiz Small height height a
forall measA vertA horizA measB vertB horizB height width lower
       upper a.
(Measure measA, C vertA, C horizA, Measure measB, C vertB,
 C horizB) =>
Map measA vertA horizA measB vertB horizB height width
-> HouseholderFlex lower upper measA vertA horizA height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
mapExtent Map Shape Small Small meas horiz Small height height
forall meas vert horiz size.
(Measure meas, C vert, C horiz) =>
Square size -> Extent meas vert horiz size size
ExtentPriv.fromSquare
   solveLeft :: Full meas vert horiz height width a
-> Quadratic Hh xl xu lower upper width a
-> Full meas vert horiz height width a
solveLeft =
      (HouseholderFlex lower upper Shape Small Small width width a
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> Full meas vert horiz height width a
-> HouseholderFlex lower upper Shape Small Small width width a
-> Full meas vert horiz height width a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((HouseholderFlex lower upper Shape Small Small width width a
  -> Full meas vert horiz height width a
  -> Full meas vert horiz height width a)
 -> Full meas vert horiz height width a
 -> HouseholderFlex lower upper Shape Small Small width width a
 -> Full meas vert horiz height width a)
-> (HouseholderFlex lower upper Shape Small Small width width a
    -> Full meas vert horiz height width a
    -> Full meas vert horiz height width a)
-> Full meas vert horiz height width a
-> HouseholderFlex lower upper Shape Small Small width width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ \HouseholderFlex lower upper Shape Small Small width width a
a -> (PlainArray
   Unpacked Arbitrary Filled Filled meas vert horiz height width a
 -> PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz height width a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall packA propA lowerA upperA measA vertA horizA heightA widthA
       packB propB lowerB upperB measB vertB horizB heightB widthB a b.
(ToPlain
   packA propA lowerA upperA measA vertA horizA heightA widthA,
 FromPlain
   packB propB lowerB upperB measB vertB horizB heightB widthB) =>
(PlainArray
   packA propA lowerA upperA measA vertA horizA heightA widthA a
 -> PlainArray
      packB propB lowerB upperB measB vertB horizB heightB widthB b)
-> ArrayMatrix
     packA propA lowerA upperA measA vertA horizA heightA widthA a
-> ArrayMatrix
     packB propB lowerB upperB measB vertB horizB heightB widthB b
ArrMatrix.lift1 ((PlainArray
    Unpacked Arbitrary Filled Filled meas vert horiz height width a
  -> PlainArray
       Unpacked Arbitrary Filled Filled meas vert horiz height width a)
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> (PlainArray
      Unpacked Arbitrary Filled Filled meas vert horiz height width a
    -> PlainArray
         Unpacked Arbitrary Filled Filled meas vert horiz height width a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
         Full meas horiz vert width height a
-> Full meas vert horiz height width a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
Full meas vert horiz height width a
-> Full meas horiz vert width height a
Basic.adjoint (Full meas horiz vert width height a
 -> Full meas vert horiz height width a)
-> (Full meas vert horiz height width a
    -> Full meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         HouseholderFlex lower upper meas horiz Small width width a
-> Full meas horiz vert width height a
-> Full meas horiz vert width height a
forall meas vert horiz height width nrhs a lower upper.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 C nrhs, Floating a) =>
HouseholderFlex lower upper meas vert Small width height a
-> Full meas vert horiz height nrhs a
-> Full meas vert horiz width nrhs a
minimumNorm (Map Shape Small Small meas horiz Small width width
-> HouseholderFlex lower upper Shape Small Small width width a
-> HouseholderFlex lower upper meas horiz Small width width a
forall measA vertA horizA measB vertB horizB height width lower
       upper a.
(Measure measA, C vertA, C horizA, Measure measB, C vertB,
 C horizB) =>
Map measA vertA horizA measB vertB horizB height width
-> HouseholderFlex lower upper measA vertA horizA height width a
-> HouseholderFlex lower upper measB vertB horizB height width a
mapExtent Map Shape Small Small meas horiz Small width width
forall meas vert horiz size.
(Measure meas, C vert, C horiz) =>
Square size -> Extent meas vert horiz size size
ExtentPriv.fromSquare HouseholderFlex lower upper Shape Small Small width width a
a) (Full meas horiz vert width height a
 -> Full meas horiz vert width height a)
-> (Full meas vert horiz height width a
    -> Full meas horiz vert width height a)
-> Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
         Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, C width, Floating a) =>
Full meas vert horiz height width a
-> Full meas horiz vert width height a
Basic.adjoint