{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Numeric.LAPACK.Matrix.Banded.Basic (
   Banded,
   General,
   Square,
   Upper,
   Lower,
   Diagonal,
   RectangularDiagonal,
   fromList,
   squareFromList,
   lowerFromList,
   upperFromList,
   mapExtent,
   mapExtentSizes,
   mapHeight,
   mapWidth,
   identityFatOrder,
   diagonalFat,
   diagonal,
   takeDiagonal,
   forceOrder,
   toFull,
   toLowerTriangular,
   toUpperTriangular,
   takeTopLeftSquare,
   takeBottomRightSquare,
   transpose,
   adjoint,
   multiplyVector,
   multiply,
   multiplyFull,
   ) where

import qualified Numeric.LAPACK.Matrix.Layout.Private as Layout
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import qualified Numeric.LAPACK.Matrix.Triangular.Basic as Triangular
import qualified Numeric.LAPACK.Matrix.Mosaic.Generic as Mosaic
import qualified Numeric.LAPACK.Matrix.Mosaic.Private as Mos
import qualified Numeric.LAPACK.Matrix.RowMajor as RowMajor
import qualified Numeric.LAPACK.Matrix.Private as Matrix
import qualified Numeric.LAPACK.Vector as Vector
import qualified Numeric.LAPACK.Private as Private
import qualified Data.Array.Comfort.Shape.Static as ShapeStatic
import Numeric.LAPACK.Matrix.Layout.Private
         (Order(RowMajor,ColumnMajor), transposeFromOrder, swapOnRowMajor,
          UnaryProxy, addOffDiagonals)
import Numeric.BLAS.Matrix.Modifier (Conjugation(NonConjugated))
import Numeric.LAPACK.Vector (Vector)
import Numeric.LAPACK.Scalar (zero, one)
import Numeric.LAPACK.Matrix.Extent.Private (Extent)
import Numeric.LAPACK.Private
         (fill, pointerSeq, pokeCInt,
          copyBlock, copySubMatrix, copySubTrapezoid)

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

import qualified Type.Data.Num.Unary.Literal as TypeNum
import qualified Type.Data.Num.Unary.Proof as Proof
import qualified Type.Data.Num.Unary as Unary
import Type.Data.Num.Unary ((:+:))
import Type.Data.Num (integralFromProxy)
import Type.Base.Proxy (Proxy(Proxy))

import qualified Data.Array.Comfort.Storable.Unchecked as Array
import qualified Data.Array.Comfort.Storable as CheckedArray
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 Foreign.Ptr (Ptr)
import Foreign.Storable (Storable)

import qualified Control.Monad.Trans.Maybe as MM
import qualified Control.Monad.Trans.Reader as MR
import Control.Monad.Trans.Cont (ContT(ContT), evalContT)
import Control.Monad.IO.Class (liftIO)
import Control.Monad (mzero, void)

import Data.Foldable (forM_)
import Data.Tuple.HT (swap)
import Data.Ord.HT (limit)


type Banded sub super meas vert horiz height width =
      Array (Layout.Banded sub super meas vert horiz height width)

type General sub super height width =
      Array (Layout.BandedGeneral sub super height width)

type Square sub super size =
      Array (Layout.BandedSquare sub super size)

type Lower sub size = Square sub TypeNum.U0 size
type Upper super size = Square TypeNum.U0 super size

type Diagonal size = Square TypeNum.U0 TypeNum.U0 size
type RectangularDiagonal meas vert horiz height width =
      Banded TypeNum.U0 TypeNum.U0 meas vert horiz height width


fromList ::
   (Unary.Natural sub, Unary.Natural super,
    Shape.C height, Shape.C width, Storable a) =>
   (UnaryProxy sub, UnaryProxy super) -> Order -> height -> width -> [a] ->
   General sub super height width a
fromList :: forall sub super height width a.
(Natural sub, Natural super, C height, C width, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order
-> height
-> width
-> [a]
-> General sub super height width a
fromList (UnaryProxy sub, UnaryProxy super)
offDiag Order
order height
height width
width =
   (UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent Size Big Big height width
-> [a]
-> Banded sub super Size Big Big height width a
forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> [a]
-> Banded sub super meas vert horiz height width a
fromListGen (UnaryProxy sub, UnaryProxy super)
offDiag Order
order (height -> width -> Extent Size Big Big height width
forall height width. height -> width -> General height width
Extent.general height
height width
width)

squareFromList ::
   (Unary.Natural sub, Unary.Natural super, Shape.C size, Storable a) =>
   (UnaryProxy sub, UnaryProxy super) -> Order -> size -> [a] ->
   Square sub super size a
squareFromList :: forall sub super size a.
(Natural sub, Natural super, C size, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order -> size -> [a] -> Square sub super size a
squareFromList (UnaryProxy sub, UnaryProxy super)
offDiag Order
order size
size =
   (UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent Shape Small Small size size
-> [a]
-> Banded sub super Shape Small Small size size a
forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> [a]
-> Banded sub super meas vert horiz height width a
fromListGen (UnaryProxy sub, UnaryProxy super)
offDiag Order
order (size -> Extent Shape Small Small size size
forall sh. sh -> Square sh
Extent.square size
size)

lowerFromList ::
   (Unary.Natural sub, Shape.C size, Storable a) =>
   UnaryProxy sub -> Order -> size -> [a] -> Lower sub size a
lowerFromList :: forall sub size a.
(Natural sub, C size, Storable a) =>
UnaryProxy sub -> Order -> size -> [a] -> Lower sub size a
lowerFromList UnaryProxy sub
numOff Order
order size
size =
   (UnaryProxy sub, UnaryProxy U0)
-> Order
-> Extent Shape Small Small size size
-> [a]
-> Banded sub U0 Shape Small Small size size a
forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> [a]
-> Banded sub super meas vert horiz height width a
fromListGen (UnaryProxy sub
numOff,UnaryProxy U0
forall a. Proxy a
Proxy) Order
order (size -> Extent Shape Small Small size size
forall sh. sh -> Square sh
Extent.square size
size)

upperFromList ::
   (Unary.Natural super, Shape.C size, Storable a) =>
   UnaryProxy super -> Order -> size -> [a] -> Upper super size a
upperFromList :: forall super size a.
(Natural super, C size, Storable a) =>
UnaryProxy super -> Order -> size -> [a] -> Upper super size a
upperFromList UnaryProxy super
numOff Order
order size
size =
   (UnaryProxy U0, UnaryProxy super)
-> Order
-> Extent Shape Small Small size size
-> [a]
-> Banded U0 super Shape Small Small size size a
forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> [a]
-> Banded sub super meas vert horiz height width a
fromListGen (UnaryProxy U0
forall a. Proxy a
Proxy,UnaryProxy super
numOff) Order
order (size -> Extent Shape Small Small size size
forall sh. sh -> Square sh
Extent.square size
size)

fromListGen ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Storable a) =>
   (UnaryProxy sub, UnaryProxy super) -> Order ->
   Extent.Extent meas vert horiz height width -> [a] ->
   Banded sub super meas vert horiz height width a
fromListGen :: forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Storable a) =>
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> [a]
-> Banded sub super meas vert horiz height width a
fromListGen (UnaryProxy sub, UnaryProxy super)
offDiag Order
order Extent meas vert horiz height width
extent =
   Banded sub super meas vert horiz height width
-> [a] -> Array (Banded sub super meas vert horiz height width) a
forall sh a. (C sh, Storable a) => sh -> [a] -> Array sh a
CheckedArray.fromList ((UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (UnaryProxy sub, UnaryProxy super)
offDiag Order
order Extent meas vert horiz height width
extent)


mapExtent ::
   (Extent.C vertA, Extent.C horizA) =>
   (Extent.C vertB, Extent.C horizB) =>
   Extent.Map measA vertA horizA measB vertB horizB height width ->
   Banded sub super measA vertA horizA height width a ->
   Banded sub super measB vertB horizB height width a
mapExtent :: forall vertA horizA vertB horizB measA measB height width sub super
       a.
(C vertA, C horizA, C vertB, C horizB) =>
Map measA vertA horizA measB vertB horizB height width
-> Banded sub super measA vertA horizA height width a
-> Banded sub super measB vertB horizB height width a
mapExtent Map measA vertA horizA measB vertB horizB height width
f = (Banded sub super measA vertA horizA height width
 -> Banded sub super measB vertB horizB height width)
-> Array (Banded sub super measA vertA horizA height width) a
-> Array (Banded sub super measB vertB horizB height width) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape ((Banded sub super measA vertA horizA height width
  -> Banded sub super measB vertB horizB height width)
 -> Array (Banded sub super measA vertA horizA height width) a
 -> Array (Banded sub super measB vertB horizB height width) a)
-> (Banded sub super measA vertA horizA height width
    -> Banded sub super measB vertB horizB height width)
-> Array (Banded sub super measA vertA horizA height width) a
-> Array (Banded sub super measB vertB horizB height width) a
forall a b. (a -> b) -> a -> b
$ Map measA vertA horizA measB vertB horizB height width
-> Banded sub super measA vertA horizA height width
-> Banded sub super measB vertB horizB height width
forall measA vertA horizA measB vertB horizB height width sub
       super.
Map measA vertA horizA measB vertB horizB height width
-> Banded sub super measA vertA horizA height width
-> Banded sub super measB vertB horizB height width
Layout.bandedMapExtent Map measA vertA horizA measB vertB horizB height width
f

mapExtentSizes ::
   (Extent.C vertA, Extent.C horizA) =>
   (Extent.C vertB, Extent.C horizB) =>
   (Extent measA vertA horizA heightA widthA ->
    Extent measB vertB horizB heightB widthB) ->
   Banded sub super measA vertA horizA heightA widthA a ->
   Banded sub super measB vertB horizB heightB widthB a
mapExtentSizes :: forall vertA horizA vertB horizB measA heightA widthA measB heightB
       widthB sub super a.
(C vertA, C horizA, C vertB, C horizB) =>
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Banded sub super measA vertA horizA heightA widthA a
-> Banded sub super measB vertB horizB heightB widthB a
mapExtentSizes Extent measA vertA horizA heightA widthA
-> Extent measB vertB horizB heightB widthB
f =
   (Banded sub super measA vertA horizA heightA widthA
 -> Banded sub super measB vertB horizB heightB widthB)
-> Array (Banded sub super measA vertA horizA heightA widthA) a
-> Array (Banded sub super measB vertB horizB heightB widthB) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(Layout.Banded (UnaryProxy sub, UnaryProxy super)
offDiag Order
order Extent measA vertA horizA heightA widthA
extent) ->
         (UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent measB vertB horizB heightB widthB
-> Banded sub super measB vertB horizB heightB widthB
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (UnaryProxy sub, UnaryProxy super)
offDiag Order
order (Extent measB vertB horizB heightB widthB
 -> Banded sub super measB vertB horizB heightB widthB)
-> Extent measB vertB horizB heightB widthB
-> Banded sub super 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) ->
   Banded sub super Extent.Size vert horiz heightA width a ->
   Banded sub super Extent.Size vert horiz heightB width a
mapHeight :: forall vert horiz heightA heightB sub super width a.
(C vert, C horiz) =>
(heightA -> heightB)
-> Banded sub super Size vert horiz heightA width a
-> Banded sub super Size vert horiz heightB width a
mapHeight = (Extent Size vert horiz heightA width
 -> Extent Size vert horiz heightB width)
-> Banded sub super Size vert horiz heightA width a
-> Banded sub super Size vert horiz heightB width a
forall vertA horizA vertB horizB measA heightA widthA measB heightB
       widthB sub super a.
(C vertA, C horizA, C vertB, C horizB) =>
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Banded sub super measA vertA horizA heightA widthA a
-> Banded sub super measB vertB horizB heightB widthB a
mapExtentSizes ((Extent Size vert horiz heightA width
  -> Extent Size vert horiz heightB width)
 -> Banded sub super Size vert horiz heightA width a
 -> Banded sub super Size vert horiz heightB width a)
-> ((heightA -> heightB)
    -> Extent Size vert horiz heightA width
    -> Extent Size vert horiz heightB width)
-> (heightA -> heightB)
-> Banded sub super Size vert horiz heightA width a
-> Banded sub super 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) ->
   Banded sub super Extent.Size vert horiz height widthA a ->
   Banded sub super Extent.Size vert horiz height widthB a
mapWidth :: forall vert horiz widthA widthB sub super height a.
(C vert, C horiz) =>
(widthA -> widthB)
-> Banded sub super Size vert horiz height widthA a
-> Banded sub super Size vert horiz height widthB a
mapWidth = (Extent Size vert horiz height widthA
 -> Extent Size vert horiz height widthB)
-> Banded sub super Size vert horiz height widthA a
-> Banded sub super Size vert horiz height widthB a
forall vertA horizA vertB horizB measA heightA widthA measB heightB
       widthB sub super a.
(C vertA, C horizA, C vertB, C horizB) =>
(Extent measA vertA horizA heightA widthA
 -> Extent measB vertB horizB heightB widthB)
-> Banded sub super measA vertA horizA heightA widthA a
-> Banded sub super measB vertB horizB heightB widthB a
mapExtentSizes ((Extent Size vert horiz height widthA
  -> Extent Size vert horiz height widthB)
 -> Banded sub super Size vert horiz height widthA a
 -> Banded sub super Size vert horiz height widthB a)
-> ((widthA -> widthB)
    -> Extent Size vert horiz height widthA
    -> Extent Size vert horiz height widthB)
-> (widthA -> widthB)
-> Banded sub super Size vert horiz height widthA a
-> Banded sub super 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

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

adjoint ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Banded sub super meas vert horiz height width a ->
   Banded super sub meas horiz vert width height a
adjoint :: forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Floating a) =>
Banded sub super meas vert horiz height width a
-> Banded super sub meas horiz vert width height a
adjoint = Vector (Banded super sub meas horiz vert width height) a
-> Vector (Banded super sub meas horiz vert width height) a
forall sh a. (C sh, Floating a) => Vector sh a -> Vector sh a
Vector.conjugate (Vector (Banded super sub meas horiz vert width height) a
 -> Vector (Banded super sub meas horiz vert width height) a)
-> (Banded sub super meas vert horiz height width a
    -> Vector (Banded super sub meas horiz vert width height) a)
-> Banded sub super meas vert horiz height width a
-> Vector (Banded super sub meas horiz vert width height) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Banded sub super meas vert horiz height width a
-> Vector (Banded super sub meas horiz vert width height) a
forall meas vert horiz sub super height width a.
(Measure meas, C vert, C horiz) =>
Banded sub super meas vert horiz height width a
-> Banded super sub meas horiz vert width height a
transpose


identityFatOrder ::
   (Unary.Natural sub, Unary.Natural super, Shape.C size, Class.Floating a) =>
   Order -> size -> Square sub super size a
identityFatOrder :: forall sub super size a.
(Natural sub, Natural super, C size, Floating a) =>
Order -> size -> Square sub super size a
identityFatOrder Order
order = Order -> Vector size a -> Square sub super size a
forall sub super size a.
(Natural sub, Natural super, C size, Floating a) =>
Order -> Vector size a -> Square sub super size a
diagonalFat Order
order (Vector size a -> Square sub super size a)
-> (size -> Vector size a) -> size -> Square sub super size a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. size -> Vector size a
forall sh a. (C sh, Floating a) => sh -> Vector sh a
Vector.one

diagonalFat ::
   (Unary.Natural sub, Unary.Natural super, Shape.C size, Class.Floating a) =>
   Order -> Vector size a -> Square sub super size a
diagonalFat :: forall sub super size a.
(Natural sub, Natural super, C size, Floating a) =>
Order -> Vector size a -> Square sub super size a
diagonalFat Order
order =
   case Order
order of
      Order
RowMajor -> (size -> Extent Shape Small Small size size)
-> Matrix size (Section sub super) a -> Square sub super size a
forall sub super height meas vert horiz width a.
(Natural sub, Natural super, C height) =>
(height -> Extent meas vert horiz height width)
-> Matrix height (Section sub super) a
-> Banded sub super meas vert horiz height width a
fromRowMajor size -> Extent Shape Small Small size size
forall sh. sh -> Square sh
Extent.square (Matrix size (Section sub super) a -> Square sub super size a)
-> (Vector size a -> Matrix size (Section sub super) a)
-> Vector size a
-> Square sub super size a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector size a -> Matrix size (Section sub super) a
forall sub super height a.
(Natural sub, Natural super, C height, Floating a) =>
Vector height a -> Matrix height (Section sub super) a
diagonalStripe
      Order
ColumnMajor -> (size -> Extent Shape Small Small size size)
-> Matrix size (Section super sub) a -> Square sub super size a
forall sub super width meas vert horiz height a.
(Natural sub, Natural super, C width) =>
(width -> Extent meas vert horiz height width)
-> Matrix width (Section super sub) a
-> Banded sub super meas vert horiz height width a
fromColumnMajor size -> Extent Shape Small Small size size
forall sh. sh -> Square sh
Extent.square (Matrix size (Section super sub) a -> Square sub super size a)
-> (Vector size a -> Matrix size (Section super sub) a)
-> Vector size a
-> Square sub super size a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector size a -> Matrix size (Section super sub) a
forall sub super height a.
(Natural sub, Natural super, C height, Floating a) =>
Vector height a -> Matrix height (Section sub super) a
diagonalStripe

type Section sub super =
      ShapeStatic.ZeroBased sub ::+ ()
         ::+ ShapeStatic.ZeroBased super

diagonalStripe ::
   (Unary.Natural sub, Unary.Natural super, Shape.C height, Class.Floating a) =>
   Vector height a -> RowMajor.Matrix height (Section sub super) a
diagonalStripe :: forall sub super height a.
(Natural sub, Natural super, C height, Floating a) =>
Vector height a -> Matrix height (Section sub super) a
diagonalStripe Vector height a
v =
   Either Conjugation Conjugation
-> Vector height a
-> Vector (Section sub super) a
-> Matrix height (Section sub super) 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
v (Section sub super
-> Index (Section sub super) -> Vector (Section sub super) a
forall sh a.
(Indexed sh, Floating a) =>
sh -> Index sh -> Vector sh a
Vector.unit Section sub super
forall sh. Static sh => sh
Shape.static (Index (Section sub super) -> Vector (Section sub super) a)
-> Index (Section sub super) -> Vector (Section sub super) a
forall a b. (a -> b) -> a -> b
$ Either () (Index super)
-> Either (Index sub) (Either () (Index super))
forall a b. b -> Either a b
Right (() -> Either () (Index super)
forall a b. a -> Either a b
Left ()))

fromRowMajor ::
   (Unary.Natural sub, Unary.Natural super, Shape.C height) =>
   (height -> Extent.Extent meas vert horiz height width) ->
   RowMajor.Matrix height (Section sub super) a ->
   Banded sub super meas vert horiz height width a
fromRowMajor :: forall sub super height meas vert horiz width a.
(Natural sub, Natural super, C height) =>
(height -> Extent meas vert horiz height width)
-> Matrix height (Section sub super) a
-> Banded sub super meas vert horiz height width a
fromRowMajor height -> Extent meas vert horiz height width
extent =
   ((height, Section sub super)
 -> Banded sub super meas vert horiz height width)
-> Array (height, Section sub super) a
-> Array (Banded sub super meas vert horiz height width) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(height
size,
         ShapeStatic.ZeroBased Proxy (Un sub)
kl ::+ ()
            ::+ ShapeStatic.ZeroBased Proxy (Un super)
ku) ->
         (Proxy (Un sub), Proxy (Un super))
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (Proxy (Un sub)
kl,Proxy (Un super)
ku) Order
RowMajor (Extent meas vert horiz height width
 -> Banded sub super meas vert horiz height width)
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
forall a b. (a -> b) -> a -> b
$ height -> Extent meas vert horiz height width
extent height
size)

fromColumnMajor ::
   (Unary.Natural sub, Unary.Natural super, Shape.C width) =>
   (width -> Extent.Extent meas vert horiz height width) ->
   RowMajor.Matrix width (Section super sub) a ->
   Banded sub super meas vert horiz height width a
fromColumnMajor :: forall sub super width meas vert horiz height a.
(Natural sub, Natural super, C width) =>
(width -> Extent meas vert horiz height width)
-> Matrix width (Section super sub) a
-> Banded sub super meas vert horiz height width a
fromColumnMajor width -> Extent meas vert horiz height width
extent =
   ((width, Section super sub)
 -> Banded sub super meas vert horiz height width)
-> Array (width, Section super sub) a
-> Array (Banded sub super meas vert horiz height width) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
      (\(width
size,
         ShapeStatic.ZeroBased Proxy (Un super)
ku ::+ ()
            ::+ ShapeStatic.ZeroBased Proxy (Un sub)
kl) ->
         (Proxy (Un sub), Proxy (Un super))
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (Proxy (Un sub)
kl,Proxy (Un super)
ku) Order
ColumnMajor (Extent meas vert horiz height width
 -> Banded sub super meas vert horiz height width)
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
forall a b. (a -> b) -> a -> b
$ width -> Extent meas vert horiz height width
extent width
size)


diagonal ::
   (Shape.C sh, Class.Floating a) => Order -> Vector sh a -> Diagonal sh a
diagonal :: forall sh a.
(C sh, Floating a) =>
Order -> Vector sh a -> Diagonal sh a
diagonal Order
order (Array sh
sh ForeignPtr a
x) =
   BandedSquare U0 U0 sh
-> ForeignPtr a -> Array (BandedSquare U0 U0 sh) a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array ((UnaryProxy U0, UnaryProxy U0)
-> Order -> sh -> BandedSquare U0 U0 sh
forall sub super size.
(UnaryProxy sub, UnaryProxy super)
-> Order -> size -> BandedSquare sub super size
Layout.bandedSquare (UnaryProxy U0
forall a. Proxy a
Proxy,UnaryProxy U0
forall a. Proxy a
Proxy) Order
order sh
sh) ForeignPtr a
x

takeDiagonal ::
   (Unary.Natural sub, Unary.Natural super, Shape.C sh, Class.Floating a) =>
   Square sub super sh a -> Vector sh a
takeDiagonal :: forall sub super sh a.
(Natural sub, Natural super, C sh, Floating a) =>
Square sub super sh a -> Vector sh a
takeDiagonal (Array (Layout.Banded (UnaryProxy sub
sub,UnaryProxy super
super) Order
order Extent Shape Small Small sh sh
extent) ForeignPtr a
x) =
   let size :: sh
size = Extent Shape Small Small sh sh -> sh
forall shape. Square shape -> shape
Extent.squareSize Extent Shape Small Small sh sh
extent
       kl :: Int
kl = UnaryProxy sub -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy sub
sub
       ku :: Int
ku = UnaryProxy super -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy super
super
   in if (Int
kl,Int
ku) (Int, Int) -> (Int, Int) -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
0,Int
0)
        then sh -> ForeignPtr a -> Array sh a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array sh
