{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
-- |
-- Module      : Data.Massiv.Array.Numeric
-- Copyright   : (c) Alexey Kuleshevich 2018-2019
-- License     : BSD3
-- Maintainer  : Alexey Kuleshevich <lehins@yandex.ru>
-- Stability   : experimental
-- Portability : non-portable
--
module Data.Massiv.Array.Numeric
  ( -- * Num
    (.+.)
  , (.+)
  , (+.)
  , (.-.)
  , (.-)
  , (-.)
  , (.*.)
  , (.*)
  , (*.)
  , (.^)
  , (#>)
  , (|*|)
  , multiplyTransposed
  , identityMatrix
  , lowerTriangular
  , upperTriangular
  , negateA
  , absA
  , signumA
  , fromIntegerA
  -- * Integral
  , quotA
  , remA
  , divA
  , modA
  , quotRemA
  , divModA
  -- * Fractional
  , (./.)
  , (./)
  , (.^^)
  , recipA
  , fromRationalA
  -- * Floating
  , piA
  , expA
  , logA
  , sqrtA
  , (.**)
  , logBaseA
  , sinA
  , cosA
  , tanA
  , asinA
  , acosA
  , atanA
  , sinhA
  , coshA
  , tanhA
  , asinhA
  , acoshA
  , atanhA
  -- * RealFrac
  , truncateA
  , roundA
  , ceilingA
  , floorA
  -- * RealFloat
  , atan2A
  ) where

import Data.Massiv.Array.Delayed.Pull
import Data.Massiv.Array.Delayed.Push
import Data.Massiv.Array.Manifest.Internal
import Data.Massiv.Array.Ops.Fold as A
import Data.Massiv.Array.Ops.Map as A
import Data.Massiv.Array.Ops.Transform as A
import Data.Massiv.Array.Ops.Construct
import Data.Massiv.Core
import Data.Massiv.Core.Common
import Data.Massiv.Core.Operations
import Prelude as P


infixr 8  .^, .^^
infixl 7  .*., .*, *., ./., ./, `quotA`, `remA`, `divA`, `modA`
infixl 6  .+., .+, +., .-., .-, -.

liftArray2Matching
  :: (Source r1 ix a, Source r2 ix b)
  => (a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2Matching :: (a -> b -> e) -> Array r1 ix a -> Array r2 ix b -> Array D ix e
liftArray2Matching a -> b -> e
f !Array r1 ix a
arr1 !Array r2 ix b
arr2
  | Sz ix
sz1 Sz ix -> Sz ix -> Bool
forall a. Eq a => a -> a -> Bool
== Sz ix
sz2 =
    Comp -> Sz ix -> (ix -> e) -> Array D ix e
forall r ix e.
Construct r ix e =>
Comp -> Sz ix -> (ix -> e) -> Array r ix e
makeArray
      (Array r1 ix a -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r1 ix a
arr1 Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Array r2 ix b -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r2 ix b
arr2)
      Sz ix
sz1
      (\ !ix
ix -> a -> b -> e
f (Array r1 ix a -> ix -> a
forall r ix e. Source r ix e => Array r ix e -> ix -> e
unsafeIndex Array r1 ix a
arr1 ix
ix) (Array r2 ix b -> ix -> b
forall r ix e. Source r ix e => Array r ix e -> ix -> e
unsafeIndex Array r2 ix b
arr2 ix
ix))
  | Bool
otherwise = SizeException -> Array D ix e
forall a e. Exception e => e -> a
throw (SizeException -> Array D ix e) -> SizeException -> Array D ix e
forall a b. (a -> b) -> a -> b
$ Sz ix -> Sz ix -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Array r1 ix a -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r1 ix a
arr1) (Array r2 ix b -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r2 ix b
arr2)
  where
    sz1 :: Sz ix
sz1 = Array r1 ix a -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r1 ix a
arr1
    sz2 :: Sz ix
sz2 = Array r2 ix b -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r2 ix b
arr2
{-# INLINE liftArray2Matching #-}

liftArray2M ::
     (Load r ix e, Numeric r e, MonadThrow m)
  => (e -> e -> e)
  -> Array r ix e
  -> Array r ix e
  -> m (Array r ix e)
liftArray2M :: (e -> e -> e) -> Array r ix e -> Array r ix e -> m (Array r ix e)
liftArray2M e -> e -> e
f Array r ix e
a1 Array r ix e
a2
  | Array r ix e -> Sz ix
forall r ix e. Load r 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. Load r ix e => Array r ix e -> Sz ix
size Array r ix e
a2 = Array r ix e -> m (Array r ix e)
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 r e ix a b.
(Numeric r e, Index ix) =>
(a -> b -> e) -> Array r ix a -> Array r ix b -> Array r ix e
unsafeLiftArray2 e -> e -> e
f Array r ix e
a1 Array r ix e
a2
  | Bool
otherwise = SizeException -> m (Array r ix e)
forall (m :: * -> *) e a. (MonadThrow m, 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 (Array r ix e -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r ix e
a1) (Array r ix e -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r ix e
a2)
{-# INLINE liftArray2M #-}


liftNumericArray2M ::
     (Load r ix e, 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)
liftNumericArray2M :: (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)
liftNumericArray2M 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. Load r 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. Load r ix e => Array r ix e -> Sz ix
size Array r ix e
a2 = Array r ix e -> m (Array r ix e)
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
  | Bool
otherwise = SizeException -> m (Array r ix e)
forall (m :: * -> *) e a. (MonadThrow m, 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 (Array r ix e -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r ix e
a1) (Array r ix e -> Sz ix
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r ix e
a2)
{-# INLINE liftNumericArray2M #-}


-- | Add two arrays together pointwise. Throws `SizeMismatchException` if arrays sizes do
-- not match.
--
-- @since 0.4.0
(.+.) ::
     (Load r ix e, 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 -> 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 r ix e (m :: * -> *).
(Load r ix e, 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)
liftNumericArray2M 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 (.+.) #-}

-- | Add a scalar to each element of the array. Array is on the left.
--
-- @since 0.1.0
(.+) :: (Index ix, Numeric r e) => Array r ix e -> e -> Array r ix e
.+ :: Array r ix e -> e -> Array r ix e
(.+) = 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 (.+) #-}

-- | Add a scalar to each element of the array. Array is on the right.
--
-- @since 0.4.0
(+.) :: (Index ix, Numeric r e) => e -> Array r ix e -> Array r ix 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 r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> e -> Array r ix e
plusScalar
{-# INLINE (+.) #-}

-- | Subtract two arrays pointwise. Throws `SizeMismatchException` if arrays sizes do not
-- match.
--
-- @since 0.4.0
(.-.) ::
     (Load r ix e, 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 -> 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 r ix e (m :: * -> *).
(Load r ix e, 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)
liftNumericArray2M 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 (.-.) #-}


-- | Subtract a scalar from each element of the array. Array is on the left.
--
-- @since 0.1.0
(.-) :: (Index ix, Numeric r e) => Array r ix e -> e -> Array r ix e
.- :: Array r ix e -> e -> Array r ix e
(.-) = 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 (.-) #-}

-- | Subtract a scalar from each element of the array. Array is on the right.
--
-- @since 0.4.0
(-.) :: (Index ix, Numeric r e) => e -> Array r ix e -> Array r ix 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 r e ix.
(Numeric r e, Index ix) =>
Array r ix e -> e -> Array r ix e
minusScalar
{-# INLINE (-.) #-}


-- | Multiply two arrays together pointwise.
--
-- @since 0.4.0
(.*.) ::
     (Load r ix e, 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 -> 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 r ix e (m :: * -> *).
(Load r ix e, 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)
liftNumericArray2M 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 -> e -> Array r ix e
.* :: Array r ix e -> e -> Array r ix e
(.*) = 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
*. :: 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 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
.^ :: Array r ix e -> Int -> Array r ix e
(.^) = 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 (.^) #-}

-- | Matrix multiplication
--
-- Inner dimensions must agree, otherwise `SizeMismatchException`.
(|*|) ::
     (Mutable r Ix2 e, Source r' Ix2 e, OuterSlice r Ix2 e, Source (R r) Ix1 e, Num e, MonadThrow m)
  => Array r Ix2 e
  -> Array r' Ix2 e
  -> m (Array r Ix2 e)
|*| :: Array r Ix2 e -> Array r' Ix2 e -> m (Array r Ix2 e)
(|*|) Array r Ix2 e
a1 Array r' Ix2 e
a2 = Array D Ix2 e -> Array r Ix2 e
forall r ix e r'.
(Mutable r ix e, Load r' ix e) =>
Array r' ix e -> Array r ix e
compute (Array D Ix2 e -> Array r Ix2 e)
-> m (Array D Ix2 e) -> m (Array r Ix2 e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Array r Ix2 e -> Array r' Ix2 e -> m (Array D Ix2 e)
forall r r' e (m :: * -> *).
(Mutable r Ix2 e, Source r' Ix2 e, OuterSlice r Ix2 e,
 Source (R r) Int e, Num e, MonadThrow m) =>
Array r Ix2 e -> Array r' Ix2 e -> m (Array D Ix2 e)
multArrs Array r Ix2 e
a1 Array r' Ix2 e
a2
{-# INLINE [1] (|*|) #-}

{-# RULES
"multDoubleTranspose" [~1] forall arr1 arr2 . arr1 |*| transpose arr2 =
    multiplyTransposedFused arr1 (convert arr2)
 #-}

-- | Matrix-vector product
--
-- Inner dimensions must agree, otherwise `SizeMismatchException`
--
-- @since 0.5.2
(#>) :: (MonadThrow m, Num e, Source (R r) Ix1 e, Manifest r' Ix1 e, OuterSlice r Ix2 e) =>
        Array r Ix2 e -- ^ Matrix
     -> Array r' Ix1 e -- ^ Vector
     -> m (Array D Ix1 e)
Array r Ix2 e
mm #> :: Array r Ix2 e -> Array r' Int e -> m (Array D Int e)
#> Array r' Int e
v
  | Int
mCols Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
n = SizeException -> m (Array D Int e)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m (Array D Int e))
-> SizeException -> m (Array D Int e)
forall a b. (a -> b) -> a -> b
$ Sz Ix2 -> Sz Ix2 -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Array r Ix2 e -> Sz Ix2
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r Ix2 e
mm) (Int -> Int -> Sz Ix2
Sz2 Int
n Int
1)
  | Bool
otherwise = Array D Int e -> m (Array D Int e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Array D Int e -> m (Array D Int e))
-> Array D Int e -> m (Array D Int e)
forall a b. (a -> b) -> a -> b
$ Comp -> Sz Int -> (Int -> e) -> Array D Int e
forall r ix e.
Construct r ix e =>
Comp -> Sz ix -> (ix -> e) -> Array r ix e
makeArray (Array r Ix2 e -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r Ix2 e
mm Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Array r' Int e -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r' Int e
v) (Int -> Sz Int
Sz1 Int
mRows) ((Int -> e) -> Array D Int e) -> (Int -> e) -> Array D Int e
forall a b. (a -> b) -> a -> b
$ \Int
i ->
      (e -> e -> e) -> e -> Array D Int e -> e
forall r ix e a.
Source r ix e =>
(a -> e -> a) -> a -> Array r ix e -> a
A.foldlS e -> e -> e
forall a. Num a => a -> a -> a
(+) e
0 ((e -> e -> e)
-> Array (R r) Int e -> Array r' Int e -> Array D Int e
forall r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
A.zipWith e -> e -> e
forall a. Num a => a -> a -> a
(*) (Array r Ix2 e -> Int -> Elt r Ix2 e
forall r ix e.
OuterSlice r ix e =>
Array r ix e -> Int -> Elt r ix e
unsafeOuterSlice Array r Ix2 e
mm Int
i) Array r' Int e
v)
  where
    Sz2 Int
mRows Int
mCols = Array r Ix2 e -> Sz Ix2
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r Ix2 e
mm
    Sz1 Int
n = Array r' Int e -> Sz Int
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r' Int e
v
{-# INLINE (#>) #-}



multiplyTransposedFused ::
     ( Mutable r Ix2 e
     , OuterSlice r Ix2 e
     , Source (R r) Ix1 e
     , Num e
     , MonadThrow m
     )
  => Array r Ix2 e
  -> Array r Ix2 e
  -> m (Array r Ix2 e)
multiplyTransposedFused :: Array r Ix2 e -> Array r Ix2 e -> m (Array r Ix2 e)
multiplyTransposedFused Array r Ix2 e
arr1 Array r Ix2 e
arr2 = Array D Ix2 e -> Array r Ix2 e
forall r ix e r'.
(Mutable r ix e, Load r' ix e) =>
Array r' ix e -> Array r ix e
compute (Array D Ix2 e -> Array r Ix2 e)
-> m (Array D Ix2 e) -> m (Array r Ix2 e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Array r Ix2 e -> Array r Ix2 e -> m (Array D Ix2 e)
forall r e (m :: * -> *).
(Manifest r Ix2 e, OuterSlice r Ix2 e, Source (R r) Int e, Num e,
 MonadThrow m) =>
Array r Ix2 e -> Array r Ix2 e -> m (Array D Ix2 e)
multiplyTransposed Array r Ix2 e
arr1 Array r Ix2 e
arr2
{-# INLINE multiplyTransposedFused #-}


multArrs :: forall r r' e m.
            ( Mutable r Ix2 e
            , Source r' Ix2 e
            , OuterSlice r Ix2 e
            , Source (R r) Ix1 e
            , Num e
            , MonadThrow m
            )
         => Array r Ix2 e -> Array r' Ix2 e -> m (Array D Ix2 e)
multArrs :: Array r Ix2 e -> Array r' Ix2 e -> m (Array D Ix2 e)
multArrs Array r Ix2 e
arr1 Array r' Ix2 e
arr2 = Array r Ix2 e -> Array r Ix2 e -> m (Array D Ix2 e)
forall r e (m :: * -> *).
(Manifest r Ix2 e, OuterSlice r Ix2 e, Source (R r) Int e, Num e,
 MonadThrow m) =>
Array r Ix2 e -> Array r Ix2 e -> m (Array D Ix2 e)
multiplyTransposed Array r Ix2 e
arr1 Array r Ix2 e
arr2'
  where
    arr2' :: Array r Ix2 e
    arr2' :: Array r Ix2 e
arr2' = Array D Ix2 e -> Array r Ix2 e
forall r ix e r'.
(Mutable r ix e, Load r' ix e) =>
Array r' ix e -> Array r ix e
compute (Array D Ix2 e -> Array r Ix2 e) -> Array D Ix2 e -> Array r Ix2 e
forall a b. (a -> b) -> a -> b
$ Array r' Ix2 e -> Array D Ix2 e
forall r e. Source r Ix2 e => Array r Ix2 e -> Array D Ix2 e
transpose Array r' Ix2 e
arr2
{-# INLINE multArrs #-}

-- | Computes the matrix-matrix transposed product (i.e. A * A')
multiplyTransposed ::
     ( Manifest r Ix2 e
     , OuterSlice r Ix2 e
     , Source (R r) Ix1 e
     , Num e
     , MonadThrow m
     )
  => Array r Ix2 e
  -> Array r Ix2 e
  -> m (Array D Ix2 e)
multiplyTransposed :: Array r Ix2 e -> Array r Ix2 e -> m (Array D Ix2 e)
multiplyTransposed Array r Ix2 e
arr1 Array r Ix2 e
arr2
  | Int
n1 Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
m2 = SizeException -> m (Array D Ix2 e)
forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM (SizeException -> m (Array D Ix2 e))
-> SizeException -> m (Array D Ix2 e)
forall a b. (a -> b) -> a -> b
$ Sz Ix2 -> Sz Ix2 -> SizeException
forall ix. Index ix => Sz ix -> Sz ix -> SizeException
SizeMismatchException (Array r Ix2 e -> Sz Ix2
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r Ix2 e
arr1) (Array r Ix2 e -> Sz Ix2
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r Ix2 e
arr2)
  | Bool
otherwise =
    Array D Ix2 e -> m (Array D Ix2 e)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Array D Ix2 e -> m (Array D Ix2 e))
-> Array D Ix2 e -> m (Array D Ix2 e)
forall a b. (a -> b) -> a -> b
$
    Comp -> Sz Ix2 -> (Ix2 -> e) -> Array D Ix2 e
forall ix e. Comp -> Sz ix -> (ix -> e) -> Array D ix e
DArray (Array r Ix2 e -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r Ix2 e
arr1 Comp -> Comp -> Comp
forall a. Semigroup a => a -> a -> a
<> Array r Ix2 e -> Comp
forall r ix e. Load r ix e => Array r ix e -> Comp
getComp Array r Ix2 e
arr2) (Ix2 -> Sz Ix2
forall ix. ix -> Sz ix
SafeSz (Int
m1 Int -> Int -> Ix2
:. Int
n2)) ((Ix2 -> e) -> Array D Ix2 e) -> (Ix2 -> e) -> Array D Ix2 e
forall a b. (a -> b) -> a -> b
$ \(Int
i :. Int
j) ->
      (e -> e -> e) -> e -> Array D Int e -> e
forall r ix e a.
Source r ix e =>
(a -> e -> a) -> a -> Array r ix e -> a
A.foldlS e -> e -> e
forall a. Num a => a -> a -> a
(+) e
0 ((e -> e -> e)
-> Array (R r) Int e -> Array (R r) Int e -> Array D Int e
forall r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
A.zipWith e -> e -> e
forall a. Num a => a -> a -> a
(*) (Array r Ix2 e -> Int -> Elt r Ix2 e
forall r ix e.
OuterSlice r ix e =>
Array r ix e -> Int -> Elt r ix e
unsafeOuterSlice Array r Ix2 e
arr1 Int
i) (Array r Ix2 e -> Int -> Elt r Ix2 e
forall r ix e.
OuterSlice r ix e =>
Array r ix e -> Int -> Elt r ix e
unsafeOuterSlice Array r Ix2 e
arr2 Int
j))
  where
    SafeSz (Int
m1 :. Int
n1) = Array r Ix2 e -> Sz Ix2
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r Ix2 e
arr1
    SafeSz (Int
n2 :. Int
m2) = Array r Ix2 e -> Sz Ix2
forall r ix e. Load r ix e => Array r ix e -> Sz ix
size Array r Ix2 e
arr2
{-# INLINE multiplyTransposed #-}

-- | Create an indentity matrix.
--
-- ==== __Example__
--
-- >>> import Data.Massiv.Array
-- >>> identityMatrix 5
-- Array DL Seq (Sz (5 :. 5))
--   [ [ 1, 0, 0, 0, 0 ]
--   , [ 0, 1, 0, 0, 0 ]
--   , [ 0, 0, 1, 0, 0 ]
--   , [ 0, 0, 0, 1, 0 ]
--   , [ 0, 0, 0, 0, 1 ]
--   ]
--
-- @since 0.3.6
identityMatrix :: Num e => Sz1 -> Matrix DL e
identityMatrix :: Sz Int -> Matrix DL e
identityMatrix (Sz Int
n) =
  Sz Ix2
-> e
-> (forall (m :: * -> *). Monad m => (Ix2 -> e -> m Bool) -> m ())
-> Matrix DL 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 ())
 -> Matrix DL e)
-> (forall (m :: * -> *). Monad m => (Ix2 -> e -> m Bool) -> m ())
-> Matrix DL e
forall a b. (a -> b) -> a -> b
$ \ Ix2 -> e -> m Bool
w -> Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> m Bool) -> m ()
forall (m :: * -> *) a.
Monad m =>
Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> m a) -> m ()
loopM_ 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 #-}

-- | Create a lower triangular (L in LU decomposition) matrix of size @NxN@
--
-- ==== __Example__
--
-- >>> import Data.Massiv.Array
-- >>> lowerTriangular Seq 5 (\(i :. j) -> i + j)
-- Array DL Seq (Sz (5 :. 5))
--   [ [ 0, 0, 0, 0, 0 ]
--   , [ 1, 2, 0, 0, 0 ]
--   , [ 2, 3, 4, 0, 0 ]
--   , [ 3, 4, 5, 6, 0 ]
--   , [ 4, 5, 6, 7, 8 ]
--   ]
--
-- @since 0.5.2
lowerTriangular :: Num e => Comp -> Sz1 -> (Ix2 -> e) -> Matrix DL e
lowerTriangular :: Comp -> Sz Int -> (Ix2 -> e) -> Matrix DL e
lowerTriangular Comp
comp (Sz1 Int
n) Ix2 -> e
f =
  let sz :: Sz Ix2
sz = Int -> Int -> Sz Ix2
Sz2 Int
n Int
n
   in Comp
-> Sz Ix2
-> Maybe e
-> (forall (m :: * -> *).
    Monad m =>
    Scheduler m () -> (Int -> e -> m ()) -> m ())
-> Matrix DL e
forall ix e.
Comp
-> Sz ix
-> Maybe e
-> (forall (m :: * -> *).
    Monad m =>
    Scheduler m () -> (Int -> e -> m ()) -> m ())
-> Array DL ix e
unsafeMakeLoadArrayAdjusted Comp
comp Sz Ix2
sz (e -> Maybe e
forall a. a -> Maybe a
Just e
0) ((forall (m :: * -> *).
  Monad m =>
  Scheduler m () -> (Int -> e -> m ()) -> m ())
 -> Matrix DL e)
-> (forall (m :: * -> *).
    Monad m =>
    Scheduler m () -> (Int -> e -> m ()) -> m ())
-> Matrix DL e
forall a b. (a -> b) -> a -> b
$ \Scheduler m ()
scheduler Int -> e -> m ()
wr ->
        Array D Int Int -> (Int -> m ()) -> m ()
forall r ix a (m :: * -> *) b.
(Source r ix a, 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 -> m ()) -> m ()) -> (Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
i ->
          Scheduler m () -> m () -> m ()
forall (m :: * -> *) a. Scheduler m a -> m a -> m ()
scheduleWork Scheduler m ()
scheduler (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
          Array D Int Int -> (Int -> m ()) -> m ()
forall r ix a (m :: * -> *) b.
(Source r ix a, 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 -> m ()) -> m ()) -> (Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
j ->
            let ix :: Ix2
ix = Int
i Int -> Int -> Ix2
:. Int
j
             in Int -> e -> m ()
wr (Sz Ix2 -> Ix2 -> Int
forall ix. Index ix => Sz ix -> ix -> Int
toLinearIndex Sz Ix2
sz Ix2
ix) (Ix2 -> e
f Ix2
ix)
{-# INLINE lowerTriangular #-}

-- | Create an upper triangular (U in LU decomposition) matrix of size @NxN@
--
-- ==== __Example__
--
-- >>> import Data.Massiv.Array
-- >>> upperTriangular Par 5 (\(i :. j) -> i + j)
-- Array DL Par (Sz (5 :. 5))
--   [ [ 0, 1, 2, 3, 4 ]
--   , [ 0, 2, 3, 4, 5 ]
--   , [ 0, 0, 4, 5, 6 ]
--   , [ 0, 0, 0, 6, 7 ]
--   , [ 0, 0, 0, 0, 8 ]
--   ]
--
-- @since 0.5.2
upperTriangular :: Num e => Comp -> Sz1 -> (Ix2 -> e) -> Matrix DL e
upperTriangular :: Comp -> Sz Int -> (Ix2 -> e) -> Matrix DL e
upperTriangular Comp
comp (Sz1 Int
n) Ix2 -> e
f =
  let sz :: Sz Ix2
sz = Int -> Int -> Sz Ix2
Sz2 Int
n Int
n
   in Comp
-> Sz Ix2
-> Maybe e
-> (forall (m :: * -> *).
    Monad m =>
    Scheduler m () -> (Int -> e -> m ()) -> m ())
-> Matrix DL e
forall ix e.
Comp
-> Sz ix
-> Maybe e
-> (forall (m :: * -> *).
    Monad m =>
    Scheduler m () -> (Int -> e -> m ()) -> m ())
-> Array DL ix e
unsafeMakeLoadArrayAdjusted Comp
comp Sz Ix2
sz (e -> Maybe e
forall a. a -> Maybe a
Just e
0) ((forall (m :: * -> *).
  Monad m =>
  Scheduler m () -> (Int -> e -> m ()) -> m ())
 -> Matrix DL e)
-> (forall (m :: * -> *).
    Monad m =>
    Scheduler m () -> (Int -> e -> m ()) -> m ())
-> Matrix DL e
forall a b. (a -> b) -> a -> b
$ \Scheduler m ()
scheduler Int -> e -> m ()
wr ->
        Array D Int Int -> (Int -> m ()) -> m ()
forall r ix a (m :: * -> *) b.
(Source r ix a, 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 -> m ()) -> m ()) -> (Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
i ->
          Scheduler m () -> m () -> m ()
forall (m :: * -> *) a. Scheduler m a -> m a -> m ()
scheduleWork Scheduler m ()
scheduler (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$
          Array D Int Int -> (Int -> m ()) -> m ()
forall r ix a (m :: * -> *) b.
(Source r ix a, 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 -> m ()) -> m ()) -> (Int -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \Int
j ->
            let ix :: Ix2
ix = Int
i Int -> Int -> Ix2
:. Int
j
             in Int -> e -> m ()
wr (Sz Ix2 -> Ix2 -> Int
forall ix. Index ix => Sz ix -> ix -> Int
toLinearIndex Sz Ix2
sz Ix2
ix) (Ix2 -> e
f Ix2
ix)
{-# INLINE upperTriangular #-}


negateA :: (Index ix, Numeric r e) => Array r ix e -> Array r ix e
negateA :: Array r ix e -> Array r ix e
negateA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
absA = 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 :: Array r ix e -> Array r ix e
signumA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray e -> e
forall a. Num a => a -> a
signum
{-# INLINE signumA #-}

fromIntegerA :: (Index ix, Num e) => Integer -> Array D ix e
fromIntegerA :: Integer -> Array D ix e
fromIntegerA = e -> Array D ix e
forall r ix e. Construct r ix e => e -> Array r ix e
singleton (e -> Array D ix e) -> (Integer -> e) -> Integer -> Array D ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> e
forall a. Num a => Integer -> a
fromInteger
{-# INLINE fromIntegerA #-}

(./.) ::
     (Load r ix e, 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 -> 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 r ix e (m :: * -> *).
(Load r ix e, 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)
liftNumericArray2M 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 -> e -> Array r ix e
./ :: Array r ix e -> e -> Array r ix e
(./) = 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
.^^ :: 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 r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
recipA = 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 #-}


fromRationalA
  :: (Index ix, Fractional e)
  => Rational -> Array D ix e
fromRationalA :: Rational -> Array D ix e
fromRationalA = e -> Array D ix e
forall r ix e. Construct r ix e => e -> Array r ix e
singleton (e -> Array D ix e) -> (Rational -> e) -> Rational -> Array D ix e
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> e
forall a. Fractional a => Rational -> a
fromRational
{-# INLINE fromRationalA #-}

piA
  :: (Index ix, Floating e)
  => Array D ix e
piA :: Array D ix e
piA = e -> Array D ix e
forall r ix e. Construct r ix e => e -> Array r ix e
singleton e
forall a. Floating a => a
pi
{-# INLINE piA #-}

expA :: (Index ix, NumericFloat r e) => Array r ix e -> Array r ix e
expA :: Array r ix e -> Array r ix e
expA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
sqrtA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
logA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
log
{-# INLINE logA #-}

logBaseA
  :: (Source r1 ix e, Source r2 ix e, Floating e)
  => Array r1 ix e -> Array r2 ix e -> Array D ix e
logBaseA :: 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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching e -> e -> e
forall a. Floating a => a -> a -> a
logBase
{-# INLINE logBaseA #-}

(.**)
  :: (Source r1 ix e, Source r2 ix e, Floating e)
  => Array r1 ix e -> Array r2 ix e -> Array D ix 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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching 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 :: Array r ix e -> Array r ix e
sinA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
cosA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
tanA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
asinA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
atanA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
acosA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
sinhA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
tanhA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
coshA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
asinhA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
acoshA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> 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 :: Array r ix e -> Array r ix e
atanhA = (e -> e) -> Array r ix e -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray e -> e
forall a. Floating a => a -> a
atanh
{-# INLINE atanhA #-}


quotA
  :: (Source r1 ix e, Source r2 ix e, Integral e)
  => Array r1 ix e -> Array r2 ix e -> Array D ix e
quotA :: 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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching e -> e -> e
forall a. Integral a => a -> a -> a
quot
{-# INLINE quotA #-}


remA
  :: (Source r1 ix e, Source r2 ix e, Integral e)
  => Array r1 ix e -> Array r2 ix e -> Array D ix e
remA :: 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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching e -> e -> e
forall a. Integral a => a -> a -> a
rem
{-# INLINE remA #-}

divA
  :: (Source r1 ix e, Source r2 ix e, Integral e)
  => Array r1 ix e -> Array r2 ix e -> Array D ix e
divA :: 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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching e -> e -> e
forall a. Integral a => a -> a -> a
div
{-# INLINE divA #-}

modA
  :: (Source r1 ix e, Source r2 ix e, Integral e)
  => Array r1 ix e -> Array r2 ix e -> Array D ix e
modA :: 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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching e -> e -> e
forall a. Integral a => a -> a -> a
mod
{-# INLINE modA #-}



quotRemA
  :: (Source r1 ix e, Source r2 ix e, Integral e)
  => Array r1 ix e -> Array r2 ix e -> (Array D ix e, Array D ix e)
quotRemA :: 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 r ix e1 e2.
Source r ix (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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching (e -> e -> (e, e)
forall a. Integral a => a -> a -> (a, a)
quotRem) Array r1 ix e
arr1
{-# INLINE quotRemA #-}


divModA
  :: (Source r1 ix e, Source r2 ix e, Integral e)
  => Array r1 ix e -> Array r2 ix e -> (Array D ix e, Array D ix e)
divModA :: 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 r ix e1 e2.
Source r ix (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 r1 ix e1 r2 e2 e.
(Source r1 ix e1, Source r2 ix e2) =>
(e1 -> e2 -> e) -> Array r1 ix e1 -> Array r2 ix e2 -> Array D ix e
liftArray2Matching (e -> e -> (e, e)
forall a. Integral a => a -> a -> (a, a)
divMod) Array r1 ix e
arr1
{-# INLINE divModA #-}



truncateA
  :: (Index ix, Numeric r e, RealFrac a, Integral e)
  => Array r ix a -> Array r ix e
truncateA :: Array r ix a -> Array r ix e
truncateA = (a -> e) -> Array r ix a -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray a -> e
forall a b. (RealFrac a, Integral b) => a -> b
truncate
{-# INLINE truncateA #-}


roundA :: (Index ix, Numeric r e, RealFrac a, Integral e) => Array r ix a -> Array r ix e
roundA :: Array r ix a -> Array r ix e
roundA = (a -> e) -> Array r ix a -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray a -> e
forall a b. (RealFrac a, Integral b) => a -> b
round
{-# INLINE roundA #-}


ceilingA :: (Index ix, Numeric r e, RealFrac a, Integral e) => Array r ix a -> Array r ix e
ceilingA :: Array r ix a -> Array r ix e
ceilingA = (a -> e) -> Array r ix a -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray a -> e
forall a b. (RealFrac a, Integral b) => a -> b
ceiling
{-# INLINE ceilingA #-}


floorA :: (Index ix, Numeric r e, RealFrac a, Integral e) => Array r ix a -> Array r ix e
floorA :: Array r ix a -> Array r ix e
floorA = (a -> e) -> Array r ix a -> Array r ix e
forall r e ix a.
(Numeric r e, Index ix) =>
(a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray a -> e
forall a b. (RealFrac a, Integral b) => a -> b
floor
{-# INLINE floorA #-}

atan2A ::
     (Load r ix e, Numeric r e, RealFloat e, MonadThrow m)
  => Array r ix e
  -> Array r ix e
  -> m (Array r ix e)
atan2A :: 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 r ix e (m :: * -> *).
(Load r ix e, Numeric r e, MonadThrow m) =>
(e -> e -> e) -> Array r ix e -> Array r ix e -> m (Array r ix e)
liftArray2M e -> e -> e
forall a. RealFloat a => a -> a -> a
atan2
{-# INLINE atan2A #-}