{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ConstraintKinds #-}
module Numeric.LAPACK.Matrix.Triangular.Basic (
Triangular, MatrixShape.UpLo,
Diagonal,
Upper, FlexUpper, UnitUpper,
Lower, FlexLower, UnitLower,
Symmetric, FlexSymmetric,
fromList, autoFromList,
relaxUnitDiagonal, strictNonUnitDiagonal,
identity,
diagonal,
takeDiagonal,
transpose,
adjoint,
stackDiagonal,
stackLower,
stackUpper,
stackSymmetric,
takeTopLeft,
takeTopRight,
takeBottomLeft,
takeBottomRight,
toSquare,
takeLower,
takeUpper,
fromLowerRowMajor, toLowerRowMajor,
fromUpperRowMajor, toUpperRowMajor,
forceOrder, adaptOrder,
add, sub,
Tri.PowerDiag,
Tri.PowerContentDiag,
multiplyVector,
square, power,
multiply,
multiplyFull,
) where
import qualified Numeric.LAPACK.Matrix.Symmetric.Private as Symmetric
import qualified Numeric.LAPACK.Matrix.Triangular.Private as Tri
import qualified Numeric.LAPACK.Matrix.Private as Matrix
import qualified Numeric.LAPACK.Matrix.Basic as Basic
import qualified Numeric.LAPACK.Matrix.Shape.Private as MatrixShape
import qualified Numeric.LAPACK.Matrix.Extent.Private as Extent
import qualified Numeric.LAPACK.Vector.Private as VectorPriv
import qualified Numeric.LAPACK.Vector as Vector
import Numeric.LAPACK.Matrix.Triangular.Private
(Triangular, FlexDiagonal, diagonalPointers, diagonalPointerPairs,
pack, packRect, unpack, unpackZero, unpackToTemp, uncheck, recheck)
import Numeric.LAPACK.Matrix.Shape.Private
(Order(RowMajor,ColumnMajor),
flipOrder, transposeFromOrder, uploFromOrder, uploOrder,
Unit(Unit), NonUnit(NonUnit), charFromTriDiag)
import Numeric.LAPACK.Matrix.Modifier (Conjugation(NonConjugated))
import Numeric.LAPACK.Matrix.Private (Full, Square, ShapeInt, shapeInt)
import Numeric.LAPACK.Vector (Vector)
import Numeric.LAPACK.Scalar (zero, one)
import Numeric.LAPACK.Shape.Private (Unchecked(Unchecked))
import Numeric.LAPACK.Private (fill, copyBlock)
import qualified Numeric.LAPACK.FFI.Complex as LapackComplex
import qualified Numeric.BLAS.FFI.Real as BlasReal
import qualified Numeric.BLAS.FFI.Generic as BlasGen
import qualified Numeric.Netlib.Utility as Call
import qualified Numeric.Netlib.Class as Class
import qualified Data.Array.Comfort.Storable.Unchecked as Array
import qualified Data.Array.Comfort.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.C.Types (CChar, CInt)
import Foreign.ForeignPtr (withForeignPtr)
import Foreign.Ptr (Ptr)
import Foreign.Storable (Storable, poke, peek)
import Control.Monad.Trans.Cont (ContT(ContT), evalContT)
import Control.Monad.IO.Class (liftIO)
import Data.Function.HT (powerAssociative)
import Data.Foldable (forM_)
import Data.Tuple.HT (double)
type Lower sh = FlexLower NonUnit sh
type Upper sh = FlexUpper NonUnit sh
type Symmetric sh = FlexSymmetric NonUnit sh
type Diagonal sh = FlexDiagonal NonUnit sh
type UnitLower sh = FlexLower Unit sh
type UnitUpper sh = FlexUpper Unit sh
type FlexLower diag sh = Array (MatrixShape.LowerTriangular diag sh)
type FlexUpper diag sh = Array (MatrixShape.UpperTriangular diag sh)
type FlexSymmetric diag sh = Array (MatrixShape.FlexSymmetric diag sh)
transpose ::
(MatrixShape.Content lo, MatrixShape.Content up,
MatrixShape.TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose :: Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose (Array Triangular lo diag up sh
sh ForeignPtr a
a) =
Triangular up diag lo sh
-> ForeignPtr a -> Triangular up diag lo sh a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array (Triangular lo diag up sh -> Triangular up diag lo sh
forall lo up diag sh.
(Content lo, Content up) =>
Triangular lo diag up sh -> Triangular up diag lo sh
MatrixShape.triangularTranspose Triangular lo diag up sh
sh) ForeignPtr a
a
adjoint ::
(MatrixShape.Content lo, MatrixShape.Content up,
MatrixShape.TriDiag diag, Shape.C sh, Class.Floating a) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
adjoint :: Triangular lo diag up sh a -> Triangular up diag lo sh a
adjoint = Triangular up diag lo sh a -> Triangular up diag lo sh a
forall sh a. (C sh, Floating a) => Vector sh a -> Vector sh a
Vector.conjugate (Triangular up diag lo sh a -> Triangular up diag lo sh a)
-> (Triangular lo diag up sh a -> Triangular up diag lo sh a)
-> Triangular lo diag up sh a
-> Triangular up diag lo sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular lo diag up sh a -> Triangular up diag lo sh a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose
fromList ::
(MatrixShape.Content lo, MatrixShape.Content up, Shape.C sh, Storable a) =>
Order -> sh -> [a] -> Triangular lo NonUnit up sh a
fromList :: Order -> sh -> [a] -> Triangular lo NonUnit up sh a
fromList Order
order sh
sh =
Triangular lo NonUnit up sh -> [a] -> Triangular lo NonUnit up sh a
forall sh a. (C sh, Storable a) => sh -> [a] -> Array sh a
CheckedArray.fromList
(NonUnit -> (lo, up) -> Order -> sh -> Triangular lo NonUnit up sh
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular NonUnit
NonUnit (lo, up)
forall lo up. (Content lo, Content up) => (lo, up)
MatrixShape.autoUplo Order
order sh
sh)
autoFromList ::
(MatrixShape.Content lo, MatrixShape.Content up, Storable a) =>
Order -> [a] -> Triangular lo NonUnit up ShapeInt a
autoFromList :: Order -> [a] -> Triangular lo NonUnit up ShapeInt a
autoFromList Order
order [a]
xs =
let n :: Int
n = [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs
triSize :: Int
triSize = String -> Int -> Int
MatrixShape.triangleExtent String
"Triangular.autoFromList" Int
n
uplo :: (lo, up)
uplo = (lo, up)
forall lo up. (Content lo, Content up) => (lo, up)
MatrixShape.autoUplo
size :: Int
size = (lo, up) -> Int -> Int -> Int -> Int -> Int
forall lo up a.
(Content lo, Content up) =>
(lo, up) -> a -> a -> a -> a -> a
MatrixShape.caseDiagUpLoSym (lo, up)
uplo Int
n Int
triSize Int
triSize Int
triSize
in Triangular lo NonUnit up ShapeInt
-> [a] -> Triangular lo NonUnit up ShapeInt a
forall sh a. (C sh, Storable a) => sh -> [a] -> Array sh a
Array.fromList
(NonUnit
-> (lo, up)
-> Order
-> ShapeInt
-> Triangular lo NonUnit up ShapeInt
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular
NonUnit
forall diag. TriDiag diag => diag
MatrixShape.autoDiag (lo, up)
uplo Order
order (Int -> ShapeInt
shapeInt Int
size))
[a]
xs
toSquare ::
(MatrixShape.Content lo, MatrixShape.Content up,
Shape.C sh, Class.Floating a) =>
Triangular lo diag up sh a -> Square sh a
toSquare :: Triangular lo diag up sh a -> Square sh a
toSquare (Array (MatrixShape.Triangular diag
_diag (lo, up)
uplo Order
order sh
sh) ForeignPtr a
a) =
Square sh -> (Int -> Ptr a -> IO ()) -> Square sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize (Order -> sh -> Square sh
forall sh. Order -> sh -> Square sh
MatrixShape.square Order
order sh
sh) ((Int -> Ptr a -> IO ()) -> Square sh a)
-> (Int -> Ptr a -> IO ()) -> Square sh a
forall a b. (a -> b) -> a -> b
$ \Int
size Ptr a
bPtr ->
let n :: Int
n = sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
sh
in 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 ->
(lo, up) -> IO () -> IO () -> IO () -> IO () -> IO ()
forall lo up a.
(Content lo, Content up) =>
(lo, up) -> a -> a -> a -> a -> a
MatrixShape.caseDiagUpLoSym (lo, up)
uplo
(do
a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero Int
size 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
Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
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
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1)
IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ Ptr 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
aPtr Ptr CInt
incxPtr Ptr a
bPtr Ptr CInt
incyPtr)
(Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
unpackZero Order
order Int
n Ptr a
aPtr Ptr a
bPtr)
(Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
unpackZero (Order -> Order
flipOrder Order
order) Int
n Ptr a
aPtr Ptr a
bPtr)
(Conjugation -> Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a.
Floating a =>
Conjugation -> Order -> Int -> Ptr a -> Ptr a -> IO ()
Symmetric.unpack Conjugation
NonConjugated Order
order Int
n Ptr a
aPtr Ptr a
bPtr)
takeLower ::
(Extent.C horiz, Shape.C height, Shape.C width, Class.Floating a) =>
Full Extent.Small horiz height width a -> Lower height a
takeLower :: Full Small horiz height width a -> Lower height a
takeLower =
(NonUnit, Order -> Int -> Ptr a -> IO ())
-> Full Small horiz height width a -> Lower height a
forall diag horiz height width a.
(TriDiag diag, C horiz, C height, C width, Floating a) =>
(diag, Order -> Int -> Ptr a -> IO ())
-> Full Small horiz height width a -> FlexLower diag height a
Tri.takeLower (NonUnit
MatrixShape.NonUnit, (Int -> Ptr a -> IO ()) -> Order -> Int -> Ptr a -> IO ()
forall a b. a -> b -> a
const ((Int -> Ptr a -> IO ()) -> Order -> Int -> Ptr a -> IO ())
-> (Int -> Ptr a -> IO ()) -> Order -> Int -> Ptr a -> IO ()
forall a b. (a -> b) -> a -> b
$ (Ptr a -> IO ()) -> Int -> Ptr a -> IO ()
forall a b. a -> b -> a
const ((Ptr a -> IO ()) -> Int -> Ptr a -> IO ())
-> (Ptr a -> IO ()) -> Int -> Ptr a -> IO ()
forall a b. (a -> b) -> a -> b
$ IO () -> Ptr a -> IO ()
forall a b. a -> b -> a
const (IO () -> Ptr a -> IO ()) -> IO () -> Ptr a -> IO ()
forall a b. (a -> b) -> a -> b
$ () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ())
takeUpper ::
(Extent.C vert, Shape.C height, Shape.C width, Class.Floating a) =>
Full vert Extent.Small height width a -> Upper width a
takeUpper :: Full vert Small height width a -> Upper width a
takeUpper (Array (MatrixShape.Full Order
order Extent vert Small height width
extent) ForeignPtr a
a) =
let (height
height,width
width) = Extent vert Small height width -> (height, width)
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> (height, width)
Extent.dimensions Extent vert Small height width
extent
m :: Int
m = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
n :: Int
n = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
k :: Int
k = case Order
order of Order
RowMajor -> Int
n; Order
ColumnMajor -> Int
m
in Triangular Empty NonUnit Filled width
-> (Ptr a -> IO ()) -> Upper width a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate
(NonUnit
-> (Empty, Filled)
-> Order
-> width
-> Triangular Empty NonUnit Filled width
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular NonUnit
MatrixShape.NonUnit
(Empty, Filled)
MatrixShape.upper Order
order width
width) ((Ptr a -> IO ()) -> Upper width a)
-> (Ptr a -> IO ()) -> Upper 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 -> Order -> Int -> Int -> Ptr a -> Ptr a -> IO ()
forall a.
Floating a =>
Order -> Int -> Int -> Ptr a -> Ptr a -> IO ()
packRect Order
order Int
n Int
k Ptr a
aPtr Ptr a
bPtr
fromLowerRowMajor ::
(Shape.C sh, Class.Floating a) =>
Array (Shape.Triangular Shape.Lower sh) a -> Lower sh a
fromLowerRowMajor :: Array (Triangular Lower sh) a -> Lower sh a
fromLowerRowMajor =
(Triangular Lower sh -> Triangular Filled NonUnit Empty sh)
-> Array (Triangular Lower sh) a -> Lower sh a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
(NonUnit
-> (Filled, Empty)
-> Order
-> sh
-> Triangular Filled NonUnit Empty sh
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular NonUnit
MatrixShape.NonUnit (Filled, Empty)
MatrixShape.lower Order
RowMajor (sh -> Triangular Filled NonUnit Empty sh)
-> (Triangular Lower sh -> sh)
-> Triangular Lower sh
-> Triangular Filled NonUnit Empty sh
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Triangular Lower sh -> sh
forall part size. Triangular part size -> size
Shape.triangularSize)
fromUpperRowMajor ::
(Shape.C sh, Class.Floating a) =>
Array (Shape.Triangular Shape.Upper sh) a -> Upper sh a
fromUpperRowMajor :: Array (Triangular Upper sh) a -> Upper sh a
fromUpperRowMajor =
(Triangular Upper sh -> Triangular Empty NonUnit Filled sh)
-> Array (Triangular Upper sh) a -> Upper sh a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
(NonUnit
-> (Empty, Filled)
-> Order
-> sh
-> Triangular Empty NonUnit Filled sh
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular NonUnit
MatrixShape.NonUnit (Empty, Filled)
MatrixShape.upper Order
RowMajor (sh -> Triangular Empty NonUnit Filled sh)
-> (Triangular Upper sh -> sh)
-> Triangular Upper sh
-> Triangular Empty NonUnit Filled sh
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Triangular Upper sh -> sh
forall part size. Triangular part size -> size
Shape.triangularSize)
toLowerRowMajor ::
(Shape.C sh, Class.Floating a) =>
Lower sh a -> Array (Shape.Triangular Shape.Lower sh) a
toLowerRowMajor :: Lower sh a -> Array (Triangular Lower sh) a
toLowerRowMajor =
(Triangular Filled NonUnit Empty sh -> Triangular Lower sh)
-> Lower sh a -> Array (Triangular Lower sh) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (Lower -> sh -> Triangular Lower sh
forall part size. part -> size -> Triangular part size
Shape.Triangular Lower
Shape.Lower (sh -> Triangular Lower sh)
-> (Triangular Filled NonUnit Empty sh -> sh)
-> Triangular Filled NonUnit Empty sh
-> Triangular Lower sh
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Filled NonUnit Empty sh -> sh
forall lo diag up size. Triangular lo diag up size -> size
MatrixShape.triangularSize)
(Lower sh a -> Array (Triangular Lower sh) a)
-> (Lower sh a -> Lower sh a)
-> Lower sh a
-> Array (Triangular Lower sh) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Order -> Lower sh a -> Lower sh a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forceOrder Order
MatrixShape.RowMajor
toUpperRowMajor ::
(Shape.C sh, Class.Floating a) =>
Upper sh a -> Array (Shape.Triangular Shape.Upper sh) a
toUpperRowMajor :: Upper sh a -> Array (Triangular Upper sh) a
toUpperRowMajor =
(Triangular Empty NonUnit Filled sh -> Triangular Upper sh)
-> Upper sh a -> Array (Triangular Upper sh) a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (Upper -> sh -> Triangular Upper sh
forall part size. part -> size -> Triangular part size
Shape.Triangular Upper
Shape.Upper (sh -> Triangular Upper sh)
-> (Triangular Empty NonUnit Filled sh -> sh)
-> Triangular Empty NonUnit Filled sh
-> Triangular Upper sh
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Empty NonUnit Filled sh -> sh
forall lo diag up size. Triangular lo diag up size -> size
MatrixShape.triangularSize)
(Upper sh a -> Array (Triangular Upper sh) a)
-> (Upper sh a -> Upper sh a)
-> Upper sh a
-> Array (Triangular Upper sh) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Order -> Upper sh a -> Upper sh a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forceOrder Order
MatrixShape.RowMajor
forceOrder ::
(MatrixShape.Content lo, MatrixShape.Content up, MatrixShape.TriDiag diag,
Shape.C sh, Class.Floating a) =>
Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forceOrder :: Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forceOrder Order
newOrder =
Map diag sh sh a lo up
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
forall diag sh0 sh1 a lo up.
Map diag sh0 sh1 a lo up
-> Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a
Tri.getMap (Map diag sh sh a lo up
-> Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> Map diag sh sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
forall a b. (a -> b) -> a -> b
$
Map diag sh sh a Empty Empty
-> Map diag sh sh a Empty Filled
-> Map diag sh sh a Filled Empty
-> Map diag sh sh a Filled Filled
-> Map diag sh sh a lo up
forall lo up (f :: * -> * -> *).
(Content lo, Content up) =>
f Empty Empty
-> f Empty Filled -> f Filled Empty -> f Filled Filled -> f lo up
MatrixShape.switchDiagUpLoSym
((Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a)
-> Map diag sh sh a Empty Empty
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a)
-> Map diag sh sh a Empty Empty)
-> (Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a)
-> Map diag sh sh a Empty Empty
forall a b. (a -> b) -> a -> b
$
(Triangular Empty diag Empty sh -> Triangular Empty diag Empty sh)
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (\Triangular Empty diag Empty sh
sh -> Triangular Empty diag Empty sh
sh{triangularOrder :: Order
MatrixShape.triangularOrder = Order
newOrder}))
(Order
-> (Square sh a -> Triangular Empty NonUnit Filled sh a)
-> Map diag sh sh a Empty Filled
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order
-> (Square sh a -> Triangular lo NonUnit up sh a)
-> Map diag sh sh a lo up
forceOrderMap Order
newOrder Square sh a -> Triangular Empty NonUnit Filled sh a
forall vert height width a.
(C vert, C height, C width, Floating a) =>
Full vert Small height width a -> Upper width a
takeUpper)
(Order
-> (Square sh a -> Triangular Filled NonUnit Empty sh a)
-> Map diag sh sh a Filled Empty
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order
-> (Square sh a -> Triangular lo NonUnit up sh a)
-> Map diag sh sh a lo up
forceOrderMap Order
newOrder Square sh a -> Triangular Filled NonUnit Empty sh a
forall horiz height width a.
(C horiz, C height, C width, Floating a) =>
Full Small horiz height width a -> Lower height a
takeLower)
(Order
-> (Square sh a -> Triangular Filled NonUnit Filled sh a)
-> Map diag sh sh a Filled Filled
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order
-> (Square sh a -> Triangular lo NonUnit up sh a)
-> Map diag sh sh a lo up
forceOrderMap Order
newOrder ((Square sh a -> Triangular Filled NonUnit Filled sh a)
-> Map diag sh sh a Filled Filled)
-> (Square sh a -> Triangular Filled NonUnit Filled sh a)
-> Map diag sh sh a Filled Filled
forall a b. (a -> b) -> a -> b
$
(Triangular Empty NonUnit Filled sh
-> Triangular Filled NonUnit Filled sh)
-> Triangular Empty NonUnit Filled sh a
-> Triangular Filled NonUnit Filled sh a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape
(\Triangular Empty NonUnit Filled sh
sh -> Triangular Empty NonUnit Filled sh
sh{triangularUplo :: (Filled, Filled)
MatrixShape.triangularUplo = (Filled, Filled)
forall lo up. (Content lo, Content up) => (lo, up)
MatrixShape.autoUplo})
(Triangular Empty NonUnit Filled sh a
-> Triangular Filled NonUnit Filled sh a)
-> (Square sh a -> Triangular Empty NonUnit Filled sh a)
-> Square sh a
-> Triangular Filled NonUnit Filled sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Square sh a -> Triangular Empty NonUnit Filled sh a
forall vert height width a.
(C vert, C height, C width, Floating a) =>
Full vert Small height width a -> Upper width a
takeUpper)
forceOrderMap ::
(MatrixShape.Content lo, MatrixShape.Content up, MatrixShape.TriDiag diag,
Shape.C sh, Class.Floating a) =>
Order ->
(Square sh a -> Triangular lo NonUnit up sh a) ->
Tri.Map diag sh sh a lo up
forceOrderMap :: Order
-> (Square sh a -> Triangular lo NonUnit up sh a)
-> Map diag sh sh a lo up
forceOrderMap Order
newOrder Square sh a -> Triangular lo NonUnit up sh a
f = (Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> Map diag sh sh a lo up
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> Map diag sh sh a lo up)
-> (Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> Map diag sh sh a lo up
forall a b. (a -> b) -> a -> b
$ \Triangular lo diag up sh a
a ->
if Triangular lo diag up sh -> Order
forall lo diag up size. Triangular lo diag up size -> Order
MatrixShape.triangularOrder (Triangular lo diag up sh a -> Triangular lo diag up sh
forall sh a. Array sh a -> sh
Array.shape Triangular lo diag up sh a
a) Order -> Order -> Bool
forall a. Eq a => a -> a -> Bool
== Order
newOrder
then Triangular lo diag up sh a
a
else Triangular lo NonUnit up sh a -> Triangular lo diag up sh a
forall diag lo up sh a.
TriDiag diag =>
Triangular lo NonUnit up sh a -> Triangular lo diag up sh a
uncheckedRelaxNonUnitDiagonal (Triangular lo NonUnit up sh a -> Triangular lo diag up sh a)
-> Triangular lo NonUnit up sh a -> Triangular lo diag up sh a
forall a b. (a -> b) -> a -> b
$
Square sh a -> Triangular lo NonUnit up sh a
f (Square sh a -> Triangular lo NonUnit up sh a)
-> Square sh a -> Triangular lo NonUnit up sh a
forall a b. (a -> b) -> a -> b
$ Order -> Square sh a -> Square sh a
forall vert horiz height width a.
(C vert, C horiz, C height, C width, Floating a) =>
Order
-> Full vert horiz height width a -> Full vert horiz height width a
Basic.forceOrder Order
newOrder (Square sh a -> Square sh a) -> Square sh a -> Square sh a
forall a b. (a -> b) -> a -> b
$ Triangular lo diag up sh a -> Square sh a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Square sh a
toSquare Triangular lo diag up sh a
a
uncheckedRelaxNonUnitDiagonal ::
(MatrixShape.TriDiag diag) =>
Triangular lo NonUnit up sh a -> Triangular lo diag up sh a
uncheckedRelaxNonUnitDiagonal :: Triangular lo NonUnit up sh a -> Triangular lo diag up sh a
uncheckedRelaxNonUnitDiagonal =
(Triangular lo NonUnit up sh -> Triangular lo diag up sh)
-> Triangular lo NonUnit up sh a -> Triangular lo diag up sh a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (\Triangular lo NonUnit up sh
sh -> Triangular lo NonUnit up sh
sh{triangularDiag :: diag
MatrixShape.triangularDiag = diag
forall diag. TriDiag diag => diag
MatrixShape.autoDiag})
adaptOrder ::
(MatrixShape.Content lo, MatrixShape.Content up, MatrixShape.TriDiag diag,
Shape.C sh, Class.Floating a) =>
Triangular lo diag up sh a ->
Triangular lo diag up sh a ->
Triangular lo diag up sh a
adaptOrder :: Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
adaptOrder Triangular lo diag up sh a
x = Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forceOrder (Triangular lo diag up sh -> Order
forall lo diag up size. Triangular lo diag up size -> Order
MatrixShape.triangularOrder (Triangular lo diag up sh -> Order)
-> Triangular lo diag up sh -> Order
forall a b. (a -> b) -> a -> b
$ Triangular lo diag up sh a -> Triangular lo diag up sh
forall sh a. Array sh a -> sh
Array.shape Triangular lo diag up sh a
x)
add, sub ::
(MatrixShape.Content lo, MatrixShape.Content up,
Eq lo, Eq up, Eq sh, Shape.C sh, Class.Floating a) =>
Triangular lo NonUnit up sh a ->
Triangular lo NonUnit up sh a ->
Triangular lo NonUnit up sh a
add :: Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a -> Triangular lo NonUnit up sh a
add Triangular lo NonUnit up sh a
x Triangular lo NonUnit up sh a
y = Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a -> Triangular lo NonUnit up sh a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
Vector.add (Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a -> Triangular lo NonUnit up sh a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
adaptOrder Triangular lo NonUnit up sh a
y Triangular lo NonUnit up sh a
x) Triangular lo NonUnit up sh a
y
sub :: Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a -> Triangular lo NonUnit up sh a
sub Triangular lo NonUnit up sh a
x Triangular lo NonUnit up sh a
y = Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a -> Triangular lo NonUnit up sh a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
Vector.sub (Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a -> Triangular lo NonUnit up sh a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
adaptOrder Triangular lo NonUnit up sh a
y Triangular lo NonUnit up sh a
x) Triangular lo NonUnit up sh a
y
identity ::
(MatrixShape.Content lo, MatrixShape.Content up,
Shape.C sh, Class.Floating a) =>
Order -> sh -> Triangular lo Unit up sh a
identity :: Order -> sh -> Triangular lo Unit up sh a
identity Order
order sh
sh =
let (Order
realOrder, (lo, up)
uplo) = Order -> (Order, (lo, up))
forall lo up.
(Content lo, Content up) =>
Order -> (Order, (lo, up))
autoUploOrder Order
order
in Triangular lo Unit up sh
-> (Int -> Ptr a -> IO ()) -> Triangular lo Unit up sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize (Unit -> (lo, up) -> Order -> sh -> Triangular lo Unit up sh
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular Unit
Unit (lo, up)
uplo Order
order sh
sh) ((Int -> Ptr a -> IO ()) -> Triangular lo Unit up sh a)
-> (Int -> Ptr a -> IO ()) -> Triangular lo Unit up sh a
forall a b. (a -> b) -> a -> b
$
\Int
size Ptr a
aPtr -> do
let n :: Int
n = sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
sh
let fillTriangle :: IO ()
fillTriangle = do
a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero Int
size Ptr a
aPtr
(Ptr a -> IO ()) -> [Ptr a] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ ((Ptr a -> a -> IO ()) -> a -> Ptr a -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip Ptr a -> a -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke a
forall a. Floating a => a
one) (Order -> Int -> Ptr a -> [Ptr a]
forall a. Storable a => Order -> Int -> Ptr a -> [Ptr a]
diagonalPointers Order
realOrder Int
n Ptr a
aPtr)
(lo, up) -> IO () -> IO () -> IO () -> IO () -> IO ()
forall lo up a.
(Content lo, Content up) =>
(lo, up) -> a -> a -> a -> a -> a
MatrixShape.caseDiagUpLoSym (lo, up)
uplo
(a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
one Int
n Ptr a
aPtr)
IO ()
fillTriangle
IO ()
fillTriangle
IO ()
fillTriangle
diagonal, diagonalAux ::
(MatrixShape.Content lo, MatrixShape.Content up,
Shape.C sh, Class.Floating a) =>
Order -> Vector sh a -> Triangular lo NonUnit up sh a
diagonal :: Order -> Vector sh a -> Triangular lo NonUnit up sh a
diagonal Order
order x :: Vector sh a
x@(Array sh
sh ForeignPtr a
xPtr) =
let uplo :: (lo, up)
uplo = (lo, up)
forall lo up. (Content lo, Content up) => (lo, up)
MatrixShape.autoUplo
in (lo, up)
-> Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a
-> Triangular lo NonUnit up sh a
forall lo up a.
(Content lo, Content up) =>
(lo, up) -> a -> a -> a -> a -> a
MatrixShape.caseDiagUpLoSym (lo, up)
uplo
(Triangular lo NonUnit up sh
-> ForeignPtr a -> Triangular lo NonUnit up sh a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array (NonUnit -> (lo, up) -> Order -> sh -> Triangular lo NonUnit up sh
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular NonUnit
NonUnit (lo, up)
uplo Order
order sh
sh) ForeignPtr a
xPtr)
(Order -> Vector sh a -> Triangular lo NonUnit up sh a
forall lo up sh a.
(Content lo, Content up, C sh, Floating a) =>
Order -> Vector sh a -> Triangular lo NonUnit up sh a
diagonalAux Order
order Vector sh a
x)
(Order -> Vector sh a -> Triangular lo NonUnit up sh a
forall lo up sh a.
(Content lo, Content up, C sh, Floating a) =>
Order -> Vector sh a -> Triangular lo NonUnit up sh a
diagonalAux Order
order Vector sh a
x)
(Order -> Vector sh a -> Triangular lo NonUnit up sh a
forall lo up sh a.
(Content lo, Content up, C sh, Floating a) =>
Order -> Vector sh a -> Triangular lo NonUnit up sh a
diagonalAux Order
order Vector sh a
x)
diagonalAux :: Order -> Vector sh a -> Triangular lo NonUnit up sh a
diagonalAux Order
order (Array sh
sh ForeignPtr a
x) =
let (Order
realOrder, (lo, up)
uplo) = Order -> (Order, (lo, up))
forall lo up.
(Content lo, Content up) =>
Order -> (Order, (lo, up))
autoUploOrder Order
order
in Triangular lo NonUnit up sh
-> (Int -> Ptr a -> IO ()) -> Triangular lo NonUnit up sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize
(NonUnit -> (lo, up) -> Order -> sh -> Triangular lo NonUnit up sh
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular NonUnit
NonUnit (lo, up)
uplo Order
order sh
sh) ((Int -> Ptr a -> IO ()) -> Triangular lo NonUnit up sh a)
-> (Int -> Ptr a -> IO ()) -> Triangular lo NonUnit up sh a
forall a b. (a -> b) -> a -> b
$
\Int
size Ptr a
aPtr -> do
let n :: Int
n = sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
sh
a -> Int -> Ptr a -> IO ()
forall a. Floating a => a -> Int -> Ptr a -> IO ()
fill a
forall a. Floating a => a
zero Int
size Ptr a
aPtr
ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
x ((Ptr a -> IO ()) -> IO ()) -> (Ptr a -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr a
xPtr ->
[(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_ (Order -> Int -> Ptr a -> Ptr a -> [(Ptr a, Ptr a)]
forall a b.
(Storable a, Storable b) =>
Order -> Int -> Ptr a -> Ptr b -> [(Ptr a, Ptr b)]
diagonalPointerPairs Order
realOrder Int
n Ptr a
xPtr Ptr a
aPtr) (((Ptr a, Ptr a) -> IO ()) -> IO ())
-> ((Ptr a, Ptr a) -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$
\(Ptr a
srcPtr,Ptr a
dstPtr) -> Ptr a -> a -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr a
dstPtr (a -> IO ()) -> IO a -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr a -> IO a
forall a. Storable a => Ptr a -> IO a
peek Ptr a
srcPtr
takeDiagonal, takeDiagonalAux ::
(MatrixShape.Content lo, MatrixShape.Content up,
Shape.C sh, Class.Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonal :: Triangular lo diag up sh a -> Vector sh a
takeDiagonal a :: Triangular lo diag up sh a
a@(Array (MatrixShape.Triangular diag
_diag (lo, up)
uplo Order
_order sh
sh) ForeignPtr a
aPtr) =
(lo, up)
-> Vector sh a
-> Vector sh a
-> Vector sh a
-> Vector sh a
-> Vector sh a
forall lo up a.
(Content lo, Content up) =>
(lo, up) -> a -> a -> a -> a -> a
MatrixShape.caseDiagUpLoSym (lo, up)
uplo
(sh -> ForeignPtr a -> Vector sh a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array sh
sh ForeignPtr a
aPtr)
(Triangular lo diag up sh a -> Vector sh a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonalAux Triangular lo diag up sh a
a)
(Triangular lo diag up sh a -> Vector sh a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonalAux Triangular lo diag up sh a
a)
(Triangular lo diag up sh a -> Vector sh a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonalAux Triangular lo diag up sh a
a)
takeDiagonalAux :: Triangular lo diag up sh a -> Vector sh a
takeDiagonalAux (Array (MatrixShape.Triangular diag
_diag (lo, up)
uplo Order
order sh
sh) ForeignPtr a
a) =
sh -> (Ptr a -> IO ()) -> Vector sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate sh
sh ((Ptr a -> IO ()) -> Vector sh a)
-> (Ptr a -> IO ()) -> Vector sh a
forall a b. (a -> b) -> a -> b
$ \Ptr a
xPtr ->
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 ->
((Ptr a, Ptr a) -> IO ()) -> [(Ptr a, Ptr a)] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
(\(Ptr a
dstPtr,Ptr a
srcPtr) -> Ptr a -> a -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr a
dstPtr (a -> IO ()) -> IO a -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Ptr a -> IO a
forall a. Storable a => Ptr a -> IO a
peek Ptr a
srcPtr)
(Order -> Int -> Ptr a -> Ptr a -> [(Ptr a, Ptr a)]
forall a b.
(Storable a, Storable b) =>
Order -> Int -> Ptr a -> Ptr b -> [(Ptr a, Ptr b)]
diagonalPointerPairs ((lo, up) -> Order -> Order
forall lo up.
(Content lo, Content up) =>
(lo, up) -> Order -> Order
uploOrder (lo, up)
uplo Order
order) (sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
sh) Ptr a
xPtr Ptr a
aPtr)
relaxUnitDiagonal ::
(MatrixShape.TriDiag diag) =>
Triangular lo Unit up sh a -> Triangular lo diag up sh a
relaxUnitDiagonal :: Triangular lo Unit up sh a -> Triangular lo diag up sh a
relaxUnitDiagonal = (Triangular lo Unit up sh -> Triangular lo diag up sh)
-> Triangular lo Unit up sh a -> Triangular lo diag up sh a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape Triangular lo Unit up sh -> Triangular lo diag up sh
forall diag lo up sh.
TriDiag diag =>
Triangular lo Unit up sh -> Triangular lo diag up sh
MatrixShape.relaxUnitDiagonal
strictNonUnitDiagonal ::
(MatrixShape.TriDiag diag) =>
Triangular lo diag up sh a -> Triangular lo NonUnit up sh a
strictNonUnitDiagonal :: Triangular lo diag up sh a -> Triangular lo NonUnit up sh a
strictNonUnitDiagonal = (Triangular lo diag up sh -> Triangular lo NonUnit up sh)
-> Triangular lo diag up sh a -> Triangular lo NonUnit up sh a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape Triangular lo diag up sh -> Triangular lo NonUnit up sh
forall diag lo up sh.
TriDiag diag =>
Triangular lo diag up sh -> Triangular lo NonUnit up sh
MatrixShape.strictNonUnitDiagonal
liftDiagonal ::
(Vector sh0 a -> Vector sh1 a) ->
FlexDiagonal diag sh0 a -> FlexDiagonal diag sh1 a
liftDiagonal :: (Vector sh0 a -> Vector sh1 a)
-> FlexDiagonal diag sh0 a -> FlexDiagonal diag sh1 a
liftDiagonal Vector sh0 a -> Vector sh1 a
f (Array (MatrixShape.Triangular diag
diag (Empty, Empty)
uplo Order
order sh0
sh0) ForeignPtr a
a) =
(sh1 -> Triangular Empty diag Empty sh1)
-> Vector sh1 a -> FlexDiagonal diag sh1 a
forall sh0 sh1 a. (sh0 -> sh1) -> Array sh0 a -> Array sh1 a
Array.mapShape (diag
-> (Empty, Empty)
-> Order
-> sh1
-> Triangular Empty diag Empty sh1
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular diag
diag (Empty, Empty)
uplo Order
order) (Vector sh1 a -> FlexDiagonal diag sh1 a)
-> Vector sh1 a -> FlexDiagonal diag sh1 a
forall a b. (a -> b) -> a -> b
$ Vector sh0 a -> Vector sh1 a
f (Vector sh0 a -> Vector sh1 a) -> Vector sh0 a -> Vector sh1 a
forall a b. (a -> b) -> a -> b
$ sh0 -> ForeignPtr a -> Vector sh0 a
forall sh a. sh -> ForeignPtr a -> Array sh a
Array sh0
sh0 ForeignPtr a
a
stackDiagonal ::
(MatrixShape.TriDiag diag, Shape.C sh0, Shape.C sh1, Class.Floating a) =>
FlexDiagonal diag sh0 a ->
FlexDiagonal diag sh1 a ->
FlexDiagonal diag (sh0:+:sh1) a
stackDiagonal :: FlexDiagonal diag sh0 a
-> FlexDiagonal diag sh1 a -> FlexDiagonal diag (sh0 :+: sh1) a
stackDiagonal FlexDiagonal diag sh0 a
a = (Vector sh1 a -> Vector (sh0 :+: sh1) a)
-> FlexDiagonal diag sh1 a -> FlexDiagonal diag (sh0 :+: sh1) a
forall sh0 a sh1 diag.
(Vector sh0 a -> Vector sh1 a)
-> FlexDiagonal diag sh0 a -> FlexDiagonal diag sh1 a
liftDiagonal (Array sh0 a -> Vector sh1 a -> Vector (sh0 :+: sh1) a
forall shx shy a.
(C shx, C shy, Storable a) =>
Array shx a -> Array shy a -> Array (shx :+: shy) a
Vector.append (Array sh0 a -> Vector sh1 a -> Vector (sh0 :+: sh1) a)
-> Array sh0 a -> Vector sh1 a -> Vector (sh0 :+: sh1) a
forall a b. (a -> b) -> a -> b
$ FlexDiagonal diag sh0 a -> Array sh0 a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonal FlexDiagonal diag sh0 a
a)
stackLower ::
(MatrixShape.TriDiag diag,
Shape.C sh0, Eq sh0, Shape.C sh1, Eq sh1, Class.Floating a) =>
FlexLower diag sh0 a ->
Matrix.General sh1 sh0 a ->
FlexLower diag sh1 a ->
FlexLower diag (sh0:+:sh1) a
stackLower :: FlexLower diag sh0 a
-> General sh1 sh0 a
-> FlexLower diag sh1 a
-> FlexLower diag (sh0 :+: sh1) a
stackLower FlexLower diag sh0 a
a General sh1 sh0 a
b FlexLower diag sh1 a
c =
Triangular Empty diag Filled (sh0 :+: sh1) a
-> FlexLower diag (sh0 :+: sh1) a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose (Triangular Empty diag Filled (sh0 :+: sh1) a
-> FlexLower diag (sh0 :+: sh1) a)
-> Triangular Empty diag Filled (sh0 :+: sh1) a
-> FlexLower diag (sh0 :+: sh1) a
forall a b. (a -> b) -> a -> b
$
String
-> Triangular Empty diag Filled sh0 a
-> General sh0 sh1 a
-> Triangular Empty diag Filled sh1 a
-> Triangular Empty diag Filled (sh0 :+: sh1) a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, Eq sh0, C sh1, Eq sh1,
Floating a) =>
String
-> Triangular lo diag Filled sh0 a
-> General sh0 sh1 a
-> Triangular lo diag Filled sh1 a
-> Triangular lo diag Filled (sh0 :+: sh1) a
stackAux String
"LowerTriangular" (FlexLower diag sh0 a -> Triangular Empty diag Filled sh0 a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose FlexLower diag sh0 a
a) (General sh1 sh0 a -> General sh0 sh1 a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
Basic.transpose General sh1 sh0 a
b) (FlexLower diag sh1 a -> Triangular Empty diag Filled sh1 a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose FlexLower diag sh1 a
c)
stackUpper ::
(MatrixShape.TriDiag diag,
Shape.C sh0, Eq sh0, Shape.C sh1, Eq sh1, Class.Floating a) =>
FlexUpper diag sh0 a ->
Matrix.General sh0 sh1 a ->
FlexUpper diag sh1 a ->
FlexUpper diag (sh0:+:sh1) a
stackUpper :: FlexUpper diag sh0 a
-> General sh0 sh1 a
-> FlexUpper diag sh1 a
-> FlexUpper diag (sh0 :+: sh1) a
stackUpper = String
-> FlexUpper diag sh0 a
-> General sh0 sh1 a
-> FlexUpper diag sh1 a
-> FlexUpper diag (sh0 :+: sh1) a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, Eq sh0, C sh1, Eq sh1,
Floating a) =>
String
-> Triangular lo diag Filled sh0 a
-> General sh0 sh1 a
-> Triangular lo diag Filled sh1 a
-> Triangular lo diag Filled (sh0 :+: sh1) a
stackAux String
"UpperTriangular"
stackSymmetric ::
(MatrixShape.TriDiag diag,
Shape.C sh0, Eq sh0, Shape.C sh1, Eq sh1, Class.Floating a) =>
FlexSymmetric diag sh0 a ->
Matrix.General sh0 sh1 a ->
FlexSymmetric diag sh1 a ->
FlexSymmetric diag (sh0:+:sh1) a
stackSymmetric :: FlexSymmetric diag sh0 a
-> General sh0 sh1 a
-> FlexSymmetric diag sh1 a
-> FlexSymmetric diag (sh0 :+: sh1) a
stackSymmetric = String
-> FlexSymmetric diag sh0 a
-> General sh0 sh1 a
-> FlexSymmetric diag sh1 a
-> FlexSymmetric diag (sh0 :+: sh1) a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, Eq sh0, C sh1, Eq sh1,
Floating a) =>
String
-> Triangular lo diag Filled sh0 a
-> General sh0 sh1 a
-> Triangular lo diag Filled sh1 a
-> Triangular lo diag Filled (sh0 :+: sh1) a
stackAux String
"Symmetric"
stackAux ::
(MatrixShape.Content lo, MatrixShape.TriDiag diag,
Shape.C sh0, Eq sh0, Shape.C sh1, Eq sh1, Class.Floating a) =>
String ->
Triangular lo diag MatrixShape.Filled sh0 a ->
Matrix.General sh0 sh1 a ->
Triangular lo diag MatrixShape.Filled sh1 a ->
Triangular lo diag MatrixShape.Filled (sh0:+:sh1) a
stackAux :: String
-> Triangular lo diag Filled sh0 a
-> General sh0 sh1 a
-> Triangular lo diag Filled sh1 a
-> Triangular lo diag Filled (sh0 :+: sh1) a
stackAux String
name Triangular lo diag Filled sh0 a
a General sh0 sh1 a
b Triangular lo diag Filled sh1 a
c =
let order :: Order
order = Full Big Big sh0 sh1 -> Order
forall vert horiz height width.
Full vert horiz height width -> Order
MatrixShape.fullOrder (Full Big Big sh0 sh1 -> Order) -> Full Big Big sh0 sh1 -> Order
forall a b. (a -> b) -> a -> b
$ General sh0 sh1 a -> Full Big Big sh0 sh1
forall sh a. Array sh a -> sh
Array.shape General sh0 sh1 a
b
in String
-> ((sh0 :+: sh1) -> Triangular lo diag Filled (sh0 :+: sh1))
-> Triangular lo diag Filled sh0 a
-> General sh0 sh1 a
-> Triangular lo diag Filled sh1 a
-> Triangular lo diag Filled (sh0 :+: sh1) a
forall sh0 height sh1 width sh2 a.
(Box sh0, HeightOf sh0 ~ height, C height, Eq height, Box sh1,
WidthOf sh1 ~ width, C width, Eq width, C sh2, Floating a) =>
String
-> ((height :+: width) -> sh2)
-> Array sh0 a
-> General height width a
-> Array sh1 a
-> Array sh2 a
Tri.stack String
name
(\sh0 :+: sh1
sh ->
(Triangular lo diag Filled sh0 a -> Triangular lo diag Filled sh0
forall sh a. Array sh a -> sh
Array.shape Triangular lo diag Filled sh0 a
a) {
triangularOrder :: Order
MatrixShape.triangularOrder = Order
order,
triangularSize :: sh0 :+: sh1
MatrixShape.triangularSize = sh0 :+: sh1
sh})
(Order
-> Triangular lo diag Filled sh0 a
-> Triangular lo diag Filled sh0 a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forceOrder Order
order Triangular lo diag Filled sh0 a
a) General sh0 sh1 a
b (Order
-> Triangular lo diag Filled sh1 a
-> Triangular lo diag Filled sh1 a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag, C sh, Floating a) =>
Order -> Triangular lo diag up sh a -> Triangular lo diag up sh a
forceOrder Order
order Triangular lo diag Filled sh1 a
c)
takeTopLeft ::
(MatrixShape.Content lo, MatrixShape.TriDiag diag, MatrixShape.Content up,
Shape.C sh0, Shape.C sh1, Class.Floating a) =>
Triangular lo diag up (sh0:+:sh1) a ->
Triangular lo diag up sh0 a
takeTopLeft :: Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh0 a
takeTopLeft =
Map diag (sh0 :+: sh1) sh0 a lo up
-> Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh0 a
forall diag sh0 sh1 a lo up.
Map diag sh0 sh1 a lo up
-> Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a
Tri.getMap (Map diag (sh0 :+: sh1) sh0 a lo up
-> Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a lo up
-> Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh0 a
forall a b. (a -> b) -> a -> b
$
Map diag (sh0 :+: sh1) sh0 a Empty Empty
-> Map diag (sh0 :+: sh1) sh0 a Empty Filled
-> Map diag (sh0 :+: sh1) sh0 a Filled Empty
-> Map diag (sh0 :+: sh1) sh0 a Filled Filled
-> Map diag (sh0 :+: sh1) sh0 a lo up
forall lo up (f :: * -> * -> *).
(Content lo, Content up) =>
f Empty Empty
-> f Empty Filled -> f Filled Empty -> f Filled Filled -> f lo up
MatrixShape.switchDiagUpLoSym
((Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Empty Empty
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Empty Empty)
-> (Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Empty Empty
forall a b. (a -> b) -> a -> b
$ (Vector (sh0 :+: sh1) a -> Vector sh0 a)
-> Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh0 a
forall sh0 a sh1 diag.
(Vector sh0 a -> Vector sh1 a)
-> FlexDiagonal diag sh0 a -> FlexDiagonal diag sh1 a
liftDiagonal Vector (sh0 :+: sh1) a -> Vector sh0 a
forall sh0 sh1 a.
(C sh0, C sh1, Storable a) =>
Array (sh0 :+: sh1) a -> Array sh0 a
Vector.takeLeft)
((Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Empty Filled
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Empty Filled)
-> (Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Empty Filled
forall a b. (a -> b) -> a -> b
$ Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, C sh1, Floating a) =>
Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh0 a
takeTopLeftAux)
((Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Filled Empty
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Filled Empty)
-> (Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Filled Empty
forall a b. (a -> b) -> a -> b
$ Triangular Empty diag Filled sh0 a
-> Triangular Filled diag Empty sh0 a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose (Triangular Empty diag Filled sh0 a
-> Triangular Filled diag Empty sh0 a)
-> (Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a)
-> Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh0 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, C sh1, Floating a) =>
Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh0 a
takeTopLeftAux (Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a)
-> (Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled (sh0 :+: sh1) a)
-> Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh0 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled (sh0 :+: sh1) a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose)
((Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Filled Filled
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Filled Filled)
-> (Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh0 a)
-> Map diag (sh0 :+: sh1) sh0 a Filled Filled
forall a b. (a -> b) -> a -> b
$ Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh0 a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, C sh1, Floating a) =>
Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh0 a
takeTopLeftAux)
takeTopLeftAux ::
(MatrixShape.Content lo, MatrixShape.TriDiag diag,
Shape.C sh0, Shape.C sh1, Class.Floating a) =>
Triangular lo diag MatrixShape.Filled (sh0:+:sh1) a ->
Triangular lo diag MatrixShape.Filled sh0 a
takeTopLeftAux :: Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh0 a
takeTopLeftAux =
(Triangular lo diag Filled (sh0 :+: sh1)
-> (Triangular lo diag Filled sh0, (Order, sh0 :+: sh1)))
-> Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh0 a
forall sh sha height width a.
(C sh, C sha, C height, C width, Floating a) =>
(sh -> (sha, (Order, height :+: width)))
-> Array sh a -> Array sha a
Tri.takeTopLeft
(\(MatrixShape.Triangular diag
diag (lo, Filled)
uplo Order
order sh :: sh0 :+: sh1
sh@(sh0
sh0:+:sh1
_sh1)) ->
(diag
-> (lo, Filled) -> Order -> sh0 -> Triangular lo diag Filled sh0
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular diag
diag (lo, Filled)
uplo Order
order sh0
sh0, (Order
order,sh0 :+: sh1
sh)))
takeBottomLeft ::
(MatrixShape.TriDiag diag, MatrixShape.Content up,
Shape.C sh0, Shape.C sh1, Class.Floating a) =>
Triangular MatrixShape.Filled diag up (sh0:+:sh1) a ->
Matrix.General sh1 sh0 a
takeBottomLeft :: Triangular Filled diag up (sh0 :+: sh1) a -> General sh1 sh0 a
takeBottomLeft = Full Big Big sh0 sh1 a -> General sh1 sh0 a
forall vert horiz height width a.
(C vert, C horiz) =>
Full vert horiz height width a -> Full horiz vert width height a
Basic.transpose (Full Big Big sh0 sh1 a -> General sh1 sh0 a)
-> (Triangular Filled diag up (sh0 :+: sh1) a
-> Full Big Big sh0 sh1 a)
-> Triangular Filled diag up (sh0 :+: sh1) a
-> General sh1 sh0 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular up diag Filled (sh0 :+: sh1) a -> Full Big Big sh0 sh1 a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, C sh1, Floating a) =>
Triangular lo diag Filled (sh0 :+: sh1) a -> General sh0 sh1 a
takeTopRight (Triangular up diag Filled (sh0 :+: sh1) a
-> Full Big Big sh0 sh1 a)
-> (Triangular Filled diag up (sh0 :+: sh1) a
-> Triangular up diag Filled (sh0 :+: sh1) a)
-> Triangular Filled diag up (sh0 :+: sh1) a
-> Full Big Big sh0 sh1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Filled diag up (sh0 :+: sh1) a
-> Triangular up diag Filled (sh0 :+: sh1) a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose
takeTopRight ::
(MatrixShape.Content lo, MatrixShape.TriDiag diag,
Shape.C sh0, Shape.C sh1, Class.Floating a) =>
Triangular lo diag MatrixShape.Filled (sh0:+:sh1) a ->
Matrix.General sh0 sh1 a
takeTopRight :: Triangular lo diag Filled (sh0 :+: sh1) a -> General sh0 sh1 a
takeTopRight =
(Triangular lo diag Filled (sh0 :+: sh1) -> (Order, sh0 :+: sh1))
-> Triangular lo diag Filled (sh0 :+: sh1) a -> General sh0 sh1 a
forall sh height width a.
(C sh, C height, C width, Floating a) =>
(sh -> (Order, height :+: width))
-> Array sh a -> General height width a
Tri.takeTopRight
(\(MatrixShape.Triangular diag
_diag (lo, Filled)
_uplo Order
order sh0 :+: sh1
sh) -> (Order
order,sh0 :+: sh1
sh))
takeBottomRight ::
(MatrixShape.Content lo, MatrixShape.TriDiag diag, MatrixShape.Content up,
Shape.C sh0, Shape.C sh1, Class.Floating a) =>
Triangular lo diag up (sh0:+:sh1) a ->
Triangular lo diag up sh1 a
takeBottomRight :: Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh1 a
takeBottomRight =
Map diag (sh0 :+: sh1) sh1 a lo up
-> Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh1 a
forall diag sh0 sh1 a lo up.
Map diag sh0 sh1 a lo up
-> Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a
Tri.getMap (Map diag (sh0 :+: sh1) sh1 a lo up
-> Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a lo up
-> Triangular lo diag up (sh0 :+: sh1) a
-> Triangular lo diag up sh1 a
forall a b. (a -> b) -> a -> b
$
Map diag (sh0 :+: sh1) sh1 a Empty Empty
-> Map diag (sh0 :+: sh1) sh1 a Empty Filled
-> Map diag (sh0 :+: sh1) sh1 a Filled Empty
-> Map diag (sh0 :+: sh1) sh1 a Filled Filled
-> Map diag (sh0 :+: sh1) sh1 a lo up
forall lo up (f :: * -> * -> *).
(Content lo, Content up) =>
f Empty Empty
-> f Empty Filled -> f Filled Empty -> f Filled Filled -> f lo up
MatrixShape.switchDiagUpLoSym
((Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Empty Empty
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Empty Empty)
-> (Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Empty Empty
forall a b. (a -> b) -> a -> b
$ (Vector (sh0 :+: sh1) a -> Vector sh1 a)
-> Triangular Empty diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Empty sh1 a
forall sh0 a sh1 diag.
(Vector sh0 a -> Vector sh1 a)
-> FlexDiagonal diag sh0 a -> FlexDiagonal diag sh1 a
liftDiagonal Vector (sh0 :+: sh1) a -> Vector sh1 a
forall sh0 sh1 a.
(C sh0, C sh1, Storable a) =>
Array (sh0 :+: sh1) a -> Array sh1 a
Vector.takeRight)
((Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Empty Filled
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Empty Filled)
-> (Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Empty Filled
forall a b. (a -> b) -> a -> b
$ Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, C sh1, Floating a) =>
Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh1 a
takeBottomRightAux)
((Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Filled Empty
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Filled Empty)
-> (Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Filled Empty
forall a b. (a -> b) -> a -> b
$ Triangular Empty diag Filled sh1 a
-> Triangular Filled diag Empty sh1 a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose (Triangular Empty diag Filled sh1 a
-> Triangular Filled diag Empty sh1 a)
-> (Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a)
-> Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Filled diag Empty sh1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, C sh1, Floating a) =>
Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh1 a
takeBottomRightAux (Triangular Empty diag Filled (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a)
-> (Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled (sh0 :+: sh1) a)
-> Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled sh1 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Filled diag Empty (sh0 :+: sh1) a
-> Triangular Empty diag Filled (sh0 :+: sh1) a
forall lo up diag sh a.
(Content lo, Content up, TriDiag diag) =>
Triangular lo diag up sh a -> Triangular up diag lo sh a
transpose)
((Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Filled Filled
forall diag sh0 sh1 a lo up.
(Triangular lo diag up sh0 a -> Triangular lo diag up sh1 a)
-> Map diag sh0 sh1 a lo up
Tri.Map ((Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Filled Filled)
-> (Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh1 a)
-> Map diag (sh0 :+: sh1) sh1 a Filled Filled
forall a b. (a -> b) -> a -> b
$ Triangular Filled diag Filled (sh0 :+: sh1) a
-> Triangular Filled diag Filled sh1 a
forall lo diag sh0 sh1 a.
(Content lo, TriDiag diag, C sh0, C sh1, Floating a) =>
Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh1 a
takeBottomRightAux)
takeBottomRightAux ::
(MatrixShape.Content lo, MatrixShape.TriDiag diag,
Shape.C sh0, Shape.C sh1, Class.Floating a) =>
Triangular lo diag MatrixShape.Filled (sh0:+:sh1) a ->
Triangular lo diag MatrixShape.Filled sh1 a
takeBottomRightAux :: Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh1 a
takeBottomRightAux =
(Triangular lo diag Filled (sh0 :+: sh1)
-> (Triangular lo diag Filled sh1, (Order, sh0 :+: sh1)))
-> Triangular lo diag Filled (sh0 :+: sh1) a
-> Triangular lo diag Filled sh1 a
forall sh sha height width a.
(C sh, C sha, C height, C width, Floating a) =>
(sh -> (sha, (Order, height :+: width)))
-> Array sh a -> Array sha a
Tri.takeBottomRight
(\(MatrixShape.Triangular diag
diag (lo, Filled)
uplo Order
order sh :: sh0 :+: sh1
sh@(sh0
_sh0:+:sh1
sh1)) ->
(diag
-> (lo, Filled) -> Order -> sh1 -> Triangular lo diag Filled sh1
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular diag
diag (lo, Filled)
uplo Order
order sh1
sh1, (Order
order,sh0 :+: sh1
sh)))
multiplyVector ::
(MatrixShape.Content lo, MatrixShape.Content up, MatrixShape.TriDiag diag,
Shape.C sh, Eq sh, Class.Floating a) =>
Triangular lo diag up sh a -> Vector sh a -> Vector sh a
multiplyVector :: Triangular lo diag up sh a -> Vector sh a -> Vector sh a
multiplyVector =
MultiplyRight diag sh a (Vector sh a -> Vector sh a) lo up
-> Triangular lo diag up sh a -> Vector sh a -> Vector sh a
forall diag sh a b lo up.
MultiplyRight diag sh a b lo up -> Triangular lo diag up sh a -> b
Tri.getMultiplyRight (MultiplyRight diag sh a (Vector sh a -> Vector sh a) lo up
-> Triangular lo diag up sh a -> Vector sh a -> Vector sh a)
-> MultiplyRight diag sh a (Vector sh a -> Vector sh a) lo up
-> Triangular lo diag up sh a
-> Vector sh a
-> Vector sh a
forall a b. (a -> b) -> a -> b
$
MultiplyRight diag sh a (Vector sh a -> Vector sh a) Empty Empty
-> MultiplyRight
diag sh a (Vector sh a -> Vector sh a) Empty Filled
-> MultiplyRight
diag sh a (Vector sh a -> Vector sh a) Filled Empty
-> MultiplyRight
diag sh a (Vector sh a -> Vector sh a) Filled Filled
-> MultiplyRight diag sh a (Vector sh a -> Vector sh a) lo up
forall lo up (f :: * -> * -> *).
(Content lo, Content up) =>
f Empty Empty
-> f Empty Filled -> f Filled Empty -> f Filled Filled -> f lo up
MatrixShape.switchDiagUpLoSym
((Triangular Empty diag Empty sh a -> Vector sh a -> Vector sh a)
-> MultiplyRight diag sh a (Vector sh a -> Vector sh a) Empty Empty
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight ((Triangular Empty diag Empty sh a -> Vector sh a -> Vector sh a)
-> MultiplyRight
diag sh a (Vector sh a -> Vector sh a) Empty Empty)
-> (Triangular Empty diag Empty sh a -> Vector sh a -> Vector sh a)
-> MultiplyRight diag sh a (Vector sh a -> Vector sh a) Empty Empty
forall a b. (a -> b) -> a -> b
$ Vector sh a -> Vector sh a -> Vector sh a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
Vector.mul (Vector sh a -> Vector sh a -> Vector sh a)
-> (Triangular Empty diag Empty sh a -> Vector sh a)
-> Triangular Empty diag Empty sh a
-> Vector sh a
-> Vector sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Empty diag Empty sh a -> Vector sh a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonal)
((Triangular Empty diag Filled sh a -> Vector sh a -> Vector sh a)
-> MultiplyRight
diag sh a (Vector sh a -> Vector sh a) Empty Filled
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight Triangular Empty diag Filled sh a -> Vector sh a -> Vector sh a
forall lo up diag sh a.
(UpLoSym lo up, TriDiag diag, C sh, Eq sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a -> Vector sh a
multiplyVectorTriangular)
((Triangular Filled diag Empty sh a -> Vector sh a -> Vector sh a)
-> MultiplyRight
diag sh a (Vector sh a -> Vector sh a) Filled Empty
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight Triangular Filled diag Empty sh a -> Vector sh a -> Vector sh a
forall lo up diag sh a.
(UpLoSym lo up, TriDiag diag, C sh, Eq sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a -> Vector sh a
multiplyVectorTriangular)
((Triangular Filled diag Filled sh a -> Vector sh a -> Vector sh a)
-> MultiplyRight
diag sh a (Vector sh a -> Vector sh a) Filled Filled
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight Triangular Filled diag Filled sh a -> Vector sh a -> Vector sh a
forall lo up diag sh a.
(UpLoSym lo up, TriDiag diag, C sh, Eq sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a -> Vector sh a
multiplyVectorTriangular)
multiplyVectorTriangular ::
(MatrixShape.UpLoSym lo up, MatrixShape.TriDiag diag,
Shape.C sh, Eq sh, Class.Floating a) =>
Triangular lo diag up sh a -> Vector sh a -> Vector sh a
multiplyVectorTriangular :: Triangular lo diag up sh a -> Vector sh a -> Vector sh a
multiplyVectorTriangular
(Array (MatrixShape.Triangular diag
diag (lo, up)
uplo Order
order sh
shA) ForeignPtr a
a) (Array sh
shX ForeignPtr a
x) =
sh -> (Ptr a -> IO ()) -> Vector sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate sh
shX ((Ptr a -> IO ()) -> Vector sh a)
-> (Ptr a -> IO ()) -> Vector sh a
forall a b. (a -> b) -> a -> b
$ \Ptr a
yPtr -> do
String -> Bool -> IO ()
Call.assert String
"Triangular.multiplyVector: width shapes mismatch" (sh
shA sh -> sh -> Bool
forall a. Eq a => a -> a -> Bool
== sh
shX)
let n :: Int
n = sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
shA
ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
Ptr CChar
uploPtr <- Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char (Char -> FortranIO () (Ptr CChar))
-> Char -> FortranIO () (Ptr CChar)
forall a b. (a -> b) -> a -> b
$ Order -> Char
uploFromOrder (Order -> Char) -> Order -> Char
forall a b. (a -> b) -> a -> b
$ (lo, up) -> Order -> Order
forall lo up.
(Content lo, Content up) =>
(lo, up) -> Order -> Order
uploOrder (lo, up)
uplo Order
order
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 CChar
diagPtr <- 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
$ diag -> Char
forall diag. TriDiag diag => diag -> Char
charFromTriDiag diag
diag
Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
Ptr a
aPtr <- ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall k (r :: k) (m :: k -> *) a.
((a -> m r) -> m r) -> ContT r m a
ContT (((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a))
-> ((Ptr a -> IO ()) -> IO ()) -> ContT () IO (Ptr a)
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> (Ptr a -> IO ()) -> IO ()
forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr a
a
Ptr 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
Ptr a
alphaPtr <- a -> ContT () IO (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
one
Ptr a
betaPtr <- a -> ContT () IO (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
zero
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
let runTPMV :: IO ()
runTPMV = do
Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
n Ptr a
xPtr Ptr a
yPtr
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
BlasGen.tpmv Ptr CChar
uploPtr Ptr CChar
transPtr Ptr CChar
diagPtr Ptr CInt
nPtr Ptr a
aPtr Ptr a
yPtr Ptr CInt
incyPtr
IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
(lo, up) -> IO () -> IO () -> IO () -> IO ()
forall lo up a. UpLoSym lo up => (lo, up) -> a -> a -> a -> a
MatrixShape.caseUpLoSym (lo, up)
uplo
IO ()
runTPMV
IO ()
runTPMV
(Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
spmv Ptr CChar
uploPtr Ptr CInt
nPtr Ptr a
alphaPtr Ptr a
aPtr Ptr a
xPtr Ptr CInt
incxPtr Ptr a
betaPtr Ptr a
yPtr Ptr CInt
incyPtr)
newtype SPMV a =
SPMV {
SPMV a
-> Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
getSPMV ::
Ptr CChar -> Ptr CInt -> Ptr a -> Ptr a ->
Ptr a -> Ptr CInt -> Ptr a -> Ptr a -> Ptr CInt -> IO ()
}
spmv :: Class.Floating a =>
Ptr CChar -> Ptr CInt -> Ptr a -> Ptr a ->
Ptr a -> Ptr CInt -> Ptr a -> Ptr a -> Ptr CInt -> IO ()
spmv :: Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
spmv =
SPMV a
-> Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
SPMV a
-> Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
getSPMV (SPMV a
-> Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ())
-> SPMV a
-> Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
forall a b. (a -> b) -> a -> b
$
SPMV Float
-> SPMV Double
-> SPMV (Complex Float)
-> SPMV (Complex Double)
-> SPMV a
forall a (f :: * -> *).
Floating a =>
f Float
-> f Double -> f (Complex Float) -> f (Complex Double) -> f a
Class.switchFloating
((Ptr CChar
-> Ptr CInt
-> Ptr Float
-> Ptr Float
-> Ptr Float
-> Ptr CInt
-> Ptr Float
-> Ptr Float
-> Ptr CInt
-> IO ())
-> SPMV Float
forall a.
(Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ())
-> SPMV a
SPMV Ptr CChar
-> Ptr CInt
-> Ptr Float
-> Ptr Float
-> Ptr Float
-> Ptr CInt
-> Ptr Float
-> Ptr Float
-> Ptr CInt
-> IO ()
forall a.
Real a =>
Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
BlasReal.spmv) ((Ptr CChar
-> Ptr CInt
-> Ptr Double
-> Ptr Double
-> Ptr Double
-> Ptr CInt
-> Ptr Double
-> Ptr Double
-> Ptr CInt
-> IO ())
-> SPMV Double
forall a.
(Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ())
-> SPMV a
SPMV Ptr CChar
-> Ptr CInt
-> Ptr Double
-> Ptr Double
-> Ptr Double
-> Ptr CInt
-> Ptr Double
-> Ptr Double
-> Ptr CInt
-> IO ()
forall a.
Real a =>
Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
BlasReal.spmv)
((Ptr CChar
-> Ptr CInt
-> Ptr (Complex Float)
-> Ptr (Complex Float)
-> Ptr (Complex Float)
-> Ptr CInt
-> Ptr (Complex Float)
-> Ptr (Complex Float)
-> Ptr CInt
-> IO ())
-> SPMV (Complex Float)
forall a.
(Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ())
-> SPMV a
SPMV Ptr CChar
-> Ptr CInt
-> Ptr (Complex Float)
-> Ptr (Complex Float)
-> Ptr (Complex Float)
-> Ptr CInt
-> Ptr (Complex Float)
-> Ptr (Complex Float)
-> Ptr CInt
-> IO ()
forall a.
Real a =>
Ptr CChar
-> Ptr CInt
-> Ptr (Complex a)
-> Ptr (Complex a)
-> Ptr (Complex a)
-> Ptr CInt
-> Ptr (Complex a)
-> Ptr (Complex a)
-> Ptr CInt
-> IO ()
LapackComplex.spmv) ((Ptr CChar
-> Ptr CInt
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> Ptr CInt
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> Ptr CInt
-> IO ())
-> SPMV (Complex Double)
forall a.
(Ptr CChar
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ())
-> SPMV a
SPMV Ptr CChar
-> Ptr CInt
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> Ptr CInt
-> Ptr (Complex Double)
-> Ptr (Complex Double)
-> Ptr CInt
-> IO ()
forall a.
Real a =>
Ptr CChar
-> Ptr CInt
-> Ptr (Complex a)
-> Ptr (Complex a)
-> Ptr (Complex a)
-> Ptr CInt
-> Ptr (Complex a)
-> Ptr (Complex a)
-> Ptr CInt
-> IO ()
LapackComplex.spmv)
square ::
(MatrixShape.Content lo, MatrixShape.Content up, MatrixShape.TriDiag diag,
Shape.C sh, Class.Floating a) =>
Triangular lo diag up sh a ->
Triangular lo (Tri.PowerDiag lo up diag) up sh a
square :: Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
square =
Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
forall diag sh a lo up.
Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
Tri.getPower (Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
forall a b. (a -> b) -> a -> b
$
Power diag sh a Empty Empty
-> Power diag sh a Empty Filled
-> Power diag sh a Filled Empty
-> Power diag sh a Filled Filled
-> Power diag sh a lo up
forall lo up (f :: * -> * -> *).
(Content lo, Content up) =>
f Empty Empty
-> f Empty Filled -> f Filled Empty -> f Filled Filled -> f lo up
MatrixShape.switchDiagUpLoSym
((Triangular Empty diag Empty sh a
-> Triangular Empty (PowerDiag Empty Empty diag) Empty sh a)
-> Power diag sh a Empty Empty
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power Triangular Empty diag Empty sh a
-> Triangular Empty (PowerDiag Empty Empty diag) Empty sh a
forall diag sh a.
(TriDiag diag, C sh, Floating a) =>
FlexDiagonal diag sh a -> FlexDiagonal diag sh a
squareDiagonal)
((Triangular Empty diag Filled sh a
-> Triangular Empty (PowerDiag Empty Filled diag) Filled sh a)
-> Power diag sh a Empty Filled
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power Triangular Empty diag Filled sh a
-> Triangular Empty (PowerDiag Empty Filled diag) Filled sh a
forall lo up diag sh a.
(UpLo lo up, TriDiag diag, C sh, Floating a) =>
Triangular lo diag up sh a -> Triangular lo diag up sh a
squareTriangular)
((Triangular Filled diag Empty sh a
-> Triangular Filled (PowerDiag Filled Empty diag) Empty sh a)
-> Power diag sh a Filled Empty
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power Triangular Filled diag Empty sh a
-> Triangular Filled (PowerDiag Filled Empty diag) Empty sh a
forall lo up diag sh a.
(UpLo lo up, TriDiag diag, C sh, Floating a) =>
Triangular lo diag up sh a -> Triangular lo diag up sh a
squareTriangular)
((Triangular Filled diag Filled sh a
-> Triangular Filled (PowerDiag Filled Filled diag) Filled sh a)
-> Power diag sh a Filled Filled
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power ((Triangular Filled diag Filled sh a
-> Triangular Filled (PowerDiag Filled Filled diag) Filled sh a)
-> Power diag sh a Filled Filled)
-> (Triangular Filled diag Filled sh a
-> Triangular Filled (PowerDiag Filled Filled diag) Filled sh a)
-> Power diag sh a Filled Filled
forall a b. (a -> b) -> a -> b
$ Symmetric sh a -> Symmetric sh a
forall sh a. (C sh, Floating a) => Symmetric sh a -> Symmetric sh a
squareSymmetric (Symmetric sh a -> Symmetric sh a)
-> (Triangular Filled diag Filled sh a -> Symmetric sh a)
-> Triangular Filled diag Filled sh a
-> Symmetric sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Filled diag Filled sh a -> Symmetric sh a
forall diag lo up sh a.
TriDiag diag =>
Triangular lo diag up sh a -> Triangular lo NonUnit up sh a
strictNonUnitDiagonal)
squareDiagonal ::
(MatrixShape.TriDiag diag, Shape.C sh, Class.Floating a) =>
FlexDiagonal diag sh a -> FlexDiagonal diag sh a
squareDiagonal :: FlexDiagonal diag sh a -> FlexDiagonal diag sh a
squareDiagonal =
MapDiag Empty Empty sh a diag
-> FlexDiagonal diag sh a -> FlexDiagonal diag sh a
forall lo up sh a diag.
MapDiag lo up sh a diag
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
getMapDiag (MapDiag Empty Empty sh a diag
-> FlexDiagonal diag sh a -> FlexDiagonal diag sh a)
-> MapDiag Empty Empty sh a diag
-> FlexDiagonal diag sh a
-> FlexDiagonal diag sh a
forall a b. (a -> b) -> a -> b
$
MapDiag Empty Empty sh a Unit
-> MapDiag Empty Empty sh a NonUnit
-> MapDiag Empty Empty sh a diag
forall diag (f :: * -> *).
TriDiag diag =>
f Unit -> f NonUnit -> f diag
MatrixShape.switchTriDiag
((Triangular Empty Unit Empty sh a
-> Triangular Empty Unit Empty sh a)
-> MapDiag Empty Empty sh a Unit
forall lo up sh a diag.
(Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> MapDiag lo up sh a diag
MapDiag Triangular Empty Unit Empty sh a
-> Triangular Empty Unit Empty sh a
forall a. a -> a
id)
((Triangular Empty NonUnit Empty sh a
-> Triangular Empty NonUnit Empty sh a)
-> MapDiag Empty Empty sh a NonUnit
forall lo up sh a diag.
(Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> MapDiag lo up sh a diag
MapDiag ((Triangular Empty NonUnit Empty sh a
-> Triangular Empty NonUnit Empty sh a)
-> MapDiag Empty Empty sh a NonUnit)
-> (Triangular Empty NonUnit Empty sh a
-> Triangular Empty NonUnit Empty sh a)
-> MapDiag Empty Empty sh a NonUnit
forall a b. (a -> b) -> a -> b
$
Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> Triangular Empty NonUnit Empty sh a
forall sh a. Array (Unchecked sh) a -> Array sh a
VectorPriv.recheck (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> Triangular Empty NonUnit Empty sh a)
-> (Triangular Empty NonUnit Empty sh a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
-> Triangular Empty NonUnit Empty sh a
-> Triangular Empty NonUnit Empty sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
-> (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a,
Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
Vector.mul ((Array (Unchecked (Triangular Empty NonUnit Empty sh)) a,
Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
-> (Triangular Empty NonUnit Empty sh a
-> (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a,
Array (Unchecked (Triangular Empty NonUnit Empty sh)) a))
-> Triangular Empty NonUnit Empty sh a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a,
Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
forall a. a -> (a, a)
double (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
-> (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a,
Array (Unchecked (Triangular Empty NonUnit Empty sh)) a))
-> (Triangular Empty NonUnit Empty sh a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
-> Triangular Empty NonUnit Empty sh a
-> (Array (Unchecked (Triangular Empty NonUnit Empty sh)) a,
Array (Unchecked (Triangular Empty NonUnit Empty sh)) a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Empty NonUnit Empty sh a
-> Array (Unchecked (Triangular Empty NonUnit Empty sh)) a
forall sh a. Array sh a -> Array (Unchecked sh) a
VectorPriv.uncheck)
newtype MapDiag lo up sh a diag =
MapDiag {
MapDiag lo up sh a diag
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
getMapDiag ::
Triangular lo diag up sh a ->
Triangular lo diag up sh a
}
squareTriangular ::
(MatrixShape.UpLo lo up, MatrixShape.TriDiag diag,
Shape.C sh, Class.Floating a) =>
Triangular lo diag up sh a -> Triangular lo diag up sh a
squareTriangular :: Triangular lo diag up sh a -> Triangular lo diag up sh a
squareTriangular
(Array shape :: Triangular lo diag up sh
shape@(MatrixShape.Triangular diag
diag (lo, up)
uplo Order
order sh
sh) ForeignPtr a
a) =
Triangular lo diag up sh
-> (Ptr a -> IO ()) -> Triangular lo diag up sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate Triangular lo diag up sh
shape ((Ptr a -> IO ()) -> Triangular lo diag up sh a)
-> (Ptr a -> IO ()) -> Triangular lo diag up sh a
forall a b. (a -> b) -> a -> b
$ \Ptr a
bpPtr -> do
let n :: Int
n = sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
sh
ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
Ptr CChar
sidePtr <- Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char Char
'L'
let realOrder :: Order
realOrder = (lo, up) -> Order -> Order
forall lo up.
(Content lo, Content up) =>
(lo, up) -> Order -> Order
uploOrder (lo, up)
uplo Order
order
Ptr CChar
uploPtr <- 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
uploFromOrder Order
realOrder
Ptr CChar
transPtr <- Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char Char
'N'
Ptr CChar
diagPtr <- 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
$ diag -> Char
forall diag. TriDiag diag => diag -> Char
charFromTriDiag diag
diag
Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
Ptr CInt
ldPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
n
Ptr a
aPtr <- (Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT () IO (Ptr a)
forall a r.
Storable a =>
(Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT r IO (Ptr a)
unpackToTemp (Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
unpack Order
realOrder) Int
n ForeignPtr a
a
Ptr a
bPtr <- (Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT () IO (Ptr a)
forall a r.
Storable a =>
(Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT r IO (Ptr a)
unpackToTemp (Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
unpackZero Order
realOrder) Int
n ForeignPtr a
a
Ptr a
alphaPtr <- a -> ContT () IO (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
one
IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ do
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
BlasGen.trmm Ptr CChar
sidePtr Ptr CChar
uploPtr Ptr CChar
transPtr Ptr CChar
diagPtr
Ptr CInt
nPtr Ptr CInt
nPtr Ptr a
alphaPtr Ptr a
aPtr Ptr CInt
ldPtr Ptr a
bPtr Ptr CInt
ldPtr
Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
pack Order
realOrder Int
n Ptr a
bPtr Ptr a
bpPtr
squareSymmetric ::
(Shape.C sh, Class.Floating a) => Symmetric sh a -> Symmetric sh a
squareSymmetric :: Symmetric sh a -> Symmetric sh a
squareSymmetric (Array shape :: FlexSymmetric NonUnit sh
shape@(MatrixShape.Triangular NonUnit
_diag (Filled, Filled)
_uplo Order
order sh
sh) ForeignPtr a
a) =
FlexSymmetric NonUnit sh -> (Ptr a -> IO ()) -> Symmetric sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate FlexSymmetric NonUnit sh
shape ((Ptr a -> IO ()) -> Symmetric sh a)
-> (Ptr a -> IO ()) -> Symmetric sh a
forall a b. (a -> b) -> a -> b
$
Conjugation -> Order -> Int -> ForeignPtr a -> Ptr a -> IO ()
forall a.
Floating a =>
Conjugation -> Order -> Int -> ForeignPtr a -> Ptr a -> IO ()
Symmetric.square Conjugation
NonConjugated Order
order (sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
sh) ForeignPtr a
a
power ::
(MatrixShape.Content lo, MatrixShape.Content up, MatrixShape.TriDiag diag,
Shape.C sh, Class.Floating a) =>
Int ->
Triangular lo diag up sh a ->
Triangular lo (Tri.PowerDiag lo up diag) up sh a
power :: Int
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
power Int
n =
Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
forall diag sh a lo up.
Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
Tri.getPower (Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a
forall a b. (a -> b) -> a -> b
$
Power diag sh a Empty Empty
-> Power diag sh a Empty Filled
-> Power diag sh a Filled Empty
-> Power diag sh a Filled Filled
-> Power diag sh a lo up
forall lo up (f :: * -> * -> *).
(Content lo, Content up) =>
f Empty Empty
-> f Empty Filled -> f Filled Empty -> f Filled Filled -> f lo up
MatrixShape.switchDiagUpLoSym
((Triangular Empty diag Empty sh a
-> Triangular Empty (PowerDiag Empty Empty diag) Empty sh a)
-> Power diag sh a Empty Empty
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power ((Triangular Empty diag Empty sh a
-> Triangular Empty (PowerDiag Empty Empty diag) Empty sh a)
-> Power diag sh a Empty Empty)
-> (Triangular Empty diag Empty sh a
-> Triangular Empty (PowerDiag Empty Empty diag) Empty sh a)
-> Power diag sh a Empty Empty
forall a b. (a -> b) -> a -> b
$ (a -> a)
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
forall sh a b.
(C sh, Storable a, Storable b) =>
(a -> b) -> Array sh a -> Array sh b
Array.map (a -> Int -> a
forall a b. (Num a, Integral b) => a -> b -> a
^Int
n))
((Triangular Empty diag Filled sh a
-> Triangular Empty (PowerDiag Empty Filled diag) Filled sh a)
-> Power diag sh a Empty Filled
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power ((Triangular Empty diag Filled sh a
-> Triangular Empty (PowerDiag Empty Filled diag) Filled sh a)
-> Power diag sh a Empty Filled)
-> (Triangular Empty diag Filled sh a
-> Triangular Empty (PowerDiag Empty Filled diag) Filled sh a)
-> Power diag sh a Empty Filled
forall a b. (a -> b) -> a -> b
$ Integer
-> Triangular Empty diag Filled sh a
-> Triangular Empty diag Filled sh a
forall lo up diag sh a.
(UpLo lo up, TriDiag diag, C sh, Floating a) =>
Integer -> Triangular lo diag up sh a -> Triangular lo diag up sh a
powerTriangular (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n))
((Triangular Filled diag Empty sh a
-> Triangular Filled (PowerDiag Filled Empty diag) Empty sh a)
-> Power diag sh a Filled Empty
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power ((Triangular Filled diag Empty sh a
-> Triangular Filled (PowerDiag Filled Empty diag) Empty sh a)
-> Power diag sh a Filled Empty)
-> (Triangular Filled diag Empty sh a
-> Triangular Filled (PowerDiag Filled Empty diag) Empty sh a)
-> Power diag sh a Filled Empty
forall a b. (a -> b) -> a -> b
$ Integer
-> Triangular Filled diag Empty sh a
-> Triangular Filled diag Empty sh a
forall lo up diag sh a.
(UpLo lo up, TriDiag diag, C sh, Floating a) =>
Integer -> Triangular lo diag up sh a -> Triangular lo diag up sh a
powerTriangular (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n))
((Triangular Filled diag Filled sh a
-> Triangular Filled (PowerDiag Filled Filled diag) Filled sh a)
-> Power diag sh a Filled Filled
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo (PowerDiag lo up diag) up sh a)
-> Power diag sh a lo up
Tri.Power ((Triangular Filled diag Filled sh a
-> Triangular Filled (PowerDiag Filled Filled diag) Filled sh a)
-> Power diag sh a Filled Filled)
-> (Triangular Filled diag Filled sh a
-> Triangular Filled (PowerDiag Filled Filled diag) Filled sh a)
-> Power diag sh a Filled Filled
forall a b. (a -> b) -> a -> b
$ Integer -> Symmetric sh a -> Symmetric sh a
forall sh a.
(C sh, Floating a) =>
Integer -> Symmetric sh a -> Symmetric sh a
powerSymmetric (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n) (Symmetric sh a -> Symmetric sh a)
-> (Triangular Filled diag Filled sh a -> Symmetric sh a)
-> Triangular Filled diag Filled sh a
-> Symmetric sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Filled diag Filled sh a -> Symmetric sh a
forall diag lo up sh a.
TriDiag diag =>
Triangular lo diag up sh a -> Triangular lo NonUnit up sh a
strictNonUnitDiagonal)
powerTriangular ::
(MatrixShape.UpLo lo up, MatrixShape.TriDiag diag,
Shape.C sh, Class.Floating a) =>
Integer -> Triangular lo diag up sh a -> Triangular lo diag up sh a
powerTriangular :: Integer -> Triangular lo diag up sh a -> Triangular lo diag up sh a
powerTriangular Integer
n a :: Triangular lo diag up sh a
a@(Array (MatrixShape.Triangular diag
_diag (lo, up)
_uplo Order
order sh
sh) ForeignPtr a
_) =
Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up sh a
forall lo diag up sh a.
Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up sh a
recheck (Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up sh a)
-> Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up sh a
forall a b. (a -> b) -> a -> b
$
(Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a)
-> Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a
-> Integer
-> Triangular lo diag up (Unchecked sh) a
forall a. (a -> a -> a) -> a -> a -> Integer -> a
powerAssociative Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a
forall lo up diag sh a.
(UpLo lo up, TriDiag diag, C sh, Eq sh, Floating a) =>
Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
multiplyTriangular
(Triangular lo Unit up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a
forall diag lo up sh a.
TriDiag diag =>
Triangular lo Unit up sh a -> Triangular lo diag up sh a
relaxUnitDiagonal (Triangular lo Unit up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a)
-> Triangular lo Unit up (Unchecked sh) a
-> Triangular lo diag up (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ Order -> Unchecked sh -> Triangular lo Unit up (Unchecked sh) a
forall lo up sh a.
(Content lo, Content up, C sh, Floating a) =>
Order -> sh -> Triangular lo Unit up sh a
identity Order
order (Unchecked sh -> Triangular lo Unit up (Unchecked sh) a)
-> Unchecked sh -> Triangular lo Unit up (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ sh -> Unchecked sh
forall sh. sh -> Unchecked sh
Unchecked sh
sh)
(Triangular lo diag up sh a
-> Triangular lo diag up (Unchecked sh) a
forall lo diag up sh a.
Triangular lo diag up sh a
-> Triangular lo diag up (Unchecked sh) a
uncheck Triangular lo diag up sh a
a)
Integer
n
powerSymmetric ::
(Shape.C sh, Class.Floating a) => Integer -> Symmetric sh a -> Symmetric sh a
powerSymmetric :: Integer -> Symmetric sh a -> Symmetric sh a
powerSymmetric Integer
n a0 :: Symmetric sh a
a0@(Array (MatrixShape.Triangular NonUnit
_diag (Filled, Filled)
_uplo Order
order sh
sh) ForeignPtr a
_) =
Triangular Filled NonUnit Filled (Unchecked sh) a -> Symmetric sh a
forall lo diag up sh a.
Triangular lo diag up (Unchecked sh) a
-> Triangular lo diag up sh a
recheck (Triangular Filled NonUnit Filled (Unchecked sh) a
-> Symmetric sh a)
-> Triangular Filled NonUnit Filled (Unchecked sh) a
-> Symmetric sh a
forall a b. (a -> b) -> a -> b
$
(Triangular Filled NonUnit Filled (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a)
-> Triangular Filled NonUnit Filled (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a
-> Integer
-> Triangular Filled NonUnit Filled (Unchecked sh) a
forall a. (a -> a -> a) -> a -> a -> Integer -> a
powerAssociative
(\Triangular Filled NonUnit Filled (Unchecked sh) a
a Triangular Filled NonUnit Filled (Unchecked sh) a
b ->
(Order
-> Unchecked sh -> Triangular Filled NonUnit Filled (Unchecked sh))
-> Full Small Small (Unchecked sh) (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a
forall vert height width shape a.
(C vert, C height, C width, C shape, Floating a) =>
(Order -> width -> shape)
-> Full vert Small height width a -> Array shape a
Tri.fromUpperPart
(NonUnit
-> (Filled, Filled)
-> Order
-> Unchecked sh
-> Triangular Filled NonUnit Filled (Unchecked sh)
forall lo diag up size.
diag -> (lo, up) -> Order -> size -> Triangular lo diag up size
MatrixShape.Triangular NonUnit
NonUnit (Filled, Filled)
forall lo up. (Content lo, Content up) => (lo, up)
MatrixShape.autoUplo) (Full Small Small (Unchecked sh) (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a)
-> Full Small Small (Unchecked sh) (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$
Triangular Filled NonUnit Filled (Unchecked sh) a
-> Full Small Small (Unchecked sh) (Unchecked sh) a
-> Full Small Small (Unchecked sh) (Unchecked sh) a
forall lo up diag vert horiz height width a.
(UpLoSym lo up, TriDiag diag, C vert, C horiz, C height, Eq height,
C width, Floating a) =>
Triangular lo diag up height a
-> Full vert horiz height width a -> Full vert horiz height width a
multiplyFullTriangular Triangular Filled NonUnit Filled (Unchecked sh) a
a (Full Small Small (Unchecked sh) (Unchecked sh) a
-> Full Small Small (Unchecked sh) (Unchecked sh) a)
-> Full Small Small (Unchecked sh) (Unchecked sh) a
-> Full Small Small (Unchecked sh) (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ Triangular Filled NonUnit Filled (Unchecked sh) a
-> Full Small Small (Unchecked sh) (Unchecked sh) a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Square sh a
toSquare Triangular Filled NonUnit Filled (Unchecked sh) a
b)
(Triangular Filled Unit Filled (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a
forall diag lo up sh a.
TriDiag diag =>
Triangular lo Unit up sh a -> Triangular lo diag up sh a
relaxUnitDiagonal (Triangular Filled Unit Filled (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a)
-> Triangular Filled Unit Filled (Unchecked sh) a
-> Triangular Filled NonUnit Filled (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ Order
-> Unchecked sh -> Triangular Filled Unit Filled (Unchecked sh) a
forall lo up sh a.
(Content lo, Content up, C sh, Floating a) =>
Order -> sh -> Triangular lo Unit up sh a
identity Order
order (Unchecked sh -> Triangular Filled Unit Filled (Unchecked sh) a)
-> Unchecked sh -> Triangular Filled Unit Filled (Unchecked sh) a
forall a b. (a -> b) -> a -> b
$ sh -> Unchecked sh
forall sh. sh -> Unchecked sh
Unchecked sh
sh)
(Symmetric sh a -> Triangular Filled NonUnit Filled (Unchecked sh) a
forall lo diag up sh a.
Triangular lo diag up sh a
-> Triangular lo diag up (Unchecked sh) a
uncheck Symmetric sh a
a0)
Integer
n
multiply ::
(MatrixShape.DiagUpLo lo up, MatrixShape.TriDiag diag,
Shape.C sh, Eq sh, Class.Floating a) =>
Triangular lo diag up sh a -> Triangular lo diag up sh a ->
Triangular lo diag up sh a
multiply :: Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
multiply =
Multiply diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
forall diag sh a lo up.
Multiply diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
getMultiply (Multiply diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a)
-> Multiply diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
forall a b. (a -> b) -> a -> b
$
Multiply diag sh a Empty Empty
-> Multiply diag sh a Empty Filled
-> Multiply diag sh a Filled Empty
-> Multiply diag sh a lo up
forall lo up (f :: * -> * -> *).
DiagUpLoC lo up =>
f Empty Empty -> f Empty Filled -> f Filled Empty -> f lo up
MatrixShape.switchDiagUpLo
((Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a)
-> Multiply diag sh a Empty Empty
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> Multiply diag sh a lo up
Multiply ((Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a)
-> Multiply diag sh a Empty Empty)
-> (Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a)
-> Multiply diag sh a Empty Empty
forall a b. (a -> b) -> a -> b
$ (Vector sh a -> Vector sh a)
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
forall sh0 a sh1 diag.
(Vector sh0 a -> Vector sh1 a)
-> FlexDiagonal diag sh0 a -> FlexDiagonal diag sh1 a
liftDiagonal ((Vector sh a -> Vector sh a)
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a)
-> (Triangular Empty diag Empty sh a -> Vector sh a -> Vector sh a)
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
-> Triangular Empty diag Empty sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector sh a -> Vector sh a -> Vector sh a
forall sh a.
(C sh, Eq sh, Floating a) =>
Vector sh a -> Vector sh a -> Vector sh a
Vector.mul (Vector sh a -> Vector sh a -> Vector sh a)
-> (Triangular Empty diag Empty sh a -> Vector sh a)
-> Triangular Empty diag Empty sh a
-> Vector sh a
-> Vector sh a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Empty diag Empty sh a -> Vector sh a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonal)
((Triangular Empty diag Filled sh a
-> Triangular Empty diag Filled sh a
-> Triangular Empty diag Filled sh a)
-> Multiply diag sh a Empty Filled
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> Multiply diag sh a lo up
Multiply Triangular Empty diag Filled sh a
-> Triangular Empty diag Filled sh a
-> Triangular Empty diag Filled sh a
forall lo up diag sh a.
(UpLo lo up, TriDiag diag, C sh, Eq sh, Floating a) =>
Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
multiplyTriangular)
((Triangular Filled diag Empty sh a
-> Triangular Filled diag Empty sh a
-> Triangular Filled diag Empty sh a)
-> Multiply diag sh a Filled Empty
forall diag sh a lo up.
(Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a)
-> Multiply diag sh a lo up
Multiply Triangular Filled diag Empty sh a
-> Triangular Filled diag Empty sh a
-> Triangular Filled diag Empty sh a
forall lo up diag sh a.
(UpLo lo up, TriDiag diag, C sh, Eq sh, Floating a) =>
Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
multiplyTriangular)
newtype Multiply diag sh a lo up =
Multiply {
Multiply diag sh a lo up
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
-> Triangular lo diag up sh a
getMultiply ::
Triangular lo diag up sh a ->
Triangular lo diag up sh a -> Triangular lo diag up sh a
}
multiplyTriangular ::
(MatrixShape.UpLo lo up, MatrixShape.TriDiag diag,
Shape.C sh, Eq sh, Class.Floating a) =>
Triangular lo diag up sh a ->
Triangular lo diag up sh a -> Triangular lo diag up sh a
multiplyTriangular :: Triangular lo diag up sh a
-> Triangular lo diag up sh a -> Triangular lo diag up sh a
multiplyTriangular
(Array (MatrixShape.Triangular diag
diag (lo, up)
uploA Order
orderA sh
shA) ForeignPtr a
a)
(Array shapeB :: Triangular lo diag up sh
shapeB@(MatrixShape.Triangular diag
_diag (lo, up)
uploB Order
orderB sh
shB) ForeignPtr a
b) =
Triangular lo diag up sh
-> (Ptr a -> IO ()) -> Triangular lo diag up sh a
forall sh a.
(C sh, Storable a) =>
sh -> (Ptr a -> IO ()) -> Array sh a
Array.unsafeCreate Triangular lo diag up sh
shapeB ((Ptr a -> IO ()) -> Triangular lo diag up sh a)
-> (Ptr a -> IO ()) -> Triangular lo diag up sh a
forall a b. (a -> b) -> a -> b
$ \Ptr a
cpPtr -> do
String -> Bool -> IO ()
Call.assert String
"Triangular.multiply: width shapes mismatch" (sh
shA sh -> sh -> Bool
forall a. Eq a => a -> a -> Bool
== sh
shB)
let n :: Int
n = sh -> Int
forall sh. C sh => sh -> Int
Shape.size sh
shA
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 (Char
side,Order
trans) =
case Order
orderB of
Order
ColumnMajor -> (Char
'L', Order
orderA)
Order
RowMajor -> (Char
'R', Order -> Order
flipOrder Order
orderA)
Ptr CChar
sidePtr <- Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char Char
side
let realOrderA :: Order
realOrderA = (lo, up) -> Order -> Order
forall lo up.
(Content lo, Content up) =>
(lo, up) -> Order -> Order
uploOrder (lo, up)
uploA Order
orderA
let realOrderB :: Order
realOrderB = (lo, up) -> Order -> Order
forall lo up.
(Content lo, Content up) =>
(lo, up) -> Order -> Order
uploOrder (lo, up)
uploB Order
orderB
Ptr CChar
uploPtr <- 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
uploFromOrder Order
realOrderA
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
trans
Ptr CChar
diagPtr <- 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
$ diag -> Char
forall diag. TriDiag diag => diag -> Char
charFromTriDiag diag
diag
Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
Ptr CInt
ldPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
n
Ptr a
aPtr <- (Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT () IO (Ptr a)
forall a r.
Storable a =>
(Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT r IO (Ptr a)
unpackToTemp (Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
unpack Order
realOrderA) Int
n ForeignPtr a
a
Ptr a
bPtr <- (Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT () IO (Ptr a)
forall a r.
Storable a =>
(Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT r IO (Ptr a)
unpackToTemp (Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
unpackZero Order
realOrderB) Int
n ForeignPtr a
b
Ptr a
alphaPtr <- a -> ContT () IO (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
one
IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$ do
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
BlasGen.trmm Ptr CChar
sidePtr Ptr CChar
uploPtr Ptr CChar
transPtr Ptr CChar
diagPtr
Ptr CInt
nPtr Ptr CInt
nPtr Ptr a
alphaPtr Ptr a
aPtr Ptr CInt
ldPtr Ptr a
bPtr Ptr CInt
ldPtr
Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
pack Order
realOrderB Int
n Ptr a
bPtr Ptr a
cpPtr
multiplyFull ::
(MatrixShape.Content lo, MatrixShape.Content up, MatrixShape.TriDiag diag,
Extent.C vert, Extent.C horiz,
Shape.C height, Eq height, Shape.C width,
Class.Floating a) =>
Triangular lo diag up height a ->
Full vert horiz height width a ->
Full vert horiz height width a
multiplyFull :: Triangular lo diag up height a
-> Full vert horiz height width a -> Full vert horiz height width a
multiplyFull =
MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
lo
up
-> Triangular lo diag up height a
-> Full vert horiz height width a
-> Full vert horiz height width a
forall diag sh a b lo up.
MultiplyRight diag sh a b lo up -> Triangular lo diag up sh a -> b
Tri.getMultiplyRight (MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
lo
up
-> Triangular lo diag up height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
lo
up
-> Triangular lo diag up height a
-> Full vert horiz height width a
-> Full vert horiz height width a
forall a b. (a -> b) -> a -> b
$
MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Empty
Empty
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Empty
Filled
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Filled
Empty
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Filled
Filled
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
lo
up
forall lo up (f :: * -> * -> *).
(Content lo, Content up) =>
f Empty Empty
-> f Empty Filled -> f Filled Empty -> f Filled Filled -> f lo up
MatrixShape.switchDiagUpLoSym
((Triangular Empty diag Empty height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Empty
Empty
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight ((Triangular Empty diag Empty height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Empty
Empty)
-> (Triangular Empty diag Empty height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Empty
Empty
forall a b. (a -> b) -> a -> b
$ Vector height a
-> Full vert horiz height width a -> Full vert horiz height width a
forall vert horiz height width a.
(C vert, C horiz, C height, Eq height, C width, Floating a) =>
Vector height a
-> Full vert horiz height width a -> Full vert horiz height width a
Basic.scaleRows (Vector height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> (Triangular Empty diag Empty height a -> Vector height a)
-> Triangular Empty diag Empty height a
-> Full vert horiz height width a
-> Full vert horiz height width a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Triangular Empty diag Empty height a -> Vector height a
forall lo up sh a diag.
(Content lo, Content up, C sh, Floating a) =>
Triangular lo diag up sh a -> Vector sh a
takeDiagonal)
((Triangular Empty diag Filled height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Empty
Filled
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight Triangular Empty diag Filled height a
-> Full vert horiz height width a -> Full vert horiz height width a
forall lo up diag vert horiz height width a.
(UpLoSym lo up, TriDiag diag, C vert, C horiz, C height, Eq height,
C width, Floating a) =>
Triangular lo diag up height a
-> Full vert horiz height width a -> Full vert horiz height width a
multiplyFullTriangular)
((Triangular Filled diag Empty height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Filled
Empty
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight Triangular Filled diag Empty height a
-> Full vert horiz height width a -> Full vert horiz height width a
forall lo up diag vert horiz height width a.
(UpLoSym lo up, TriDiag diag, C vert, C horiz, C height, Eq height,
C width, Floating a) =>
Triangular lo diag up height a
-> Full vert horiz height width a -> Full vert horiz height width a
multiplyFullTriangular)
((Triangular Filled diag Filled height a
-> Full vert horiz height width a
-> Full vert horiz height width a)
-> MultiplyRight
diag
height
a
(Full vert horiz height width a -> Full vert horiz height width a)
Filled
Filled
forall diag sh a b lo up.
(Triangular lo diag up sh a -> b)
-> MultiplyRight diag sh a b lo up
Tri.MultiplyRight Triangular Filled diag Filled height a
-> Full vert horiz height width a -> Full vert horiz height width a
forall lo up diag vert horiz height width a.
(UpLoSym lo up, TriDiag diag, C vert, C horiz, C height, Eq height,
C width, Floating a) =>
Triangular lo diag up height a
-> Full vert horiz height width a -> Full vert horiz height width a
multiplyFullTriangular)
multiplyFullTriangular ::
(MatrixShape.UpLoSym lo up, MatrixShape.TriDiag diag,
Extent.C vert, Extent.C horiz,
Shape.C height, Eq height, Shape.C width,
Class.Floating a) =>
Triangular lo diag up height a ->
Full vert horiz height width a ->
Full vert horiz height width a
multiplyFullTriangular :: Triangular lo diag up height a
-> Full vert horiz height width a -> Full vert horiz height width a
multiplyFullTriangular
(Array (MatrixShape.Triangular diag
diag (lo, up)
uploA Order
orderA height
shA) ForeignPtr a
a)
(Array shapeB :: Full vert horiz height width
shapeB@(MatrixShape.Full Order
orderB Extent vert horiz height width
extentB) ForeignPtr a
b) =
Full vert horiz height width
-> (Int -> Ptr a -> IO ()) -> Full vert horiz height width a
forall sh a.
(C sh, Storable a) =>
sh -> (Int -> Ptr a -> IO ()) -> Array sh a
Array.unsafeCreateWithSize Full vert horiz height width
shapeB ((Int -> Ptr a -> IO ()) -> Full vert horiz height width a)
-> (Int -> Ptr a -> IO ()) -> Full vert horiz height width a
forall a b. (a -> b) -> a -> b
$ \Int
size Ptr a
cPtr -> do
let (height
height,width
width) = Extent vert horiz height width -> (height, width)
forall vert horiz height width.
(C vert, C horiz) =>
Extent vert horiz height width -> (height, width)
Extent.dimensions Extent vert horiz height width
extentB
String -> Bool -> IO ()
Call.assert String
"Triangular.multiplyFull: shapes mismatch" (height
shA height -> height -> Bool
forall a. Eq a => a -> a -> Bool
== height
height)
let m0 :: Int
m0 = height -> Int
forall sh. C sh => sh -> Int
Shape.size height
height
let n0 :: Int
n0 = width -> Int
forall sh. C sh => sh -> Int
Shape.size width
width
ContT () IO () -> IO ()
forall (m :: * -> *) r. Monad m => ContT r m r -> m r
evalContT (ContT () IO () -> IO ()) -> ContT () IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
let (Char
side,Order
trans,(Int
m,Int
n)) =
case Order
orderB of
Order
ColumnMajor -> (Char
'L', Order
orderA, (Int
m0,Int
n0))
Order
RowMajor -> (Char
'R', Order -> Order
flipOrder Order
orderA, (Int
n0,Int
m0))
Ptr CChar
sidePtr <- Char -> FortranIO () (Ptr CChar)
forall r. Char -> FortranIO r (Ptr CChar)
Call.char Char
side
let realOrderA :: Order
realOrderA = (lo, up) -> Order -> Order
forall lo up.
(Content lo, Content up) =>
(lo, up) -> Order -> Order
uploOrder (lo, up)
uploA Order
orderA
Ptr CChar
uploPtr <- 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
uploFromOrder Order
realOrderA
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
trans
Ptr CChar
diagPtr <- 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
$ diag -> Char
forall diag. TriDiag diag => diag -> Char
charFromTriDiag diag
diag
Ptr CInt
mPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
m
Ptr CInt
nPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.cint Int
n
Ptr a
alphaPtr <- a -> FortranIO () (Ptr a)
forall a r. Floating a => a -> FortranIO r (Ptr a)
Call.number a
forall a. Floating a => a
one
Ptr a
aPtr <- (Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> FortranIO () (Ptr a)
forall a r.
Storable a =>
(Int -> Ptr a -> Ptr a -> IO ())
-> Int -> ForeignPtr a -> ContT r IO (Ptr a)
unpackToTemp (Order -> Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Order -> Int -> Ptr a -> Ptr a -> IO ()
unpack Order
realOrderA) Int
m0 ForeignPtr a
a
Ptr CInt
ldaPtr <- Int -> FortranIO () (Ptr CInt)
forall r. Int -> FortranIO r (Ptr CInt)
Call.leadingDim Int
m0
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 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
m
let runTRMM :: IO ()
runTRMM = do
Int -> Ptr a -> Ptr a -> IO ()
forall a. Floating a => Int -> Ptr a -> Ptr a -> IO ()
copyBlock Int
size Ptr a
bPtr Ptr a
cPtr
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
forall a.
Floating a =>
Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> IO ()
BlasGen.trmm Ptr CChar
sidePtr Ptr CChar
uploPtr Ptr CChar
transPtr Ptr CChar
diagPtr
Ptr CInt
mPtr Ptr CInt
nPtr Ptr a
alphaPtr Ptr a
aPtr Ptr CInt
ldaPtr Ptr a
cPtr Ptr CInt
ldbPtr
IO () -> ContT () IO ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ContT () IO ()) -> IO () -> ContT () IO ()
forall a b. (a -> b) -> a -> b
$
(lo, up) -> IO () -> IO () -> IO () -> IO ()
forall lo up a. UpLoSym lo up => (lo, up) -> a -> a -> a -> a
MatrixShape.caseUpLoSym (lo, up)
uploA
IO ()
runTRMM
IO ()
runTRMM
(Ptr CChar
-> 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 CChar
-> Ptr CInt
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr CInt
-> Ptr a
-> Ptr a
-> Ptr CInt
-> IO ()
BlasGen.symm Ptr CChar
sidePtr Ptr CChar
uploPtr
Ptr CInt
mPtr Ptr CInt
nPtr Ptr a
alphaPtr Ptr a
aPtr Ptr CInt
ldaPtr Ptr a
bPtr Ptr CInt
ldbPtr Ptr a
betaPtr Ptr a
cPtr Ptr CInt
ldbPtr)
autoUploOrder ::
(MatrixShape.Content lo, MatrixShape.Content up) => Order -> (Order, (lo,up))
autoUploOrder :: Order -> (Order, (lo, up))
autoUploOrder Order
order =
case (lo, up)
forall lo up. (Content lo, Content up) => (lo, up)
MatrixShape.autoUplo of
(lo, up)
uplo -> ((lo, up) -> Order -> Order
forall lo up.
(Content lo, Content up) =>
(lo, up) -> Order -> Order
uploOrder (lo, up)
uplo Order
order, (lo, up)
uplo)