size ForeignPtr a
x
        else
            sh -> (Int -> Ptr a -> IO ()) -> Array sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize sh
size ((Int -> Ptr a -> IO ()) -> Array sh a)
-> (Int -> Ptr a -> IO ()) -> Array sh a
forall a b. (a -> b) -> a -> b
$ \Int
n Ptr a
yPtr -> 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
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
               Ptr a
xPtr <- ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall {k} (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
x
               let k :: Int
k =
                     case Order
order of
                        Order
RowMajor -> Int
kl
                        Order
ColumnMajor -> Int
ku
               Ptr CInt
incxPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint (Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kuInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
               Ptr CInt
incyPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
1
               IO () -> ContT () IO ()
forall a. IO a -> ContT () IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
                  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
nPtr (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
xPtr Int
k) Ptr CInt
incxPtr Ptr a
yPtr Ptr CInt
incyPtr


multiplyVector ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Eq width, Class.Floating a) =>
   Banded sub super meas vert horiz height width a ->
   Vector width a -> Vector height a
multiplyVector :: forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Eq width, Floating a) =>
Banded sub super meas vert horiz height width a
-> Vector width a -> Vector height a
multiplyVector
   (Array (Layout.Banded (UnaryProxy sub, UnaryProxy super)
numOff Order
order Extent meas vert horiz height width
extent) ForeignPtr a
a) (Array width
width ForeignPtr a
x) =
      let height :: height
