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

import qualified Numeric.LAPACK.Matrix.Shape.Private as MatrixShape
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.Shape.Private
         (Order(RowMajor, ColumnMajor), transposeFromOrder, flipOrder)
import Numeric.LAPACK.Matrix.Modifier (Conjugation(NonConjugated))
import Numeric.LAPACK.Matrix.Private
         (Full, Tall, Wide, 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.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.C vert, Extent.C horiz, Shape.C height, Shape.C width) =>
   Full vert horiz height width a ->
   Either (Tall height width a) (Wide height width a)
caseTallWide :: Full vert horiz height width a
-> Either (Tall height width a) (Wide height width a)
caseTallWide (Array Full 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 vert horiz height width
-> Either (Tall height width) (Wide height width)
forall vert horiz height width.
(C vert, C horiz, C height, C width) =>
Full vert horiz height width
-> Either (Tall height width) (Wide height width)
MatrixShape.caseTallWide Full vert horiz height width
shape


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

adjoint ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Full vert horiz height width a -> Full horiz vert width height a
adjoint :: Full vert horiz height width a -> Full horiz vert width height a
adjoint = Full vert horiz height width a -> Full horiz vert width height a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full vert horiz height width a -> Full horiz vert width height a)
-> (Full vert horiz height width a
    -> Full vert horiz height width a)
-> Full vert horiz height width a
-> Full horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full vert horiz height width a -> Full vert horiz height width a
forall sh a. (C sh, Floating a) => Vector sh a -> Vector sh a
Vector.conjugate


swapMultiply ::
   (Extent.C vertA, Extent.C vertB, Extent.C horizA, Extent.C horizB) =>
   (matrix ->
    Full horizA vertA widthA heightA a ->
    Full horizB vertB widthB heightB a) ->
   Full vertA horizA heightA widthA a ->
   matrix ->
   Full vertB horizB heightB widthB a
swapMultiply :: (matrix
 -> Full horizA vertA widthA heightA a
 -> Full horizB vertB widthB heightB a)
-> Full vertA horizA heightA widthA a
-> matrix
-> Full vertB horizB heightB widthB a
swapMultiply matrix
-> Full horizA vertA widthA heightA a
-> Full horizB vertB widthB heightB a
multiplyTrans Full vertA horizA heightA widthA a
a matrix
b = Full horizB vertB widthB heightB a
-> Full vertB horizB heightB widthB a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full horizB vertB widthB heightB a
 -> Full vertB horizB heightB widthB a)
-> Full horizB vertB widthB heightB a
-> Full vertB horizB heightB widthB a
forall a b. (a -> b) -> a -> b
$ matrix
-> Full horizA vertA widthA heightA a
-> Full horizB vertB widthB heightB a
multiplyTrans matrix
b (Full horizA vertA widthA heightA a
 -> Full horizB vertB widthB heightB a)
-> Full horizA vertA widthA heightA a
-> Full horizB vertB widthB heightB a
forall a b. (a -> b) -> a -> b
$ Full vertA horizA heightA widthA a
-> Full horizA vertA widthA heightA a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose Full vertA horizA heightA widthA a
a


mapHeight ::
   (Extent.GeneralTallWide vert horiz,
    Extent.GeneralTallWide horiz vert) =>
   (heightA -> heightB) ->
   Full vert horiz heightA width a ->
   Full vert horiz heightB width a
mapHeight :: (heightA -> heightB)
-> Full vert horiz heightA width a
-> Full vert horiz heightB width a
mapHeight heightA -> heightB
f =
   (Full vert horiz heightA width -> Full vert horiz heightB width)
-> Full vert horiz heightA width a
-> Full vert horiz heightB width a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(MatrixShape.Full Order
order Extent vert horiz heightA width
extent) ->
         Order
-> Extent vert horiz heightB width -> Full vert horiz heightB width
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
order (Extent vert horiz heightB width -> Full vert horiz heightB width)
-> Extent vert horiz heightB width -> Full vert horiz heightB width
forall a b. (a -> b) -> a -> b
$ (heightA -> heightB)
-> Extent vert horiz heightA width
-> Extent vert horiz heightB width
forall vert horiz heightA heightB width.
GeneralTallWide vert horiz =>
(heightA -> heightB)
-> Extent vert horiz heightA width
-> Extent vert horiz heightB width
Extent.mapHeight heightA -> heightB
f Extent vert horiz heightA width
extent)

mapWidth ::
   (Extent.GeneralTallWide vert horiz,
    Extent.GeneralTallWide horiz vert) =>
   (widthA -> widthB) ->
   Full vert horiz height widthA a ->
   Full vert horiz height widthB a
mapWidth :: (widthA -> widthB)
-> Full vert horiz height widthA a
-> Full vert horiz height widthB a
mapWidth widthA -> widthB
f =
   (Full vert horiz height widthA -> Full vert horiz height widthB)
