Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,38 @@ jobs:
matrix:
include:
# -- Linux --
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.0.2" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.2.2" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.4.4" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.6.5" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.8.4" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "8.10.7" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.0.2" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.2.7" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.4.5" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.4.5", flags: "-system-erf" }
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.4.5", flags: "-system-expm1"}
- { cabal: "3.6", os: ubuntu-latest, ghc: "9.6.2" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.0.2" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.2.2" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.4.4" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.6.5" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.8.4" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "8.10.7" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.0.2" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.2.8" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.8" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.8", flags: "-system-erf" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.4.8", flags: "-system-expm1"}
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.6.4" }
- { cabal: "3.10", os: ubuntu-latest, ghc: "9.8.2" }
# -- Win --
- { cabal: "3.6", os: windows-latest, ghc: "8.4.4" }
- { cabal: "3.6", os: windows-latest, ghc: "8.6.5" }
- { cabal: "3.6", os: windows-latest, ghc: "8.8.4" }
- { cabal: "3.6", os: windows-latest, ghc: "8.10.4" }
- { cabal: "3.6", os: windows-latest, ghc: "9.0.2" }
- { cabal: "3.6", os: windows-latest, ghc: "9.2.7" }
- { cabal: "3.6", os: windows-latest, ghc: "9.4.5" }
- { cabal: "3.6", os: windows-latest, ghc: "9.6.2" }
- { cabal: "3.10", os: windows-latest, ghc: "8.4.4" }
- { cabal: "3.10", os: windows-latest, ghc: "8.6.5" }
- { cabal: "3.10", os: windows-latest, ghc: "8.8.4" }
- { cabal: "3.10", os: windows-latest, ghc: "8.10.7" }
- { cabal: "3.10", os: windows-latest, ghc: "9.0.2" }
- { cabal: "3.10", os: windows-latest, ghc: "9.2.8" }
- { cabal: "3.10", os: windows-latest, ghc: "9.4.8" }
- { cabal: "3.10", os: windows-latest, ghc: "9.6.4" }
- { cabal: "3.10", os: windows-latest, ghc: "9.8.2" }
# MacOS
- { cabal: "3.6", os: macOS-latest, ghc: "8.4.4" }
- { cabal: "3.6", os: macOS-latest, ghc: "8.6.5" }
- { cabal: "3.6", os: macOS-latest, ghc: "8.8.4" }
- { cabal: "3.6", os: macOS-latest, ghc: "8.10.4" }
- { cabal: "3.6", os: macOS-latest, ghc: "9.2.7" }
- { cabal: "3.6", os: macOS-latest, ghc: "9.4.5" }
- { cabal: "3.6", os: macOS-latest, ghc: "9.6.2" }
- { cabal: "3.10", os: macOS-latest, ghc: "8.4.4" }
- { cabal: "3.10", os: macOS-latest, ghc: "8.6.5" }
- { cabal: "3.10", os: macOS-latest, ghc: "8.8.4" }
- { cabal: "3.10", os: macOS-latest, ghc: "8.10.7" }
- { cabal: "3.10", os: macOS-latest, ghc: "9.2.8" }
- { cabal: "3.10", os: macOS-latest, ghc: "9.4.8" }
- { cabal: "3.10", os: macOS-latest, ghc: "9.6.4" }
- { cabal: "3.10", os: macOS-latest, ghc: "9.8.2" }
fail-fast: false

steps:
Expand Down
30 changes: 12 additions & 18 deletions Numeric/RootFinding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,31 @@ import Numeric.MathFunctions.Constants (m_epsilon)
----------------------------------------------------------------