height = Extent meas vert horiz height width -> height
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> height
Extent.height Extent meas vert horiz height width
extent
      in height -> (Ptr a -> IO ()) -> Array height a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate height
height ((Ptr a -> IO ()) -> Array height a)
-> (Ptr a -> IO ()) -> Array height a
forall a b. (a -> b) -> a -> b
$ \Ptr a
yPtr -> do

   String -> Bool -> IO ()
Call.assert String
"Banded.multiplyVector: shapes mismatch"
      (Extent meas vert horiz height width -> width
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> width
Extent.width Extent meas vert horiz height width
extent width -> width -> Bool
forall a. Eq a => a -> a -> Bool
== width
width)
   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 -> (Int, Int))
-> Full meas vert horiz height width -> (Int, Int)
forall a b. (a -> b) -> a -> b
$ Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
order Extent meas vert horiz height width
extent
   let (Int
kl,Int
ku) = Order -> (UnaryProxy sub, UnaryProxy super) -> (Int, Int)
forall sub super.
(Natural sub, Natural super) =>
Order -> (UnaryProxy sub, UnaryProxy super) -> (Int, Int)
Layout.numOffDiagonals Order
order (UnaryProxy sub, UnaryProxy super)
numOff
   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 CInt
klPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
kl
      Ptr CInt
kuPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
ku
      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 -> FortranIO () (Ptr CInt)) -> Int -> FortranIO () (Ptr CInt)
forall a b. (a -> b) -> a -> b
$ Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
      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 a. IO a -> ContT () IO a
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 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 CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
Private.gbmv Ptr CChar
transPtr Ptr CInt
mPtr Ptr CInt
nPtr Ptr CInt
klPtr Ptr CInt
kuPtr
            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 ::
   (Unary.Natural subA, Unary.Natural superA,
    Unary.Natural subB, Unary.Natural superB,
    (subA :+: subB) ~ subC,
    (superA :+: superB) ~ superC,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Shape.C fuse, Eq fuse,
    Class.Floating a) =>
   Banded subA superA meas vert horiz height fuse a ->
   Banded subB superB meas vert horiz fuse width a ->
   Banded subC superC meas vert horiz height width a