-> Full vert horiz height widthA a
-> Full vert horiz height widthB a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(MatrixShape.Full Order
order Extent vert horiz height widthA
extent) ->
         Order
-> Extent vert horiz height widthB -> Full vert horiz height widthB
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
order (Extent vert horiz height widthB -> Full vert horiz height widthB)
-> Extent vert horiz height widthB -> Full vert horiz height widthB
forall a b. (a -> b) -> a -> b
$ (widthA -> widthB)
-> Extent vert horiz height widthA
-> Extent vert horiz height widthB
forall vert horiz widthA widthB height.
GeneralTallWide vert horiz =>
(widthA -> widthB)
-> Extent vert horiz height widthA
-> Extent vert horiz height widthB
Extent.mapWidth widthA -> widthB
f Extent vert horiz height widthA
extent)

uncheck ::
   (Extent.C vert, Extent.C horiz) =>
   Full vert horiz height width a ->
   Full vert horiz (Unchecked height) (Unchecked width) a
uncheck :: Full vert horiz height width a
-> Full vert horiz (Unchecked height) (Unchecked width) a
uncheck =
   (Full vert horiz height width
 -> Full vert horiz (Unchecked height) (Unchecked width))
-> Full vert horiz height width a
-> Full vert horiz (Unchecked height) (Unchecked width) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(MatrixShape.Full Order
order Extent vert horiz height width
extent) ->
         Order
-> Extent vert horiz (Unchecked height) (Unchecked width)
-> Full vert horiz (Unchecked height) (Unchecked width)
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
order (Extent vert horiz (Unchecked height) (Unchecked width)
 -> Full vert horiz (Unchecked height) (Unchecked width))
-> Extent vert horiz (Unchecked height) (Unchecked width)
-> Full vert horiz (Unchecked height) (Unchecked width)
forall a b. (a -> b) -> a -> b
$ (height -> Unchecked height)
-> (width -> Unchecked width)
-> Extent vert horiz height width
-> Extent vert horiz (Unchecked height) (Unchecked width)
forall vert horiz height (f :: * -> *) width.
(C vert, C horiz) =>
(height -> f height)
-> (width -> f width)
-> Extent vert horiz height width
-> Extent 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 Extent vert horiz height width
extent)

recheck ::
   (Extent.C vert, Extent.C horiz) =>
   Full vert horiz (Unchecked height) (Unchecked width) a ->
   Full vert horiz height width a
recheck :: Full vert horiz (Unchecked height) (Unchecked width) a
-> Full vert horiz height width a
recheck =
   (Full vert horiz (Unchecked height) (Unchecked width)
 -> Full vert horiz height width)
-> Full vert horiz (Unchecked height) (Unchecked width) a
-> Full vert horiz height width a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(MatrixShape.Full Order
order Extent vert horiz (Unchecked height) (Unchecked width)
extent) ->
         Order
-> Extent vert horiz height width -> Full vert horiz height width
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
order (Extent vert horiz height width -> Full vert horiz height width)
-> Extent vert horiz height width -> Full vert horiz height width
forall a b. (a -> b) -> a -> b
$ Extent vert horiz (Unchecked height) (Unchecked width)
-> Extent vert horiz height width
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz (Unchecked height) (Unchecked width)
-> Extent vert horiz height width
Extent.recheck Extent vert horiz (Unchecked height) (Unchecked width)
extent)


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
MatrixShape.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
MatrixShape.general Order
order) ())