-- | The result of searching for a root of a mathematical function.
data Root a = NotBracketed
-- ^ The function does not have opposite signs when
-- evaluated at the lower and upper bounds of the search.
| SearchFailed
-- ^ The search failed to converge to within the given
-- error tolerance after the given number of iterations.
| Root !a
-- ^ A root was successfully found.
deriving (Eq, Read, Show, Typeable, Data, Foldable, Traversable
, Generic
)
data Root a
= NotBracketed
-- ^ The function does not have opposite signs when
-- evaluated at the lower and upper bounds of the search.
| SearchFailed
-- ^ The search failed to converge to within the given
-- error tolerance after the given number of iterations.
| Root !a
-- ^ A root was successfully found.
deriving (Eq, Read, Show, Typeable, Data, Foldable, Traversable, Functor, Generic)

instance (NFData a) => NFData (Root a) where
rnf NotBracketed = ()
rnf SearchFailed = ()
rnf (Root a) = rnf a

instance Functor Root where
fmap _ NotBracketed = NotBracketed
fmap _ SearchFailed = SearchFailed
fmap f (Root a) = Root (f a)

instance Applicative Root where
pure = return
pure = Root
(<*>) = ap

instance Monad Root where
NotBracketed >>= _ = NotBracketed
SearchFailed >>= _ = SearchFailed
Root a >>= f = f a
return = Root
return = pure

instance MonadPlus Root where
mzero = empty
Expand Down
1 change: 0 additions & 1 deletion Numeric/SpecFunctions/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module Numeric.SpecFunctions.Internal

import Data.Bits ((.&.), (.|.), shiftR)
import Data.Int (Int64)
import Data.Word (Word)
import Data.Default.Class
import qualified Data.Vector.Unboxed as U
import Data.Vector.Unboxed ((!))
Expand Down
59 changes: 29 additions & 30 deletions Numeric/Sum.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ import Control.Arrow ((***))
import Control.DeepSeq (NFData(..))
import Data.Bits (shiftR)
import Data.Data (Typeable, Data)
import Data.Semigroup (Semigroup(..))
import Data.Semigroup (Semigroup(..)) -- Needed for GHC <8.4
import Data.Vector.Generic (Vector(..))
-- Needed for GHC 7.2 & 7.4 to derive Unbox instances
import Control.Monad (liftM)
import Data.Vector.Generic.Mutable (MVector(..))