multiply :: forall subA superA subB superB subC superC meas vert horiz height
       width fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 (subA :+: subB) ~ subC, (superA :+: superB) ~ superC, Measure meas,
 C vert, C horiz, C height, C width, C fuse, Eq fuse, Floating a) =>
Banded subA superA meas vert horiz height fuse a
-> Banded subB superB meas vert horiz fuse width a
-> Banded subC superC meas vert horiz height width a
multiply
      (Array (Layout.Banded (UnaryProxy subA, UnaryProxy superA)
numOffA Order
orderA Extent meas vert horiz height fuse
extentA) ForeignPtr a
a)
      (Array (Layout.Banded (UnaryProxy subB, UnaryProxy superB)
numOffB Order
orderB Extent meas vert horiz fuse width
extentB) ForeignPtr a
b) =
   case ((UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> ((Nat subC, Nat superC), (UnaryProxy subC, UnaryProxy superC))
forall subA superA subB superB subC superC.
(Natural subA, Natural superA, Natural subB, Natural superB,
 (subA :+: subB) ~ subC, (superA :+: superB) ~ superC) =>
(UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> ((Nat subC, Nat superC), (UnaryProxy subC, UnaryProxy superC))
addOffDiagonals (UnaryProxy subA, UnaryProxy superA)
numOffA (UnaryProxy subB, UnaryProxy superB)
numOffB, 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
      (((Nat subC, Nat superC), (UnaryProxy subC, UnaryProxy superC))
_, Maybe (Extent meas vert horiz height width)
Nothing) -> String -> Banded subC superC meas vert horiz height width a
forall a. HasCallStack => String -> a
error String
"Banded.multiply: shapes mismatch"
      (((Nat subC
Proof.Nat, Nat superC
Proof.Nat), (UnaryProxy subC, UnaryProxy superC)
numOffC), Just Extent meas vert horiz height width
extent) ->
         Banded subC superC meas vert horiz height width
-> (Ptr a -> IO ())
-> Banded subC superC meas vert horiz height width a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate
               ((UnaryProxy subC, UnaryProxy superC)
-> Order
-> Extent meas vert horiz height width
-> Banded subC superC meas vert horiz height width
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (UnaryProxy subC, UnaryProxy superC)
numOffC Order
orderB Extent meas vert horiz height width
extent) ((Ptr a -> IO ())
 -> Banded subC superC meas vert horiz height width a)
-> (Ptr a -> IO ())
-> Banded subC superC meas vert horiz height width a
forall a b. (a -> b) -> a -> b
$ \Ptr a
cPtr ->
            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
                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
            in case (Order
orderA,Order
orderB) of
                  (Order
ColumnMajor,Order
ColumnMajor) ->
                     Order
-> (UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall subA superA subB superB height width fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 C height, C width, C fuse, Floating a) =>
Order
-> (UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyColumnMajor Order
ColumnMajor
                        (UnaryProxy subA, UnaryProxy superA)
numOffA (UnaryProxy subB, UnaryProxy superB)
numOffB (height
height,fuse
fuse,width
width) ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr
                  (Order
RowMajor,Order
ColumnMajor) ->
                     Order
-> (UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall subA superA subB superB height width fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 C height, C width, C fuse, Floating a) =>
Order
-> (UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyColumnMajor Order
RowMajor
                        (UnaryProxy subA, UnaryProxy superA)
numOffA (UnaryProxy subB, UnaryProxy superB)
numOffB (height
height,fuse
fuse,width
width) ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr
                  (Order
ColumnMajor,Order
RowMajor) ->
                     (UnaryProxy superB, UnaryProxy subB)
-> (UnaryProxy superA, UnaryProxy subA)
-> (width, fuse, height)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall subA superA subB superB height width fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 C height, C width, C fuse, Floating a) =>
(UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyColumnRowMajor
                        ((UnaryProxy subB, UnaryProxy superB)
-> (UnaryProxy superB, UnaryProxy subB)
forall a b. (a, b) -> (b, a)
swap (UnaryProxy subB, UnaryProxy superB)
numOffB) ((UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy superA, UnaryProxy subA)
forall a b. (a, b) -> (b, a)
swap (UnaryProxy subA, UnaryProxy superA)
numOffA)
                        (width
width,fuse
fuse,height
height) ForeignPtr a
b ForeignPtr a
a Ptr a
cPtr
                  (Order
RowMajor,Order
RowMajor) ->
                     Order
-> (UnaryProxy superB, UnaryProxy subB)
-> (UnaryProxy superA, UnaryProxy subA)
-> (width, fuse, height)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall subA superA subB superB height width fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 C height, C width, C fuse, Floating a) =>
Order
-> (UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyColumnMajor Order
ColumnMajor
                        ((UnaryProxy subB, UnaryProxy superB)
-> (UnaryProxy superB, UnaryProxy subB)
forall a b. (a, b) -> (b, a)
swap (UnaryProxy subB, UnaryProxy superB)
numOffB) ((UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy superA, UnaryProxy subA)
forall a b. (a, b) -> (b, a)
swap (UnaryProxy subA, UnaryProxy superA)
numOffA)
                        (width
width,fuse
fuse,height
height) ForeignPtr a
b ForeignPtr a
a Ptr a
cPtr

multiplyColumnMajor ::
   (Unary.Natural subA, Unary.Natural superA,
    Unary.Natural subB, Unary.Natural superB,
    Shape.C height, Shape.C width, Shape.C fuse,
    Class.Floating a) =>
   Order ->
   (UnaryProxy subA, UnaryProxy superA) ->
   (UnaryProxy subB, UnaryProxy superB) ->
   (height, fuse, width) ->
   ForeignPtr a -> ForeignPtr a -> Ptr a -> IO ()
multiplyColumnMajor :: forall subA superA subB superB height width fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 C height, C width, C fuse, Floating a) =>
Order
-> (UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyColumnMajor Order
orderA (UnaryProxy subA
subA,UnaryProxy superA
superA) (UnaryProxy subB
subB,UnaryProxy superB
superB)
      (height
height,fuse
fuse,width
width) ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr = do
   let m :: Int
m = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
   let k :: Int
k = fuse -> Int
forall sh. C sh => sh -> Int
Shape.size fuse
fuse
   let n :: Int
n = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
   let (Int
kla,Int
kua) = (UnaryProxy subA -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy subA
subA, UnaryProxy superA -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy superA
superA)
   let (Int
klb,Int
kub) = (UnaryProxy subB -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy subB
subB, UnaryProxy superB -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy superB
superB)
   let ku :: Int
ku = Int
kuaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kub
   let kl :: Int
kl = Int
klaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
klb
   let lda0 :: Int
lda0 = Int
klaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kua
   let ldb0 :: Int
ldb0 = Int
klbInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kub
   let ldc0 :: Int
ldc0 = Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ldb0
   let lda :: Int
lda = Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1
   let ldc :: Int
ldc = Int
ldc0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1
   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
orderA
      Ptr CInt
mPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
      Ptr CInt
nPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
      Ptr CInt
klPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
      Ptr CInt
kuPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
      let ((Ptr CInt
miPtr,Ptr CInt
kliPtr),(Ptr CInt
niPtr,Ptr CInt
kuiPtr)) =
            Order
-> ((Ptr CInt, Ptr CInt), (Ptr CInt, Ptr CInt))
-> ((Ptr CInt, Ptr CInt), (Ptr CInt, Ptr CInt))
forall a. Order -> (a, a) -> (a, a)
swapOnRowMajor Order
orderA ((Ptr CInt
mPtr,Ptr CInt
klPtr),(Ptr CInt
nPtr,Ptr CInt
kuPtr))
      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
bPtr <- ((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
b
      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 a. IO a -> ContT () IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
         [Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
n [Int
0..]) ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
i -> do
            let top :: Int
top = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
ku)
            let bottom :: Int
bottom = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
m (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
            let left :: Int
left = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
kub)
            let right :: Int
right = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
k (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
klbInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
            Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
miPtr (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
bottomInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
top
            Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
niPtr (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
rightInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
left
            let d :: Int
d = Int
topInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
left; kli :: Int
kli = Int
klaInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
d; kui :: Int
kui = Int
kuaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
d
            Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
kuiPtr Int
kui
            Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
kliPtr Int
kli
            let j0 :: Int
j0 = Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ldc
            let j1 :: Int
j1 = Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ldc0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
topInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
            let j2 :: Int
j2 = Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ldc0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
bottomInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
            a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero (Int
j1Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
j0) (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
cPtr Int
j0)
            let aOffset :: Int
aOffset =
                  case Order
orderA of
                     Order
ColumnMajor -> Int
left
                     Order
RowMajor -> Int
top
            Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> 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 CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
Private.gbmv Ptr CChar
transPtr Ptr CInt
mPtr Ptr CInt
nPtr Ptr CInt
klPtr Ptr CInt
kuPtr
               Ptr a
alphaPtr
               (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
aOffsetInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda)) Ptr CInt
ldaPtr
               (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ldb0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
leftInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kub)) Ptr CInt
incxPtr
               Ptr a
betaPtr
               (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
cPtr Int
j1) Ptr CInt
incyPtr
            a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero (Int
j0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ldcInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
j2) (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
cPtr Int
j2)

multiplyColumnRowMajor ::
   (Unary.Natural subA, Unary.Natural superA,
    Unary.Natural subB, Unary.Natural superB,
    Shape.C height, Shape.C width, Shape.C fuse,
    Class.Floating a) =>
   (UnaryProxy subA, UnaryProxy superA) ->
   (UnaryProxy subB, UnaryProxy superB) ->
   (height, fuse, width) ->
   ForeignPtr a -> ForeignPtr a -> Ptr a -> IO ()
multiplyColumnRowMajor :: forall subA superA subB superB height width fuse a.
(Natural subA, Natural superA, Natural subB, Natural superB,
 C height, C width, C fuse, Floating a) =>
(UnaryProxy subA, UnaryProxy superA)
-> (UnaryProxy subB, UnaryProxy superB)
-> (height, fuse, width)
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyColumnRowMajor (UnaryProxy subA
subA,UnaryProxy superA
superA) (UnaryProxy subB
subB,UnaryProxy superB
superB)
      (height
height,fuse
fuse,width
width) ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr = do
   let m :: Int
m = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
   let k :: Int
k = fuse -> Int
forall sh. C sh => sh -> Int
Shape.size fuse
fuse
   let n :: Int
n = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
   let (Int
kla,Int
kua) = (UnaryProxy subA -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy subA
subA, UnaryProxy superA -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy superA
superA)
   let (Int
klb,Int
kub) = (UnaryProxy subB -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy subB
subB, UnaryProxy superB -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy superB
superB)
   let ku :: Int
ku = Int
kuaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kub
   let kl :: Int
kl = Int
klaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
klb
   let lda0 :: Int
lda0 = Int
klaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kua
   let ldb0 :: Int
ldb0 = Int
klbInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kub
   let ldc0 :: Int
ldc0 = Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
   let ldc :: Int
ldc = Int
ldc0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1
   a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero (Int
ldcInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n) Ptr a
cPtr
   ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
      Ptr CInt
mPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
      Ptr CInt
nPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
      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 a
bPtr <- ((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
b
      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
      Ptr CInt
ldc0Ptr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim (Int -> FortranIO () (Ptr CInt)) -> Int -> FortranIO () (Ptr CInt)
forall a b. (a -> b) -> a -> b
$ Int
ldc0 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ if Int
ldb0Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==Int
0 then Int
1 else Int
0
      IO () -> ContT () IO ()
forall a. IO a -> ContT () IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
         [Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
k [Int
0..]) ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
i -> do
            let top :: Int
top = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
kua)
            let bottom :: Int
bottom = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
m (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
klaInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
            let left :: Int
left = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
klb)
            let right :: Int
right = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
n (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kubInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
            Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
mPtr (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
bottomInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
top
            Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
nPtr (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
rightInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
left
            Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
BlasGen.geru Ptr CInt
mPtr Ptr CInt
nPtr Ptr a
alphaPtr
               (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
topInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kua)) Ptr CInt
incxPtr
               (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ldb0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
leftInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
klb)) Ptr CInt
incyPtr
               (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
cPtr (Int
leftInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ldc0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
topInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku)) Ptr CInt
ldc0Ptr


multiplyFull ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Shape.C fuse, Eq fuse,
    Class.Floating a) =>
   Banded sub super meas vert horiz height fuse a ->
   Matrix.Full meas vert horiz fuse width a -> Matrix.Full meas vert horiz height width a
multiplyFull :: forall sub super meas vert horiz height width fuse a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, C fuse, Eq fuse, Floating a) =>
Banded sub super meas vert horiz height fuse a
-> Full meas vert horiz fuse width a
-> Full meas vert horiz height width a
multiplyFull
      (Array (Layout.Banded (UnaryProxy sub, UnaryProxy super)
numOff 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
"Banded.multiplyFull: 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 ->
            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
                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
            in case Order
orderB of
                  Order
ColumnMajor ->
                     (UnaryProxy sub, UnaryProxy super)
-> (height, fuse, width)
-> Order
-> Extent meas vert horiz height fuse
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall sub super meas vert horiz height width fuse a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, C fuse, Floating a) =>
(UnaryProxy sub, UnaryProxy super)
-> (height, fuse, width)
-> Order
-> Extent meas vert horiz height fuse
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyFullColumnMajor
                        (UnaryProxy sub, UnaryProxy super)
numOff (height
height,fuse
fuse,width
width) Order
orderA Extent meas vert horiz height fuse
extentA ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr
                  Order
RowMajor ->
                     (UnaryProxy sub, UnaryProxy super)
-> (height, fuse, width)
-> Order
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
forall sub super height width fuse a.
(Natural sub, Natural super, C height, C width, C fuse,
 Floating a) =>
(UnaryProxy sub, UnaryProxy super)
-> (height, fuse, width)
-> Order
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyFullRowMajor
                        (UnaryProxy sub, UnaryProxy super)
numOff (height
height,fuse
fuse,width
width) Order
orderA ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr

multiplyFullColumnMajor ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Shape.C fuse,
    Class.Floating a) =>
   (UnaryProxy sub, UnaryProxy super) ->
   (height, fuse, width) ->
   Order -> Extent.Extent meas vert horiz height fuse ->
   ForeignPtr a -> ForeignPtr a -> Ptr a -> IO ()
multiplyFullColumnMajor :: forall sub super meas vert horiz height width fuse a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, C fuse, Floating a) =>
(UnaryProxy sub, UnaryProxy super)
-> (height, fuse, width)
-> Order
-> Extent meas vert horiz height fuse
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyFullColumnMajor (UnaryProxy sub, UnaryProxy super)
numOff (height
height,fuse
fuse,width
width) Order
orderA Extent meas vert horiz height fuse
extentA ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr = do
   let (Int
m,Int
n) = Full meas vert horiz height fuse -> (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 fuse -> (Int, Int))
-> Full meas vert horiz height fuse -> (Int, Int)
forall a b. (a -> b) -> a -> b
$ Order
-> Extent meas vert horiz height fuse
-> Full meas vert horiz height fuse
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
orderA Extent meas vert horiz height fuse
extentA
   let k :: Int
k = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
   let (Int
kl,Int
ku) = Order -> (UnaryProxy sub, UnaryProxy super) -> (Int, Int)
forall sub super.
(Natural sub, Natural super) =>
Order -> (UnaryProxy sub, UnaryProxy super) -> (Int, Int)
Layout.numOffDiagonals Order
orderA (UnaryProxy sub, UnaryProxy super)
numOff
   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
orderA
      Ptr CInt
mPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
m
      Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
      Ptr CInt
klPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
kl
      Ptr CInt
kuPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
ku
      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 -> FortranIO () (Ptr CInt)) -> Int -> FortranIO () (Ptr CInt)
forall a b. (a -> b) -> a -> b
$ Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
      Ptr a
bPtr <- ((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
b
      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 a. IO a -> ContT () IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
         [(Ptr a, Ptr a)] -> ((Ptr a, Ptr a) -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Int -> [(Ptr a, Ptr a)] -> [(Ptr a, Ptr a)]
forall a. Int -> [a] -> [a]
take Int
k ([(Ptr a, Ptr a)] -> [(Ptr a, Ptr a)])
-> [(Ptr a, Ptr a)] -> [(Ptr a, Ptr a)]
forall a b. (a -> b) -> a -> b
$
                [Ptr a] -> [Ptr a] -> [(Ptr a, Ptr a)]
forall a b. [a] -> [b] -> [(a, b)]
zip (Int -> Ptr a -> [Ptr a]
forall a. Storable a => Int -> Ptr a -> [Ptr a]
pointerSeq (fuse -> Int
forall sh. C sh => sh -> Int
Shape.size fuse
fuse) Ptr a
bPtr)
                    (Int -> Ptr a -> [Ptr a]
forall a. Storable a => Int -> Ptr a -> [Ptr a]
pointerSeq (height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height) Ptr a
cPtr)) (((Ptr a, Ptr a) -> IO ()) -> IO ())
-> ((Ptr a, Ptr a) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
            \(Ptr a
xPtr,Ptr a
yPtr) ->
               Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> 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 CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
Private.gbmv Ptr CChar
transPtr Ptr CInt
mPtr Ptr CInt
nPtr Ptr CInt
klPtr Ptr CInt
kuPtr
                  Ptr a
alphaPtr Ptr a
aPtr Ptr CInt
ldaPtr Ptr a
xPtr Ptr CInt
incxPtr
                  Ptr a
betaPtr Ptr a
yPtr Ptr CInt
incyPtr

multiplyFullRowMajor ::
   (Unary.Natural sub, Unary.Natural super,
    Shape.C height, Shape.C width, Shape.C fuse,
    Class.Floating a) =>
   (UnaryProxy sub, UnaryProxy super) ->
   (height, fuse, width) ->
   Order -> ForeignPtr a -> ForeignPtr a -> Ptr a -> IO ()
multiplyFullRowMajor :: forall sub super height width fuse a.
(Natural sub, Natural super, C height, C width, C fuse,
 Floating a) =>
(UnaryProxy sub, UnaryProxy super)
-> (height, fuse, width)
-> Order
-> ForeignPtr a
-> ForeignPtr a
-> Ptr a
-> IO ()
multiplyFullRowMajor (UnaryProxy sub
sub,UnaryProxy super
super) (height
height,fuse
fuse,width
width) Order
orderA ForeignPtr a
a ForeignPtr a
b Ptr a
cPtr = do
   let m :: Int
m = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
   let n :: Int
n = fuse -> Int
forall sh. C sh => sh -> Int
Shape.size fuse
fuse
   let k :: Int
k = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
   let kl :: Int
kl = UnaryProxy sub -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy sub
sub
   let ku :: Int
ku = UnaryProxy super -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy super
super
   let lda0 :: Int
lda0 = Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
   let lda :: Int
lda = Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1
   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
'N'
      Ptr CInt
kPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
k
      Ptr CInt
dPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
      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 a
bPtr <- ((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
b
      Ptr CInt
ldbPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
k
      Ptr CInt
incxPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint (Int -> FortranIO () (Ptr CInt)) -> Int -> FortranIO () (Ptr CInt)
forall a b. (a -> b) -> a -> b
$
         case Order
orderA of
            Order
RowMajor -> Int
1
            Order
ColumnMajor -> Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
lda0
      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 a. IO a -> ContT () IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
         [(Int, (Ptr a, Ptr a))]
-> ((Int, (Ptr a, Ptr a)) -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Int -> [(Int, (Ptr a, Ptr a))] -> [(Int, (Ptr a, Ptr a))]
forall a. Int -> [a] -> [a]
take Int
m ([(Int, (Ptr a, Ptr a))] -> [(Int, (Ptr a, Ptr a))])
-> [(Int, (Ptr a, Ptr a))] -> [(Int, (Ptr a, Ptr a))]
forall a b. (a -> b) -> a -> b
$ [Int] -> [(Ptr a, Ptr a)] -> [(Int, (Ptr a, Ptr a))]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] ([(Ptr a, Ptr a)] -> [(Int, (Ptr a, Ptr a))])
-> [(Ptr a, Ptr a)] -> [(Int, (Ptr a, Ptr a))]
forall a b. (a -> b) -> a -> b
$
                [Ptr a] -> [Ptr a] -> [(Ptr a, Ptr a)]
forall a b. [a] -> [b] -> [(a, b)]
zip (Int -> Ptr a -> [Ptr a]
forall a. Storable a => Int -> Ptr a -> [Ptr a]
pointerSeq Int
lda Ptr a
aPtr) (Int -> Ptr a -> [Ptr a]
forall a. Storable a => Int -> Ptr a -> [Ptr a]
pointerSeq Int
k Ptr a
cPtr)) (((Int, (Ptr a, Ptr a)) -> IO ()) -> IO ())
-> ((Int, (Ptr a, Ptr a)) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
            \(Int
i,(Ptr a
xPtr,Ptr a
yPtr)) -> do
               let firstRow :: Int
firstRow = (Int, Int) -> Int -> Int
forall a. Ord a => (a, a) -> a -> a
limit (Int
0,Int
n) (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
kl)
               let last1Row :: Int
last1Row = (Int, Int) -> Int -> Int
forall a. Ord a => (a, a) -> a -> a
limit (Int
0,Int
n) (Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kuInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
               let biPtr :: Ptr a
biPtr = Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
firstRowInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
k)
               let xOffset :: Int
xOffset =
                     case Order
orderA of
                        Order
RowMajor -> Int
firstRowInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kl
                        Order
ColumnMajor -> (Int
firstRowInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
i)Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
               let xiPtr :: Ptr a
xiPtr = Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
xPtr Int
xOffset
               Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
dPtr (Int -> IO ()) -> Int -> IO ()
forall a b. (a -> b) -> a -> b
$ Int
last1Row Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
firstRow
               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
kPtr Ptr CInt
dPtr
                  Ptr a
alphaPtr Ptr a
biPtr Ptr CInt
ldbPtr Ptr a
xiPtr Ptr CInt
incxPtr
                  Ptr a
betaPtr Ptr a
yPtr Ptr CInt
incyPtr


forceOrder ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Order ->
   Banded sub super meas vert horiz height width a ->
   Banded sub super meas vert horiz height width a
forceOrder :: forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Floating a) =>
Order
-> Banded sub super meas vert horiz height width a
-> Banded sub super meas vert horiz height width a
forceOrder Order
newOrder Banded sub super meas vert horiz height width a
a =
   if Order
newOrder Order -> Order -> Bool
forall a. Eq a => a -> a -> Bool
== Banded sub super meas vert horiz height width -> Order
forall sub super meas vert horiz height width.
Banded sub super meas vert horiz height width -> Order
Layout.bandedOrder (Banded sub super meas vert horiz height width a
-> Banded sub super meas vert horiz height width
forall sh a. Array sh a -> sh
Array.shape Banded sub super meas vert horiz height width a
a)
      then Banded sub super meas vert horiz height width a
a
      else Banded sub super meas vert horiz height width a
-> Banded sub super meas vert horiz height width a
forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Floating a) =>
Banded sub super meas vert horiz height width a
-> Banded sub super meas vert horiz height width a
flipOrder Banded sub super meas vert horiz height width a
a

flipOrder ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Banded sub super meas vert horiz height width a ->
   Banded sub super meas vert horiz height width a
flipOrder :: forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Floating a) =>
Banded sub super meas vert horiz height width a
-> Banded sub super meas vert horiz height width a
flipOrder (Array (Layout.Banded (UnaryProxy sub
sub,UnaryProxy super
super) Order
order Extent meas vert horiz height width
extent) ForeignPtr a
a) =
   Banded sub super meas vert horiz height width
-> (Ptr a -> IO ())
-> Array (Banded sub super meas vert horiz height width) a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate
      ((UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (UnaryProxy sub
sub,UnaryProxy super
super) (Order -> Order
Layout.flipOrder Order
order) Extent meas vert horiz height width
extent) ((Ptr a -> IO ())
 -> Array (Banded sub super meas vert horiz height width) a)
-> (Ptr a -> IO ())
-> Array (Banded sub super meas vert horiz height width) a
forall a b. (a -> b) -> a -> b
$
      \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 -> do
      let (height
height,width
width) = Extent meas vert horiz height width -> (height, width)
forall meas vert horiz height width.
(Measure meas, C vert, C horiz) =>
Extent meas vert horiz height width -> (height, width)
Extent.dimensions Extent meas vert horiz height width
extent
      let m :: Int
m = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
      let n :: Int
n = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
      let kl :: Int
kl = UnaryProxy sub -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy sub
sub
      let ku :: Int
ku = UnaryProxy super -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy super
super
      case Order
order of
         Order
ColumnMajor -> Int -> Int -> Int -> Int -> Ptr a -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Int -> Ptr a -> Ptr a -> IO ()
flipOrderArray Int
m Int
n Int
kl Int
ku Ptr a
aPtr Ptr a
bPtr
         Order
RowMajor -> Int -> Int -> Int -> Int -> Ptr a -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Int -> Ptr a -> Ptr a -> IO ()
flipOrderArray Int
n Int
m Int
ku Int
kl Ptr a
aPtr Ptr a
bPtr

flipOrderArray ::
   (Class.Floating a) => Int -> Int -> Int -> Int -> Ptr a -> Ptr a -> IO ()
flipOrderArray :: forall a.
Floating a =>
Int -> Int -> Int -> Int -> Ptr a -> Ptr a -> IO ()
flipOrderArray Int
m Int
n Int
kl Int
ku Ptr a
aPtr Ptr a
bPtr = ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
   let lda0 :: Int
lda0 = Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
   let lda :: Int
lda = Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1
   Ptr CInt
incxPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
lda
   Ptr CInt
inczPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
0
   Ptr a
zPtr <- a -> FortranIO () (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
zero
   Ptr CInt
dPtr <- FortranIO () (Ptr CInt)
forall a r. Storable a => FortranIO r (Ptr a)
Call.alloca
   IO () -> ContT () IO ()
forall a. IO a -> ContT () IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ do
      [Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
kl [Int
0..]) ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
i -> do
         let xPtr :: Ptr a
xPtr = Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
i)
         let yPtr :: Ptr a
yPtr = Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr Int
i
         let left :: Int
left = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
m (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
i
         let right :: Int
right = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
m (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
i
         Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
dPtr Int
left
         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
dPtr Ptr a
zPtr Ptr CInt
inczPtr Ptr a
yPtr Ptr CInt
incxPtr
         Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
dPtr (Int
rightInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
left)
         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
dPtr Ptr a
xPtr Ptr CInt
incxPtr
                           (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
yPtr (Int
leftInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda)) Ptr CInt
incxPtr
         Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
dPtr (Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
right)
         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
dPtr Ptr a
zPtr Ptr CInt
inczPtr
                           (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
yPtr (Int
rightInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda)) Ptr CInt
incxPtr
      [Int] -> (Int -> IO ()) -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take (Int
kuInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) [Int
0..]) ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
i -> do
         let xPtr :: Ptr a
xPtr = Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
kuInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
i)
         let yPtr :: Ptr a
yPtr = Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
i)
         let right :: Int
right = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
m (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
i)
         Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
dPtr Int
right
         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
dPtr Ptr a
xPtr Ptr CInt
incxPtr Ptr a
yPtr Ptr CInt
incxPtr
         Ptr CInt -> Int -> IO ()
pokeCInt Ptr CInt
dPtr (Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
right)
         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
dPtr Ptr a
zPtr Ptr CInt
inczPtr
                           (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
yPtr (Int
rightInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda)) Ptr CInt
incxPtr


toLowerTriangular ::
   (Unary.Natural sub, Shape.C sh, Class.Floating a) =>
   Lower sub sh a -> Triangular.Lower sh a
toLowerTriangular :: forall sub sh a.
(Natural sub, C sh, Floating a) =>
Lower sub sh a -> Lower sh a
toLowerTriangular =
   Mosaic Packed NoMirror Upper sh a
-> Array (Mosaic Packed NoMirror Lower sh) a
Mosaic Packed NoMirror Upper sh a
-> Mosaic Packed NoMirror (TriTransposed Upper) sh a
forall uplo pack mirror sh a.
UpLo uplo =>
Mosaic pack mirror uplo sh a
-> Mosaic pack mirror (TriTransposed uplo) sh a
Mosaic.transpose (Mosaic Packed NoMirror Upper sh a
 -> Array (Mosaic Packed NoMirror Lower sh) a)
-> (Lower sub sh a -> Mosaic Packed NoMirror Upper sh a)
-> Lower sub sh a
-> Array (Mosaic Packed NoMirror Lower sh) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Upper sub sh a -> Mosaic Packed NoMirror Upper sh a
forall super sh a.
(Natural super, C sh, Floating a) =>
Upper super sh a -> Upper sh a
toUpperTriangular (Upper sub sh a -> Mosaic Packed NoMirror Upper sh a)
-> (Lower sub sh a -> Upper sub sh a)
-> Lower sub sh a
-> Mosaic Packed NoMirror Upper sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Lower sub sh a -> Upper sub sh a
forall meas vert horiz sub super height width a.
(Measure meas, C vert, C horiz) =>
Banded sub super meas vert horiz height width a
-> Banded super sub meas horiz vert width height a
transpose

toUpperTriangular ::
   (Unary.Natural super, Shape.C sh, Class.Floating a) =>
   Upper super sh a -> Triangular.Upper sh a
toUpperTriangular :: forall super sh a.
(Natural super, C sh, Floating a) =>
Upper super sh a -> Upper sh a
toUpperTriangular (Array (Layout.Banded (UnaryProxy U0
_sub,UnaryProxy super
super) Order
order Extent Shape Small Small sh sh
extent) ForeignPtr a
a) =
   let size :: sh
size = Extent Shape Small Small sh sh -> sh
forall shape. Square shape -> shape
Extent.squareSize Extent Shape Small Small sh sh
extent
   in Triangular Upper sh
-> (Int -> Ptr a -> IO ()) -> Array (Triangular Upper sh) a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize (Order -> sh -> Triangular Upper sh
forall size. Order -> size -> UpperTriangular size
Layout.upperTriangular Order
order sh
size) ((Int -> Ptr a -> IO ()) -> Array (Triangular Upper sh) a)
-> (Int -> Ptr a -> IO ()) -> Array (Triangular Upper sh) a
forall a b. (a -> b) -> a -> b
$
      Int -> Order -> Int -> ForeignPtr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Order -> Int -> ForeignPtr a -> Int -> Ptr a -> IO ()
Mos.fromBanded (UnaryProxy super -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy super
super) Order
order (sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
size) ForeignPtr a
a

toFull ::
   (Unary.Natural sub, Unary.Natural super,
    Extent.Measure meas, Extent.C vert, Extent.C horiz,
    Shape.C height, Shape.C width, Class.Floating a) =>
   Banded sub super meas vert horiz height width a ->
   Matrix.Full meas vert horiz height width a
toFull :: forall sub super meas vert horiz height width a.
(Natural sub, Natural super, Measure meas, C vert, C horiz,
 C height, C width, Floating a) =>
Banded sub super meas vert horiz height width a
-> Full meas vert horiz height width a
toFull (Array (Layout.Banded (UnaryProxy sub
sub,UnaryProxy super
super) Order
order Extent meas vert horiz height width
extent) ForeignPtr a
a) =
   Full meas vert horiz height width
-> (Int -> Ptr a -> IO ())
-> Array (Full meas vert horiz height width) a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize (Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
forall meas vert horiz height width.
Order
-> Extent meas vert horiz height width
-> Full meas vert horiz height width
Layout.Full Order
order Extent meas vert horiz height width
extent) ((Int -> Ptr a -> IO ())
 -> Array (Full meas vert horiz height width) a)
-> (Int -> Ptr a -> IO ())
-> Array (Full meas vert horiz height width) a
forall a b. (a -> b) -> a -> b
$ \Int
bSize 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 -> 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
      a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero Int
bSize Ptr a
bPtr
      case Order
order of
         Order
ColumnMajor -> (UnaryProxy sub, UnaryProxy super)
-> (height, width) -> Ptr a -> Ptr a -> IO ()
forall sub super height width a.
(Natural sub, Natural super, C height, C width, Floating a) =>
(UnaryProxy sub, UnaryProxy super)
-> (height, width) -> Ptr a -> Ptr a -> IO ()
toFullColumnMajor (UnaryProxy sub
sub,UnaryProxy super
super) (height
height,width
width) Ptr a
aPtr Ptr a
bPtr
         Order
RowMajor -> (UnaryProxy super, UnaryProxy sub)
-> (width, height) -> Ptr a -> Ptr a -> IO ()
forall sub super height width a.
(Natural sub, Natural super, C height, C width, Floating a) =>
(UnaryProxy sub, UnaryProxy super)
-> (height, width) -> Ptr a -> Ptr a -> IO ()
toFullColumnMajor (UnaryProxy super
super,UnaryProxy sub
sub) (width
width,height
height) Ptr a
aPtr Ptr a
bPtr

toFullColumnMajor ::
   (Unary.Natural sub, Unary.Natural super, Shape.C height, Shape.C width,
    Class.Floating a) =>
   (UnaryProxy sub, UnaryProxy super) -> (height,width) ->
   Ptr a -> Ptr a -> IO ()
toFullColumnMajor :: forall sub super height width a.
(Natural sub, Natural super, C height, C width, Floating a) =>
(UnaryProxy sub, UnaryProxy super)
-> (height, width) -> Ptr a -> Ptr a -> IO ()
toFullColumnMajor (UnaryProxy sub
sub,UnaryProxy super
super) (height
height,width
width) Ptr a
aPtr Ptr a
bPtr = do
   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 kl :: Int
kl = UnaryProxy sub -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy sub
sub
   let ku :: Int
ku = UnaryProxy super -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy super
super
   let lda0 :: Int
lda0 = Int
klInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
   let lda :: Int
lda = Int
lda0Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1

   IO (Maybe ()) -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO (Maybe ()) -> IO ()) -> IO (Maybe ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ MaybeT IO () -> IO (Maybe ())
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
MM.runMaybeT (MaybeT IO () -> IO (Maybe ())) -> MaybeT IO () -> IO (Maybe ())
forall a b. (a -> b) -> a -> b
$ (ReaderT Int (MaybeT IO) () -> Int -> MaybeT IO ())
-> Int -> ReaderT Int (MaybeT IO) () -> MaybeT IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip ReaderT Int (MaybeT IO) () -> Int -> MaybeT IO ()
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
MR.runReaderT Int
n (ReaderT Int (MaybeT IO) () -> MaybeT IO ())
-> ReaderT Int (MaybeT IO) () -> MaybeT IO ()
forall a b. (a -> b) -> a -> b
$
      if Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lda0
         then do -- diagonal stripe
            let col0 :: Int
col0 = Int
ku
            Int -> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a. Int -> (Int -> IO a) -> ReaderT Int (MaybeT IO) a
withRightBound Int
col0 ((Int -> IO ()) -> ReaderT Int (MaybeT IO) ())
-> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a b. (a -> b) -> a -> b
$ \Int
col ->
               Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyUpperTrapezoid (Int
colInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kl) Int
col Int
lda0 (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr Int
ku) Int
m Ptr a
bPtr
            let col1 :: Int
col1 = Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
kl
            Int -> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a. Int -> (Int -> IO a) -> ReaderT Int (MaybeT IO) a
withRightBound Int
col1 ((Int -> IO ()) -> ReaderT Int (MaybeT IO) ())
-> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a b. (a -> b) -> a -> b
$ \Int
col ->
               Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubMatrix Int
lda (Int
colInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
col0)
                  Int
lda (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
col0Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda))
                  (Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
col0Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
m))
            let col2 :: Int
col2 = Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
            Int -> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a. Int -> (Int -> IO a) -> ReaderT Int (MaybeT IO) a
withRightBound Int
col2 ((Int -> IO ()) -> ReaderT Int (MaybeT IO) ())
-> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a b. (a -> b) -> a -> b
$ \Int
col ->
               Char -> Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Char -> Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubTrapezoid Char
'L' Int
lda0 (Int
colInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
col1)
                  Int
lda0 (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
col1Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda))
                  Int
m (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
col1Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
lda0))
         else do -- full block in the middle
            let col0 :: Int
col0 = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
kl
            Int -> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a. Int -> (Int -> IO a) -> ReaderT Int (MaybeT IO) a
withRightBound Int
col0 ((Int -> IO ()) -> ReaderT Int (MaybeT IO) ())
-> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a b. (a -> b) -> a -> b
$ \Int
col ->
               Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyUpperTrapezoid (Int
colInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
kl) Int
col Int
lda0 (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr Int
ku) Int
m Ptr a
bPtr
            let col1 :: Int
col1 = Int
ku
            Int -> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a. Int -> (Int -> IO a) -> ReaderT Int (MaybeT IO) a
withRightBound Int
col1 ((Int -> IO ()) -> ReaderT Int (MaybeT IO) ())
-> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a b. (a -> b) -> a -> b
$ \Int
col ->
               Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubMatrix Int
m (Int
colInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
col0)
                  Int
lda0 (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
col0Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
ldaInt -> Int -> Int
forall a. Num a => a -> a -> a
+(Int
col1Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
col0)))
                  Int
m (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
col0Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
m))
            let col2 :: Int
col2 = Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
ku
            Int -> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a. Int -> (Int -> IO a) -> ReaderT Int (MaybeT IO) a
withRightBound Int
col2 ((Int -> IO ()) -> ReaderT Int (MaybeT IO) ())
-> (Int -> IO ()) -> ReaderT Int (MaybeT IO) ()
forall a b. (a -> b) -> a -> b
$ \Int
col ->
               Char -> Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Char -> Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubTrapezoid Char
'L' Int
m (Int
colInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
col1)
                  Int
lda0 (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int
kuInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
lda))
                  Int
m (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr (Int
kuInt -> Int -> Int
forall a. Num a => a -> a -> a
*Int
m))

withRightBound ::
   Int -> (Int -> IO a) -> MR.ReaderT Int (MM.MaybeT IO) a
withRightBound :: forall a. Int -> (Int -> IO a) -> ReaderT Int (MaybeT IO) a
withRightBound Int
col Int -> IO a
act = do
   Int
n <- ReaderT Int (MaybeT IO) Int
forall (m :: * -> *) r. Monad m => ReaderT r m r
MR.ask
   if Int
nInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<=Int
col
     then IO a -> ReaderT Int (MaybeT IO) a
forall a. IO a -> ReaderT Int (MaybeT IO) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Int -> IO a
act Int
n) ReaderT Int (MaybeT IO) a
-> ReaderT Int (MaybeT IO) a -> ReaderT Int (MaybeT IO) a
forall a b.
ReaderT Int (MaybeT IO) a
-> ReaderT Int (MaybeT IO) b -> ReaderT Int (MaybeT IO) b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ReaderT Int (MaybeT IO) a
forall a. ReaderT Int (MaybeT IO) a
forall (m :: * -> *) a. MonadPlus m => m a
mzero
     else IO a -> ReaderT Int (MaybeT IO) a
forall a. IO a -> ReaderT Int (MaybeT IO) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Int -> IO a
act Int
col)

copyUpperTrapezoid ::
   (Class.Floating a) =>
   Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyUpperTrapezoid :: forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copyUpperTrapezoid Int
m Int
n Int
lda Ptr a
aPtr Int
ldb Ptr a
bPtr = do
   let d :: Int
d = Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
n
   Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubMatrix Int
d Int
n Int
lda Ptr a
aPtr Int
ldb Ptr a
bPtr
   Char -> Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
forall a.
Floating a =>
Char -> Int -> Int -> Int -> Ptr a -> Int -> Ptr a -> IO ()
copySubTrapezoid Char
'U' Int
n Int
n
      Int
lda (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr Int
d)
      Int
ldb (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
bPtr Int
d)


takeTopLeftSquare ::
   (Unary.Natural sub, Unary.Natural super,
    Shape.C sh0, Shape.C sh1, Class.Floating a) =>
   Square sub super (sh0 ::+ sh1) a ->
   Square sub super sh0 a
takeTopLeftSquare :: forall sub super sh0 sh1 a.
(Natural sub, Natural super, C sh0, C sh1, Floating a) =>
Square sub super (sh0 ::+ sh1) a -> Square sub super sh0 a
takeTopLeftSquare (Array (Layout.Banded (UnaryProxy sub, UnaryProxy super)
offDiag Order
order Extent Shape Small Small (sh0 ::+ sh1) (sh0 ::+ sh1)
extent) ForeignPtr a
a) =
   case Extent Shape Small Small (sh0 ::+ sh1) (sh0 ::+ sh1) -> sh0 ::+ sh1
forall shape. Square shape -> shape
Extent.squareSize Extent Shape Small Small (sh0 ::+ sh1) (sh0 ::+ sh1)
extent of
      sh0
sh0 ::+ sh1
_sh1 ->
         BandedSquare sub super sh0
-> (Int -> Ptr a -> IO ()) -> Square sub super sh0 a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize
               ((UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent Shape Small Small sh0 sh0
-> BandedSquare sub super sh0
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (UnaryProxy sub, UnaryProxy super)
offDiag Order
order (sh0 -> Extent Shape Small Small sh0 sh0
forall sh. sh -> Square sh
Extent.square sh0
sh0)) ((Int -> Ptr a -> IO ()) -> Square sub super sh0 a)
-> (Int -> Ptr a -> IO ()) -> Square sub super sh0 a
forall a b. (a -> b) -> a -> b
$
            \Int
n 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 -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
n Ptr a
aPtr Ptr a
bPtr

takeBottomRightSquare ::
   (Unary.Natural sub, Unary.Natural super,
    Shape.C sh0, Shape.C sh1, Class.Floating a) =>
   Square sub super (sh0 ::+ sh1) a ->
   Square sub super sh1 a
takeBottomRightSquare :: forall sub super sh0 sh1 a.
(Natural sub, Natural super, C sh0, C sh1, Floating a) =>
Square sub super (sh0 ::+ sh1) a -> Square sub super sh1 a
takeBottomRightSquare (Array (Layout.Banded (UnaryProxy sub
sub,UnaryProxy super
super) Order
order Extent Shape Small Small (sh0 ::+ sh1) (sh0 ::+ sh1)
extent) ForeignPtr a
a) =
   case Extent Shape Small Small (sh0 ::+ sh1) (sh0 ::+ sh1) -> sh0 ::+ sh1
forall shape. Square shape -> shape
Extent.squareSize Extent Shape Small Small (sh0 ::+ sh1) (sh0 ::+ sh1)
extent of
      sh0
sh0 ::+ sh1
sh1 ->
         BandedSquare sub super sh1
-> (Int -> Ptr a -> IO ()) -> Square sub super sh1 a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize
            ((UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent Shape Small Small sh1 sh1
-> BandedSquare sub super sh1
forall sub super meas vert horiz height width.
(UnaryProxy sub, UnaryProxy super)
-> Order
-> Extent meas vert horiz height width
-> Banded sub super meas vert horiz height width
Layout.Banded (UnaryProxy sub
sub,UnaryProxy super
super) Order
order (sh1 -> Extent Shape Small Small sh1 sh1
forall sh. sh -> Square sh
Extent.square sh1
sh1)) ((Int -> Ptr a -> IO ()) -> Square sub super sh1 a)
-> (Int -> Ptr a -> IO ()) -> Square sub super sh1 a
forall a b. (a -> b) -> a -> b
$
            \Int
n 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 ->
            Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
n
               (Ptr a -> Int -> Ptr a
forall a. Storable a => Ptr a -> Int -> Ptr a
advancePtr Ptr a
aPtr (Int -> Ptr a) -> Int -> Ptr a
forall a b. (a -> b) -> a -> b
$
                  (UnaryProxy sub -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy sub
sub Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ UnaryProxy super -> Int
forall x y. (Integer x, Num y) => Proxy x -> y
integralFromProxy UnaryProxy super
super)
                     Int -> Int -> Int
forall a. Num a => a -> a -> a
* sh0 -> Int
forall sh. C sh => sh -> Int
Shape.size sh0
sh0)
               Ptr a
bPtr