flattenRow :: General () width a -> Vector width a
flattenRow :: General () width a -> Vector width a
flattenRow = (Full 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 Big Big () width -> width
forall vert horiz height width.
(C vert, C horiz) =>
Full vert horiz height width -> width
MatrixShape.fullWidth

flattenColumn :: General height () a -> Vector height a
flattenColumn :: General height () a -> Vector height a
flattenColumn = (Full 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 Big Big height () -> height
forall vert horiz height width.
(C vert, C horiz) =>
Full vert horiz height width -> height
MatrixShape.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.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Full vert horiz height width a ->
   Full vert horiz height width a
forceRowMajor :: Full vert horiz height width a -> Full vert horiz height width a
forceRowMajor (Array shape :: Full vert horiz height width
shape@(MatrixShape.Full Order
order Extent vert horiz height width
extent) ForeignPtr a
x) =
   case Order
order of
      Order
RowMajor -> Full vert horiz height width
-> ForeignPtr a -> Full vert horiz height width a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array Full vert horiz height width
shape ForeignPtr a
x
      Order
ColumnMajor ->
         Full vert horiz height width
-> (Ptr a -> IO ()) -> Full vert horiz height width a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate (Order
-> Extent vert horiz height width -> Full vert horiz height width
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
RowMajor Extent vert horiz height width
extent) ((Ptr a -> IO ()) -> Full vert horiz height width a)
-> (Ptr a -> IO ()) -> Full 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 vert horiz height width -> (height, width)
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> (height, width)
Extent.dimensions Extent 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.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Order ->
   Full vert horiz height width a ->
   Full vert horiz height width a
forceOrder :: Order
-> Full vert horiz height width a -> Full vert horiz height width a
forceOrder Order
order =
   case Order
order of
      Order
RowMajor -> Full vert horiz height width a -> Full vert horiz height width a
forall vert horiz height width a.
(C vert, C horiz, C height, C width, Floating a) =>
Full vert horiz height width a -> Full vert horiz height width a
forceRowMajor
      Order
ColumnMajor -> Full horiz vert width height a -> Full vert horiz height width a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full horiz vert width height a -> Full vert horiz height width a)
-> (Full vert horiz height width a
    -> Full horiz vert width height a)
-> Full vert horiz height width a
-> Full vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full horiz vert width height a -> Full horiz vert width height a
forall vert horiz height width a.
(C vert, C horiz, C height, C width, Floating a) =>
Full vert horiz height width a -> Full vert horiz height width a
forceRowMajor (Full horiz vert width height a -> Full horiz vert width height a)
-> (Full vert horiz height width a
    -> Full horiz vert width height a)
-> Full vert horiz height width a
-> Full horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full vert horiz height width a -> Full horiz vert width height a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose


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

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

takeLeft ::
   (Extent.C vert, Shape.C height, Shape.C width0, Shape.C width1,
    Class.Floating a) =>
   Full Extent.Big vert height (width0:+:width1) a ->
   Full Extent.Big vert height width0 a
takeLeft :: Full Big vert height (width0 :+: width1) a
-> Full Big vert height width0 a
takeLeft = Full vert Big width0 height a -> Full Big vert height width0 a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full vert Big width0 height a -> Full Big vert height width0 a)
-> (Full Big vert height (width0 :+: width1) a
    -> Full vert Big width0 height a)
-> Full Big vert height (width0 :+: width1) a
-> Full Big vert height width0 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full vert Big (width0 :+: width1) height a
-> Full vert Big width0 height a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full vert Big (height0 :+: height1) width a
-> Full vert Big height0 width a
takeTop (Full vert Big (width0 :+: width1) height a
 -> Full vert Big width0 height a)
-> (Full Big vert height (width0 :+: width1) a
    -> Full vert Big (width0 :+: width1) height a)
-> Full Big vert height (width0 :+: width1) a
-> Full vert Big width0 height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Big vert height (width0 :+: width1) a
-> Full vert Big (width0 :+: width1) height a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose

takeRight ::
   (Extent.C vert, Shape.C height, Shape.C width0, Shape.C width1,
    Class.Floating a) =>
   Full Extent.Big vert height (width0:+:width1) a ->
   Full Extent.Big vert height width1 a
takeRight :: Full Big vert height (width0 :+: width1) a
-> Full Big vert height width1 a
takeRight = Full vert Big width1 height a -> Full Big vert height width1 a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full vert Big width1 height a -> Full Big vert height width1 a)
-> (Full Big vert height (width0 :+: width1) a
    -> Full vert Big width1 height a)
-> Full Big vert height (width0 :+: width1) a
-> Full Big vert height width1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full vert Big (width0 :+: width1) height a
-> Full vert Big width1 height a
forall vert height0 height1 width a.
(C vert, C height0, C height1, C width, Floating a) =>
Full vert Big (height0 :+: height1) width a
-> Full vert Big height1 width a
takeBottom (Full vert Big (width0 :+: width1) height a
 -> Full vert Big width1 height a)
-> (Full Big vert height (width0 :+: width1) a
    -> Full vert Big (width0 :+: width1) height a)
-> Full Big vert height (width0 :+: width1) a
-> Full vert Big width1 height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Big vert height (width0 :+: width1) a
-> Full vert Big (width0 :+: width1) height a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose


splitRows ::
   (Extent.C vert, Shape.C width, Class.Floating a) =>
   Int ->
   Full vert Extent.Big ShapeInt width a ->
   Full vert Extent.Big (ShapeInt:+:ShapeInt) width a
splitRows :: Int
-> Full vert Big ShapeInt width a
-> Full vert Big (ShapeInt :+: ShapeInt) width a
splitRows Int
k =
   (Full vert Big ShapeInt width
 -> Full vert Big (ShapeInt :+: ShapeInt) width)
-> Full vert Big ShapeInt width a
-> Full vert Big (ShapeInt :+: ShapeInt) width a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(MatrixShape.Full Order
order Extent vert Big ShapeInt width
extent) ->
         Order
-> Extent vert Big (ShapeInt :+: ShapeInt) width
-> Full vert Big (ShapeInt :+: ShapeInt) width
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
order (Extent vert Big (ShapeInt :+: ShapeInt) width
 -> Full vert Big (ShapeInt :+: ShapeInt) width)
-> Extent vert Big (ShapeInt :+: ShapeInt) width
-> Full vert Big (ShapeInt :+: ShapeInt) width
forall a b. (a -> b) -> a -> b
$
         (ShapeInt :+: ShapeInt)
-> Extent vert Big ShapeInt width
-> Extent vert Big (ShapeInt :+: ShapeInt) width
forall vert heightB heightA width.
C vert =>
heightB
-> Extent vert Big heightA width -> Extent vert Big heightB width
Extent.reduceWideHeight
            (Int -> ShapeInt -> ShapeInt :+: ShapeInt
forall n. Real n => n -> ZeroBased n -> ZeroBased n :+: ZeroBased n
Shape.zeroBasedSplit Int
k (ShapeInt -> ShapeInt :+: ShapeInt)
-> ShapeInt -> ShapeInt :+: ShapeInt
forall a b. (a -> b) -> a -> b
$ Extent vert Big ShapeInt width -> ShapeInt
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> height
Extent.height Extent vert Big ShapeInt width
extent)
            Extent vert Big ShapeInt width
extent)

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

takeColumns, dropColumns ::
   (Extent.C horiz, Shape.C height, Class.Floating a) =>
   Int ->
   Full Extent.Big horiz height ShapeInt a ->
   Full Extent.Big horiz height ShapeInt a
takeColumns :: Int
-> Full Big horiz height ShapeInt a
-> Full Big horiz height ShapeInt a
takeColumns Int
k = Full horiz Big ShapeInt height a
-> Full Big horiz height ShapeInt a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full horiz Big ShapeInt height a
 -> Full Big horiz height ShapeInt a)
-> (Full Big horiz height ShapeInt a
    -> Full horiz Big ShapeInt height a)
-> Full Big horiz height ShapeInt a
-> Full Big horiz height ShapeInt a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Full horiz Big ShapeInt height a
-> Full horiz Big ShapeInt height a
forall vert width a.
(C vert, C width, Floating a) =>
Int
-> Full vert Big ShapeInt width a -> Full vert Big ShapeInt width a
takeRows Int
k (Full horiz Big ShapeInt height a
 -> Full horiz Big ShapeInt height a)
-> (Full Big horiz height ShapeInt a
    -> Full horiz Big ShapeInt height a)
-> Full Big horiz height ShapeInt a
-> Full horiz Big ShapeInt height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Big horiz height ShapeInt a
-> Full horiz Big ShapeInt height a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose
dropColumns :: Int
-> Full Big horiz height ShapeInt a
-> Full Big horiz height ShapeInt a
dropColumns Int
k = Full horiz Big ShapeInt height a
-> Full Big horiz height ShapeInt a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full horiz Big ShapeInt height a
 -> Full Big horiz height ShapeInt a)
-> (Full Big horiz height ShapeInt a
    -> Full horiz Big ShapeInt height a)
-> Full Big horiz height ShapeInt a
-> Full Big horiz height ShapeInt a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Full horiz Big ShapeInt height a
-> Full horiz Big ShapeInt height a
forall vert width a.
(C vert, C width, Floating a) =>
Int
-> Full vert Big ShapeInt width a -> Full vert Big ShapeInt width a
dropRows Int
k (Full horiz Big ShapeInt height a
 -> Full horiz Big ShapeInt height a)
-> (Full Big horiz height ShapeInt a
    -> Full horiz Big ShapeInt height a)
-> Full Big horiz height ShapeInt a
-> Full horiz Big ShapeInt height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full Big horiz height ShapeInt a
-> Full horiz Big ShapeInt height a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full 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 vertA Extent.Big height widthA a ->
   Full vertB Extent.Big height widthB a ->
   Full vertC Extent.Big height (widthA:+:widthB) a
beside :: OrderBias
-> AppendMode vertA vertB vertC height widthA widthB
-> Full vertA Big height widthA a
-> Full vertB Big height widthB a
-> Full vertC Big height (widthA :+: widthB) a
beside OrderBias
orderBias (Extent.AppendMode Extent vertA Big height widthA
-> Extent vertB Big height widthB
-> Extent vertC Big height (widthA :+: widthB)
appendMode)
      (Array (MatrixShape.Full Order
orderA Extent vertA Big height widthA
extentA) ForeignPtr a
a)
      (Array (MatrixShape.Full Order
orderB Extent vertB Big height widthB
extentB) ForeignPtr a
b) =
   let (height
heightA,widthA
widthA) = Extent vertA Big height widthA -> (height, widthA)
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> (height, width)
Extent.dimensions Extent vertA Big height widthA
extentA
       (height
heightB,widthB
widthB) = Extent vertB Big height widthB -> (height, widthB)
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> (height, width)
Extent.dimensions Extent 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 vertC Big height (widthA :+: widthB) a
create Order
order Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ()
act =
          Full vertC Big height (widthA :+: widthB)