import qualified Data.Foldable as F
Expand Down Expand Up @@ -115,16 +113,16 @@ instance MVector U.MVector KahanSum where
basicLength (MV_KahanSum mvec) = GM.basicLength mvec
basicUnsafeSlice idx len (MV_KahanSum mvec) = MV_KahanSum (GM.basicUnsafeSlice idx len mvec)
basicOverlaps (MV_KahanSum mvec) (MV_KahanSum mvec') = basicOverlaps mvec mvec'
basicUnsafeNew len = MV_KahanSum `liftM` basicUnsafeNew len
basicUnsafeNew len = MV_KahanSum <$> basicUnsafeNew len
basicInitialize (MV_KahanSum mvec) = basicInitialize mvec
basicUnsafeReplicate len val = MV_KahanSum `liftM` basicUnsafeReplicate len ((\ (KahanSum a b) -> (a, b)) val)
basicUnsafeRead (MV_KahanSum mvec) idx = (\ (a, b) -> KahanSum a b) `liftM` basicUnsafeRead mvec idx
basicUnsafeReplicate len val = MV_KahanSum <$> basicUnsafeReplicate len ((\ (KahanSum a b) -> (a, b)) val)
basicUnsafeRead (MV_KahanSum mvec) idx = (\ (a, b) -> KahanSum a b) <$> basicUnsafeRead mvec idx
basicUnsafeWrite (MV_KahanSum mvec) idx val = basicUnsafeWrite mvec idx ((\ (KahanSum a b) -> (a, b)) val)
basicClear (MV_KahanSum mvec) = basicClear mvec
basicSet (MV_KahanSum mvec) val = basicSet mvec ((\ (KahanSum a b) -> (a, b)) val)
basicUnsafeCopy (MV_KahanSum mvec) (MV_KahanSum mvec') = GM.basicUnsafeCopy mvec mvec'
basicUnsafeMove (MV_KahanSum mvec) (MV_KahanSum mvec') = basicUnsafeMove mvec mvec'
basicUnsafeGrow (MV_KahanSum mvec) len = MV_KahanSum `liftM` basicUnsafeGrow mvec len
basicUnsafeGrow (MV_KahanSum mvec) len = MV_KahanSum <$> basicUnsafeGrow mvec len

newtype instance U.Vector KahanSum = V_KahanSum (U.Vector (Double, Double))
instance Vector U.Vector KahanSum where
Expand All @@ -135,11 +133,11 @@ instance Vector U.Vector KahanSum where
{-# INLINE basicUnsafeIndexM #-}
{-# INLINE G.basicUnsafeCopy #-}
{-# INLINE elemseq #-}
basicUnsafeFreeze (MV_KahanSum mvec) = V_KahanSum `liftM` basicUnsafeFreeze mvec
basicUnsafeThaw (V_KahanSum vec) = MV_KahanSum `liftM` basicUnsafeThaw vec
basicUnsafeFreeze (MV_KahanSum mvec) = V_KahanSum <$> basicUnsafeFreeze mvec
basicUnsafeThaw (V_KahanSum vec) = MV_KahanSum <$> basicUnsafeThaw vec
basicLength (V_KahanSum vec) = G.basicLength vec
basicUnsafeSlice idx len (V_KahanSum vec) = V_KahanSum (G.basicUnsafeSlice idx len vec)
basicUnsafeIndexM (V_KahanSum vec) idx = (\ (a, b) -> KahanSum a b) `liftM` basicUnsafeIndexM vec idx
basicUnsafeIndexM (V_KahanSum vec) idx = (\ (a, b) -> KahanSum a b) <$> basicUnsafeIndexM vec idx
basicUnsafeCopy (MV_KahanSum mvec) (V_KahanSum vec) = G.basicUnsafeCopy mvec vec
elemseq (V_KahanSum vec) val = elemseq vec ((\ (KahanSum a b) -> (a, b)) val)

Expand All @@ -154,11 +152,11 @@ instance NFData KahanSum where
-- | @since 0.3.0.0
instance Monoid KahanSum where
mempty = zero
s `mappend` KahanSum s' _ = add s s'
mappend = (<>)

-- | @since 0.3.0.0
instance Semigroup KahanSum where
(<>) = mappend
s <> KahanSum s' _ = add s s'

kahanAdd :: KahanSum -> Double -> KahanSum
kahanAdd (KahanSum sum c) x = KahanSum sum' c'
Expand Down Expand Up @@ -195,16 +193,16 @@ instance MVector U.MVector KBNSum where
basicLength (MV_KBNSum mvec) = GM.basicLength mvec
basicUnsafeSlice idx len (MV_KBNSum mvec) = MV_KBNSum (GM.basicUnsafeSlice idx len mvec)
basicOverlaps (MV_KBNSum mvec) (MV_KBNSum mvec') = basicOverlaps mvec mvec'
basicUnsafeNew len = MV_KBNSum `liftM` basicUnsafeNew len
basicUnsafeNew len = MV_KBNSum <$> basicUnsafeNew len
basicInitialize (MV_KBNSum mvec) = basicInitialize mvec
basicUnsafeReplicate len val = MV_KBNSum `liftM` basicUnsafeReplicate len ((\ (KBNSum a b) -> (a, b)) val)
basicUnsafeRead (MV_KBNSum mvec) idx = (\ (a, b) -> KBNSum a b) `liftM` basicUnsafeRead mvec idx
basicUnsafeReplicate len val = MV_KBNSum <$> basicUnsafeReplicate len ((\ (KBNSum a b) -> (a, b)) val)
basicUnsafeRead (MV_KBNSum mvec) idx = (\ (a, b) -> KBNSum a b) <$> basicUnsafeRead mvec idx
basicUnsafeWrite (MV_KBNSum mvec) idx val = basicUnsafeWrite mvec idx ((\ (KBNSum a b) -> (a, b)) val)
basicClear (MV_KBNSum mvec) = basicClear mvec
basicSet (MV_KBNSum mvec) val = basicSet mvec ((\ (KBNSum a b) -> (a, b)) val)
basicUnsafeCopy (MV_KBNSum mvec) (MV_KBNSum mvec') = GM.basicUnsafeCopy mvec mvec'
basicUnsafeMove (MV_KBNSum mvec) (MV_KBNSum mvec') = basicUnsafeMove mvec mvec'
basicUnsafeGrow (MV_KBNSum mvec) len = MV_KBNSum `liftM` basicUnsafeGrow mvec len
basicUnsafeGrow (MV_KBNSum mvec) len = MV_KBNSum <$> basicUnsafeGrow mvec len

newtype instance U.Vector KBNSum = V_KBNSum (U.Vector (Double, Double))
instance Vector U.Vector KBNSum where
Expand All @@ -215,11 +213,11 @@ instance Vector U.Vector KBNSum where
{-# INLINE basicUnsafeIndexM #-}
{-# INLINE G.basicUnsafeCopy #-}
{-# INLINE elemseq #-}
basicUnsafeFreeze (MV_KBNSum mvec) = V_KBNSum `liftM` basicUnsafeFreeze mvec
basicUnsafeThaw (V_KBNSum vec) = MV_KBNSum `liftM` basicUnsafeThaw vec
basicUnsafeFreeze (MV_KBNSum mvec) = V_KBNSum <$> basicUnsafeFreeze mvec
basicUnsafeThaw (V_KBNSum vec) = MV_KBNSum <$> basicUnsafeThaw vec
basicLength (V_KBNSum vec) = G.basicLength vec
basicUnsafeSlice idx len (V_KBNSum vec) = V_KBNSum (G.basicUnsafeSlice idx len vec)
basicUnsafeIndexM (V_KBNSum vec) idx = (\ (a, b) -> KBNSum a b) `liftM` basicUnsafeIndexM vec idx
basicUnsafeIndexM (V_KBNSum vec) idx = (\ (a, b) -> KBNSum a b) <$> basicUnsafeIndexM vec idx
basicUnsafeCopy (MV_KBNSum mvec) (V_KBNSum vec) = G.basicUnsafeCopy mvec vec
elemseq (V_KBNSum vec) val = elemseq vec ((\ (KBNSum a b) -> (a, b)) val)

Expand All @@ -234,11 +232,12 @@ instance NFData KBNSum where
-- | @since 0.3.0.0
instance Monoid KBNSum where
mempty = zero
s `mappend` KBNSum s' c' = add (add s s') c'
mappend = (<>)

-- | @since 0.3.0.0
instance Semigroup KBNSum where
(<>) = mappend
s <> KBNSum s' c' = add (add s s') c'


kbnAdd :: KBNSum -> Double -> KBNSum
kbnAdd (KBNSum sum c) x = KBNSum sum' c'
Expand Down Expand Up @@ -282,16 +281,16 @@ instance MVector U.MVector KB2Sum where
basicLength (MV_KB2Sum mvec) = GM.basicLength mvec
basicUnsafeSlice idx len (MV_KB2Sum mvec) = MV_KB2Sum (GM.basicUnsafeSlice idx len mvec)
basicOverlaps (MV_KB2Sum mvec) (MV_KB2Sum mvec') = basicOverlaps mvec mvec'
basicUnsafeNew len = MV_KB2Sum `liftM` basicUnsafeNew len
basicUnsafeNew len = MV_KB2Sum <$> basicUnsafeNew len
basicInitialize (MV_KB2Sum mvec) = basicInitialize mvec
basicUnsafeReplicate len val = MV_KB2Sum `liftM` basicUnsafeReplicate len ((\ (KB2Sum a b c) -> (a, b, c)) val)
basicUnsafeRead (MV_KB2Sum mvec) idx = (\ (a, b, c) -> KB2Sum a b c) `liftM` basicUnsafeRead mvec idx
basicUnsafeReplicate len val = MV_KB2Sum <$> basicUnsafeReplicate len ((\ (KB2Sum a b c) -> (a, b, c)) val)
basicUnsafeRead (MV_KB2Sum mvec) idx = (\ (a, b, c) -> KB2Sum a b c) <$> basicUnsafeRead mvec idx
basicUnsafeWrite (MV_KB2Sum mvec) idx val = basicUnsafeWrite mvec idx ((\ (KB2Sum a b c) -> (a, b, c)) val)
basicClear (MV_KB2Sum mvec) = basicClear mvec
basicSet (MV_KB2Sum mvec) val = basicSet mvec ((\ (KB2Sum a b c) -> (a, b, c)) val)
basicUnsafeCopy (MV_KB2Sum mvec) (MV_KB2Sum mvec') = GM.basicUnsafeCopy mvec mvec'
basicUnsafeMove (MV_KB2Sum mvec) (MV_KB2Sum mvec') = basicUnsafeMove mvec mvec'
basicUnsafeGrow (MV_KB2Sum mvec) len = MV_KB2Sum `liftM` basicUnsafeGrow mvec len
basicUnsafeGrow (MV_KB2Sum mvec) len = MV_KB2Sum <$> basicUnsafeGrow mvec len

newtype instance U.Vector KB2Sum = V_KB2Sum (U.Vector (Double, Double, Double))
instance Vector U.Vector KB2Sum where
Expand All @@ -302,11 +301,11 @@ instance Vector U.Vector KB2Sum where
{-# INLINE basicUnsafeIndexM #-}
{-# INLINE G.basicUnsafeCopy #-}
{-# INLINE elemseq #-}
basicUnsafeFreeze (MV_KB2Sum mvec) = V_KB2Sum `liftM` basicUnsafeFreeze mvec
basicUnsafeThaw (V_KB2Sum vec) = MV_KB2Sum `liftM` basicUnsafeThaw vec
basicUnsafeFreeze (MV_KB2Sum mvec) = V_KB2Sum <$> basicUnsafeFreeze mvec
basicUnsafeThaw (V_KB2Sum vec) = MV_KB2Sum <$> basicUnsafeThaw vec
basicLength (V_KB2Sum vec) = G.basicLength vec
basicUnsafeSlice idx len (V_KB2Sum vec) = V_KB2Sum (G.basicUnsafeSlice idx len vec)
basicUnsafeIndexM (V_KB2Sum vec) idx = (\ (a, b, c) -> KB2Sum a b c) `liftM` basicUnsafeIndexM vec idx
basicUnsafeIndexM (V_KB2Sum vec) idx = (\ (a, b, c) -> KB2Sum a b c) <$> basicUnsafeIndexM vec idx
basicUnsafeCopy (MV_KB2Sum mvec) (V_KB2Sum vec) = G.basicUnsafeCopy mvec vec
elemseq (V_KB2Sum vec) val = elemseq vec ((\ (KB2Sum a b c) -> (a, b, c)) val)

Expand All @@ -320,11 +319,11 @@ instance NFData KB2Sum where
-- | @since 0.3.0.0
instance Monoid KB2Sum where
mempty = zero
s `mappend` KB2Sum s' c' cc' = add (add (add s s') c') cc'
mappend = (<>)

-- | @since 0.3.0.0
instance Semigroup KB2Sum where
(<>) = mappend
s <> KB2Sum s' c' cc' = add (add (add s s') c') cc'


kb2Add :: KB2Sum -> Double -> KB2Sum
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Changes in 0.3.4.4

* Support for future versions of GHC. Monoid and Monad instances now have
canonical form


## Changes in 0.3.4.3

* Support for `QuickCheck >= 2.14`. Test no longer fail
Expand Down
2 changes: 1 addition & 1 deletion math-functions.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: math-functions
version: 0.3.4.3
version: 0.3.4.4
cabal-version: >= 1.10
license: BSD2
license-file: LICENSE
Expand Down