aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array/Nested
diff options
context:
space:
mode:
authorTom Smeding <t.j.smeding@uu.nl>2024-05-27 14:10:57 +0200
committerTom Smeding <t.j.smeding@uu.nl>2024-05-27 14:10:57 +0200
commit9e5945120bbcfeff15ee7356398e06ab5ba25561 (patch)
tree9e9432d60b901776ebf552b501724e4c0a7b18f3 /src/Data/Array/Nested
parente80b2593edc3d216905279ebcfa797593a1efbfc (diff)
Fast (C) Floating ops
Diffstat (limited to 'src/Data/Array/Nested')
-rw-r--r--src/Data/Array/Nested/Internal.hs56
-rw-r--r--src/Data/Array/Nested/Internal/Arith.hs63
2 files changed, 92 insertions, 27 deletions
diff --git a/src/Data/Array/Nested/Internal.hs b/src/Data/Array/Nested/Internal.hs
index ef2ad6b..f8d16aa 100644
--- a/src/Data/Array/Nested/Internal.hs
+++ b/src/Data/Array/Nested/Internal.hs
@@ -1048,34 +1048,36 @@ instance (NumElt a, PrimElt a) => Num (Mixed sh a) where
signum = mliftNumElt1 numEltSignum
fromInteger _ = error "Data.Array.Nested.fromIntegral: No singletons available, use explicit mreplicate"
-instance (FloatElt a, NumElt a, PrimElt a, Fractional a) => Fractional (Mixed sh a) where
+instance (FloatElt a, NumElt a, PrimElt a) => Fractional (Mixed sh a) where
fromRational _ = error "Data.Array.Nested.fromRational: No singletons available, use explicit mreplicate"
recip = mliftNumElt1 floatEltRecip
(/) = mliftNumElt2 floatEltDiv
-instance (FloatElt a, NumElt a, PrimElt a, Floating a) => Floating (Mixed sh a) where
+instance (FloatElt a, NumElt a, PrimElt a) => Floating (Mixed sh a) where
pi = error "Data.Array.Nested.pi: No singletons available, use explicit mreplicate"
- exp = mliftPrim exp
- log = mliftPrim log
- sqrt = mliftPrim sqrt
- (**) = mliftPrim2 (**)
- logBase = mliftPrim2 logBase
- sin = mliftPrim sin
- cos = mliftPrim cos
- tan = mliftPrim tan
- asin = mliftPrim asin
- acos = mliftPrim acos
- atan = mliftPrim atan
- sinh = mliftPrim sinh
- cosh = mliftPrim cosh
- tanh = mliftPrim tanh
- asinh = mliftPrim asinh
- acosh = mliftPrim acosh
- atanh = mliftPrim atanh
- log1p = mliftPrim GHC.Float.log1p
- expm1 = mliftPrim GHC.Float.expm1
- log1pexp = mliftPrim GHC.Float.log1pexp
- log1mexp = mliftPrim GHC.Float.log1mexp
+ exp = mliftNumElt1 floatEltExp
+ log = mliftNumElt1 floatEltLog
+ sqrt = mliftNumElt1 floatEltSqrt
+
+ (**) = mliftNumElt2 floatEltPow
+ logBase = mliftNumElt2 floatEltLogbase
+
+ sin = mliftNumElt1 floatEltSin
+ cos = mliftNumElt1 floatEltCos
+ tan = mliftNumElt1 floatEltTan
+ asin = mliftNumElt1 floatEltAsin
+ acos = mliftNumElt1 floatEltAcos
+ atan = mliftNumElt1 floatEltAtan
+ sinh = mliftNumElt1 floatEltSinh
+ cosh = mliftNumElt1 floatEltCosh
+ tanh = mliftNumElt1 floatEltTanh
+ asinh = mliftNumElt1 floatEltAsinh
+ acosh = mliftNumElt1 floatEltAcosh
+ atanh = mliftNumElt1 floatEltAtanh
+ log1p = mliftNumElt1 floatEltLog1p
+ expm1 = mliftNumElt1 floatEltExpm1
+ log1pexp = mliftNumElt1 floatEltLog1pexp
+ log1mexp = mliftNumElt1 floatEltLog1mexp
mtoRanked :: forall sh a. Elt a => Mixed sh a -> Ranked (X.Rank sh) a
mtoRanked arr
@@ -1367,12 +1369,12 @@ instance (NumElt a, PrimElt a) => Num (Ranked n a) where
signum = arithPromoteRanked signum
fromInteger _ = error "Data.Array.Nested.fromIntegral: No singletons available, use explicit rreplicateScal"
-instance (FloatElt a, NumElt a, PrimElt a, Fractional a) => Fractional (Ranked n a) where
+instance (FloatElt a, NumElt a, PrimElt a) => Fractional (Ranked n a) where
fromRational _ = error "Data.Array.Nested.fromRational: No singletons available, use explicit rreplicateScal"
recip = arithPromoteRanked recip
(/) = arithPromoteRanked2 (/)
-instance (FloatElt a, NumElt a, PrimElt a, Floating a) => Floating (Ranked n a) where
+instance (FloatElt a, NumElt a, PrimElt a) => Floating (Ranked n a) where
pi = error "Data.Array.Nested.pi: No singletons available, use explicit rreplicateScal"
exp = arithPromoteRanked exp
log = arithPromoteRanked log
@@ -1698,12 +1700,12 @@ instance (NumElt a, PrimElt a) => Num (Shaped sh a) where
signum = arithPromoteShaped signum
fromInteger _ = error "Data.Array.Nested.fromIntegral: No singletons available, use explicit sreplicateScal"
-instance (FloatElt a, NumElt a, PrimElt a, Fractional a) => Fractional (Shaped sh a) where
+instance (FloatElt a, NumElt a, PrimElt a) => Fractional (Shaped sh a) where
fromRational _ = error "Data.Array.Nested.fromRational: No singletons available, use explicit sreplicateScal"
recip = arithPromoteShaped recip
(/) = arithPromoteShaped2 (/)
-instance (FloatElt a, NumElt a, PrimElt a, Floating a) => Floating (Shaped sh a) where
+instance (FloatElt a, NumElt a, PrimElt a) => Floating (Shaped sh a) where
pi = error "Data.Array.Nested.pi: No singletons available, use explicit sreplicateScal"
exp = arithPromoteShaped exp
log = arithPromoteShaped log
diff --git a/src/Data/Array/Nested/Internal/Arith.hs b/src/Data/Array/Nested/Internal/Arith.hs
index 07d5d8a..95fcfcf 100644
--- a/src/Data/Array/Nested/Internal/Arith.hs
+++ b/src/Data/Array/Nested/Internal/Arith.hs
@@ -361,12 +361,75 @@ instance NumElt CInt where
class FloatElt a where
floatEltDiv :: SNat n -> RS.Array n a -> RS.Array n a -> RS.Array n a
+ floatEltPow :: SNat n -> RS.Array n a -> RS.Array n a -> RS.Array n a
+ floatEltLogbase :: SNat n -> RS.Array n a -> RS.Array n a -> RS.Array n a
floatEltRecip :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltExp :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltLog :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltSqrt :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltSin :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltCos :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltTan :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltAsin :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltAcos :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltAtan :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltSinh :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltCosh :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltTanh :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltAsinh :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltAcosh :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltAtanh :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltLog1p :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltExpm1 :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltLog1pexp :: SNat n -> RS.Array n a -> RS.Array n a
+ floatEltLog1mexp :: SNat n -> RS.Array n a -> RS.Array n a
instance FloatElt Float where
floatEltDiv = divVectorFloat
+ floatEltPow = powVectorFloat
+ floatEltLogbase = logbaseVectorFloat
floatEltRecip = recipVectorFloat
+ floatEltExp = expVectorFloat
+ floatEltLog = logVectorFloat
+ floatEltSqrt = sqrtVectorFloat
+ floatEltSin = sinVectorFloat
+ floatEltCos = cosVectorFloat
+ floatEltTan = tanVectorFloat
+ floatEltAsin = asinVectorFloat
+ floatEltAcos = acosVectorFloat
+ floatEltAtan = atanVectorFloat
+ floatEltSinh = sinhVectorFloat
+ floatEltCosh = coshVectorFloat
+ floatEltTanh = tanhVectorFloat
+ floatEltAsinh = asinhVectorFloat
+ floatEltAcosh = acoshVectorFloat
+ floatEltAtanh = atanhVectorFloat
+ floatEltLog1p = log1pVectorFloat
+ floatEltExpm1 = expm1VectorFloat
+ floatEltLog1pexp = log1pexpVectorFloat
+ floatEltLog1mexp = log1mexpVectorFloat
instance FloatElt Double where
floatEltDiv = divVectorDouble
+ floatEltPow = powVectorDouble
+ floatEltLogbase = logbaseVectorDouble
floatEltRecip = recipVectorDouble
+ floatEltExp = expVectorDouble
+ floatEltLog = logVectorDouble
+ floatEltSqrt = sqrtVectorDouble
+ floatEltSin = sinVectorDouble
+ floatEltCos = cosVectorDouble
+ floatEltTan = tanVectorDouble
+ floatEltAsin = asinVectorDouble
+ floatEltAcos = acosVectorDouble
+ floatEltAtan = atanVectorDouble
+ floatEltSinh = sinhVectorDouble
+ floatEltCosh = coshVectorDouble
+ floatEltTanh = tanhVectorDouble
+ floatEltAsinh = asinhVectorDouble
+ floatEltAcosh = acoshVectorDouble
+ floatEltAtanh = atanhVectorDouble
+ floatEltLog1p = log1pVectorDouble
+ floatEltExpm1 = expm1VectorDouble
+ floatEltLog1pexp = log1pexpVectorDouble
+ floatEltLog1mexp = log1mexpVectorDouble