{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Numeric.LAPACK.Matrix.Basic where

import qualified Numeric.LAPACK.Matrix.Layout.Private as Layout
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import qualified Numeric.LAPACK.Matrix.RowMajor as RowMajor
import qualified Numeric.LAPACK.Vector as Vector
import qualified Numeric.LAPACK.Private as Private
import Numeric.LAPACK.Matrix.Layout.Private
         (Order(RowMajor, ColumnMajor), transposeFromOrder, flipOrder)
import Numeric.LAPACK.Matrix.Modifier (Conjugation(NonConjugated))
import Numeric.LAPACK.Matrix.Private
         (Full, Tall, Wide, Square, General, fromFull, ShapeInt, revealOrder)
import Numeric.LAPACK.Vector (Vector)
import Numeric.LAPACK.Scalar (RealOf, zero, one)
import Numeric.LAPACK.Shape.Private (Unchecked(Unchecked))
import Numeric.LAPACK.Matrix.Extent (Extent)
import Numeric.LAPACK.Private
         (pointerSeq, copyTransposed, copySubMatrix, copyBlock)

import qualified Numeric.BLAS.FFI.Generic as BlasGen
import qualified Numeric.Netlib.Utility as Call
import qualified Numeric.Netlib.Class as Class

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 Data.Array.Comfort.Shape ((::+)((::+)))

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

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

import Data.Complex (Complex)


caseTallWide ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width) =>
   Full meas vert horiz height width a ->
   Either (Tall height width a) (Wide height width a)
caseTallWide :: Full meas vert horiz height width a
-> Either (Tall height width a) (Wide height width a)
caseTallWide (Array Full meas vert horiz height width
shape ForeignPtr a
a) =
   (Tall height width
 -> Either (Tall height width a) (Wide height width a))
-> (Wide height width
    -> Either (Tall height width a) (Wide height width a))
-> Either (Tall height width) (Wide 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))
-> (Tall height width -> Tall height width a)
-> Tall height width
-> Either (Tall height width a) (Wide height width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Tall height width -> ForeignPtr a -> Tall height width a)
-> ForeignPtr a -> Tall height width -> Tall height width a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Tall height width -> ForeignPtr a -> Tall height width a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array 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))
-> (Wide height width -> Wide height width a)
-> Wide height width
-> Either (Tall height width a) (Wide height width a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Wide height width -> ForeignPtr a -> Wide height width a)
-> ForeignPtr a -> Wide height width -> Wide height width a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Wide height width -> ForeignPtr a -> Wide height width a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array ForeignPtr a
a) (Either (Tall height width) (Wide height width)
 -> Either (Tall height width a) (Wide height width a))
-> Either (Tall height width) (Wide height width)
-> Either (Tall height width a) (Wide height width a)
forall a b. (a -> b) -> a -> b
$
   Full meas vert horiz height width
-> Either (Tall height width) (Wide height width)
forall meas vert horiz height width.
(Measure meas, C vert, C horiz, C height, C width) =>
Full meas vert horiz height width
-> Either (Tall height width) (Wide height width)
Layout.caseTallWide Full meas vert horiz height width
shape


transpose ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   Full meas vert horiz height width a -> Full meas horiz vert width height a
transpose :: Full meas vert horiz height width a
-> Full meas horiz vert width height a
transpose = (Full meas vert horiz height width
 -> Full meas horiz vert width height)
-> Full meas vert horiz height width a
-> Full meas horiz vert width height a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape Full meas vert horiz height width
-> Full meas horiz vert width height
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width
-> Full meas horiz vert width height
Layout.transpose

