{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Massiv.Core.Operations
( Numeric(..)
, NumericFloat(..)
) where
import Data.Massiv.Core.Common
class Num e => Numeric r e where
{-# MINIMAL unsafeLiftArray, unsafeLiftArray2 #-}
plusScalar :: Index ix => Array r ix e -> e -> Array r ix e
plusScalar arr e = unsafeLiftArray (+ e) arr
{-# INLINE plusScalar #-}
minusScalar :: Index ix => Array r ix e -> e -> Array r ix e
minusScalar arr e = unsafeLiftArray (subtract e) arr
{-# INLINE minusScalar #-}
multiplyScalar :: Index ix => Array r ix e -> e -> Array r ix e
multiplyScalar arr e = unsafeLiftArray (* e) arr
{-# INLINE multiplyScalar #-}
absPointwise :: Index ix => Array r ix e -> Array r ix e
absPointwise = unsafeLiftArray abs
{-# INLINE absPointwise #-}
additionPointwise :: Index ix => Array r ix e -> Array r ix e -> Array r ix e
additionPointwise = unsafeLiftArray2 (+)
{-# INLINE additionPointwise #-}
subtractionPointwise :: Index ix => Array r ix e -> Array r ix e -> Array r ix e
subtractionPointwise = unsafeLiftArray2 (-)
{-# INLINE subtractionPointwise #-}
multiplicationPointwise :: Index ix => Array r ix e -> Array r ix e -> Array r ix e
multiplicationPointwise = unsafeLiftArray2 (*)
{-# INLINE multiplicationPointwise #-}
powerPointwise :: Index ix => Array r ix e -> Int -> Array r ix e
powerPointwise arr pow = unsafeLiftArray (^ pow) arr
{-# INLINE powerPointwise #-}
unsafeLiftArray :: Index ix => (a -> e) -> Array r ix a -> Array r ix e
unsafeLiftArray2 :: Index ix => (a -> b -> e) -> Array r ix a -> Array r ix b -> Array r ix e
class (Numeric r e, Floating e) => NumericFloat r e where
divideScalar :: Index ix => Array r ix e -> e -> Array r ix e
divideScalar arr e = unsafeLiftArray (/ e) arr
{-# INLINE divideScalar #-}
divisionPointwise :: Index ix => Array r ix e -> Array r ix e -> Array r ix e
divisionPointwise = unsafeLiftArray2 (/)
{-# INLINE divisionPointwise #-}
recipPointwise :: Index ix => Array r ix e -> Array r ix e
recipPointwise = unsafeLiftArray recip
{-# INLINE recipPointwise #-}
sqrtPointwise :: Index ix => Array r ix e -> Array r ix e
sqrtPointwise = unsafeLiftArray sqrt
{-# INLINE sqrtPointwise #-}