-> (Ptr a -> IO ()) -> Full vertC Big height (widthA :+: widthB) a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate
             (Order
-> Extent vertC Big height (widthA :+: widthB)
-> Full vertC Big height (widthA :+: widthB)
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
order (Extent vertC Big height (widthA :+: widthB)
 -> Full vertC Big height (widthA :+: widthB))
-> Extent vertC Big height (widthA :+: widthB)
-> Full vertC Big height (widthA :+: widthB)
forall a b. (a -> b) -> a -> b
$ Extent vertA Big height widthA
-> Extent vertB Big height widthB
-> Extent vertC Big height (widthA :+: widthB)
appendMode Extent vertA Big height widthA
extentA Extent vertB Big height widthB
extentB) ((Ptr a -> IO ()) -> Full vertC Big height (widthA :+: widthB) a)
-> (Ptr a -> IO ()) -> Full 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 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 vertC Big height (widthA :+: widthB) a
create Order
RowMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full vertC Big height (widthA :+: widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full 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 vertC Big height (widthA :+: widthB) a
create Order
RowMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full vertC Big height (widthA :+: widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full 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 vertC Big height (widthA :+: widthB) a
create Order
ColumnMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full vertC Big height (widthA :+: widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full 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 vertC Big height (widthA :+: widthB) a
create Order
RowMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full vertC Big height (widthA :+: widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full 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 vertC Big height (widthA :+: widthB) a
create Order
ColumnMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full vertC Big height (widthA :+: widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full 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 vertC Big height (widthA :+: widthB) a
create Order
ColumnMajor ((Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
 -> Full vertC Big height (widthA :+: widthB) a)
-> (Ptr a -> Ptr a -> Ptr a -> Ptr a -> IO ())
-> Full 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.Big horizA heightA width a ->
   Full Extent.Big horizB heightB width a ->
   Full Extent.Big horizC (heightA:+:heightB) width a
above :: OrderBias
-> AppendMode horizA horizB horizC width heightA heightB
-> Full Big horizA heightA width a
-> Full Big horizB heightB width a
-> Full Big horizC (heightA :+: heightB) width a
above OrderBias
orderBias AppendMode horizA horizB horizC width heightA heightB
appendMode Full Big horizA heightA width a
a Full Big horizB heightB width a
b =
   Full horizC Big width (heightA :+: heightB) a
-> Full Big horizC (heightA :+: heightB) width a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full horizC Big width (heightA :+: heightB) a
 -> Full Big horizC (heightA :+: heightB) width a)
-> Full horizC Big width (heightA :+: heightB) a
-> Full Big horizC (heightA :+: heightB) width a
forall a b. (a -> b) -> a -> b
$ OrderBias
-> AppendMode horizA horizB horizC width heightA heightB
-> Full horizA Big width heightA a
-> Full horizB Big width heightB a
-> Full 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 vertA Big height widthA a
-> Full vertB Big height widthB a
-> Full vertC Big height (widthA :+: widthB) a
beside OrderBias
orderBias AppendMode horizA horizB horizC width heightA heightB
appendMode (Full Big horizA heightA width a -> Full horizA Big width heightA a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose Full Big horizA heightA width a
a) (Full Big horizB heightB width a -> Full horizB Big width heightB a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose Full Big horizB heightB width a
b)

stack ::
   (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 vert horiz heightA widthA a -> General heightA widthB a ->
   General heightB widthA a -> Full vert horiz heightB widthB a ->
   Full vert horiz (heightA:+:heightB) (widthA:+:widthB) a
stack :: Full vert horiz heightA widthA a
-> General heightA widthB a
-> General heightB widthA a
-> Full vert horiz heightB widthB a
-> Full vert horiz (heightA :+: heightB) (widthA :+: widthB) a
stack Full vert horiz heightA widthA a
a General heightA widthB a
b General heightB widthA a
c Full vert horiz heightB widthB a
d =
   (Full Big Big (heightA :+: heightB) (widthA :+: widthB)
 -> Full vert horiz (heightA :+: heightB) (widthA :+: widthB))
-> Array (Full Big Big (heightA :+: heightB) (widthA :+: widthB)) a
-> Full vert horiz (heightA :+: heightB) (widthA :+: widthB) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(MatrixShape.Full Order
order Extent Big Big (heightA :+: heightB) (widthA :+: widthB)
_) ->
         Order
-> Extent vert horiz (heightA :+: heightB) (widthA :+: widthB)
-> Full vert horiz (heightA :+: heightB) (widthA :+: widthB)
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
order (Extent vert horiz (heightA :+: heightB) (widthA :+: widthB)
 -> Full vert horiz (heightA :+: heightB) (widthA :+: widthB))
-> Extent vert horiz (heightA :+: heightB) (widthA :+: widthB)
-> Full vert horiz (heightA :+: heightB) (widthA :+: widthB)
forall a b. (a -> b) -> a -> b
$
         Extent vert horiz heightA widthA
-> Extent vert horiz heightB widthB
-> Extent vert horiz (heightA :+: heightB) (widthA :+: widthB)
forall vert horiz heightA widthA heightB widthB.
(C vert, C horiz) =>
Extent vert horiz heightA widthA
-> Extent vert horiz heightB widthB
-> Extent vert horiz (heightA :+: heightB) (widthA :+: widthB)
Extent.stack
            (Full vert horiz heightA widthA -> Extent vert horiz heightA widthA
forall vert horiz height width.
Full vert horiz height width -> Extent vert horiz height width
MatrixShape.fullExtent (Full vert horiz heightA widthA
 -> Extent vert horiz heightA widthA)
-> Full vert horiz heightA widthA
-> Extent vert horiz heightA widthA
forall a b. (a -> b) -> a -> b
$ Full vert horiz heightA widthA a -> Full vert horiz heightA widthA
forall sh a. Array sh a -> sh
Array.shape Full vert horiz heightA widthA a
a)
            (Full vert horiz heightB widthB -> Extent vert horiz heightB widthB
forall vert horiz height width.
Full vert horiz height width -> Extent vert horiz height width
MatrixShape.fullExtent (Full vert horiz heightB widthB
 -> Extent vert horiz heightB widthB)
-> Full vert horiz heightB widthB
-> Extent vert horiz heightB widthB
forall a b. (a -> b) -> a -> b
$ Full vert horiz heightB widthB a -> Full vert horiz heightB widthB
forall sh a. Array sh a -> sh
Array.shape Full vert horiz heightB widthB a
d)) (Array (Full Big Big (heightA :+: heightB) (widthA :+: widthB)) a
 -> Full vert horiz (heightA :+: heightB) (widthA :+: widthB) a)
-> Array (Full Big Big (heightA :+: heightB) (widthA :+: widthB)) a
-> Full vert horiz (heightA :+: heightB) (widthA :+: widthB) a
forall a b. (a -> b) -> a -> b
$
   OrderBias
-> AppendMode Big Big Big (widthA :+: widthB) heightA heightB
-> Full Big Big heightA (widthA :+: widthB) a
-> Full Big Big heightB (widthA :+: widthB) a
-> Array (Full 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 Big horizA heightA width a
-> Full Big horizB heightB width a
-> Full Big horizC (heightA :+: heightB) width a
above OrderBias
RightBias 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 Big Big heightA widthA a
-> General heightA widthB a
-> Full 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 vertA Big height widthA a
-> Full vertB Big height widthB a
-> Full vertC Big height (widthA :+: widthB) a
beside OrderBias
RightBias 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 vert horiz heightA widthA a -> Full Big Big heightA widthA a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> General height width a
fromFull Full vert horiz heightA widthA a
a) General heightA widthB a
b)
      (OrderBias
-> AppendMode Big Big Big heightB widthA widthB
-> General heightB widthA a
-> Full Big Big heightB widthB a
-> Full 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 vertA Big height widthA a
-> Full vertB Big height widthB a
-> Full vertC Big height (widthA :+: widthB) a
beside OrderBias
RightBias 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 vert horiz heightB widthB a -> Full Big Big heightB widthB a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> General height width a
fromFull Full vert horiz heightB widthB a
d))


liftRowMajor ::
   (Extent.C vert, Extent.C horiz) =>
   (Array (height, width) a -> Array (height, width) b) ->
   (Array (width, height) a -> Array (width, height) b) ->
   Full vert horiz height width a ->
   Full vert horiz height width b
liftRowMajor :: (Array (height, width) a -> Array (height, width) b)
-> (Array (width, height) a -> Array (width, height) b)
-> Full vert horiz height width a
-> Full 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 vert horiz height width a
a =
   (Array (height, width) a -> Full vert horiz height width b)
-> (Array (width, height) a -> Full vert horiz height width b)
-> Either (Array (height, width) a) (Array (width, height) a)
-> Full vert horiz height width b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
      (Full vert horiz height width
-> Array (height, width) b -> Full vert horiz height width b
forall sh1 sh0 a. sh1 -> Array sh0 a -> Array sh1 a
Array.reshape (Full vert horiz height width a -> Full vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Full vert horiz height width a
a) (Array (height, width) b -> Full vert horiz height width b)
-> (Array (height, width) a -> Array (height, width) b)
-> Array (height, width) a
-> Full 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 vert horiz height width
-> Array (width, height) b -> Full vert horiz height width b
forall sh1 sh0 a. sh1 -> Array sh0 a -> Array sh1 a
Array.reshape (Full vert horiz height width a -> Full vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Full vert horiz height width a
a) (Array (width, height) b -> Full vert horiz height width b)
-> (Array (width, height) a -> Array (width, height) b)
-> Array (width, height) a
-> Full 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 vert horiz height width b)
-> Either (Array (height, width) a) (Array (width, height) a)
-> Full vert horiz height width b
forall a b. (a -> b) -> a -> b
$
   Full vert horiz height width a
-> Either (Array (height, width) a) (Array (width, height) a)
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a
-> Either (Array (height, width) a) (Array (width, height) a)
revealOrder Full vert horiz height width a
a

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


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


scaleRowsReal ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Eq height, Shape.C width,
    Class.Floating a) =>
   Vector height (RealOf a) ->
   Full vert horiz height width a ->
   Full vert horiz height width a
scaleRowsReal :: Vector height (RealOf a)
-> Full vert horiz height width a -> Full vert horiz height width a
scaleRowsReal =
   ScaleRowsReal
  (Array height) (Array (Full vert horiz height width)) a
-> Vector height (RealOf a)
-> Full vert horiz height width a
-> Full 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 vert horiz height width)) a
 -> Vector height (RealOf a)
 -> Full vert horiz height width a
 -> Full vert horiz height width a)
-> ScaleRowsReal
     (Array height) (Array (Full vert horiz height width)) a
-> Vector height (RealOf a)
-> Full vert horiz height width a
-> Full vert horiz height width a
forall a b. (a -> b) -> a -> b
$
   ScaleRowsReal
  (Array height) (Array (Full vert horiz height width)) Float
-> ScaleRowsReal
     (Array height) (Array (Full vert horiz height width)) Double
-> ScaleRowsReal
     (Array height)
     (Array (Full vert horiz height width))
     (Complex Float)
-> ScaleRowsReal
     (Array height)
     (Array (Full vert horiz height width))
     (Complex Double)
-> ScaleRowsReal
     (Array height) (Array (Full 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 vert horiz height width) Float
 -> Array (Full vert horiz height width) Float)
-> ScaleRowsReal
     (Array height) (Array (Full 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 vert horiz height width) Float
-> Array (Full vert horiz height width) Float
forall vert horiz height width a.
(C vert, C horiz, C height, Eq height, C width, Floating a) =>
Vector height a
-> Full vert horiz height width a -> Full vert horiz height width a
scaleRows)
      ((Array height (RealOf Double)
 -> Array (Full vert horiz height width) Double
 -> Array (Full vert horiz height width) Double)
-> ScaleRowsReal
     (Array height) (Array (Full 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 vert horiz height width) Double
-> Array (Full vert horiz height width) Double
forall vert horiz height width a.
(C vert, C horiz, C height, Eq height, C width, Floating a) =>
Vector height a
-> Full vert horiz height width a -> Full vert horiz height width a
scaleRows)
      ((Array height (RealOf (Complex Float))
 -> Array (Full vert horiz height width) (Complex Float)
 -> Array (Full vert horiz height width) (Complex Float))
-> ScaleRowsReal
     (Array height)
     (Array (Full 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 vert horiz height width) (Complex Float)
-> Array (Full vert horiz height width) (Complex Float)
forall vert horiz height width a.
(C vert, C horiz, C height, Eq height, C width, Real a) =>
Vector height a
-> Full vert horiz height width (Complex a)
-> Full vert horiz height width (Complex a)
scaleRowsComplex)
      ((Array height (RealOf (Complex Double))
 -> Array (Full vert horiz height width) (Complex Double)
 -> Array (Full vert horiz height width) (Complex Double))
-> ScaleRowsReal
     (Array height)
     (Array (Full 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 vert horiz height width) (Complex Double)
-> Array (Full vert horiz height width) (Complex Double)
forall vert horiz height width a.
(C vert, C horiz, C height, Eq height, C width, Real a) =>
Vector height a
-> Full vert horiz height width (Complex a)
-> Full 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.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
   Vector width (RealOf a) ->
   Full vert horiz height width a ->
   Full vert horiz height width a
scaleColumnsReal :: Vector width (RealOf a)
-> Full vert horiz height width a -> Full vert horiz height width a
scaleColumnsReal Vector width (RealOf a)
x = Full horiz vert width height a -> Full vert horiz height width a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose (Full horiz vert width height a -> Full vert horiz height width a)
-> (Full vert horiz height width a
    -> Full horiz vert width height a)
-> Full vert horiz height width a
-> Full vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector width (RealOf a)
-> Full horiz vert width height a -> Full horiz vert width height a
forall vert horiz height width a.
(C vert, C horiz, C height, Eq height, C width, Floating a) =>
Vector height (RealOf a)
-> Full vert horiz height width a -> Full vert horiz height width a
scaleRowsReal Vector width (RealOf a)
x (Full horiz vert width height a -> Full horiz vert width height a)
-> (Full vert horiz height width a
    -> Full horiz vert width height a)
-> Full vert horiz height width a
-> Full horiz vert width height a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Full vert horiz height width a -> Full horiz vert width height a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
transpose



multiplyVector ::
   (Extent.C vert, Extent.C horiz, Shape.C height, Shape.C width, Eq width,
    Class.Floating a) =>
   Full vert horiz height width a -> Vector width a -> Vector height a
multiplyVector :: Full vert horiz height width a -> Vector width a -> Vector height a
multiplyVector Full vert horiz height width a
a Vector width a
x =
   let width :: width
width = Full vert horiz height width -> width
forall vert horiz height width.
(C vert, C horiz) =>
Full vert horiz height width -> width
MatrixShape.fullWidth (Full vert horiz height width -> width)
-> Full vert horiz height width -> width
forall a b. (a -> b) -> a -> b
$ Full vert horiz height width a -> Full vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Full 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 vert horiz height width a -> Vector width a -> Vector height a
forall vert horiz height width a.
(C vert, C horiz, C height, C width, Floating a) =>
Full vert horiz height width a -> Vector width a -> Vector height a
multiplyVectorUnchecked Full 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.C vert, Extent.C horiz, Shape.C height, Shape.C width,
    Class.Floating a) =>
   Full vert horiz height width a -> Vector width a -> Vector height a
multiplyVectorUnchecked :: Full vert horiz height width a -> Vector width a -> Vector height a
multiplyVectorUnchecked
   (Array shape :: Full vert horiz height width
shape@(MatrixShape.Full Order
order Extent 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 vert horiz height width -> height
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> height
Extent.height Extent 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 vert horiz height width -> (Int, Int)
forall vert horiz height width.
(C vert, C horiz, C height, C width) =>
Full vert horiz height width -> (Int, Int)
MatrixShape.dimensions Full 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.C vert, Extent.C horiz,
    Shape.C height,
    Shape.C fuse, Eq fuse,
    Shape.C width,
    Class.Floating a) =>
   Full vert horiz height fuse a ->
   Full vert horiz fuse width a ->
   Full vert horiz height width a
-- preserve order of the right factor
multiply :: Full vert horiz height fuse a
-> Full vert horiz fuse width a -> Full vert horiz height width a
multiply
   (Array (MatrixShape.Full Order
orderA Extent vert horiz height fuse
extentA) ForeignPtr a
a)
   (Array (MatrixShape.Full Order
orderB Extent vert horiz fuse width
extentB) ForeignPtr a
b) =
   case Extent vert horiz height fuse
-> Extent vert horiz fuse width
-> Maybe (Extent vert horiz height width)
forall vert horiz fuse height width.
(C vert, C horiz, Eq fuse) =>
Extent vert horiz height fuse
-> Extent vert horiz fuse width
-> Maybe (Extent vert horiz height width)
Extent.fuse Extent vert horiz height fuse
extentA Extent vert horiz fuse width
extentB of
      Maybe (Extent vert horiz height width)
Nothing -> String -> Full vert horiz height width a
forall a. HasCallStack => String -> a
error String
"multiply: fuse shapes mismatch"
      Just Extent vert horiz height width
extent ->
         Full vert horiz height width
-> (Ptr a -> IO ()) -> Full vert horiz height width a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate (Order
-> Extent vert horiz height width -> Full vert horiz height width
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
orderB Extent vert horiz height width
extent) ((Ptr a -> IO ()) -> Full vert horiz height width a)
-> (Ptr a -> IO ()) -> Full vert horiz height width a
forall a b. (a -> b) -> a -> b
$ \Ptr a
cPtr -> do

      let (height
height,fuse
fuse) = Extent vert horiz height fuse -> (height, fuse)
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> (height, width)
Extent.dimensions Extent vert horiz height fuse
extentA
      let width :: width
width = Extent vert horiz fuse width -> width
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> width
Extent.width Extent 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 vert horiz height fuse a
-> Full vert horiz fuse width a -> Full vert horiz height width a
multiplyColumnMajor
   (Array (MatrixShape.Full Order
orderA Extent vert horiz height fuse
extentA) ForeignPtr a
a)
   (Array (MatrixShape.Full Order
orderB Extent vert horiz fuse width
extentB) ForeignPtr a
b) =
   case Extent vert horiz height fuse
-> Extent vert horiz fuse width
-> Maybe (Extent vert horiz height width)
forall vert horiz fuse height width.
(C vert, C horiz, Eq fuse) =>
Extent vert horiz height fuse
-> Extent vert horiz fuse width
-> Maybe (Extent vert horiz height width)
Extent.fuse Extent vert horiz height fuse
extentA Extent vert horiz fuse width
extentB of
      Maybe (Extent vert horiz height width)
Nothing -> String -> Full vert horiz height width a
forall a. HasCallStack => String -> a
error String
"multiply: fuse shapes mismatch"
      Just Extent vert horiz height width
extent ->
         Full vert horiz height width
-> (Ptr a -> IO ()) -> Full vert horiz height width a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate (Order
-> Extent vert horiz height width -> Full vert horiz height width
forall vert horiz height width.
Order
-> Extent vert horiz height width -> Full vert horiz height width
MatrixShape.Full Order
ColumnMajor Extent vert horiz height width
extent) ((Ptr a -> IO ()) -> Full vert horiz height width a)
-> (Ptr a -> IO ()) -> Full vert horiz height width a
forall a b. (a -> b) -> a -> b
$ \Ptr a
cPtr -> do

      let (height
height,fuse
fuse) = Extent vert horiz height fuse -> (height, fuse)
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> (height, width)
Extent.dimensions Extent vert horiz height fuse
extentA
      let width :: width
width = Extent vert horiz fuse width -> width
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> width
Extent.width Extent 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