adjoint ::
   (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 -> Full meas horiz vert width height a
adjoint :: Full meas vert horiz height width a
-> Full meas horiz vert width height a
adjoint = 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
transpose (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)
-> 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 vert horiz height width a
forall sh a. (C sh, Floating a) => Vector sh a -> Vector sh a
Vector.conjugate


swapMultiply ::
   (Extent.Measure measA, Extent.C vertA, Extent.C horizA,
    Extent.Measure measB, Extent.C vertB, Extent.C horizB) =>
   (matrix ->
    Full measA horizA vertA widthA heightA a ->
    Full measB horizB vertB widthB heightB a) ->
   Full measA vertA horizA heightA widthA a ->
   matrix ->
   Full measB vertB horizB heightB widthB a
swapMultiply :: (matrix
 -> Full measA horizA vertA widthA heightA a
 -> Full measB horizB vertB widthB heightB a)
-> Full measA vertA horizA heightA widthA a
-> matrix
-> Full measB vertB horizB heightB widthB a
swapMultiply matrix
-> Full measA horizA vertA widthA heightA a
-> Full measB horizB vertB widthB heightB a
multiplyTrans Full measA vertA horizA heightA widthA a
a matrix
b = Full measB horizB vertB widthB heightB a
-> Full measB vertB horizB heightB widthB 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
transpose (Full measB horizB vertB widthB heightB a
 -> Full measB vertB horizB heightB widthB a)
-> Full measB horizB vertB widthB heightB a
-> Full measB vertB horizB heightB widthB a
forall a b. (a -> b) -> a -> b
$ matrix
-> Full measA horizA vertA widthA heightA a
-> Full measB horizB vertB widthB heightB a
multiplyTrans matrix
b (Full measA horizA vertA widthA heightA a
 -> Full measB horizB vertB widthB heightB a)
-> Full measA horizA vertA widthA heightA a
-> Full measB horizB vertB widthB heightB a
forall a b. (a -> b) -> a -> b
$ Full measA vertA horizA heightA widthA a
-> Full measA horizA vertA widthA heightA 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
transpose Full measA vertA horizA heightA widthA a
a


mapExtent ::
   (Extent measA vertA horizA heightA widthA ->
    Extent measB vertB horizB heightB widthB) ->
   Full measA vertA horizA heightA widthA a ->
   Full measB vertB horizB heightB widthB a
mapExtent :: (Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
mapExtent Extent measA vertA horizA heightA widthA
-> Extent measB vertB horizB heightB widthB
f =
   (Full measA vertA horizA heightA widthA
 -> Full measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(Layout.Full Order
order Extent measA vertA horizA heightA widthA
extent) ->
         Order
-> Extent measB vertB horizB heightB widthB
-> Full measB vertB horizB heightB widthB
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
order (Extent measB vertB horizB heightB widthB
 -> Full measB vertB horizB heightB widthB)
-> Extent measB vertB horizB heightB widthB
-> Full measB vertB horizB heightB widthB
forall a b. (a -> b) -> a -> b
$ Extent measA vertA horizA heightA widthA
-> Extent measB vertB horizB heightB widthB
f Extent measA vertA horizA heightA widthA
extent)

mapHeight ::
   (Extent.C vert, Extent.C horiz) =>
   (heightA -> heightB) ->
   Full Extent.Size vert horiz heightA width a ->
   Full Extent.Size vert horiz heightB width a
mapHeight :: (heightA -> heightB)
-> Full Size vert horiz heightA width a
-> Full Size vert horiz heightB width a
mapHeight = (Extent Size vert horiz heightA width
 -> Extent Size vert horiz heightB width)
-> Full Size vert horiz heightA width a
-> Full Size vert horiz heightB width a
forall measA vertA horizA heightA widthA measB vertB horizB heightB
       widthB a.
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
mapExtent ((Extent Size vert horiz heightA width
  -> Extent Size vert horiz heightB width)
 -> Full Size vert horiz heightA width a
 -> Full Size vert horiz heightB width a)
-> ((heightA -> heightB)
    -> Extent Size vert horiz heightA width
    -> Extent Size vert horiz heightB width)
-> (heightA -> heightB)
-> Full Size vert horiz heightA width a
-> Full Size vert horiz heightB width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (heightA -> heightB)
-> Extent Size vert horiz heightA width
-> Extent Size vert horiz heightB width
forall vert horiz heightA heightB width.
(C vert, C horiz) =>
(heightA -> heightB)
-> Extent Size vert horiz heightA width
-> Extent Size vert horiz heightB width
Extent.mapHeight

mapWidth ::
   (Extent.C vert, Extent.C horiz) =>
   (widthA -> widthB) ->
   Full Extent.Size vert horiz height widthA a ->
   Full Extent.Size vert horiz height widthB a
mapWidth :: (widthA -> widthB)
-> Full Size vert horiz height widthA a
-> Full Size vert horiz height widthB a
mapWidth = (Extent Size vert horiz height widthA
 -> Extent Size vert horiz height widthB)
-> Full Size vert horiz height widthA a
-> Full Size vert horiz height widthB a
forall measA vertA horizA heightA widthA measB vertB horizB heightB
       widthB a.
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
mapExtent ((Extent Size vert horiz height widthA
  -> Extent Size vert horiz height widthB)
 -> Full Size vert horiz height widthA a
 -> Full Size vert horiz height widthB a)
-> ((widthA -> widthB)
    -> Extent Size vert horiz height widthA
    -> Extent Size vert horiz height widthB)
-> (widthA -> widthB)
-> Full Size vert horiz height widthA a
-> Full Size vert horiz height widthB a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (widthA -> widthB)
-> Extent Size vert horiz height widthA
-> Extent Size vert horiz height widthB
forall vert horiz widthA widthB height.
(C vert, C horiz) =>
(widthA -> widthB)
-> Extent Size vert horiz height widthA
-> Extent Size vert horiz height widthB
Extent.mapWidth

uncheck ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   Full meas vert horiz height width a ->
   Full meas vert horiz (Unchecked height) (Unchecked width) a
uncheck :: Full meas vert horiz height width a
-> Full meas vert horiz (Unchecked height) (Unchecked width) a
uncheck = (Extent meas vert horiz height width
 -> Extent meas vert horiz (Unchecked height) (Unchecked width))
-> Full meas vert horiz height width a
-> Full meas vert horiz (Unchecked height) (Unchecked width) a
forall measA vertA horizA heightA widthA measB vertB horizB heightB
       widthB a.
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
mapExtent ((Extent meas vert horiz height width
  -> Extent meas vert horiz (Unchecked height) (Unchecked width))
 -> Full meas vert horiz height width a
 -> Full meas vert horiz (Unchecked height) (Unchecked width) a)
-> (Extent meas vert horiz height width
    -> Extent meas vert horiz (Unchecked height) (Unchecked width))
-> Full meas vert horiz height width a
-> Full meas vert horiz (Unchecked height) (Unchecked width) a
forall a b. (a -> b) -> a -> b
$ (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)
Extent.mapWrap height -> Unchecked height
forall sh. sh -> Unchecked sh
Unchecked width -> Unchecked width
forall sh. sh -> Unchecked sh
Unchecked

recheck ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   Full meas vert horiz (Unchecked height) (Unchecked width) a ->
   Full meas vert horiz height width a
recheck :: Full meas vert horiz (Unchecked height) (Unchecked width) a
-> Full meas vert horiz height width a
recheck = (Extent meas vert horiz (Unchecked height) (Unchecked width)
 -> Extent meas vert horiz height width)
-> Full meas vert horiz (Unchecked height) (Unchecked width) a
-> Full meas vert horiz height width a
forall measA vertA horizA heightA widthA measB vertB horizB heightB
       widthB a.
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
mapExtent Extent meas vert horiz (Unchecked height) (Unchecked width)
-> Extent meas vert horiz height width
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz (Unchecked height) (Unchecked width)
-> Extent meas vert horiz height width
Extent.recheck


singleRow :: Order -> Vector width a -> General () width a
singleRow :: Order -> Vector width a -> General () width a
singleRow Order
order = (width -> General () width) -> Vector width a -> General () width a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (Order -> () -> width -> General () width
forall height width.
Order -> height -> width -> General height width
Layout.general Order
order ())

singleColumn :: Order -> Vector height a -> General height () a
singleColumn :: Order -> Vector height a -> General height () a
singleColumn Order
order = (height -> General height ())
-> Vector height a -> General height () a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape ((height -> () -> General height ())
-> () -> height -> General height ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Order -> height -> () -> General height ()
forall height width.
Order -> height -> width -> General height width
Layout.general Order
order) ())

flattenRow :: General () width a -> Vector width a
flattenRow :: General () width a -> Vector width a
flattenRow = (Full Size Big Big () width -> width)
-> General () width a -> Vector width a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape Full Size Big Big () width -> width
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width -> width
Layout.fullWidth

flattenColumn :: General height () a -> Vector height a
flattenColumn :: General height () a -> Vector height a
flattenColumn = (Full Size Big Big height () -> height)
-> General height () a -> Vector height a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape Full Size Big Big height () -> height
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width -> height
Layout.fullHeight

liftRow ::
   Order ->
   (Vector height0 a -> Vector height1 b) ->
   General () height0 a -> General () height1 b
liftRow :: Order
-> (Vector height0 a -> Vector height1 b)
-> General () height0 a
-> General () height1 b
liftRow Order
order Vector height0 a -> Vector height1 b
f = Order -> Vector height1 b -> General () height1 b
forall width a. Order -> Vector width a -> General () width a
singleRow Order
order (Vector height1 b -> General () height1 b)
-> (General () height0 a -> Vector height1 b)
-> General () height0 a
-> General () height1 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector height0 a -> Vector height1 b
f (Vector height0 a -> Vector height1 b)
-> (General () height0 a -> Vector height0 a)
-> General () height0 a
-> Vector height1 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. General () height0 a -> Vector height0 a
forall width a. General () width a -> Vector width a
flattenRow

liftColumn ::
   Order ->
   (Vector height0 a -> Vector height1 b) ->
   General height0 () a -> General height1 () b
liftColumn :: Order
-> (Vector height0 a -> Vector height1 b)
-> General height0 () a
-> General height1 () b
liftColumn Order
order Vector height0 a -> Vector height1 b
f = Order -> Vector height1 b -> General height1 () b
forall height a. Order -> Vector height a -> General height () a
singleColumn Order
order (Vector height1 b -> General height1 () b)
-> (General height0 () a -> Vector height1 b)
-> General height0 () a
-> General height1 () b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector height0 a -> Vector height1 b
f (Vector height0 a -> Vector height1 b)
-> (General height0 () a -> Vector height0 a)
-> General height0 () a
-> Vector height1 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. General height0 () a -> Vector height0 a
forall height a. General height () a -> Vector height a
flattenColumn

unliftRow ::
   Order ->
   (General () height0 a -> General () height1 b) ->
   Vector height0 a -> Vector height1 b
unliftRow :: Order
-> (General () height0 a -> General () height1 b)
-> Vector height0 a
-> Vector height1 b
unliftRow Order
order General () height0 a -> General () height1 b
f = General () height1 b -> Vector height1 b
forall width a. General () width a -> Vector width a
flattenRow (General () height1 b -> Vector height1 b)
-> (Vector height0 a -> General () height1 b)
-> Vector height0 a
-> Vector height1 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. General () height0 a -> General () height1 b
f (General () height0 a -> General () height1 b)
-> (Vector height0 a -> General () height0 a)
-> Vector height0 a
-> General () height1 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Order -> Vector height0 a -> General () height0 a
forall width a. Order -> Vector width a -> General () width a
singleRow Order
order

unliftColumn ::
   Order ->
   (General height0 () a -> General height1 () b) ->
   Vector height0 a -> Vector height1 b
unliftColumn :: Order
-> (General height0 () a -> General height1 () b)
-> Vector height0 a
-> Vector height1 b
unliftColumn Order
order General height0 () a -> General height1 () b
f = General height1 () b -> Vector height1 b
forall height a. General height () a -> Vector height a
flattenColumn (General height1 () b -> Vector height1 b)
-> (Vector height0 a -> General height1 () b)
-> Vector height0 a
-> Vector height1 b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. General height0 () a -> General height1 () b
f (General height0 () a -> General height1 () b)
-> (Vector height0 a -> General height0 () a)
-> Vector height0 a
-> General height1 () b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Order -> Vector height0 a -> General height0 () a
forall height a. Order -> Vector height a -> General height () a
singleColumn Order
order


forceRowMajor ::
   (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 ->
   Full meas vert horiz height width a
forceRowMajor :: Full meas vert horiz height width a
-> Full meas vert horiz height width a
forceRowMajor (Array shape :: Full meas vert horiz height width
shape@(Layout.Full Order
order Extent meas vert horiz height width
extent) ForeignPtr a
x) =
   case Order
order of
      Order
RowMajor -> Full meas vert horiz height width
-> ForeignPtr a -> Full meas vert horiz height width a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array Full meas vert horiz height width
shape ForeignPtr a
x
      Order
ColumnMajor ->
         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
RowMajor 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
yPtr ->
         ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
x ((Ptr a -> IO ()) -> IO ()) -> (Ptr a -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr a
xPtr -> 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 n :: Int
n = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
            let m :: Int
m = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
            Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
Private.copyTransposed Int
n Int
m Ptr a
xPtr Int
n Ptr a
yPtr

forceOrder ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Order ->
   Full meas vert horiz height width a ->
   Full meas vert horiz height width a
forceOrder :: Order
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forceOrder Order
order =
   case Order
order of
      Order
RowMajor -> Full meas vert horiz height width 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 vert horiz height width a
forceRowMajor
      Order
ColumnMajor -> 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
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
. Full meas horiz vert width height 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 vert horiz height width a
forceRowMajor (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
transpose


takeSub ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C heightA, Shape.C height, Shape.C width, Class.Floating a) =>
   heightA -> Int -> ForeignPtr a ->
   Layout.Full meas vert horiz height width ->
   Full meas vert horiz height width a
takeSub :: heightA
-> Int
-> ForeignPtr a
-> Full meas vert horiz height width
-> Full meas vert horiz height width a
takeSub heightA
heightA Int
k ForeignPtr a
a shape :: Full meas vert horiz height width
shape@(Layout.Full Order
order Extent meas vert horiz height width
extentB) =
   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 Full meas vert horiz height width
shape ((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
blockSize Ptr a
bPtr ->
   ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
a ((Ptr a -> IO ()) -> IO ()) -> (Ptr a -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr ->
   let ma :: Int
ma = heightA -> Int
forall sh. C sh => sh -> Int
Shape.size heightA
heightA
       mb :: Int
mb = 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
extentB
       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 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
extentB
   in case Order
order of
         Order
RowMajor -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
blockSize (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
kInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n)) Ptr a
bPtr
         Order
ColumnMajor -> 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
ma (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr Int
k) Int
mb Ptr a
bPtr

takeTop ::
   (Extent.C vert, Shape.C height0, Shape.C height1, Shape.C width,
    Class.Floating a) =>
   Full Extent.Size vert Extent.Big (height0::+height1) width a ->
   Full Extent.Size vert Extent.Big height0 width a
takeTop :: Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height0 width a
takeTop (Array (Layout.Full Order
order Extent Size vert Big (height0 ::+ height1) width
extentA) ForeignPtr a
a) =
   let heightA :: height0 ::+ height1
heightA@(height0
heightB::+height1
_) = Extent Size vert Big (height0 ::+ height1) width
-> height0 ::+ height1
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> height
Extent.height Extent Size vert Big (height0 ::+ height1) width
extentA
       extentB :: Extent Size vert Big height0 width
extentB = height0
-> Extent Size vert Big (height0 ::+ height1) width
-> Extent Size vert Big height0 width
forall vert heightB heightA width.
C vert =>
heightB
-> Extent Size vert Big heightA width
-> Extent Size vert Big heightB width
Extent.reduceWideHeight height0
heightB Extent Size vert Big (height0 ::+ height1) width
extentA
   in (height0 ::+ height1)
-> Int
-> ForeignPtr a
-> Full Size vert Big height0 width
-> Full Size vert Big height0 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
takeSub height0 ::+ height1
heightA Int
0 ForeignPtr a
a (Full Size vert Big height0 width
 -> Full Size vert Big height0 width a)
-> Full Size vert Big height0 width
-> Full Size vert Big height0 width a
forall a b. (a -> b) -> a -> b
$ Order
-> Extent Size vert Big height0 width
-> Full Size vert Big height0 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 Size vert Big height0 width
extentB

takeBottom ::
   (Extent.C vert, Shape.C height0, Shape.C height1, Shape.C width,
    Class.Floating a) =>
   Full Extent.Size vert Extent.Big (height0::+height1) width a ->
   Full Extent.Size vert Extent.Big height1 width a
takeBottom :: Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height1 width a
takeBottom (Array (Layout.Full Order
order Extent Size vert Big (height0 ::+ height1) width
extentA) ForeignPtr a
a) =
   let heightA :: height0 ::+ height1
heightA@(height0
height0::+height1
heightB) = Extent Size vert Big (height0 ::+ height1) width
-> height0 ::+ height1
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> height
Extent.height Extent Size vert Big (height0 ::+ height1) width
extentA
       extentB :: Extent Size vert Big height1 width
extentB = height1
-> Extent Size vert Big (height0 ::+ height1) width
-> Extent Size vert Big height1 width
forall vert heightB heightA width.
C vert =>
heightB
-> Extent Size vert Big heightA width
-> Extent Size vert Big heightB width
Extent.reduceWideHeight height1
heightB Extent Size vert Big (height0 ::+ height1) width
extentA
   in (height0 ::+ height1)
-> Int
-> ForeignPtr a
-> Full Size vert Big height1 width
-> Full Size vert Big height1 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
takeSub height0 ::+ height1
heightA (height0 -> Int
forall sh. C sh => sh -> Int
Shape.size height0
height0) ForeignPtr a
a (Full Size vert Big height1 width
 -> Full Size vert Big height1 width a)
-> Full Size vert Big height1 width
-> Full Size vert Big height1 width a
forall a b. (a -> b) -> a -> b
$ Order
-> Extent Size vert Big height1 width
-> Full Size vert Big height1 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 Size vert Big height1 width
extentB

takeLeft ::
   (Extent.C vert, Shape.C height, Shape.C width0, Shape.C width1,
    Class.Floating a) =>
   Full Extent.Size Extent.Big vert height (width0::+width1) a ->
   Full Extent.Size Extent.Big vert height width0 a
takeLeft :: Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width0 a
takeLeft = Full Size vert Big width0 height a
-> Full Size Big vert height width0 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
transpose (Full Size vert Big width0 height a
 -> Full Size Big vert height width0 a)
-> (Full Size Big vert height (width0 ::+ width1) a
    -> Full Size vert Big width0 height a)
-> Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width0 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size vert Big (width0 ::+ width1) height a
-> Full Size vert Big width0 height a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height0 width a
takeTop (Full Size vert Big (width0 ::+ width1) height a
 -> Full Size vert Big width0 height a)
-> (Full Size Big vert height (width0 ::+ width1) a
    -> Full Size vert Big (width0 ::+ width1) height a)
-> Full Size Big vert height (width0 ::+ width1) a
-> Full Size vert Big width0 height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size Big vert height (width0 ::+ width1) a
-> Full Size vert Big (width0 ::+ width1) 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
transpose

takeRight ::
   (Extent.C vert, Shape.C height, Shape.C width0, Shape.C width1,
    Class.Floating a) =>
   Full Extent.Size Extent.Big vert height (width0::+width1) a ->
   Full Extent.Size Extent.Big vert height width1 a
takeRight :: Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width1 a
takeRight = Full Size vert Big width1 height a
-> Full Size Big vert height width1 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
transpose (Full Size vert Big width1 height a
 -> Full Size Big vert height width1 a)
-> (Full Size Big vert height (width0 ::+ width1) a
    -> Full Size vert Big width1 height a)
-> Full Size Big vert height (width0 ::+ width1) a
-> Full Size Big vert height width1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size vert Big (width0 ::+ width1) height a
-> Full Size vert Big width1 height a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height1 width a
takeBottom (Full Size vert Big (width0 ::+ width1) height a
 -> Full Size vert Big width1 height a)
-> (Full Size Big vert height (width0 ::+ width1) a
    -> Full Size vert Big (width0 ::+ width1) height a)
-> Full Size Big vert height (width0 ::+ width1) a
-> Full Size vert Big width1 height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size Big vert height (width0 ::+ width1) a
-> Full Size vert Big (width0 ::+ width1) 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
transpose


splitRows ::
   (Extent.C vert, Extent.C horiz, Shape.C width, Class.Floating a) =>
   Int ->
   Full Extent.Size vert horiz ShapeInt width a ->
   Full Extent.Size vert horiz (ShapeInt::+ShapeInt) width a
splitRows :: Int
-> Full Size vert horiz ShapeInt width a
-> Full Size vert horiz (ShapeInt ::+ ShapeInt) width a
splitRows = (Extent Size vert horiz ShapeInt width
 -> Extent Size vert horiz (ShapeInt ::+ ShapeInt) width)
-> Full Size vert horiz ShapeInt width a
-> Full Size vert horiz (ShapeInt ::+ ShapeInt) width a
forall measA vertA horizA heightA widthA measB vertB horizB heightB
       widthB a.
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
mapExtent ((Extent Size vert horiz ShapeInt width
  -> Extent Size vert horiz (ShapeInt ::+ ShapeInt) width)
 -> Full Size vert horiz ShapeInt width a
 -> Full Size vert horiz (ShapeInt ::+ ShapeInt) width a)
-> (Int
    -> Extent Size vert horiz ShapeInt width
    -> Extent Size vert horiz (ShapeInt ::+ ShapeInt) width)
-> Int
-> Full Size vert horiz ShapeInt width a
-> Full Size vert horiz (ShapeInt ::+ ShapeInt) width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ShapeInt -> ShapeInt ::+ ShapeInt)
-> Extent Size vert horiz ShapeInt width
-> Extent Size vert horiz (ShapeInt ::+ ShapeInt) width
forall vert horiz heightA heightB width.
(C vert, C horiz) =>
(heightA -> heightB)
-> Extent Size vert horiz heightA width
-> Extent Size vert horiz heightB width
Extent.mapHeight ((ShapeInt -> ShapeInt ::+ ShapeInt)
 -> Extent Size vert horiz ShapeInt width
 -> Extent Size vert horiz (ShapeInt ::+ ShapeInt) width)
-> (Int -> ShapeInt -> ShapeInt ::+ ShapeInt)
-> Int
-> Extent Size vert horiz ShapeInt width
-> Extent Size vert horiz (ShapeInt ::+ ShapeInt) width
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> ShapeInt -> ShapeInt ::+ ShapeInt
forall n. Real n => n -> ZeroBased n -> ZeroBased n ::+ ZeroBased n
Shape.zeroBasedSplit

takeRows, dropRows ::
   (Extent.C vert, Shape.C width, Class.Floating a) =>
   Int ->
   Full Extent.Size vert Extent.Big ShapeInt width a ->
   Full Extent.Size vert Extent.Big ShapeInt width a
takeRows :: Int
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big ShapeInt width a
takeRows Int
k = Full Size vert Big (ShapeInt ::+ ShapeInt) width a
-> Full Size vert Big ShapeInt width a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height0 width a
takeTop (Full Size vert Big (ShapeInt ::+ ShapeInt) width a
 -> Full Size vert Big ShapeInt width a)
-> (Full Size vert Big ShapeInt width a
    -> Full Size vert Big (ShapeInt ::+ ShapeInt) width a)
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big ShapeInt width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big (ShapeInt ::+ ShapeInt) width a
forall vert horiz width a.
(C vert, C horiz, C width, Floating a) =>
Int
-> Full Size vert horiz ShapeInt width a
-> Full Size vert horiz (ShapeInt ::+ ShapeInt) width a
splitRows Int
k
dropRows :: Int
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big ShapeInt width a
dropRows Int
k = Full Size vert Big (ShapeInt ::+ ShapeInt) width a
-> Full Size vert Big ShapeInt width a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full Size vert Big (height0 ::+ height1) width a
-> Full Size vert Big height1 width a
takeBottom (Full Size vert Big (ShapeInt ::+ ShapeInt) width a
 -> Full Size vert Big ShapeInt width a)
-> (Full Size vert Big ShapeInt width a
    -> Full Size vert Big (ShapeInt ::+ ShapeInt) width a)
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big ShapeInt width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big (ShapeInt ::+ ShapeInt) width a
forall vert horiz width a.
(C vert, C horiz, C width, Floating a) =>
Int
-> Full Size vert horiz ShapeInt width a
-> Full Size vert horiz (ShapeInt ::+ ShapeInt) width a
splitRows Int
k

takeColumns, dropColumns ::
   (Extent.C horiz, Shape.C height, Class.Floating a) =>
   Int ->
   Full Extent.Size Extent.Big horiz height ShapeInt a ->
   Full Extent.Size Extent.Big horiz height ShapeInt a
takeColumns :: Int
-> Full Size Big horiz height ShapeInt a
-> Full Size Big horiz height ShapeInt a
takeColumns Int
k = Full Size horiz Big ShapeInt height a
-> Full Size Big horiz height ShapeInt 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
transpose (Full Size horiz Big ShapeInt height a
 -> Full Size Big horiz height ShapeInt a)
-> (Full Size Big horiz height ShapeInt a
    -> Full Size horiz Big ShapeInt height a)
-> Full Size Big horiz height ShapeInt a
-> Full Size Big horiz height ShapeInt a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Full Size horiz Big ShapeInt height a
-> Full Size horiz Big ShapeInt height a
forall vert width a.
(C vert, C width, Floating a) =>
Int
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big ShapeInt width a
takeRows Int
k (Full Size horiz Big ShapeInt height a
 -> Full Size horiz Big ShapeInt height a)
-> (Full Size Big horiz height ShapeInt a
    -> Full Size horiz Big ShapeInt height a)
-> Full Size Big horiz height ShapeInt a
-> Full Size horiz Big ShapeInt height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size Big horiz height ShapeInt a
-> Full Size horiz Big ShapeInt 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
transpose
dropColumns :: Int
-> Full Size Big horiz height ShapeInt a
-> Full Size Big horiz height ShapeInt a
dropColumns Int
k = Full Size horiz Big ShapeInt height a
-> Full Size Big horiz height ShapeInt 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
transpose (Full Size horiz Big ShapeInt height a
 -> Full Size Big horiz height ShapeInt a)
-> (Full Size Big horiz height ShapeInt a
    -> Full Size horiz Big ShapeInt height a)
-> Full Size Big horiz height ShapeInt a
-> Full Size Big horiz height ShapeInt a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Full Size horiz Big ShapeInt height a
-> Full Size horiz Big ShapeInt height a
forall vert width a.
(C vert, C width, Floating a) =>
Int
-> Full Size vert Big ShapeInt width a
-> Full Size vert Big ShapeInt width a
dropRows Int
k (Full Size horiz Big ShapeInt height a
 -> Full Size horiz Big ShapeInt height a)
-> (Full Size Big horiz height ShapeInt a
    -> Full Size horiz Big ShapeInt height a)
-> Full Size Big horiz height ShapeInt a
-> Full Size horiz Big ShapeInt height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Size Big horiz height ShapeInt a
-> Full Size horiz Big ShapeInt 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
transpose


data OrderBias = LeftBias | RightBias | ContiguousBias
   deriving (OrderBias -> OrderBias -> Bool
(OrderBias -> OrderBias -> Bool)
-> (OrderBias -> OrderBias -> Bool) -> Eq OrderBias
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrderBias -> OrderBias -> Bool
$c/= :: OrderBias -> OrderBias -> Bool
== :: OrderBias -> OrderBias -> Bool
$c== :: OrderBias -> OrderBias -> Bool
Eq, Eq OrderBias
Eq OrderBias
-> (OrderBias -> OrderBias -> Ordering)
-> (OrderBias -> OrderBias -> Bool)
-> (OrderBias -> OrderBias -> Bool)
-> (OrderBias -> OrderBias -> Bool)
-> (OrderBias -> OrderBias -> Bool)
-> (OrderBias -> OrderBias -> OrderBias)
-> (OrderBias -> OrderBias -> OrderBias)
-> Ord OrderBias
OrderBias -> OrderBias -> Bool
OrderBias -> OrderBias -> Ordering
OrderBias -> OrderBias -> OrderBias
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OrderBias -> OrderBias -> OrderBias
$cmin :: OrderBias -> OrderBias -> OrderBias
max :: OrderBias -> OrderBias -> OrderBias
$cmax :: OrderBias -> OrderBias -> OrderBias
>= :: OrderBias -> OrderBias -> Bool
$c>= :: OrderBias -> OrderBias -> Bool
> :: OrderBias -> OrderBias -> Bool
$c> :: OrderBias -> OrderBias -> Bool
<= :: OrderBias -> OrderBias -> Bool
$c<= :: OrderBias -> OrderBias -> Bool
< :: OrderBias -> OrderBias -> Bool
$c< :: OrderBias -> OrderBias -> Bool
compare :: OrderBias -> OrderBias -> Ordering
$ccompare :: OrderBias -> OrderBias -> Ordering
$cp1Ord :: Eq OrderBias
Ord, Int -> OrderBias
OrderBias -> Int
OrderBias -> [OrderBias]
OrderBias -> OrderBias
OrderBias -> OrderBias -> [OrderBias]
OrderBias -> OrderBias -> OrderBias -> [OrderBias]
(OrderBias -> OrderBias)
-> (OrderBias -> OrderBias)
-> (Int -> OrderBias)
-> (OrderBias -> Int)
-> (OrderBias -> [OrderBias])
-> (OrderBias -> OrderBias -> [OrderBias])
-> (OrderBias -> OrderBias -> [OrderBias])
-> (OrderBias -> OrderBias -> OrderBias -> [OrderBias])
-> Enum OrderBias
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: OrderBias -> OrderBias -> OrderBias -> [OrderBias]
$cenumFromThenTo :: OrderBias -> OrderBias -> OrderBias -> [OrderBias]
enumFromTo :: OrderBias -> OrderBias -> [OrderBias]
$cenumFromTo :: OrderBias -> OrderBias -> [OrderBias]
enumFromThen :: OrderBias -> OrderBias -> [OrderBias]
$cenumFromThen :: OrderBias -> OrderBias -> [OrderBias]
enumFrom :: OrderBias -> [OrderBias]
$cenumFrom :: OrderBias -> [OrderBias]
fromEnum :: OrderBias -> Int
$cfromEnum :: OrderBias -> Int
toEnum :: Int -> OrderBias
$ctoEnum :: Int -> OrderBias
pred :: OrderBias -> OrderBias
$cpred :: OrderBias -> OrderBias
succ :: OrderBias -> OrderBias
$csucc :: OrderBias -> OrderBias
Enum, Int -> OrderBias -> ShowS
[OrderBias] -> ShowS
OrderBias -> String
(Int -> OrderBias -> ShowS)
-> (OrderBias -> String)
-> ([OrderBias] -> ShowS)
-> Show OrderBias
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrderBias] -> ShowS
$cshowList :: [OrderBias] -> ShowS
show :: OrderBias -> String
$cshow :: OrderBias -> String
showsPrec :: Int -> OrderBias -> ShowS
$cshowsPrec :: Int -> OrderBias -> ShowS
Show)

beside ::
   (Extent.C vertA, Extent.C vertB, Extent.C vertC,
    Shape.C height, Eq height, Shape.C widthA, Shape.C widthB,
    Class.Floating a) =>
   OrderBias ->
   Extent.AppendMode vertA vertB vertC height widthA widthB ->
   Full Extent.Size vertA Extent.Big height widthA a ->
   Full Extent.Size vertB Extent.Big height widthB a ->
   Full Extent.Size vertC Extent.Big height (widthA::+widthB) a
beside :: OrderBias
-> AppendMode vertA vertB vertC height widthA widthB
-> Full Size vertA Big height widthA a
-> Full Size vertB Big height widthB a
-> Full Size vertC Big height (widthA ::+ widthB) a
beside OrderBias
orderBias (Extent.AppendMode Extent Size vertA Big height widthA
-> Extent Size vertB Big height widthB
-> Extent Size vertC Big height (widthA ::+ widthB)
appendMode)
      (Array (Layout.Full Order
orderA Extent Size vertA Big height widthA
extentA) ForeignPtr a
a)
      (Array (Layout.Full Order
orderB Extent Size vertB Big height widthB
extentB) ForeignPtr a
b) =
   let (height
heightA,widthA
widthA) = Extent Size vertA Big 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 Size vertA Big height widthA
extentA
       (height
heightB,widthB
widthB) = Extent Size vertB Big 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 Size vertB Big height widthB
extentB
       n :: Int
n = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
heightA
       ma :: Int
ma = widthA -> Int
forall sh. C sh => sh -> Int
Shape.size widthA
widthA; volA :: Int
volA = Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ma
       mb :: Int
mb = widthB -> Int
forall sh. C sh => sh -> Int
Shape.size widthB
widthB; volB :: Int
volB = Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
mb
       m :: Int
m = Int
maInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
mb
       create :: Order
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
create Order
order Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ()
act =
          Full Size vertC Big height (widthA ::+ widthB)
-> (Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate
             (Order
-> Extent Size vertC Big height (widthA ::+ widthB)
-> Full Size vertC Big height (widthA ::+ widthB)
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
order (Extent Size vertC Big height (widthA ::+ widthB)
 -> Full Size vertC Big height (widthA ::+ widthB))
-> Extent Size vertC Big height (widthA ::+ widthB)
-> Full Size vertC Big height (widthA ::+ widthB)
forall a b. (a -> b) -> a -> b
$ Extent Size vertA Big height widthA
-> Extent Size vertB Big height widthB
-> Extent Size vertC Big height (widthA ::+ widthB)
appendMode Extent Size vertA Big height widthA
extentA Extent Size vertB Big height widthB
extentB) ((Ptr a -> IO ())
 -> Full Size vertC Big height (widthA ::+ widthB) a)
-> (Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$ \Ptr a
cPtr ->
          ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
a ((Ptr a -> IO ()) -> IO ()) -> (Ptr a -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr ->
          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 ->
          Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ()
act Ptr a
aPtr Ptr a
bPtr Ptr a
cPtr (Ptr a -> IO ()) -> Ptr a -> IO ()
forall a b. (a -> b) -> a -> b
$ Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
cPtr (Int -> Ptr a) -> Int -> Ptr a
forall a b. (a -> b) -> a -> b
$
          case Order
order of
             Order
RowMajor -> Int
ma
             Order
ColumnMajor -> Int
volA
   in
    if height
heightA height -> height -> Bool
forall a. Eq a => a -> a -> Bool
/= height
heightB
      then String -> Full Size vertC Big height (widthA ::+ widthB) a
forall a. HasCallStack => String -> a
error String
"beside: mismatching heights"
      else
         case (Order
orderA,Order
orderB) of
            (Order
RowMajor,Order
RowMajor) ->
               Order
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
create Order
RowMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full Size vertC Big height (widthA ::+ widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr Ptr a
bPtr Ptr a
cPtr Ptr a
_ -> 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
maPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
ma
                  Ptr CInt
mbPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
mb
                  Ptr CInt
incxPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
1
                  Ptr CInt
incyPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
1
                  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
$
                     [IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_ ([IO ()] -> IO ()) -> [IO ()] -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> [IO ()] -> [IO ()]
forall a. Int -> [a] -> [a]
take Int
n ([IO ()] -> [IO ()]) -> [IO ()] -> [IO ()]
forall a b. (a -> b) -> a -> b
$
                     (Ptr a -> Ptr a -> Ptr a -> IO ())
-> [Ptr a] -> [Ptr a] -> [Ptr a] -> [IO ()]
forall a b c d. (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
zipWith3
                        (\Ptr a
akPtr Ptr a
bkPtr Ptr a
ckPtr -> do
                           Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
forall a.
Floating a =>
Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
BlasGen.copy Ptr CInt
maPtr Ptr a
akPtr Ptr CInt
incxPtr Ptr a
ckPtr Ptr CInt
incyPtr
                           Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
forall a.
Floating a =>
Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
BlasGen.copy Ptr CInt
mbPtr Ptr a
bkPtr Ptr CInt
incxPtr
                              (Ptr a
ckPtr Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
`advancePtr` Int
ma) Ptr CInt
incyPtr)
                        (Int -> Ptr a -> [Ptr a]
forall a. Storable a => Int -> Ptr a -> [Ptr a]
pointerSeq Int
ma Ptr a
aPtr)
                        (Int -> Ptr a -> [Ptr a]
forall a. Storable a => Int -> Ptr a -> [Ptr a]
pointerSeq Int
mb Ptr a
bPtr)
                        (Int -> Ptr a -> [Ptr a]
forall a. Storable a => Int -> Ptr a -> [Ptr a]
pointerSeq Int
m Ptr a
cPtr)
            (Order
RowMajor,Order
ColumnMajor) ->
               case OrderBias
orderBias of
                  OrderBias
LeftBias ->
                     Order
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
create Order
RowMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full Size vertC Big height (widthA ::+ widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr Ptr a
bPtr Ptr a
clPtr Ptr a
crPtr -> 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
ma Int
n Int
ma Ptr a
aPtr Int
m Ptr a
clPtr
                        Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyTransposed Int
mb Int
n Ptr a
bPtr Int
m Ptr a
crPtr
                  OrderBias
_ ->
                     Order
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
create Order
ColumnMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full Size vertC Big height (widthA ::+ widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr Ptr a
bPtr Ptr a
clPtr Ptr a
crPtr -> do
                        Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyTransposed Int
n Int
ma Ptr a
aPtr Int
n Ptr a
clPtr
                        Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
volB Ptr a
bPtr Ptr a
crPtr
            (Order
ColumnMajor,Order
RowMajor) ->
               case OrderBias
orderBias of
                  OrderBias
RightBias ->
                     Order
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
create Order
RowMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full Size vertC Big height (widthA ::+ widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr Ptr a
bPtr Ptr a
clPtr Ptr a
crPtr -> do
                        Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyTransposed Int
ma Int
n Ptr a
aPtr Int
m Ptr a
clPtr
                        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
m Ptr a
crPtr
                  OrderBias
_ ->
                     Order
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
create Order
ColumnMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full Size vertC Big height (widthA ::+ widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr Ptr a
bPtr Ptr a
clPtr Ptr a
crPtr -> do
                        Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
volA Ptr a
aPtr Ptr a
clPtr
                        Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyTransposed Int
n Int
mb Ptr a
bPtr Int
n Ptr a
crPtr
            (Order
ColumnMajor,Order
ColumnMajor) ->
               Order
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
create Order
ColumnMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full Size vertC Big height (widthA ::+ widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full Size vertC Big height (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$ \Ptr a
aPtr Ptr a
bPtr Ptr a
clPtr Ptr a
crPtr -> 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
naPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
volA
                  Ptr CInt
nbPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
volB
                  Ptr CInt
incxPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
1
                  Ptr CInt
incyPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
1
                  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
                     Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
forall a.
Floating a =>
Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
BlasGen.copy Ptr CInt
naPtr Ptr a
aPtr Ptr CInt
incxPtr Ptr a
clPtr Ptr CInt
incyPtr
                     Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
forall a.
Floating a =>
Ptr CInt -> Ptr a -> Ptr CInt -> Ptr a -> Ptr CInt -> IO ()
BlasGen.copy Ptr CInt
nbPtr Ptr a
bPtr Ptr CInt
incxPtr Ptr a
crPtr Ptr CInt
incyPtr

above ::
   (Extent.C horizA, Extent.C horizB, Extent.C horizC,
    Shape.C width, Eq width, Shape.C heightA, Shape.C heightB,
    Class.Floating a) =>
   OrderBias ->
   Extent.AppendMode horizA horizB horizC width heightA heightB ->
   Full Extent.Size Extent.Big horizA heightA width a ->
   Full Extent.Size Extent.Big horizB heightB width a ->
   Full Extent.Size Extent.Big horizC (heightA::+heightB) width a
above :: OrderBias
-> AppendMode horizA horizB horizC width heightA heightB
-> Full Size Big horizA heightA width a
-> Full Size Big horizB heightB width a
-> Full Size Big horizC (heightA ::+ heightB) width a
above OrderBias
orderBias AppendMode horizA horizB horizC width heightA heightB
appendMode Full Size Big horizA heightA width a
a Full Size Big horizB heightB width a
b =
   Full Size horizC Big width (heightA ::+ heightB) a
-> Full Size Big horizC (heightA ::+ heightB) 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
transpose (Full Size horizC Big width (heightA ::+ heightB) a
 -> Full Size Big horizC (heightA ::+ heightB) width a)
-> Full Size horizC Big width (heightA ::+ heightB) a
-> Full Size Big horizC (heightA ::+ heightB) width a
forall a b. (a -> b) -> a -> b
$ OrderBias
-> AppendMode horizA horizB horizC width heightA heightB
-> Full Size horizA Big width heightA a
-> Full Size horizB Big width heightB a
-> Full Size horizC Big width (heightA ::+ heightB) a
forall vertA vertB vertC height widthA widthB a.
(C vertA, C vertB, C vertC, C height, Eq height, C widthA,
 C widthB, Floating a) =>
OrderBias
-> AppendMode vertA vertB vertC height widthA widthB
-> Full Size vertA Big height widthA a
-> Full Size vertB Big height widthB a
-> Full Size vertC Big height (widthA ::+ widthB) a
beside OrderBias
orderBias AppendMode horizA horizB horizC width heightA heightB
appendMode (Full Size Big horizA heightA width a
-> Full Size horizA Big width heightA 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
transpose Full Size Big horizA heightA width a
a) (Full Size Big horizB heightB width a
-> Full Size horizB Big width heightB 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
transpose Full Size Big horizB heightB width a
b)

stack ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C heightA, Eq heightA, Shape.C heightB, Eq heightB,
    Shape.C widthA, Eq widthA, Shape.C widthB, Eq widthB, Class.Floating a) =>
   Full meas vert horiz heightA widthA a -> General heightA widthB a ->
   General heightB widthA a -> Full meas vert horiz heightB widthB a ->
   Full meas vert horiz (heightA::+heightB) (widthA::+widthB) a
stack :: Full meas vert horiz heightA widthA a
-> General heightA widthB a
-> General heightB widthA a
-> Full meas vert horiz heightB widthB a
-> Full meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a
stack = OrderBias
-> OrderBias
-> Full meas vert horiz heightA widthA a
-> General heightA widthB a
-> General heightB widthA a
-> Full meas vert horiz heightB widthB a
-> Full meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a
forall meas vert horiz heightA heightB widthA widthB a.
(Measure meas, C vert, C horiz, C heightA, Eq heightA, C heightB,
 Eq heightB, C widthA, Eq widthA, C widthB, Eq widthB,
 Floating a) =>
OrderBias
-> OrderBias
-> Full meas vert horiz heightA widthA a
-> General heightA widthB a
-> General heightB widthA a
-> Full meas vert horiz heightB widthB a
-> Full meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a
stackBiased OrderBias
RightBias OrderBias
RightBias

stackMosaic ::
   (Shape.C shA, Eq shA, Shape.C shB, Eq shB, Class.Floating a) =>
   Square shA a -> General shA shB a ->
   General shB shA a -> Square shB a ->
   Square (shA::+shB) a
stackMosaic :: Square shA a
-> General shA shB a
-> General shB shA a
-> Square shB a
-> Square (shA ::+ shB) a
stackMosaic = OrderBias
-> OrderBias
-> Square shA a
-> General shA shB a
-> General shB shA a
-> Square shB a
-> Square (shA ::+ shB) a
forall meas vert horiz heightA heightB widthA widthB a.
(Measure meas, C vert, C horiz, C heightA, Eq heightA, C heightB,
 Eq heightB, C widthA, Eq widthA, C widthB, Eq widthB,
 Floating a) =>
OrderBias
-> OrderBias
-> Full meas vert horiz heightA widthA a
-> General heightA widthB a
-> General heightB widthA a
-> Full meas vert horiz heightB widthB a
-> Full meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a
stackBiased OrderBias
LeftBias OrderBias
RightBias

stackBiased ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C heightA, Eq heightA, Shape.C heightB, Eq heightB,
    Shape.C widthA, Eq widthA, Shape.C widthB, Eq widthB, Class.Floating a) =>
   OrderBias -> OrderBias ->
   Full meas vert horiz heightA widthA a -> General heightA widthB a ->
   General heightB widthA a -> Full meas vert horiz heightB widthB a ->
   Full meas vert horiz (heightA::+heightB) (widthA::+widthB) a
stackBiased :: OrderBias
-> OrderBias
-> Full meas vert horiz heightA widthA a
-> General heightA widthB a
-> General heightB widthA a
-> Full meas vert horiz heightB widthB a
-> Full meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a
stackBiased OrderBias
vertBias OrderBias
horizBias Full meas vert horiz heightA widthA a
a General heightA widthB a
b General heightB widthA a
c Full meas vert horiz heightB widthB a
d =
   (Extent Size Big Big (heightA ::+ heightB) (widthA ::+ widthB)
 -> Extent
      meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB))
-> Full Size Big Big (heightA ::+ heightB) (widthA ::+ widthB) a
-> Full meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a
forall measA vertA horizA heightA widthA measB vertB horizB heightB
       widthB a.
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Full measA vertA horizA heightA widthA a
-> Full measB vertB horizB heightB widthB a
mapExtent
      (\ Extent Size Big Big (heightA ::+ heightB) (widthA ::+ widthB)
_ ->
         Extent meas vert horiz heightA widthA
-> Extent meas vert horiz heightB widthB
-> Extent meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB)
forall meas vert horiz heightA widthA heightB widthB.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz heightA widthA
-> Extent meas vert horiz heightB widthB
-> Extent meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB)
Extent.stack
            (Full meas vert horiz heightA widthA
-> Extent meas vert horiz heightA widthA
forall meas vert horiz height width.
Full meas vert horiz height width
-> Extent meas vert horiz height width
Layout.fullExtent (Full meas vert horiz heightA widthA
 -> Extent meas vert horiz heightA widthA)
-> Full meas vert horiz heightA widthA
-> Extent meas vert horiz heightA widthA
forall a b. (a -> b) -> a -> b
$ Full meas vert horiz heightA widthA a
-> Full meas vert horiz heightA widthA
forall sh a. Array sh a -> sh
Array.shape Full meas vert horiz heightA widthA a
a)
            (Full meas vert horiz heightB widthB
-> Extent meas vert horiz heightB widthB
forall meas vert horiz height width.
Full meas vert horiz height width
-> Extent meas vert horiz height width
Layout.fullExtent (Full meas vert horiz heightB widthB
 -> Extent meas vert horiz heightB widthB)
-> Full meas vert horiz heightB widthB
-> Extent meas vert horiz heightB widthB
forall a b. (a -> b) -> a -> b
$ Full meas vert horiz heightB widthB a
-> Full meas vert horiz heightB widthB
forall sh a. Array sh a -> sh
Array.shape Full meas vert horiz heightB widthB a
d)) (Full Size Big Big (heightA ::+ heightB) (widthA ::+ widthB) a
 -> Full
      meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a)
-> Full Size Big Big (heightA ::+ heightB) (widthA ::+ widthB) a
-> Full meas vert horiz (heightA ::+ heightB) (widthA ::+ widthB) a
forall a b. (a -> b) -> a -> b
$
   OrderBias
-> AppendMode Big Big Big (widthA ::+ widthB) heightA heightB
-> Full Size Big Big heightA (widthA ::+ widthB) a
-> Full Size Big Big heightB (widthA ::+ widthB) a
-> Full Size Big Big (heightA ::+ heightB) (widthA ::+ widthB) a
forall horizA horizB horizC width heightA heightB a.
(C horizA, C horizB, C horizC, C width, Eq width, C heightA,
 C heightB, Floating a) =>
OrderBias
-> AppendMode horizA horizB horizC width heightA heightB
-> Full Size Big horizA heightA width a
-> Full Size Big horizB heightB width a
-> Full Size Big horizC (heightA ::+ heightB) width a
above OrderBias
vertBias AppendMode Big Big Big (widthA ::+ widthB) heightA heightB
forall vertA vertB height widthA widthB.
(C vertA, C vertB) =>
AppendMode vertA vertB (Append vertA vertB) height widthA widthB
Extent.appendAny
      (OrderBias
-> AppendMode Big Big Big heightA widthA widthB
-> Full Size Big Big heightA widthA a
-> General heightA widthB a
-> Full Size Big Big heightA (widthA ::+ widthB) a
forall vertA vertB vertC height widthA widthB a.
(C vertA, C vertB, C vertC, C height, Eq height, C widthA,
 C widthB, Floating a) =>
OrderBias
-> AppendMode vertA vertB vertC height widthA widthB
-> Full Size vertA Big height widthA a
-> Full Size vertB Big height widthB a
-> Full Size vertC Big height (widthA ::+ widthB) a
beside OrderBias
horizBias AppendMode Big Big Big heightA widthA widthB
forall vertA vertB height widthA widthB.
(C vertA, C vertB) =>
AppendMode vertA vertB (Append vertA vertB) height widthA widthB
Extent.appendAny (Full meas vert horiz heightA widthA a
-> Full Size Big Big heightA widthA a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width a -> General height width a
fromFull Full meas vert horiz heightA widthA a
a) General heightA widthB a
b)
      (OrderBias
-> AppendMode Big Big Big heightB widthA widthB
-> General heightB widthA a
-> Full Size Big Big heightB widthB a
-> Full Size Big Big heightB (widthA ::+ widthB) a
forall vertA vertB vertC height widthA widthB a.
(C vertA, C vertB, C vertC, C height, Eq height, C widthA,
 C widthB, Floating a) =>
OrderBias
-> AppendMode vertA vertB vertC height widthA widthB
-> Full Size vertA Big height widthA a
-> Full Size vertB Big height widthB a
-> Full Size vertC Big height (widthA ::+ widthB) a
beside OrderBias
horizBias AppendMode Big Big Big heightB widthA widthB
forall vertA vertB height widthA widthB.
(C vertA, C vertB) =>
AppendMode vertA vertB (Append vertA vertB) height widthA widthB
Extent.appendAny General heightB widthA a
c (Full meas vert horiz heightB widthB a
-> Full Size Big Big heightB widthB a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width a -> General height width a
fromFull Full meas vert horiz heightB widthB a
d))


liftRowMajor ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz) =>
   (Array (height, width) a -> Array (height, width) b) ->
   (Array (width, height) a -> Array (width, height) b) ->
   Full meas vert horiz height width a ->
   Full meas vert horiz height width b
liftRowMajor :: (Array (height, width) a -> Array (height, width) b)
-> (Array (width, height) a -> Array (width, height) b)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width b
liftRowMajor Array (height, width) a -> Array (height, width) b
fr Array (width, height) a -> Array (width, height) b
fc Full meas vert horiz height width a
a =
   (Array (height, width) a -> Full meas vert horiz height width b)
-> (Array (width, height) a -> Full meas vert horiz height width b)
-> Either (Array (height, width) a) (Array (width, height) a)
-> Full meas vert horiz height width b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
      (Full meas vert horiz height width
-> Array (height, width) b -> Full meas vert horiz height width b
forall sh1 sh0 a. sh1 -> Array sh0 a -> Array sh1 a
Array.reshape (Full meas vert horiz height width a
-> Full meas vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Full meas vert horiz height width a
a) (Array (height, width) b -> Full meas vert horiz height width b)
-> (Array (height, width) a -> Array (height, width) b)
-> Array (height, width) a
-> Full meas vert horiz height width b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array (height, width) a -> Array (height, width) b
fr)
      (Full meas vert horiz height width
-> Array (width, height) b -> Full meas vert horiz height width b
forall sh1 sh0 a. sh1 -> Array sh0 a -> Array sh1 a
Array.reshape (Full meas vert horiz height width a
-> Full meas vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Full meas vert horiz height width a
a) (Array (width, height) b -> Full meas vert horiz height width b)
-> (Array (width, height) a -> Array (width, height) b)
-> Array (width, height) a
-> Full meas vert horiz height width b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array (width, height) a -> Array (width, height) b
fc) (Either (Array (height, width) a) (Array (width, height) a)
 -> Full meas vert horiz height width b)
-> Either (Array (height, width) a) (Array (width, height) a)
-> Full meas vert horiz height width b
forall a b. (a -> b) -> a -> b
$
   Full meas vert horiz height width a
-> Either (Array (height, width) a) (Array (width, height) a)
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width a
-> Either (Array (height, width) a) (Array (width, height) a)
revealOrder Full meas vert horiz height width a
a

scaleRows ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Class.Floating a) =>
   Vector height a ->
   Full meas vert horiz height width a ->
   Full meas vert horiz height width a
scaleRows :: Vector height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleRows Vector height a
x = (Array (height, width) a -> Array (height, width) a)
-> (Array (width, height) a -> Array (width, height) a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall meas vert horiz height width a b.
(Measure meas, C vert, C horiz) =>
(Array (height, width) a -> Array (height, width) b)
-> (Array (width, height) a -> Array (width, height) b)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width b
liftRowMajor (Vector height a
-> Array (height, width) a -> Array (height, width) a
forall height width a.
(C height, Eq height, C width, Floating a) =>
Vector height a -> Matrix height width a -> Matrix height width a
RowMajor.scaleRows Vector height a
x) (Vector height a
-> Array (width, height) a -> Array (width, height) a
forall height width a.
(C height, C width, Eq width, Floating a) =>
Vector width a -> Matrix height width a -> Matrix height width a
RowMajor.scaleColumns Vector height a
x)

scaleColumns ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
   Vector width a ->
   Full meas vert horiz height width a ->
   Full meas vert horiz height width a
scaleColumns :: Vector width a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleColumns Vector width a
x = 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
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
. Vector width a
-> Full meas horiz vert width height a
-> Full meas horiz vert width height a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Floating a) =>
Vector height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleRows Vector width a
x (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
transpose


scaleRowsComplex ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Class.Real a) =>
   Vector height a ->
   Full meas vert horiz height width (Complex a) ->
   Full meas vert horiz height width (Complex a)
scaleRowsComplex :: Vector height a
-> Full meas vert horiz height width (Complex a)
-> Full meas vert horiz height width (Complex a)
scaleRowsComplex Vector height a
x =
   (Array (height, width) (Complex a)
 -> Array (height, width) (Complex a))
-> (Array (width, height) (Complex a)
    -> Array (width, height) (Complex a))
-> Full meas vert horiz height width (Complex a)
-> Full meas vert horiz height width (Complex a)
forall meas vert horiz height width a b.
(Measure meas, C vert, C horiz) =>
(Array (height, width) a -> Array (height, width) b)
-> (Array (width, height) a -> Array (width, height) b)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width b
liftRowMajor
      (Matrix height (width, Enumeration ComplexPart) a
-> Array (height, width) (Complex a)
forall a height width.
Real a =>
Matrix height (width, Enumeration ComplexPart) a
-> Matrix height width (Complex a)
RowMajor.recomplex (Matrix height (width, Enumeration ComplexPart) a
 -> Array (height, width) (Complex a))
-> (Array (height, width) (Complex a)
    -> Matrix height (width, Enumeration ComplexPart) a)
-> Array (height, width) (Complex a)
-> Array (height, width) (Complex a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector height a
-> Matrix height (width, Enumeration ComplexPart) a
-> Matrix height (width, Enumeration ComplexPart) a
forall height width a.
(C height, Eq height, C width, Floating a) =>
Vector height a -> Matrix height width a -> Matrix height width a
RowMajor.scaleRows Vector height a
x (Matrix height (width, Enumeration ComplexPart) a
 -> Matrix height (width, Enumeration ComplexPart) a)
-> (Array (height, width) (Complex a)
    -> Matrix height (width, Enumeration ComplexPart) a)
-> Array (height, width) (Complex a)
-> Matrix height (width, Enumeration ComplexPart) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array (height, width) (Complex a)
-> Matrix height (width, Enumeration ComplexPart) a
forall a height width.
Real a =>
Matrix height width (Complex a)
-> Matrix height (width, Enumeration ComplexPart) a
RowMajor.decomplex)
      (Matrix width (height, Enumeration ComplexPart) a
-> Array (width, height) (Complex a)
forall a height width.
Real a =>
Matrix height (width, Enumeration ComplexPart) a
-> Matrix height width (Complex a)
RowMajor.recomplex (Matrix width (height, Enumeration ComplexPart) a
 -> Array (width, height) (Complex a))
-> (Array (width, height) (Complex a)
    -> Matrix width (height, Enumeration ComplexPart) a)
-> Array (width, height) (Complex a)
-> Array (width, height) (Complex a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Vector (height, Enumeration ComplexPart) a
-> Matrix width (height, Enumeration ComplexPart) a
-> Matrix width (height, Enumeration ComplexPart) a
forall height width a.
(C height, C width, Eq width, Floating a) =>
Vector width a -> Matrix height width a -> Matrix height width a
RowMajor.scaleColumns
         (Either Conjugation Conjugation
-> Vector height a
-> Vector (Enumeration ComplexPart) a
-> Vector (height, Enumeration ComplexPart) a
forall height width a.
(C height, C width, Floating a) =>
Either Conjugation Conjugation
-> Vector height a -> Vector width a -> Matrix height width a
RowMajor.tensorProduct (Conjugation -> Either Conjugation Conjugation
forall a b. a -> Either a b
Left Conjugation
NonConjugated) Vector height a
x
            (Enumeration ComplexPart -> Vector (Enumeration ComplexPart) a
forall sh a. (C sh, Floating a) => sh -> Vector sh a
Vector.one Enumeration ComplexPart
forall n. Enumeration n
Shape.Enumeration)) (Matrix width (height, Enumeration ComplexPart) a
 -> Matrix width (height, Enumeration ComplexPart) a)
-> (Array (width, height) (Complex a)
    -> Matrix width (height, Enumeration ComplexPart) a)
-> Array (width, height) (Complex a)
-> Matrix width (height, Enumeration ComplexPart) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
       Array (width, height) (Complex a)
-> Matrix width (height, Enumeration ComplexPart) a
forall a height width.
Real a =>
Matrix height width (Complex a)
-> Matrix height (width, Enumeration ComplexPart) a
RowMajor.decomplex)

scaleColumnsComplex ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Class.Real a) =>
   Vector width a ->
   Full meas vert horiz height width (Complex a) ->
   Full meas vert horiz height width (Complex a)
scaleColumnsComplex :: Vector width a
-> Full meas vert horiz height width (Complex a)
-> Full meas vert horiz height width (Complex a)
scaleColumnsComplex Vector width a
x = Full meas horiz vert width height (Complex a)
-> Full meas vert horiz height width (Complex 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
transpose (Full meas horiz vert width height (Complex a)
 -> Full meas vert horiz height width (Complex a))
-> (Full meas vert horiz height width (Complex a)
    -> Full meas horiz vert width height (Complex a))
-> Full meas vert horiz height width (Complex a)
-> Full meas vert horiz height width (Complex a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector width a
-> Full meas horiz vert width height (Complex a)
-> Full meas horiz vert width height (Complex a)
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Real a) =>
Vector height a
-> Full meas vert horiz height width (Complex a)
-> Full meas vert horiz height width (Complex a)
scaleRowsComplex Vector width a
x (Full meas horiz vert width height (Complex a)
 -> Full meas horiz vert width height (Complex a))
-> (Full meas vert horiz height width (Complex a)
    -> Full meas horiz vert width height (Complex a))
-> Full meas vert horiz height width (Complex a)
-> Full meas horiz vert width height (Complex a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full meas vert horiz height width (Complex a)
-> Full meas horiz vert width height (Complex 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
transpose


scaleRowsReal ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Eq height, Shape.C width, Class.Floating a) =>
   Vector height (RealOf a) ->
   Full meas vert horiz height width a ->
   Full meas vert horiz height width a
scaleRowsReal :: Vector height (RealOf a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleRowsReal =
   ScaleRowsReal
  (Array height) (Array (Full meas vert horiz height width)) a
-> Vector height (RealOf a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall (f :: * -> *) (g :: * -> *) a.
ScaleRowsReal f g a -> f (RealOf a) -> g a -> g a
getScaleRowsReal (ScaleRowsReal
   (Array height) (Array (Full meas vert horiz height width)) a
 -> Vector height (RealOf a)
 -> Full meas vert horiz height width a
 -> Full meas vert horiz height width a)
-> ScaleRowsReal
     (Array height) (Array (Full meas vert horiz height width)) a
-> Vector height (RealOf a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$
   ScaleRowsReal
  (Array height) (Array (Full meas vert horiz height width)) Float
-> ScaleRowsReal
     (Array height) (Array (Full meas vert horiz height width)) Double
-> ScaleRowsReal
     (Array height)
     (Array (Full meas vert horiz height width))
     (Complex Float)
-> ScaleRowsReal
     (Array height)
     (Array (Full meas vert horiz height width))
     (Complex Double)
-> ScaleRowsReal
     (Array height) (Array (Full meas vert horiz height width)) a
forall a (f :: * -> *).
Floating a =>
f Float
-> f Double -> f (Complex Float) -> f (Complex Double) -> f a
Class.switchFloating
      ((Array height (RealOf Float)
 -> Array (Full meas vert horiz height width) Float
 -> Array (Full meas vert horiz height width) Float)
-> ScaleRowsReal
     (Array height) (Array (Full meas vert horiz height width)) Float
forall (f :: * -> *) (g :: * -> *) a.
(f (RealOf a) -> g a -> g a) -> ScaleRowsReal f g a
ScaleRowsReal Array height (RealOf Float)
-> Array (Full meas vert horiz height width) Float
-> Array (Full meas vert horiz height width) Float
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Floating a) =>
Vector height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleRows)
      ((Array height (RealOf Double)
 -> Array (Full meas vert horiz height width) Double
 -> Array (Full meas vert horiz height width) Double)
-> ScaleRowsReal
     (Array height) (Array (Full meas vert horiz height width)) Double
forall (f :: * -> *) (g :: * -> *) a.
(f (RealOf a) -> g a -> g a) -> ScaleRowsReal f g a
ScaleRowsReal Array height (RealOf Double)
-> Array (Full meas vert horiz height width) Double
-> Array (Full meas vert horiz height width) Double
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Floating a) =>
Vector height a
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleRows)
      ((Array height (RealOf (Complex Float))
 -> Array (Full meas vert horiz height width) (Complex Float)
 -> Array (Full meas vert horiz height width) (Complex Float))
-> ScaleRowsReal
     (Array height)
     (Array (Full meas vert horiz height width))
     (Complex Float)
forall (f :: * -> *) (g :: * -> *) a.
(f (RealOf a) -> g a -> g a) -> ScaleRowsReal f g a
ScaleRowsReal Array height (RealOf (Complex Float))
-> Array (Full meas vert horiz height width) (Complex Float)
-> Array (Full meas vert horiz height width) (Complex Float)
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Real a) =>
Vector height a
-> Full meas vert horiz height width (Complex a)
-> Full meas vert horiz height width (Complex a)
scaleRowsComplex)
      ((Array height (RealOf (Complex Double))
 -> Array (Full meas vert horiz height width) (Complex Double)
 -> Array (Full meas vert horiz height width) (Complex Double))
-> ScaleRowsReal
     (Array height)
     (Array (Full meas vert horiz height width))
     (Complex Double)
forall (f :: * -> *) (g :: * -> *) a.
(f (RealOf a) -> g a -> g a) -> ScaleRowsReal f g a
ScaleRowsReal Array height (RealOf (Complex Double))
-> Array (Full meas vert horiz height width) (Complex Double)
-> Array (Full meas vert horiz height width) (Complex Double)
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Real a) =>
Vector height a
-> Full meas vert horiz height width (Complex a)
-> Full meas vert horiz height width (Complex a)
scaleRowsComplex)

newtype ScaleRowsReal f g a =
   ScaleRowsReal {ScaleRowsReal f g a -> f (RealOf a) -> g a -> g a
getScaleRowsReal :: f (RealOf a) -> g a -> g a}

scaleColumnsReal ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
   Vector width (RealOf a) ->
   Full meas vert horiz height width a ->
   Full meas vert horiz height width a
scaleColumnsReal :: Vector width (RealOf a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleColumnsReal Vector width (RealOf a)
x = 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
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
. Vector width (RealOf a)
-> Full meas horiz vert width height a
-> Full meas horiz vert width height a
forall meas vert horiz height width a.
(Measure meas, C vert, C horiz, C height, Eq height, C width,
 Floating a) =>
Vector height (RealOf a)
-> Full meas vert horiz height width a
-> Full meas vert horiz height width a
scaleRowsReal Vector width (RealOf a)
x (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
transpose



multiplyVector ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
   Full meas vert horiz height width a -> Vector width a -> Vector height a
multiplyVector :: Full meas vert horiz height width a
-> Vector width a -> Vector height a
multiplyVector Full meas vert horiz height width a
a Vector width a
x =
   let width :: width
width = Full meas vert horiz height width -> width
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Full meas vert horiz height width -> width
Layout.fullWidth (Full meas vert horiz height width -> width)
-> Full meas vert horiz height width -> width
forall a b. (a -> b) -> a -> b
$ Full meas vert horiz height width a
-> Full meas vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Full meas vert horiz height width a
a
   in if width
width width -> width -> Bool
forall a. Eq a => a -> a -> Bool
== Vector width a -> width
forall sh a. Array sh a -> sh
Array.shape Vector width a
x
         then 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, Floating a) =>
Full meas vert horiz height width a
-> Vector width a -> Vector height a
multiplyVectorUnchecked Full meas vert horiz height width a
a Vector width a
x
         else String -> Vector height a
forall a. HasCallStack => String -> a
error String
"multiplyVector: width shapes mismatch"

multiplyVectorUnchecked ::
   (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 -> Vector width a -> Vector height a
multiplyVectorUnchecked :: Full meas vert horiz height width a
-> Vector width a -> Vector height a
multiplyVectorUnchecked
   (Array shape :: Full meas vert horiz height width
shape@(Layout.Full Order
order Extent meas vert horiz height width
extent) ForeignPtr a
a) (Array width
_ ForeignPtr a
x) =
      height -> (Ptr a -> IO ()) -> Vector height a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate (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) ((Ptr a -> IO ()) -> Vector height a)
-> (Ptr a -> IO ()) -> Vector height a
forall a b. (a -> b) -> a -> b
$ \Ptr a
yPtr -> 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
   let lda :: Int
lda = Int
m
   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
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
$ Order -> Char
transposeFromOrder Order
order
      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
alphaPtr <- a -> FortranIO () (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
one
      Ptr a
aPtr <- ((Ptr a -> IO ()) -> IO ()) -> FortranIO () (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> FortranIO () (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> FortranIO () (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
lda
      Ptr a
xPtr <- ((Ptr a -> IO ()) -> IO ()) -> FortranIO () (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> FortranIO () (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> FortranIO () (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
x
      Ptr CInt
incxPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
1
      Ptr a
betaPtr <- a -> FortranIO () (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
zero
      Ptr CInt
incyPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
1
      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 CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
Private.gemv
            Ptr CChar
transPtr Ptr CInt
mPtr Ptr CInt
nPtr Ptr a
alphaPtr Ptr a
aPtr Ptr CInt
ldaPtr
            Ptr a
xPtr Ptr CInt
incxPtr Ptr a
betaPtr Ptr a
yPtr Ptr CInt
incyPtr

{- |
Multiply two matrices with the same dimension constraints.
E.g. you can multiply 'General' and 'General' matrices,
or 'Square' and 'Square' matrices.
It may seem to be overly strict in this respect,
but that design supports type inference the best.
You can lift the restrictions by generalizing operands
with 'Square.toFull', 'Matrix.fromFull',
'Matrix.generalizeTall' or 'Matrix.generalizeWide'.
-}
multiply, multiplyColumnMajor ::
   (Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height,
    Shape.C fuse, Eq fuse,
    Shape.C width,
    Class.Floating a) =>
   Full meas vert horiz height fuse a ->
   Full meas vert horiz fuse width a ->
   Full meas vert horiz height width a
-- preserve order of the right factor
multiply :: Full meas vert horiz height fuse a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
multiply
   (Array (Layout.Full Order
orderA Extent meas vert horiz height fuse
extentA) ForeignPtr a
a)
   (Array (Layout.Full Order
orderB 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 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
"multiply: fuse shapes mismatch"
      Just Extent meas vert horiz height width
extent ->
         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
orderB 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
cPtr -> do

      let (height
height,fuse
fuse) = Extent meas vert horiz height fuse -> (height, fuse)
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 fuse
extentA
      let width :: width
width = 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
      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 = fuse -> Int
forall sh. C sh => sh -> Int
Shape.size fuse
fuse
      case Order
orderB of
         Order
RowMajor ->
            Order
-> Order
-> Int
-> Int
-> Int
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall a.
Floating a =>
Order
-> Order
-> Int
-> Int
-> Int
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
Private.multiplyMatrix (Order -> Order
flipOrder Order
orderB) (Order -> Order
flipOrder Order
orderA)
               Int
n Int
k Int
m ForeignPtr a
b ForeignPtr a
a Ptr a
cPtr
         Order
ColumnMajor -> Order
-> Order
-> Int
-> Int
-> Int
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall a.
Floating a =>
Order
-> Order
-> Int
-> Int
-> Int
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
Private.multiplyMatrix Order
orderA Order
orderB Int
m Int
k Int
n ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr

-- always return ColumnMajor
multiplyColumnMajor :: Full meas vert horiz height fuse a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
multiplyColumnMajor
   (Array (Layout.Full Order
orderA Extent meas vert horiz height fuse
extentA) ForeignPtr a
a)
   (Array (Layout.Full Order
orderB 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 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
"multiply: fuse shapes mismatch"
      Just Extent meas vert horiz height width
extent ->
         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
ColumnMajor 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
cPtr -> do

      let (height
height,fuse
fuse) = Extent meas vert horiz height fuse -> (height, fuse)
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 fuse
extentA
      let width :: width
width = 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
      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 = fuse -> Int
forall sh. C sh => sh -> Int
Shape.size fuse
fuse
      Order
-> Order
-> Int
-> Int
-> Int
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall a.
Floating a =>
Order
-> Order
-> Int
-> Int
-> Int
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
Private.multiplyMatrix Order
orderA Order
orderB Int
m Int
k Int
n ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr