{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Massiv.Array.Numeric (
Numeric,
NumericFloat,
liftNumArray2M,
(.+),
(+.),
(.+.),
(!+!),
sumArraysM,
sumArrays',
(.-),
(-.),
(.-.),
(!-!),
(.*),
(*.),
(.*.),
(!*!),
(.^),
productArraysM,
productArrays',
(!.!),
dotM,
(.><),
(!><),
multiplyMatrixByVector,
(><.),
(><!),
multiplyVectorByMatrix,
(.><.),
(!><!),
multiplyMatrices,
multiplyMatricesTransposed,
normL2,
identityMatrix,
lowerTriangular,
upperTriangular,
negateA,
absA,
signumA,
quotA,
remA,
divA,
modA,
quotRemA,
divModA,
(./),
(/.),
(./.),
(!/!),
(.^^),
recipA,
expA,
logA,
sqrtA,
(.**),
logBaseA,
sinA,
cosA,
tanA,
asinA,
acosA,
atanA,
sinhA,
coshA,
tanhA,
asinhA,
acoshA,
atanhA,
truncateA,
roundA,
ceilingA,
floorA,
atan2A,
) where
import Control.Monad (when)
import Control.Scheduler
import qualified Data.Foldable as F
import Data.Function
import Data.Massiv.Array.Delayed.Pull
import Data.Massiv.Array.Delayed.Push
import Data.Massiv.Array.Manifest.Internal
import Data.Massiv.Array.Ops.Construct
import Data.Massiv.Array.Ops.Map as A
import Data.Massiv.Core
import Data.Massiv.Core.Common as A
import Data.Massiv.Core.Operations
import System.IO.Unsafe
import Prelude as P
infixr 8 .^, .^^
infixl 7 !*!, .*., .*, *., !/!, ./., ./, /., `quotA`, `remA`, `divA`, `modA`
infixl 6 !+!, .+., .+, +., !-!, .-., .-, -.
liftNumArray2M
:: (Index ix, Numeric r e, MonadThrow m)
=> (e -> e -> e)
-> Array r ix e
-> Array r ix e
-> m (Array r ix e)
liftNumArray2M :: forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> m (Array r ix e)
liftNumArray2M e -> e -> e
f Array r ix e
a1 Array r ix e
a2
| Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a1 Sz ix -> Sz ix -> Bool
forall a. Eq a => a -> a -> Bool
== Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a2 = Array r ix e -> m (Array r ix e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Array r ix e -> m (Array r ix e))
-> Array r ix e -> m (Array r ix e)
forall a b. (a -> b) -> a -> b
$ (e -> e -> e) -> Array r ix e -> Array r ix e -> Array r ix e
forall ix.
Index ix =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> Array r ix e
unsafeLiftArray2 e -> e -> e
f Array r ix e
a1 Array r ix e
a2
| Sz ix -> Bool
forall ix. Index ix => Sz ix -> Bool
isZeroSz Sz ix
sz1 Bool -> Bool -> Bool
&& Sz ix -> Bool
forall ix. Index ix => Sz ix -> Bool
isZeroSz Sz ix
sz2 = Array r ix e -> m (Array r ix e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Array r ix e -> m (Array r ix e))
-> Array r ix e -> m (Array r ix e)
forall a b. (a -> b) -> a -> b
$ Sz ix -> Array r ix e -> Array r ix e
forall r ix ix' e.
(Size r, Index ix, Index ix') =>
Sz ix' -> Array r ix e -> Array r ix' e
forall ix ix' e.
(Index ix, Index ix') =>
Sz ix' -> Array r ix e -> Array r ix' e
unsafeResize Sz ix
forall ix. Index ix => Sz ix
zeroSz Array r ix e
a1
| Bool
otherwise = SizeException -> m (Array r ix e)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (SizeException -> m (Array r ix e))
-> SizeException -> m (Array r ix e)
forall a b. (a -> b) -> a -> b
$ Sz ix -> Sz ix -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException Sz ix
sz1 Sz ix
sz2
where
!sz1 :: Sz ix
sz1 = Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a1
!sz2 :: Sz ix
sz2 = Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a2
{-# INLINE liftNumArray2M #-}
applyExactSize2M
:: (Index ix, Size r, MonadThrow m)
=> (Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e
-> Array r ix e
-> m (Array r ix e)
applyExactSize2M :: forall ix r (m :: * -> *) e.
(Index ix, Size r, MonadThrow m) =>
(Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
applyExactSize2M Array r ix e -> Array r ix e -> Array r ix e
f Array r ix e
a1 Array r ix e
a2
| Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a1 Sz ix -> Sz ix -> Bool
forall a. Eq a => a -> a -> Bool
== Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a2 = Array r ix e -> m (Array r ix e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Array r ix e -> m (Array r ix e))
-> Array r ix e -> m (Array r ix e)
forall a b. (a -> b) -> a -> b
$! Array r ix e -> Array r ix e -> Array r ix e
f Array r ix e
a1 Array r ix e
a2
| Sz ix -> Bool
forall ix. Index ix => Sz ix -> Bool
isZeroSz Sz ix
sz1 Bool -> Bool -> Bool
&& Sz ix -> Bool
forall ix. Index ix => Sz ix -> Bool
isZeroSz Sz ix
sz2 = Array r ix e -> m (Array r ix e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Array r ix e -> m (Array r ix e))
-> Array r ix e -> m (Array r ix e)
forall a b. (a -> b) -> a -> b
$! Sz ix -> Array r ix e -> Array r ix e
forall r ix ix' e.
(Size r, Index ix, Index ix') =>
Sz ix' -> Array r ix e -> Array r ix' e
forall ix ix' e.
(Index ix, Index ix') =>
Sz ix' -> Array r ix e -> Array r ix' e
unsafeResize Sz ix
forall ix. Index ix => Sz ix
zeroSz Array r ix e
a1
| Bool
otherwise = SizeException -> m (Array r ix e)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (SizeException -> m (Array r ix e))
-> SizeException -> m (Array r ix e)
forall a b. (a -> b) -> a -> b
$! Sz ix -> Sz ix -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException Sz ix
sz1 Sz ix
sz2
where
!sz1 :: Sz ix
sz1 = Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a1
!sz2 :: Sz ix
sz2 = Array r ix e -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix e
a2
{-# INLINE applyExactSize2M #-}
(.+.) :: (Index ix, Numeric r e, MonadThrow m) => Array r ix e -> Array r ix e -> m (Array r ix e)
.+. :: forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
(.+.) = (Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
forall ix r (m :: * -> *) e.
(Index ix, Size r, MonadThrow m) =>
(Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
applyExactSize2M Array r ix e -> Array r ix e -> Array r ix e
forall ix. Index ix => Array r ix e -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> Array r ix e -> Array r ix e
additionPointwise
{-# INLINE (.+.) #-}
(!+!) :: (HasCallStack, Index ix, Numeric r e) => Array r ix e -> Array r ix e -> Array r ix e
!+! :: forall ix r e.
(HasCallStack, Index ix, Numeric r e) =>
Array r ix e -> Array r ix e -> Array r ix e
(!+!) Array r ix e
a1 Array r ix e
a2 = Either SomeException (Array r ix e) -> Array r ix e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Array r ix e
a1 Array r ix e -> Array r ix e -> Either SomeException (Array r ix e)
forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
.+. Array r ix e
a2)
{-# INLINE (!+!) #-}
(.+) :: (Index ix, Numeric r e) => Array r ix e -> e -> Array r ix e
.+ :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> e -> Array r ix e
(.+) = Array r ix e -> e -> Array r ix e
forall ix. Index ix => Array r ix e -> e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> e -> Array r ix e
plusScalar
{-# INLINE (.+) #-}
(+.) :: (Index ix, Numeric r e) => e -> Array r ix e -> Array r ix e
+. :: forall ix r e.
(Index ix, Numeric r e) =>
e -> Array r ix e -> Array r ix e
(+.) = (Array r ix e -> e -> Array r ix e)
-> e -> Array r ix e -> Array r ix e
forall a b c. (a -> b -> c) -> b -> a -> c
flip Array r ix e -> e -> Array r ix e
forall ix. Index ix => Array r ix e -> e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> e -> Array r ix e
plusScalar
{-# INLINE (+.) #-}
(.-.)
:: (Index ix, Numeric r e, MonadThrow m) => Array r ix e -> Array r ix e -> m (Array r ix e)
.-. :: forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
(.-.) = (Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
forall ix r (m :: * -> *) e.
(Index ix, Size r, MonadThrow m) =>
(Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
applyExactSize2M Array r ix e -> Array r ix e -> Array r ix e
forall ix. Index ix => Array r ix e -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> Array r ix e -> Array r ix e
subtractionPointwise
{-# INLINE (.-.) #-}
(!-!) :: (Index ix, Numeric r e) => Array r ix e -> Array r ix e -> Array r ix e
!-! :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> Array r ix e -> Array r ix e
(!-!) Array r ix e
a1 Array r ix e
a2 = Either SomeException (Array r ix e) -> Array r ix e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Array r ix e
a1 Array r ix e -> Array r ix e -> Either SomeException (Array r ix e)
forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
.-. Array r ix e
a2)
{-# INLINE (!-!) #-}
(.-) :: (Index ix, Numeric r e) => Array r ix e -> e -> Array r ix e
.- :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> e -> Array r ix e
(.-) = Array r ix e -> e -> Array r ix e
forall ix. Index ix => Array r ix e -> e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> e -> Array r ix e
minusScalar
{-# INLINE (.-) #-}
(-.) :: (Index ix, Numeric r e) => e -> Array r ix e -> Array r ix e
-. :: forall ix r e.
(Index ix, Numeric r e) =>
e -> Array r ix e -> Array r ix e
(-.) = e -> Array r ix e -> Array r ix e
forall ix. Index ix => e -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
e -> Array r ix e -> Array r ix e
scalarMinus
{-# INLINE (-.) #-}
(.*.)
:: (Index ix, Numeric r e, MonadThrow m) => Array r ix e -> Array r ix e -> m (Array r ix e)
.*. :: forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
(.*.) = (Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
forall ix r (m :: * -> *) e.
(Index ix, Size r, MonadThrow m) =>
(Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
applyExactSize2M Array r ix e -> Array r ix e -> Array r ix e
forall ix. Index ix => Array r ix e -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> Array r ix e -> Array r ix e
multiplicationPointwise
{-# INLINE (.*.) #-}
(!*!) :: (Index ix, Numeric r e) => Array r ix e -> Array r ix e -> Array r ix e
!*! :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> Array r ix e -> Array r ix e
(!*!) Array r ix e
a1 Array r ix e
a2 = Either SomeException (Array r ix e) -> Array r ix e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Array r ix e
a1 Array r ix e -> Array r ix e -> Either SomeException (Array r ix e)
forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
.*. Array r ix e
a2)
{-# INLINE (!*!) #-}
(.*) :: (Index ix, Numeric r e) => Array r ix e -> e -> Array r ix e
.* :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> e -> Array r ix e
(.*) = Array r ix e -> e -> Array r ix e
forall ix. Index ix => Array r ix e -> e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> e -> Array r ix e
multiplyScalar
{-# INLINE (.*) #-}
(*.) :: (Index ix, Numeric r e) => e -> Array r ix e -> Array r ix e
*. :: forall ix r e.
(Index ix, Numeric r e) =>
e -> Array r ix e -> Array r ix e
(*.) = (Array r ix e -> e -> Array r ix e)
-> e -> Array r ix e -> Array r ix e
forall a b c. (a -> b -> c) -> b -> a -> c
flip Array r ix e -> e -> Array r ix e
forall ix. Index ix => Array r ix e -> e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> e -> Array r ix e
multiplyScalar
{-# INLINE (*.) #-}
(.^) :: (Index ix, Numeric r e) => Array r ix e -> Int -> Array r ix e
.^ :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> Int -> Array r ix e
(.^) = Array r ix e -> Int -> Array r ix e
forall ix. Index ix => Array r ix e -> Int -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> Int -> Array r ix e
powerPointwise
{-# INLINE (.^) #-}
(!.!) :: (Numeric r e, Source r e) => Vector r e -> Vector r e -> e
!.! :: forall r e.
(Numeric r e, Source r e) =>
Vector r e -> Vector r e -> e
(!.!) Vector r e
v1 Vector r e
v2 = Either SomeException e -> e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Either SomeException e -> e) -> Either SomeException e -> e
forall a b. (a -> b) -> a -> b
$ Vector r e -> Vector r e -> Either SomeException e
forall r e (m :: * -> *).
(FoldNumeric r e, Source r e, MonadThrow m) =>
Vector r e -> Vector r e -> m e
dotM Vector r e
v1 Vector r e
v2
{-# INLINE (!.!) #-}
dotM :: (FoldNumeric r e, Source r e, MonadThrow m) => Vector r e -> Vector r e -> m e
dotM :: forall r e (m :: * -> *).
(FoldNumeric r e, Source r e, MonadThrow m) =>
Vector r e -> Vector r e -> m e
dotM Vector r e
v1 Vector r e
v2
| Vector r e -> Sz Int
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Vector r e
v1 Sz Int -> Sz Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Vector r e -> Sz Int
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Vector r e
v2 = SizeException -> m e
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (SizeException -> m e) -> SizeException -> m e
forall a b. (a -> b) -> a -> b
$ Sz Int -> Sz Int -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Vector r e -> Sz Int
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Vector r e
v1) (Vector r e -> Sz Int
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Vector r e
v2)
| Comp
comp Comp -> Comp -> Bool
forall a. Eq a => a -> a -> Bool
== Comp
Seq = e -> m e
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> m e) -> e -> m e
forall a b. (a -> b) -> a -> b
$! Vector r e -> Vector r e -> e
forall ix. Index ix => Array r ix e -> Array r ix e -> e
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Array r ix e -> e
unsafeDotProduct Vector r e
v1 Vector r e
v2
| Bool
otherwise = e -> m e
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> m e) -> e -> m e
forall a b. (a -> b) -> a -> b
$! IO e -> e
forall a. IO a -> a
unsafePerformIO (IO e -> e) -> IO e -> e
forall a b. (a -> b) -> a -> b
$ Vector r e -> Vector r e -> IO e
forall (m :: * -> *) ix r b.
(MonadUnliftIO m, Index ix, FoldNumeric r b, Source r b) =>
Array r ix b -> Array r ix b -> m b
unsafeDotProductIO Vector r e
v1 Vector r e
v2
where
comp :: Comp
comp = Vector r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Vector r e
v1 Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Vector r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Vector r e
v2
{-# INLINE dotM #-}
unsafeDotProductIO
:: (MonadUnliftIO m, Index ix, FoldNumeric r b, Source r b)
=> Array r ix b
-> Array r ix b
-> m b
unsafeDotProductIO :: forall (m :: * -> *) ix r b.
(MonadUnliftIO m, Index ix, FoldNumeric r b, Source r b) =>
Array r ix b -> Array r ix b -> m b
unsafeDotProductIO Array r ix b
v1 Array r ix b
v2 = do
[b]
results <-
Comp -> (Scheduler RealWorld b -> m ()) -> m [b]
forall (m :: * -> *) a b.
MonadUnliftIO m =>
Comp -> (Scheduler RealWorld a -> m b) -> m [a]
withScheduler Comp
comp ((Scheduler RealWorld b -> m ()) -> m [b])
-> (Scheduler RealWorld b -> m ()) -> m [b]
forall a b. (a -> b) -> a -> b
$ \Scheduler RealWorld b
scheduler ->
Int -> Int -> (Int -> Int -> m ()) -> m ()
forall a. Int -> Int -> (Int -> Int -> a) -> a
splitLinearly (Scheduler RealWorld b -> Int
forall s a. Scheduler s a -> Int
numWorkers Scheduler RealWorld b
scheduler) Int
totalLength ((Int -> Int -> m ()) -> m ()) -> (Int -> Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
chunkLength Int
slackStart -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
let n :: Sz Int
n = Int -> Sz Int
forall ix. ix -> Sz ix
SafeSz Int
chunkLength
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> IO ()) -> IO ()
forall (f :: * -> *) a.
Applicative f =>
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> f a) -> f ()
loopA_ Int
0 (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
slackStart) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
chunkLength) ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ !Int
start ->
Scheduler RealWorld b -> IO b -> IO ()
forall s (m :: * -> *) a.
MonadPrimBase s m =>
Scheduler s a -> m a -> m ()
scheduleWork Scheduler RealWorld b
scheduler (IO b -> IO ()) -> IO b -> IO ()
forall a b. (a -> b) -> a -> b
$
b -> IO b
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> IO b) -> b -> IO b
forall a b. (a -> b) -> a -> b
$!
Array r Int b -> Array r Int b -> b
forall ix. Index ix => Array r ix b -> Array r ix b -> b
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Array r ix e -> e
unsafeDotProduct (Int -> Sz Int -> Array r ix b -> Array r Int b
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix b -> Array r Int b
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
start Sz Int
n Array r ix b
v1) (Int -> Sz Int -> Array r ix b -> Array r Int b
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix b -> Array r Int b
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
start Sz Int
n Array r ix b
v2)
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
slackStart Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
totalLength) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
let k :: Sz Int
k = Int -> Sz Int
forall ix. ix -> Sz ix
SafeSz (Int
totalLength Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
slackStart)
Scheduler RealWorld b -> IO b -> IO ()
forall s (m :: * -> *) a.
MonadPrimBase s m =>
Scheduler s a -> m a -> m ()
scheduleWork Scheduler RealWorld b
scheduler (IO b -> IO ()) -> IO b -> IO ()
forall a b. (a -> b) -> a -> b
$
b -> IO b
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> IO b) -> b -> IO b
forall a b. (a -> b) -> a -> b
$!
Array r Int b -> Array r Int b -> b
forall ix. Index ix => Array r ix b -> Array r ix b -> b
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Array r ix e -> e
unsafeDotProduct (Int -> Sz Int -> Array r ix b -> Array r Int b
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix b -> Array r Int b
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
slackStart Sz Int
k Array r ix b
v1) (Int -> Sz Int -> Array r ix b -> Array r Int b
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix b -> Array r Int b
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
slackStart Sz Int
k Array r ix b
v2)
b -> m b
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$! (b -> b -> b) -> b -> [b] -> b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' b -> b -> b
forall a. Num a => a -> a -> a
(+) b
0 [b]
results
where
totalLength :: Int
totalLength = Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem (Array r ix b -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix b
v1)
comp :: Comp
comp = Array r ix b -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Array r ix b
v1 Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Array r ix b -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Array r ix b
v2
{-# INLINE unsafeDotProductIO #-}
normL2 :: (FoldNumeric r e, Source r e, Index ix, Floating e) => Array r ix e -> e
normL2 :: forall r e ix.
(FoldNumeric r e, Source r e, Index ix, Floating e) =>
Array r ix e -> e
normL2 Array r ix e
v
| Array r ix e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Array r ix e
v Comp -> Comp -> Bool
forall a. Eq a => a -> a -> Bool
== Comp
Seq = e -> e
forall a. Floating a => a -> a
sqrt (e -> e) -> e -> e
forall a b. (a -> b) -> a -> b
$! Array r ix e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Int -> e
powerSumArray Array r ix e
v Int
2
| Bool
otherwise = e -> e
forall a. Floating a => a -> a
sqrt (e -> e) -> e -> e
forall a b. (a -> b) -> a -> b
$! IO e -> e
forall a. IO a -> a
unsafePerformIO (IO e -> e) -> IO e -> e
forall a b. (a -> b) -> a -> b
$ Array r ix e -> Int -> IO e
forall (m :: * -> *) ix r b.
(MonadUnliftIO m, Index ix, FoldNumeric r b, Source r b) =>
Array r ix b -> Int -> m b
powerSumArrayIO Array r ix e
v Int
2
{-# INLINE normL2 #-}
powerSumArrayIO
:: (MonadUnliftIO m, Index ix, FoldNumeric r b, Source r b)
=> Array r ix b
-> Int
-> m b
powerSumArrayIO :: forall (m :: * -> *) ix r b.
(MonadUnliftIO m, Index ix, FoldNumeric r b, Source r b) =>
Array r ix b -> Int -> m b
powerSumArrayIO Array r ix b
v Int
p = do
[b]
results <-
Comp -> (Scheduler RealWorld b -> m ()) -> m [b]
forall (m :: * -> *) a b.
MonadUnliftIO m =>
Comp -> (Scheduler RealWorld a -> m b) -> m [a]
withScheduler (Array r ix b -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Array r ix b
v) ((Scheduler RealWorld b -> m ()) -> m [b])
-> (Scheduler RealWorld b -> m ()) -> m [b]
forall a b. (a -> b) -> a -> b
$ \Scheduler RealWorld b
scheduler ->
Int -> Int -> (Int -> Int -> m ()) -> m ()
forall a. Int -> Int -> (Int -> Int -> a) -> a
splitLinearly (Scheduler RealWorld b -> Int
forall s a. Scheduler s a -> Int
numWorkers Scheduler RealWorld b
scheduler) Int
totalLength ((Int -> Int -> m ()) -> m ()) -> (Int -> Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
chunkLength Int
slackStart -> IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
let n :: Sz Int
n = Int -> Sz Int
forall ix. ix -> Sz ix
SafeSz Int
chunkLength
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> IO ()) -> IO ()
forall (f :: * -> *) a.
Applicative f =>
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> f a) -> f ()
loopA_ Int
0 (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
slackStart) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
chunkLength) ((Int -> IO ()) -> IO ()) -> (Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \ !Int
start ->
Scheduler RealWorld b -> IO b -> IO ()
forall s (m :: * -> *) a.
MonadPrimBase s m =>
Scheduler s a -> m a -> m ()
scheduleWork Scheduler RealWorld b
scheduler (IO b -> IO ()) -> IO b -> IO ()
forall a b. (a -> b) -> a -> b
$ b -> IO b
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> IO b) -> b -> IO b
forall a b. (a -> b) -> a -> b
$! Array r Int b -> Int -> b
forall ix. Index ix => Array r ix b -> Int -> b
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Int -> e
powerSumArray (Int -> Sz Int -> Array r ix b -> Array r Int b
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix b -> Array r Int b
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
start Sz Int
n Array r ix b
v) Int
p
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
slackStart Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
totalLength) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
let k :: Sz Int
k = Int -> Sz Int
forall ix. ix -> Sz ix
SafeSz (Int
totalLength Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
slackStart)
Scheduler RealWorld b -> IO b -> IO ()
forall s (m :: * -> *) a.
MonadPrimBase s m =>
Scheduler s a -> m a -> m ()
scheduleWork Scheduler RealWorld b
scheduler (IO b -> IO ()) -> IO b -> IO ()
forall a b. (a -> b) -> a -> b
$ b -> IO b
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> IO b) -> b -> IO b
forall a b. (a -> b) -> a -> b
$! Array r Int b -> Int -> b
forall ix. Index ix => Array r ix b -> Int -> b
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Int -> e
powerSumArray (Int -> Sz Int -> Array r ix b -> Array r Int b
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix b -> Array r Int b
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice Int
slackStart Sz Int
k Array r ix b
v) Int
p
b -> m b
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> m b) -> b -> m b
forall a b. (a -> b) -> a -> b
$! (b -> b -> b) -> b -> [b] -> b
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' b -> b -> b
forall a. Num a => a -> a -> a
(+) b
0 [b]
results
where
totalLength :: Int
totalLength = Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem (Array r ix b -> Sz ix
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Array r ix b
v)
{-# INLINE powerSumArrayIO #-}
(.><)
:: (MonadThrow m, FoldNumeric r e, Source r e)
=> Matrix r e
-> Vector r e
-> m (Vector D e)
.>< :: forall (m :: * -> *) r e.
(MonadThrow m, FoldNumeric r e, Source r e) =>
Matrix r e -> Vector r e -> m (Vector D e)
(.><) Matrix r e
mm Vector r e
v
| Int
mCols Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
n = SizeException -> m (Vector D e)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (SizeException -> m (Vector D e))
-> SizeException -> m (Vector D e)
forall a b. (a -> b) -> a -> b
$ Sz Ix2 -> Sz Ix2 -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
mm) (Int -> Int -> Sz Ix2
Sz2 Int
n Int
1)
| Int
mRows Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
|| Int
mCols Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Vector D e -> m (Vector D e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector D e -> m (Vector D e)) -> Vector D e -> m (Vector D e)
forall a b. (a -> b) -> a -> b
$ Comp -> Vector D e -> Vector D e
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array D ix e -> Array D ix e
setComp Comp
comp Vector D e
forall r ix e. Load r ix e => Array r ix e
empty
| Bool
otherwise = Vector D e -> m (Vector D e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector D e -> m (Vector D e)) -> Vector D e -> m (Vector D e)
forall a b. (a -> b) -> a -> b
$ Comp -> Sz Int -> (Int -> e) -> Vector D e
forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (ix -> e) -> Array r ix e
makeArray Comp
comp (Int -> Sz Int
Sz1 Int
mRows) ((Int -> e) -> Vector D e) -> (Int -> e) -> Vector D e
forall a b. (a -> b) -> a -> b
$ \Int
i ->
Vector r e -> Vector r e -> e
forall ix. Index ix => Array r ix e -> Array r ix e -> e
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Array r ix e -> e
unsafeDotProduct (Int -> Sz Int -> Matrix r e -> Vector r e
forall ix. Index ix => Int -> Sz Int -> Array r ix e -> Vector r e
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
n) Sz Int
sz Matrix r e
mm) Vector r e
v
where
comp :: Comp
comp = Matrix r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Matrix r e
mm Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Vector r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Vector r e
v
Sz2 Int
mRows Int
mCols = Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
mm
sz :: Sz Int
sz@(Sz1 Int
n) = Vector r e -> Sz Int
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Vector r e
v
{-# INLINE (.><) #-}
multiplyMatrixByVector
:: (MonadThrow m, Numeric r e, Manifest r e)
=> Matrix r e
-> Vector r e
-> m (Vector r e)
multiplyMatrixByVector :: forall (m :: * -> *) r e.
(MonadThrow m, Numeric r e, Manifest r e) =>
Matrix r e -> Vector r e -> m (Vector r e)
multiplyMatrixByVector Matrix r e
mm Vector r e
v = Array D Int e -> Vector r e
forall r ix e r'.
(Manifest r e, Load r' ix e) =>
Array r' ix e -> Array r ix e
compute (Array D Int e -> Vector r e)
-> m (Array D Int e) -> m (Vector r e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Matrix r e
mm Matrix r e -> Vector r e -> m (Array D Int e)
forall (m :: * -> *) r e.
(MonadThrow m, FoldNumeric r e, Source r e) =>
Matrix r e -> Vector r e -> m (Vector D e)
.>< Vector r e
v
{-# INLINE multiplyMatrixByVector #-}
(!><)
:: (Numeric r e, Source r e)
=> Matrix r e
-> Vector r e
-> Vector D e
!>< :: forall r e.
(Numeric r e, Source r e) =>
Matrix r e -> Vector r e -> Vector D e
(!><) Matrix r e
mm Vector r e
v = Either SomeException (Vector D e) -> Vector D e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Matrix r e
mm Matrix r e -> Vector r e -> Either SomeException (Vector D e)
forall (m :: * -> *) r e.
(MonadThrow m, FoldNumeric r e, Source r e) =>
Matrix r e -> Vector r e -> m (Vector D e)
.>< Vector r e
v)
{-# INLINE (!><) #-}
(><.)
:: (MonadThrow m, Numeric r e, Manifest r e)
=> Vector r e
-> Matrix r e
-> m (Vector r e)
><. :: forall (m :: * -> *) r e.
(MonadThrow m, Numeric r e, Manifest r e) =>
Vector r e -> Matrix r e -> m (Vector r e)
(><.) = Vector r e -> Matrix r e -> m (Vector r e)
forall (m :: * -> *) r e.
(MonadThrow m, Numeric r e, Manifest r e) =>
Vector r e -> Matrix r e -> m (Vector r e)
multiplyVectorByMatrix
{-# INLINE (><.) #-}
multiplyVectorByMatrix
:: (MonadThrow m, Numeric r e, Manifest r e)
=> Vector r e
-> Matrix r e
-> m (Vector r e)
multiplyVectorByMatrix :: forall (m :: * -> *) r e.
(MonadThrow m, Numeric r e, Manifest r e) =>
Vector r e -> Matrix r e -> m (Vector r e)
multiplyVectorByMatrix Vector r e
v Matrix r e
mm
| Int
mRows Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
n = SizeException -> m (Vector r e)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (SizeException -> m (Vector r e))
-> SizeException -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$ Sz Ix2 -> Sz Ix2 -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Int -> Int -> Sz Ix2
Sz2 Int
1 Int
n) (Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
mm)
| Int
mRows Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
|| Int
mCols Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Vector r e -> m (Vector r e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e -> m (Vector r e)) -> Vector r e -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (Vector r e)) -> Vector r e
forall a. (forall s. ST s a) -> a
runST (Comp -> MArray (PrimState (ST s)) r Int e -> ST s (Vector r e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
unsafeFreeze Comp
comp (MArray s r Int e -> ST s (Vector r e))
-> ST s (MArray s r Int e) -> ST s (Vector r e)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Sz Int -> ST s (MArray (PrimState (ST s)) r Int e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
unsafeNew Sz Int
forall ix. Index ix => Sz ix
zeroSz)
| Bool
otherwise =
Vector r e -> m (Vector r e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Vector r e -> m (Vector r e)) -> Vector r e -> m (Vector r e)
forall a b. (a -> b) -> a -> b
$!
IO (Vector r e) -> Vector r e
forall a. IO a -> a
unsafePerformIO (IO (Vector r e) -> Vector r e) -> IO (Vector r e) -> Vector r e
forall a b. (a -> b) -> a -> b
$ do
MArray RealWorld r Int e
mv <- Sz Int -> e -> IO (MArray (PrimState IO) r Int e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
newMArray (Int -> Sz Int
forall ix. Index ix => ix -> Sz ix
Sz Int
mCols) e
0
Comp -> (Scheduler RealWorld () -> IO ()) -> IO ()
withMassivScheduler_ Comp
comp ((Scheduler RealWorld () -> IO ()) -> IO ())
-> (Scheduler RealWorld () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Scheduler RealWorld ()
scheduler -> do
let loopCols :: e -> Int -> Int -> Int -> IO ()
loopCols e
x Int
ivto =
((Int -> Int -> IO ()) -> Int -> Int -> IO ())
-> Int -> Int -> IO ()
forall a. (a -> a) -> a
fix (((Int -> Int -> IO ()) -> Int -> Int -> IO ())
-> Int -> Int -> IO ())
-> ((Int -> Int -> IO ()) -> Int -> Int -> IO ())
-> Int
-> Int
-> IO ()
forall a b. (a -> b) -> a -> b
$ \Int -> Int -> IO ()
go Int
im Int
iv ->
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
iv Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
ivto) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
e
_ <- MArray (PrimState IO) r Int e -> (e -> IO e) -> Int -> IO e
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> (e -> m e) -> Int -> m e
unsafeLinearModify MArray RealWorld r Int e
MArray (PrimState IO) r Int e
mv (\e
a -> e -> IO e
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (e -> IO e) -> e -> IO e
forall a b. (a -> b) -> a -> b
$ e
a e -> e -> e
forall a. Num a => a -> a -> a
+ Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
mm Int
im e -> e -> e
forall a. Num a => a -> a -> a
* e
x) Int
iv
Int -> Int -> IO ()
go (Int
im Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int
iv Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
loopRows :: Int -> Int -> Int -> IO ()
loopRows Int
i0 Int
from Int
to =
(((Int -> IO ()) -> Int -> IO ()) -> Int -> IO ())
-> Int -> ((Int -> IO ()) -> Int -> IO ()) -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Int -> IO ()) -> Int -> IO ()) -> Int -> IO ()
forall a. (a -> a) -> a
fix Int
i0 (((Int -> IO ()) -> Int -> IO ()) -> IO ())
-> ((Int -> IO ()) -> Int -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int -> IO ()
go Int
i ->
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
mRows) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
e -> Int -> Int -> Int -> IO ()
loopCols (Vector r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Vector r e
v Int
i) Int
to (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
mCols Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
from) Int
from
Int -> IO ()
go (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Scheduler RealWorld () -> Int -> (Int -> Int -> IO ()) -> IO ()
forall s (m :: * -> *).
MonadPrimBase s m =>
Scheduler s () -> Int -> (Int -> Int -> m ()) -> m ()
splitLinearlyM_ Scheduler RealWorld ()
scheduler Int
mCols (Int -> Int -> Int -> IO ()
loopRows Int
0)
Comp -> MArray (PrimState IO) r Int e -> IO (Vector r e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
unsafeFreeze Comp
comp MArray RealWorld r Int e
MArray (PrimState IO) r Int e
mv
where
comp :: Comp
comp = Matrix r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Matrix r e
mm Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Vector r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Vector r e
v
Sz2 Int
mRows Int
mCols = Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
mm
Sz1 Int
n = Vector r e -> Sz Int
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Vector r e
v
{-# INLINE multiplyVectorByMatrix #-}
(><!)
:: (Numeric r e, Manifest r e)
=> Vector r e
-> Matrix r e
-> Vector r e
><! :: forall r e.
(Numeric r e, Manifest r e) =>
Vector r e -> Matrix r e -> Vector r e
(><!) Vector r e
v Matrix r e
mm = Either SomeException (Vector r e) -> Vector r e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Vector r e
v Vector r e -> Matrix r e -> Either SomeException (Vector r e)
forall (m :: * -> *) r e.
(MonadThrow m, Numeric r e, Manifest r e) =>
Vector r e -> Matrix r e -> m (Vector r e)
><. Matrix r e
mm)
{-# INLINE (><!) #-}
(!><!) :: (Numeric r e, Manifest r e) => Matrix r e -> Matrix r e -> Matrix r e
!><! :: forall r e.
(Numeric r e, Manifest r e) =>
Matrix r e -> Matrix r e -> Matrix r e
(!><!) Matrix r e
a1 Matrix r e
a2 = Either SomeException (Matrix r e) -> Matrix r e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Matrix r e
a1 Matrix r e -> Matrix r e -> Either SomeException (Matrix r e)
forall r e (m :: * -> *).
(Numeric r e, Manifest r e, MonadThrow m) =>
Matrix r e -> Matrix r e -> m (Matrix r e)
`multiplyMatrices` Matrix r e
a2)
{-# INLINE (!><!) #-}
(.><.) :: (Numeric r e, Manifest r e, MonadThrow m) => Matrix r e -> Matrix r e -> m (Matrix r e)
.><. :: forall r e (m :: * -> *).
(Numeric r e, Manifest r e, MonadThrow m) =>
Matrix r e -> Matrix r e -> m (Matrix r e)
(.><.) = Matrix r e -> Matrix r e -> m (Matrix r e)
forall r e (m :: * -> *).
(Numeric r e, Manifest r e, MonadThrow m) =>
Matrix r e -> Matrix r e -> m (Matrix r e)
multiplyMatrices
{-# INLINE (.><.) #-}
multiplyMatrices
:: (Numeric r e, Manifest r e, MonadThrow m) => Matrix r e -> Matrix r e -> m (Matrix r e)
multiplyMatrices :: forall r e (m :: * -> *).
(Numeric r e, Manifest r e, MonadThrow m) =>
Matrix r e -> Matrix r e -> m (Matrix r e)
multiplyMatrices Matrix r e
arrA Matrix r e
arrB
| Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
mB = SizeException -> m (Matrix r e)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (SizeException -> m (Matrix r e))
-> SizeException -> m (Matrix r e)
forall a b. (a -> b) -> a -> b
$ Sz Ix2 -> Sz Ix2 -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
arrA) (Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
arrB)
| Matrix r e -> Bool
forall ix r e. (Index ix, Size r) => Array r ix e -> Bool
isEmpty Matrix r e
arrA Bool -> Bool -> Bool
|| Matrix r e -> Bool
forall ix r e. (Index ix, Size r) => Array r ix e -> Bool
isEmpty Matrix r e
arrB = Matrix r e -> m (Matrix r e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Matrix r e -> m (Matrix r e)) -> Matrix r e -> m (Matrix r e)
forall a b. (a -> b) -> a -> b
$ (forall s. ST s (Matrix r e)) -> Matrix r e
forall a. (forall s. ST s a) -> a
runST (Comp -> MArray (PrimState (ST s)) r Ix2 e -> ST s (Matrix r e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
unsafeFreeze Comp
comp (MArray s r Ix2 e -> ST s (Matrix r e))
-> ST s (MArray s r Ix2 e) -> ST s (Matrix r e)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Sz Ix2 -> ST s (MArray (PrimState (ST s)) r Ix2 e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> m (MArray (PrimState m) r ix e)
unsafeNew Sz Ix2
forall ix. Index ix => Sz ix
zeroSz)
| Bool
otherwise = Matrix r e -> m (Matrix r e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Matrix r e -> m (Matrix r e)) -> Matrix r e -> m (Matrix r e)
forall a b. (a -> b) -> a -> b
$! IO (Matrix r e) -> Matrix r e
forall a. IO a -> a
unsafePerformIO (IO (Matrix r e) -> Matrix r e) -> IO (Matrix r e) -> Matrix r e
forall a b. (a -> b) -> a -> b
$ do
MArray RealWorld r Ix2 e
marrC <- Sz Ix2 -> e -> IO (MArray (PrimState IO) r Ix2 e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Sz ix -> e -> m (MArray (PrimState m) r ix e)
newMArray (Ix2 -> Sz Ix2
forall ix. ix -> Sz ix
SafeSz (Int
mA Int -> Int -> Ix2
:. Int
nB)) e
0
Comp -> (Scheduler RealWorld () -> IO ()) -> IO ()
forall (m :: * -> *) a b.
MonadUnliftIO m =>
Comp -> (Scheduler RealWorld a -> m b) -> m ()
withScheduler_ Comp
comp ((Scheduler RealWorld () -> IO ()) -> IO ())
-> (Scheduler RealWorld () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Scheduler RealWorld ()
scheduler -> do
let withC00 :: Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB Int -> e -> IO ()
f =
let !ixC00 :: Int
ixC00 = Int
iA Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
jB
in Int -> e -> IO ()
f Int
ixC00 (e -> IO ()) -> IO e -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< MArray (PrimState IO) r Ix2 e -> Int -> IO e
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
unsafeLinearRead MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00
withC01 :: Int -> (Int -> e -> IO ()) -> IO ()
withC01 Int
ixC00 Int -> e -> IO ()
f =
let !ixC01 :: Int
ixC01 = Int
ixC00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in Int -> e -> IO ()
f Int
ixC01 (e -> IO ()) -> IO e -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< MArray (PrimState IO) r Ix2 e -> Int -> IO e
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
unsafeLinearRead MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC01
withC10 :: Int -> (Int -> e -> IO ()) -> IO ()
withC10 Int
ixC00 Int -> e -> IO ()
f =
let !ixC10 :: Int
ixC10 = Int
ixC00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
nB
in Int -> e -> IO ()
f Int
ixC10 (e -> IO ()) -> IO e -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< MArray (PrimState IO) r Ix2 e -> Int -> IO e
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
unsafeLinearRead MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC10
withC11 :: Int -> (Int -> e -> IO ()) -> IO ()
withC11 Int
ixC01 Int -> e -> IO ()
f =
let !ixC11 :: Int
ixC11 = Int
ixC01 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
nB
in Int -> e -> IO ()
f Int
ixC11 (e -> IO ()) -> IO e -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< MArray (PrimState IO) r Ix2 e -> Int -> IO e
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> m e
unsafeLinearRead MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC11
withB00 :: Int -> Int -> (Int -> e -> IO ()) -> IO ()
withB00 Int
iB Int
jB Int -> e -> IO ()
f =
let !ixB00 :: Int
ixB00 = Int
iB Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
jB
in Int -> e -> IO ()
f Int
ixB00 (e -> IO ()) -> e -> IO ()
forall a b. (a -> b) -> a -> b
$! Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB Int
ixB00
withB00B10 :: Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withB00B10 Int
iB Int
jB Int -> e -> Int -> e -> IO ()
f =
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withB00 Int
iB Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixB00 e
b00 ->
let !ixB10 :: Int
ixB10 = Int
ixB00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
nB
in Int -> e -> Int -> e -> IO ()
f Int
ixB00 e
b00 Int
ixB10 (e -> IO ()) -> e -> IO ()
forall a b. (a -> b) -> a -> b
$! Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB Int
ixB10
withA00 :: Int -> Int -> (Int -> e -> IO ()) -> IO ()
withA00 Int
iA Int
jA Int -> e -> IO ()
f =
let !ixA00 :: Int
ixA00 = Int
iA Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
jA
in Int -> e -> IO ()
f Int
ixA00 (e -> IO ()) -> e -> IO ()
forall a b. (a -> b) -> a -> b
$! Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrA Int
ixA00
withA00A10 :: Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withA00A10 Int
iA Int
jA Int -> e -> Int -> e -> IO ()
f =
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withA00 Int
iA Int
jA ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixA00 e
a00 ->
let !ixA10 :: Int
ixA10 = Int
ixA00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
nA
in Int -> e -> Int -> e -> IO ()
f Int
ixA00 e
a00 Int
ixA10 (e -> IO ()) -> e -> IO ()
forall a b. (a -> b) -> a -> b
$! Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrA Int
ixA10
let loopColsB_UnRowBColA_UnRowA :: e -> e -> e -> e -> Int -> Int -> Int -> IO ()
loopColsB_UnRowBColA_UnRowA e
a00 e
a01 e
a10 e
a11 Int
iA Int
iB Int
jB
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n2B = do
Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withB00B10 Int
iB Int
jB ((Int -> e -> Int -> e -> IO ()) -> IO ())
-> (Int -> e -> Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixB00 e
b00 Int
ixB10 e
b10 -> do
let !b01 :: e
b01 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB (Int
ixB00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
!b11 :: e
b11 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB (Int
ixB10 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a01 e -> e -> e
forall a. Num a => a -> a -> a
* e
b10)
Int -> (Int -> e -> IO ()) -> IO ()
withC01 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC01 e
c01 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC01 (e
c01 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b01 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a01 e -> e -> e
forall a. Num a => a -> a -> a
* e
b11)
Int -> (Int -> e -> IO ()) -> IO ()
withC10 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC10 e
c10 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC10 (e
c10 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a10 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a11 e -> e -> e
forall a. Num a => a -> a -> a
* e
b10)
Int -> (Int -> e -> IO ()) -> IO ()
withC11 Int
ixC01 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC11 e
c11 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC11 (e
c11 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a10 e -> e -> e
forall a. Num a => a -> a -> a
* e
b01 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a11 e -> e -> e
forall a. Num a => a -> a -> a
* e
b11)
e -> e -> e -> e -> Int -> Int -> Int -> IO ()
loopColsB_UnRowBColA_UnRowA e
a00 e
a01 e
a10 e
a11 Int
iA Int
iB (Int
jB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
nB = Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withB00B10 Int
iB Int
jB ((Int -> e -> Int -> e -> IO ()) -> IO ())
-> (Int -> e -> Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
_ e
b00 Int
_ e
b10 ->
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a01 e -> e -> e
forall a. Num a => a -> a -> a
* e
b10)
Int -> (Int -> e -> IO ()) -> IO ()
withC10 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC10 e
c10 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC10 (e
c10 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a10 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a11 e -> e -> e
forall a. Num a => a -> a -> a
* e
b10)
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
loopColsB_UnRowBColA_RowA :: e -> e -> Int -> Int -> Int -> IO ()
loopColsB_UnRowBColA_RowA e
a00 e
a01 Int
iA Int
iB Int
jB
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n2B = do
Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withB00B10 Int
iB Int
jB ((Int -> e -> Int -> e -> IO ()) -> IO ())
-> (Int -> e -> Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixB00 e
b00 Int
ixB10 e
b10 -> do
let !b01 :: e
b01 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB (Int
ixB00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
!b11 :: e
b11 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB (Int
ixB10 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a01 e -> e -> e
forall a. Num a => a -> a -> a
* e
b10)
Int -> (Int -> e -> IO ()) -> IO ()
withC01 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC01 e
c01 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC01 (e
c01 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b01 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a01 e -> e -> e
forall a. Num a => a -> a -> a
* e
b11)
e -> e -> Int -> Int -> Int -> IO ()
loopColsB_UnRowBColA_RowA e
a00 e
a01 Int
iA Int
iB (Int
jB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
nB = Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withB00B10 Int
iB Int
jB ((Int -> e -> Int -> e -> IO ()) -> IO ())
-> (Int -> e -> Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
_ e
b00 Int
_ e
b10 ->
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a01 e -> e -> e
forall a. Num a => a -> a -> a
* e
b10)
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
loopColsB_RowBColA_UnRowA :: e -> e -> Int -> Int -> Int -> IO ()
loopColsB_RowBColA_UnRowA e
a00 e
a10 Int
iA Int
iB Int
jB
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n2B = do
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withB00 Int
iB Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixB00 e
b00 -> do
let !b01 :: e
b01 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB (Int
ixB00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00)
Int -> (Int -> e -> IO ()) -> IO ()
withC01 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC01 e
c01 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC01 (e
c01 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b01)
Int -> (Int -> e -> IO ()) -> IO ()
withC10 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC10 e
c10 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC10 (e
c10 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a10 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00)
Int -> (Int -> e -> IO ()) -> IO ()
withC11 Int
ixC01 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC11 e
c11 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC11 (e
c11 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a10 e -> e -> e
forall a. Num a => a -> a -> a
* e
b01)
e -> e -> Int -> Int -> Int -> IO ()
loopColsB_RowBColA_UnRowA e
a00 e
a10 Int
iA Int
iB (Int
jB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
nB = Int -> Int -> (Int -> e -> IO ()) -> IO ()
withB00 Int
iB Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
_ e
b00 ->
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00)
Int -> (Int -> e -> IO ()) -> IO ()
withC10 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC10 e
c10 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC10 (e
c10 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a10 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00)
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
loopColsB_RowBColA_RowA :: e -> Int -> Int -> Int -> IO ()
loopColsB_RowBColA_RowA e
a00 Int
iA Int
iB Int
jB
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n2B = do
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withB00 Int
iB Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixB00 e
b00 -> do
let !b01 :: e
b01 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrB (Int
ixB00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00)
Int -> (Int -> e -> IO ()) -> IO ()
withC01 Int
ixC00 ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC01 e
c01 -> do
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC01 (e
c01 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b01)
e -> Int -> Int -> Int -> IO ()
loopColsB_RowBColA_RowA e
a00 Int
iA Int
iB (Int
jB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Int
jB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
nB = Int -> Int -> (Int -> e -> IO ()) -> IO ()
withB00 Int
iB Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
_ e
b00 ->
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withC00 Int
iA Int
jB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixC00 e
c00 ->
MArray (PrimState IO) r Ix2 e -> Int -> e -> IO ()
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
MArray (PrimState m) r ix e -> Int -> e -> m ()
unsafeLinearWrite MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC Int
ixC00 (e
c00 e -> e -> e
forall a. Num a => a -> a -> a
+ e
a00 e -> e -> e
forall a. Num a => a -> a -> a
* e
b00)
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
loopRowsB_UnRowA :: Int -> Int -> IO ()
loopRowsB_UnRowA Int
iA Int
iB
| Int
iB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
m2B = do
Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withA00A10 Int
iA Int
iB ((Int -> e -> Int -> e -> IO ()) -> IO ())
-> (Int -> e -> Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixA00 e
a00 Int
ixA10 e
a10 -> do
let !a01 :: e
a01 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrA (Int
ixA00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
!a11 :: e
a11 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrA (Int
ixA10 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
e -> e -> e -> e -> Int -> Int -> Int -> IO ()
loopColsB_UnRowBColA_UnRowA e
a00 e
a01 e
a10 e
a11 Int
iA Int
iB Int
0
Int -> Int -> IO ()
loopRowsB_UnRowA Int
iA (Int
iB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Int
iB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
mB =
Int -> Int -> (Int -> e -> Int -> e -> IO ()) -> IO ()
withA00A10 Int
iA Int
iB ((Int -> e -> Int -> e -> IO ()) -> IO ())
-> (Int -> e -> Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
_ e
a00 Int
_ e
a10 -> e -> e -> Int -> Int -> Int -> IO ()
loopColsB_RowBColA_UnRowA e
a00 e
a10 Int
iA Int
iB Int
0
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
loopRowsB_RowA :: Int -> Int -> IO ()
loopRowsB_RowA Int
iA Int
iB
| Int
iB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
m2B = do
Int -> Int -> (Int -> e -> IO ()) -> IO ()
withA00 Int
iA Int
iB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
ixA00 e
a00 -> do
let !a01 :: e
a01 = Matrix r e -> Int -> e
forall ix. Index ix => Array r ix e -> Int -> e
forall r e ix. (Source r e, Index ix) => Array r ix e -> Int -> e
unsafeLinearIndex Matrix r e
arrA (Int
ixA00 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
e -> e -> Int -> Int -> Int -> IO ()
loopColsB_UnRowBColA_RowA e
a00 e
a01 Int
iA Int
iB Int
0
Int -> Int -> IO ()
loopRowsB_RowA Int
iA (Int
iB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Int
iB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
mB = Int -> Int -> (Int -> e -> IO ()) -> IO ()
withA00 Int
iA Int
iB ((Int -> e -> IO ()) -> IO ()) -> (Int -> e -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Int
_ e
a00 -> e -> Int -> Int -> Int -> IO ()
loopColsB_RowBColA_RowA e
a00 Int
iA Int
iB Int
0
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
loopRowsA :: Int -> IO ()
loopRowsA Int
iA
| Int
iA Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
m2A = do
Scheduler RealWorld () -> IO () -> IO ()
forall s (m :: * -> *).
MonadPrimBase s m =>
Scheduler s () -> m () -> m ()
scheduleWork_ Scheduler RealWorld ()
scheduler (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> IO ()
loopRowsB_UnRowA Int
iA Int
0
Int -> IO ()
loopRowsA (Int
iA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2)
| Int
iA Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
mA = Scheduler RealWorld () -> IO () -> IO ()
forall s (m :: * -> *).
MonadPrimBase s m =>
Scheduler s () -> m () -> m ()
scheduleWork_ Scheduler RealWorld ()
scheduler (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Int -> Int -> IO ()
loopRowsB_RowA Int
iA Int
0
| Bool
otherwise = () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Int -> IO ()
loopRowsA Int
0
Comp -> MArray (PrimState IO) r Ix2 e -> IO (Matrix r e)
forall r e ix (m :: * -> *).
(Manifest r e, Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
forall ix (m :: * -> *).
(Index ix, PrimMonad m) =>
Comp -> MArray (PrimState m) r ix e -> m (Array r ix e)
unsafeFreeze Comp
comp MArray RealWorld r Ix2 e
MArray (PrimState IO) r Ix2 e
marrC
where
comp :: Comp
comp = Matrix r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Matrix r e
arrA Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Matrix r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Matrix r e
arrB
m2A :: Int
m2A = Int
mA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
mA Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
2
m2B :: Int
m2B = Int
mB Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
mB Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
2
n2B :: Int
n2B = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nB Int -> Int -> Int
forall a. Integral a => a -> a -> a
`rem` Int
2
Sz (Int
mA :. Int
nA) = Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
arrA
Sz (Int
mB :. Int
nB) = Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
arrB
{-# INLINEABLE multiplyMatrices #-}
multiplyMatricesTransposed
:: (Numeric r e, Manifest r e, MonadThrow m)
=> Matrix r e
-> Matrix r e
-> m (Matrix D e)
multiplyMatricesTransposed :: forall r e (m :: * -> *).
(Numeric r e, Manifest r e, MonadThrow m) =>
Matrix r e -> Matrix r e -> m (Matrix D e)
multiplyMatricesTransposed Matrix r e
arr1 Matrix r e
arr2
| Int
n1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
m2 = SizeException -> m (Matrix D e)
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (SizeException -> m (Matrix D e))
-> SizeException -> m (Matrix D e)
forall a b. (a -> b) -> a -> b
$ Sz Ix2 -> Sz Ix2 -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
arr1) (Int -> Int -> Sz Ix2
Sz2 Int
m2 Int
n2)
| Matrix r e -> Bool
forall ix r e. (Index ix, Size r) => Array r ix e -> Bool
isEmpty Matrix r e
arr1 Bool -> Bool -> Bool
|| Matrix r e -> Bool
forall ix r e. (Index ix, Size r) => Array r ix e -> Bool
isEmpty Matrix r e
arr2 = Matrix D e -> m (Matrix D e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Matrix D e -> m (Matrix D e)) -> Matrix D e -> m (Matrix D e)
forall a b. (a -> b) -> a -> b
$ Comp -> Matrix D e -> Matrix D e
forall r ix e. Strategy r => Comp -> Array r ix e -> Array r ix e
forall ix e. Comp -> Array D ix e -> Array D ix e
setComp Comp
comp Matrix D e
forall r ix e. Load r ix e => Array r ix e
empty
| Bool
otherwise =
Matrix D e -> m (Matrix D e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Matrix D e -> m (Matrix D e)) -> Matrix D e -> m (Matrix D e)
forall a b. (a -> b) -> a -> b
$
Comp -> Sz Ix2 -> (Ix2 -> e) -> Matrix D e
forall r ix e.
Load r ix e =>
Comp -> Sz ix -> (ix -> e) -> Array r ix e
makeArray Comp
comp (Ix2 -> Sz Ix2
forall ix. ix -> Sz ix
SafeSz (Int
m1 Int -> Int -> Ix2
:. Int
n2)) ((Ix2 -> e) -> Matrix D e) -> (Ix2 -> e) -> Matrix D e
forall a b. (a -> b) -> a -> b
$ \(Int
i :. Int
j) ->
Array r Int e -> Array r Int e -> e
forall ix. Index ix => Array r ix e -> Array r ix e -> e
forall r e ix.
(FoldNumeric r e, Index ix) =>
Array r ix e -> Array r ix e -> e
unsafeDotProduct (Int -> Sz Int -> Matrix r e -> Array r Int e
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix e -> Array r Int e
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice (Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
n1) Sz Int
n Matrix r e
arr1) (Int -> Sz Int -> Matrix r e -> Array r Int e
forall ix.
Index ix =>
Int -> Sz Int -> Array r ix e -> Array r Int e
forall r e ix.
(Source r e, Index ix) =>
Int -> Sz Int -> Array r ix e -> Array r Int e
unsafeLinearSlice (Int
j Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
n1) Sz Int
n Matrix r e
arr2)
where
comp :: Comp
comp = Matrix r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Matrix r e
arr1 Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Matrix r e -> Comp
forall r ix e. Strategy r => Array r ix e -> Comp
forall ix e. Array r ix e -> Comp
getComp Matrix r e
arr2
n :: Sz Int
n = Int -> Sz Int
forall ix. ix -> Sz ix
SafeSz Int
n1
SafeSz (Int
m1 :. Int
n1) = Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
arr1
SafeSz (Int
n2 :. Int
m2) = Matrix r e -> Sz Ix2
forall r ix e. Size r => Array r ix e -> Sz ix
forall ix e. Array r ix e -> Sz ix
size Matrix r e
arr2
{-# INLINE multiplyMatricesTransposed #-}
identityMatrix :: Num e => Sz1 -> Matrix DL e
identityMatrix :: forall e. Num e => Sz Int -> Matrix DL e
identityMatrix (Sz Int
n) =
Sz Ix2
-> e
-> (forall {m :: * -> *}. Monad m => (Ix2 -> e -> m Bool) -> m ())
-> Array DL Ix2 e
forall ix e.
Index ix =>
Sz ix
-> e
-> (forall (m :: * -> *). Monad m => (ix -> e -> m Bool) -> m ())
-> Array DL ix e
makeLoadArrayS (Int -> Int -> Sz Ix2
Sz2 Int
n Int
n) e
0 ((forall {m :: * -> *}. Monad m => (Ix2 -> e -> m Bool) -> m ())
-> Array DL Ix2 e)
-> (forall {m :: * -> *}. Monad m => (Ix2 -> e -> m Bool) -> m ())
-> Array DL Ix2 e
forall a b. (a -> b) -> a -> b
$ \Ix2 -> e -> m Bool
w -> Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> m Bool) -> m ()
forall (f :: * -> *) a.
Applicative f =>
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> f a) -> f ()
loopA_ Int
0 (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
n) (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ((Int -> m Bool) -> m ()) -> (Int -> m Bool) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
i -> Ix2 -> e -> m Bool
w (Int
i Int -> Int -> Ix2
:. Int
i) e
1
{-# INLINE identityMatrix #-}
lowerTriangular :: forall e. Num e => Comp -> Sz1 -> (Ix2 -> e) -> Matrix DL e
lowerTriangular :: forall e. Num e => Comp -> Sz Int -> (Ix2 -> e) -> Matrix DL e
lowerTriangular Comp
comp (Sz1 Int
n) Ix2 -> e
f = Comp -> Sz Ix2 -> Loader e -> Array DL Ix2 e
forall ix e. Comp -> Sz ix -> Loader e -> Array DL ix e
DLArray Comp
comp (Ix2 -> Sz Ix2
forall ix. ix -> Sz ix
SafeSz (Int
n Int -> Int -> Ix2
:. Int
n)) Scheduler s ()
-> Int
-> (Int -> e -> ST s ())
-> (Int -> Sz Int -> e -> ST s ())
-> ST s ()
Loader e
load
where
load :: Loader e
load :: Loader e
load Scheduler s ()
scheduler Int
startAt Int -> e -> ST s ()
uWrite Int -> Sz Int -> e -> ST s ()
uSet = do
Array D Int Int -> (Int -> ST s ()) -> ST s ()
forall r a ix (m :: * -> *) b.
(Source r a, Index ix, Monad m) =>
Array r ix a -> (a -> m b) -> m ()
forM_ (Int
0 Int -> Int -> Array D Int Int
forall ix. Index ix => ix -> ix -> Array D ix ix
..: Int
n) ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Int
i -> do
let !k :: Int
k = Int
startAt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
n
Scheduler s () -> ST s () -> ST s ()
forall s (m :: * -> *).
MonadPrimBase s m =>
Scheduler s () -> m () -> m ()
scheduleWork_ Scheduler s ()
scheduler (ST s () -> ST s ()) -> ST s () -> ST s ()
forall a b. (a -> b) -> a -> b
$ do
Array D Int Int -> (Int -> ST s ()) -> ST s ()
forall r a ix (m :: * -> *) b.
(Source r a, Index ix, Monad m) =>
Array r ix a -> (a -> m b) -> m ()
forM_ (Int
0 Int -> Int -> Array D Int Int
forall ix. Index ix => ix -> ix -> Array D ix ix
... Int
i) ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Int
j -> Int -> e -> ST s ()
uWrite (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
j) (Ix2 -> e
f (Int
i Int -> Int -> Ix2
:. Int
j))
Int -> Sz Int -> e -> ST s ()
uSet (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) (Int -> Sz Int
forall ix. Index ix => ix -> Sz ix
Sz (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)) e
0
{-# INLINE lowerTriangular #-}
upperTriangular :: forall e. Num e => Comp -> Sz1 -> (Ix2 -> e) -> Matrix DL e
upperTriangular :: forall e. Num e => Comp -> Sz Int -> (Ix2 -> e) -> Matrix DL e
upperTriangular Comp
comp (Sz1 Int
n) Ix2 -> e
f = Comp -> Sz Ix2 -> Loader e -> Array DL Ix2 e
forall ix e. Comp -> Sz ix -> Loader e -> Array DL ix e
DLArray Comp
comp (Ix2 -> Sz Ix2
forall ix. ix -> Sz ix
SafeSz (Int
n Int -> Int -> Ix2
:. Int
n)) Scheduler s ()
-> Int
-> (Int -> e -> ST s ())
-> (Int -> Sz Int -> e -> ST s ())
-> ST s ()
Loader e
load
where
load :: Loader e
load :: Loader e
load Scheduler s ()
scheduler Int
startAt Int -> e -> ST s ()
uWrite Int -> Sz Int -> e -> ST s ()
uSet = do
Array D Int Int -> (Int -> ST s ()) -> ST s ()
forall r a ix (m :: * -> *) b.
(Source r a, Index ix, Monad m) =>
Array r ix a -> (a -> m b) -> m ()
forM_ (Int
0 Int -> Int -> Array D Int Int
forall ix. Index ix => ix -> ix -> Array D ix ix
..: Int
n) ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Int
i -> do
let !k :: Int
k = Int
startAt Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
n
Scheduler s () -> ST s () -> ST s ()
forall s (m :: * -> *).
MonadPrimBase s m =>
Scheduler s () -> m () -> m ()
scheduleWork_ Scheduler s ()
scheduler (ST s () -> ST s ()) -> ST s () -> ST s ()
forall a b. (a -> b) -> a -> b
$ do
Int -> Sz Int -> e -> ST s ()
uSet Int
k (Int -> Sz Int
forall ix. ix -> Sz ix
SafeSz Int
i) e
0
Array D Int Int -> (Int -> ST s ()) -> ST s ()
forall r a ix (m :: * -> *) b.
(Source r a, Index ix, Monad m) =>
Array r ix a -> (a -> m b) -> m ()
forM_ (Int
i Int -> Int -> Array D Int Int
forall ix. Index ix => ix -> ix -> Array D ix ix
..: Int
n) ((Int -> ST s ()) -> ST s ()) -> (Int -> ST s ()) -> ST s ()
forall a b. (a -> b) -> a -> b
$ \Int
j -> Int -> e -> ST s ()
uWrite (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
j) (Ix2 -> e
f (Int
i Int -> Int -> Ix2
:. Int
j))
{-# INLINE upperTriangular #-}
negateA :: (Index ix, Numeric r e) => Array r ix e -> Array r ix e
negateA :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> Array r ix e
negateA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Num a => a -> a
negate
{-# INLINE negateA #-}
absA :: (Index ix, Numeric r e) => Array r ix e -> Array r ix e
absA :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> Array r ix e
absA = Array r ix e -> Array r ix e
forall ix. Index ix => Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> Array r ix e
absPointwise
{-# INLINE absA #-}
signumA :: (Index ix, Numeric r e) => Array r ix e -> Array r ix e
signumA :: forall ix r e.
(Index ix, Numeric r e) =>
Array r ix e -> Array r ix e
signumA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Num a => a -> a
signum
{-# INLINE signumA #-}
(./.)
:: (Index ix, NumericFloat r e, MonadThrow m)
=> Array r ix e
-> Array r ix e
-> m (Array r ix e)
./. :: forall ix r e (m :: * -> *).
(Index ix, NumericFloat r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
(./.) = (Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
forall ix r (m :: * -> *) e.
(Index ix, Size r, MonadThrow m) =>
(Array r ix e -> Array r ix e -> Array r ix e)
-> Array r ix e -> Array r ix e -> m (Array r ix e)
applyExactSize2M Array r ix e -> Array r ix e -> Array r ix e
forall ix. Index ix => Array r ix e -> Array r ix e -> Array r ix e
forall r e ix.
(NumericFloat r e, Index ix) =>
Array r ix e -> Array r ix e -> Array r ix e
divisionPointwise
{-# INLINE (./.) #-}
(!/!) :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e -> Array r ix e
!/! :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e -> Array r ix e
(!/!) Array r ix e
a1 Array r ix e
a2 = Either SomeException (Array r ix e) -> Array r ix e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Array r ix e
a1 Array r ix e -> Array r ix e -> Either SomeException (Array r ix e)
forall ix r e (m :: * -> *).
(Index ix, NumericFloat r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
./. Array r ix e
a2)
{-# INLINE (!/!) #-}
(/.) :: (Index ix, NumericFloat r e) => e -> Array r ix e -> Array r ix e
/. :: forall ix r e.
(Index ix, NumericFloat r e) =>
e -> Array r ix e -> Array r ix e
(/.) = e -> Array r ix e -> Array r ix e
forall ix. Index ix => e -> Array r ix e -> Array r ix e
forall r e ix.
(NumericFloat r e, Index ix) =>
e -> Array r ix e -> Array r ix e
scalarDivide
{-# INLINE (/.) #-}
(./) :: (Index ix, NumericFloat r e) => Array r ix e -> e -> Array r ix e
./ :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> e -> Array r ix e
(./) = Array r ix e -> e -> Array r ix e
forall ix. Index ix => Array r ix e -> e -> Array r ix e
forall r e ix.
(NumericFloat r e, Index ix) =>
Array r ix e -> e -> Array r ix e
divideScalar
{-# INLINE (./) #-}
(.^^)
:: (Index ix, Numeric r e, Fractional e, Integral b)
=> Array r ix e
-> b
-> Array r ix e
.^^ :: forall ix r e b.
(Index ix, Numeric r e, Fractional e, Integral b) =>
Array r ix e -> b -> Array r ix e
(.^^) Array r ix e
arr b
n = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray (e -> b -> e
forall a b. (Fractional a, Integral b) => a -> b -> a
^^ b
n) Array r ix e
arr
{-# INLINE (.^^) #-}
recipA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
recipA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
recipA = Array r ix e -> Array r ix e
forall ix. Index ix => Array r ix e -> Array r ix e
forall r e ix.
(NumericFloat r e, Index ix) =>
Array r ix e -> Array r ix e
recipPointwise
{-# INLINE recipA #-}
expA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
expA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
expA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
exp
{-# INLINE expA #-}
sqrtA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
sqrtA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
sqrtA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
sqrt
{-# INLINE sqrtA #-}
logA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
logA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
logA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
log
{-# INLINE logA #-}
logBaseA
:: (Index ix, Source r1 e, Source r2 e, Floating e)
=> Array r1 ix e
-> Array r2 ix e
-> Array D ix e
logBaseA :: forall ix r1 e r2.
(Index ix, Source r1 e, Source r2 e, Floating e) =>
Array r1 ix e -> Array r2 ix e -> Array D ix e
logBaseA = (e -> e -> e) -> Array r1 ix e -> Array r2 ix e -> Array D ix e
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> e
forall a. Floating a => a -> a -> a
logBase
{-# INLINE logBaseA #-}
(.**)
:: (Index ix, Source r1 e, Source r2 e, Floating e)
=> Array r1 ix e
-> Array r2 ix e
-> Array D ix e
.** :: forall ix r1 e r2.
(Index ix, Source r1 e, Source r2 e, Floating e) =>
Array r1 ix e -> Array r2 ix e -> Array D ix e
(.**) = (e -> e -> e) -> Array r1 ix e -> Array r2 ix e -> Array D ix e
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> e
forall a. Floating a => a -> a -> a
(**)
{-# INLINE (.**) #-}
sinA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
sinA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
sinA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
sin
{-# INLINE sinA #-}
cosA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
cosA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
cosA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
cos
{-# INLINE cosA #-}
tanA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
tanA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
tanA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
tan
{-# INLINE tanA #-}
asinA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
asinA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
asinA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
asin
{-# INLINE asinA #-}
atanA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
atanA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
atanA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
atan
{-# INLINE atanA #-}
acosA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
acosA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
acosA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
acos
{-# INLINE acosA #-}
sinhA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
sinhA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
sinhA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
sinh
{-# INLINE sinhA #-}
tanhA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
tanhA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
tanhA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
tanh
{-# INLINE tanhA #-}
coshA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
coshA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
coshA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
cosh
{-# INLINE coshA #-}
asinhA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
asinhA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
asinhA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
asinh
{-# INLINE asinhA #-}
acoshA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
acoshA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
acoshA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
acosh
{-# INLINE acoshA #-}
atanhA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
atanhA :: forall ix r e.
(Index ix, NumericFloat r e) =>
Array r ix e -> Array r ix e
atanhA = (e -> e) -> Array r ix e -> Array r ix e
forall ix. Index ix => (e -> e) -> Array r ix e -> Array r ix e
forall r e ix.
(Numeric r e, Index ix) =>
(e -> e) -> Array r ix e -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
atanh
{-# INLINE atanhA #-}
quotA
:: (HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e)
=> Array r1 ix e
-> Array r2 ix e
-> Array D ix e
quotA :: forall ix r1 e r2.
(HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e) =>
Array r1 ix e -> Array r2 ix e -> Array D ix e
quotA = (e -> e -> e) -> Array r1 ix e -> Array r2 ix e -> Array D ix e
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> e
forall a. Integral a => a -> a -> a
quot
{-# INLINE quotA #-}
remA
:: (HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e)
=> Array r1 ix e
-> Array r2 ix e
-> Array D ix e
remA :: forall ix r1 e r2.
(HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e) =>
Array r1 ix e -> Array r2 ix e -> Array D ix e
remA = (e -> e -> e) -> Array r1 ix e -> Array r2 ix e -> Array D ix e
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> e
forall a. Integral a => a -> a -> a
rem
{-# INLINE remA #-}
divA
:: (HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e)
=> Array r1 ix e
-> Array r2 ix e
-> Array D ix e
divA :: forall ix r1 e r2.
(HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e) =>
Array r1 ix e -> Array r2 ix e -> Array D ix e
divA = (e -> e -> e) -> Array r1 ix e -> Array r2 ix e -> Array D ix e
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> e
forall a. Integral a => a -> a -> a
div
{-# INLINE divA #-}
modA
:: (HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e)
=> Array r1 ix e
-> Array r2 ix e
-> Array D ix e
modA :: forall ix r1 e r2.
(HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e) =>
Array r1 ix e -> Array r2 ix e -> Array D ix e
modA = (e -> e -> e) -> Array r1 ix e -> Array r2 ix e -> Array D ix e
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> e
forall a. Integral a => a -> a -> a
mod
{-# INLINE modA #-}
quotRemA
:: (HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e)
=> Array r1 ix e
-> Array r2 ix e
-> (Array D ix e, Array D ix e)
quotRemA :: forall ix r1 e r2.
(HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e) =>
Array r1 ix e -> Array r2 ix e -> (Array D ix e, Array D ix e)
quotRemA Array r1 ix e
arr1 = Array D ix (e, e) -> (Array D ix e, Array D ix e)
forall ix r e1 e2.
(Index ix, Source r (e1, e2)) =>
Array r ix (e1, e2) -> (Array D ix e1, Array D ix e2)
A.unzip (Array D ix (e, e) -> (Array D ix e, Array D ix e))
-> (Array r2 ix e -> Array D ix (e, e))
-> Array r2 ix e
-> (Array D ix e, Array D ix e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e -> (e, e))
-> Array r1 ix e -> Array r2 ix e -> Array D ix (e, e)
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> (e, e)
forall a. Integral a => a -> a -> (a, a)
quotRem Array r1 ix e
arr1
{-# INLINE quotRemA #-}
divModA
:: (HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e)
=> Array r1 ix e
-> Array r2 ix e
-> (Array D ix e, Array D ix e)
divModA :: forall ix r1 e r2.
(HasCallStack, Index ix, Source r1 e, Source r2 e, Integral e) =>
Array r1 ix e -> Array r2 ix e -> (Array D ix e, Array D ix e)
divModA Array r1 ix e
arr1 = Array D ix (e, e) -> (Array D ix e, Array D ix e)
forall ix r e1 e2.
(Index ix, Source r (e1, e2)) =>
Array r ix (e1, e2) -> (Array D ix e1, Array D ix e2)
A.unzip (Array D ix (e, e) -> (Array D ix e, Array D ix e))
-> (Array r2 ix e -> Array D ix (e, e))
-> Array r2 ix e
-> (Array D ix e, Array D ix e)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (e -> e -> (e, e))
-> Array r1 ix e -> Array r2 ix e -> Array D ix (e, e)
forall ix r1 a r2 b e.
(HasCallStack, Index ix, Source r1 a, Source r2 b) =>
(a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2' e -> e -> (e, e)
forall a. Integral a => a -> a -> (a, a)
divMod Array r1 ix e
arr1
{-# INLINE divModA #-}
truncateA :: (Index ix, Source r a, RealFrac a, Integral e) => Array r ix a -> Array D ix e
truncateA :: forall ix r a e.
(Index ix, Source r a, RealFrac a, Integral e) =>
Array r ix a -> Array D ix e
truncateA = (a -> e) -> Array r ix a -> Array D ix e
forall ix r e' e.
(Index ix, Source r e') =>
(e' -> e) -> Array r ix e' -> Array D ix e
A.map a -> e
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
truncate
{-# INLINE truncateA #-}
roundA :: (Index ix, Source r a, RealFrac a, Integral e) => Array r ix a -> Array D ix e
roundA :: forall ix r a e.
(Index ix, Source r a, RealFrac a, Integral e) =>
Array r ix a -> Array D ix e
roundA = (a -> e) -> Array r ix a -> Array D ix e
forall ix r e' e.
(Index ix, Source r e') =>
(e' -> e) -> Array r ix e' -> Array D ix e
A.map a -> e
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
round
{-# INLINE roundA #-}
ceilingA :: (Index ix, Source r a, RealFrac a, Integral e) => Array r ix a -> Array D ix e
ceilingA :: forall ix r a e.
(Index ix, Source r a, RealFrac a, Integral e) =>
Array r ix a -> Array D ix e
ceilingA = (a -> e) -> Array r ix a -> Array D ix e
forall ix r e' e.
(Index ix, Source r e') =>
(e' -> e) -> Array r ix e' -> Array D ix e
A.map a -> e
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
ceiling
{-# INLINE ceilingA #-}
floorA :: (Index ix, Source r a, RealFrac a, Integral e) => Array r ix a -> Array D ix e
floorA :: forall ix r a e.
(Index ix, Source r a, RealFrac a, Integral e) =>
Array r ix a -> Array D ix e
floorA = (a -> e) -> Array r ix a -> Array D ix e
forall ix r e' e.
(Index ix, Source r e') =>
(e' -> e) -> Array r ix e' -> Array D ix e
A.map a -> e
forall b. Integral b => a -> b
forall a b. (RealFrac a, Integral b) => a -> b
floor
{-# INLINE floorA #-}
atan2A
:: (Index ix, Numeric r e, RealFloat e, MonadThrow m)
=> Array r ix e
-> Array r ix e
-> m (Array r ix e)
atan2A :: forall ix r e (m :: * -> *).
(Index ix, Numeric r e, RealFloat e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
atan2A = (e -> e -> e) -> Array r ix e -> Array r ix e -> m (Array r ix e)
forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> m (Array r ix e)
liftNumArray2M e -> e -> e
forall a. RealFloat a => a -> a -> a
atan2
{-# INLINE atan2A #-}
sumArrays' :: (HasCallStack, Foldable t, Load r ix e, Numeric r e) => t (Array r ix e) -> Array r ix e
sumArrays' :: forall (t :: * -> *) r ix e.
(HasCallStack, Foldable t, Load r ix e, Numeric r e) =>
t (Array r ix e) -> Array r ix e
sumArrays' = Either SomeException (Array r ix e) -> Array r ix e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Either SomeException (Array r ix e) -> Array r ix e)
-> (t (Array r ix e) -> Either SomeException (Array r ix e))
-> t (Array r ix e)
-> Array r ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t (Array r ix e) -> Either SomeException (Array r ix e)
forall (t :: * -> *) r ix e (m :: * -> *).
(Foldable t, Load r ix e, Numeric r e, MonadThrow m) =>
t (Array r ix e) -> m (Array r ix e)
sumArraysM
{-# INLINE sumArrays' #-}
sumArraysM
:: (Foldable t, Load r ix e, Numeric r e, MonadThrow m) => t (Array r ix e) -> m (Array r ix e)
sumArraysM :: forall (t :: * -> *) r ix e (m :: * -> *).
(Foldable t, Load r ix e, Numeric r e, MonadThrow m) =>
t (Array r ix e) -> m (Array r ix e)
sumArraysM t (Array r ix e)
as =
case t (Array r ix e) -> [Array r ix e]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList t (Array r ix e)
as of
[] -> Array r ix e -> m (Array r ix e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Array r ix e
forall r ix e. Load r ix e => Array r ix e
empty
(Array r ix e
x : [Array r ix e]
xs) -> (Array r ix e -> Array r ix e -> m (Array r ix e))
-> Array r ix e -> [Array r ix e] -> m (Array r ix e)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
F.foldlM Array r ix e -> Array r ix e -> m (Array r ix e)
forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
(.+.) Array r ix e
x [Array r ix e]
xs
{-# INLINE sumArraysM #-}
productArrays'
:: (HasCallStack, Foldable t, Load r ix e, Numeric r e) => t (Array r ix e) -> Array r ix e
productArrays' :: forall (t :: * -> *) r ix e.
(HasCallStack, Foldable t, Load r ix e, Numeric r e) =>
t (Array r ix e) -> Array r ix e
productArrays' = Either SomeException (Array r ix e) -> Array r ix e
forall a. HasCallStack => Either SomeException a -> a
throwEither (Either SomeException (Array r ix e) -> Array r ix e)
-> (t (Array r ix e) -> Either SomeException (Array r ix e))
-> t (Array r ix e)
-> Array r ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t (Array r ix e) -> Either SomeException (Array r ix e)
forall (t :: * -> *) r ix e (m :: * -> *).
(Foldable t, Load r ix e, Numeric r e, MonadThrow m) =>
t (Array r ix e) -> m (Array r ix e)
productArraysM
{-# INLINE productArrays' #-}
productArraysM
:: (Foldable t, Load r ix e, Numeric r e, MonadThrow m) => t (Array r ix e) -> m (Array r ix e)
productArraysM :: forall (t :: * -> *) r ix e (m :: * -> *).
(Foldable t, Load r ix e, Numeric r e, MonadThrow m) =>
t (Array r ix e) -> m (Array r ix e)
productArraysM t (Array r ix e)
as =
case t (Array r ix e) -> [Array r ix e]
forall a. t a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList t (Array r ix e)
as of
[] -> Array r ix e -> m (Array r ix e)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Array r ix e
forall r ix e. Load r ix e => Array r ix e
empty
(Array r ix e
x : [Array r ix e]
xs) -> (Array r ix e -> Array r ix e -> m (Array r ix e))
-> Array r ix e -> [Array r ix e] -> m (Array r ix e)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
F.foldlM Array r ix e -> Array r ix e -> m (Array r ix e)
forall ix r e (m :: * -> *).
(Index ix, Numeric r e, MonadThrow m) =>
Array r ix e -> Array r ix e -> m (Array r ix e)
(.*.) Array r ix e
x [Array r ix e]
xs
{-# INLINE productArraysM #-}