log-domain 0.11.2 → 0.12
raw patch · 5 files changed
+30/−37 lines, 5 filesdep −safecopydep ~basedep ~doctestdep ~hashable
Dependencies removed: safecopy
Dependency ranges changed: base, doctest, hashable
Files
- .travis.yml +3/−0
- CHANGELOG.markdown +5/−0
- log-domain.cabal +2/−3
- src/Numeric/Log.hs +19/−33
- src/Numeric/Log/Signed.hs +1/−1
.travis.yml view
@@ -28,6 +28,9 @@ - env: CABALVER=1.24 GHCVER=8.0.2 compiler: ": #GHC 8.0.2" addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.2,hlint], sources: [hvr-ghc]}}+ - env: CABALVER=2.0 GHCVER=8.2.1+ compiler: ": #GHC 8.2.1"+ addons: {apt: {packages: [cabal-install-2.0,ghc-8.2.1,hlint], sources: [hvr-ghc]}} - env: CABALVER=1.24 GHCVER=head compiler: ": #GHC head" addons: {apt: {packages: [cabal-install-1.24,ghc-head,hlint], sources: [hvr-ghc]}}
CHANGELOG.markdown view
@@ -1,3 +1,8 @@+0.12+----+* Drop `safecopy` support+* Removed some unused constraints.+ 0.11.2 ------ * Support `doctest-0.12`
log-domain.cabal view
@@ -1,6 +1,6 @@ name: log-domain category: Numeric-version: 0.11.2+version: 0.12 license: BSD3 cabal-version: >= 1.8 license-file: LICENSE@@ -59,7 +59,6 @@ hashable >= 1.2.5 && < 1.3, semigroupoids >= 4 && < 6, semigroups >= 0.8.4 && < 1,- safecopy >= 0.8.1 && < 0.10, vector >= 0.9 && < 0.13 exposed-modules:@@ -85,7 +84,7 @@ else build-depends: base,- doctest >= 0.11.1 && < 0.13,+ doctest >= 0.11.1 && < 0.14, generic-deriving, log-domain, semigroups >= 0.9,
src/Numeric/Log.hs view
@@ -41,10 +41,8 @@ import Data.Hashable.Lifted import Data.Int import Data.List as List hiding (sum)-#if __GLASGOW_HASKELL__ < 710-import Data.Monoid-#endif-import Data.SafeCopy+import Data.List.NonEmpty (NonEmpty(..))+import Data.Semigroup import Data.Semigroup.Foldable import Data.Semigroup.Traversable import Data.Serialize as Serialize@@ -68,24 +66,6 @@ -- | @Log@-domain @Float@ and @Double@ values. newtype Log a = Exp { ln :: a } deriving (Eq,Ord,Data,Typeable,Generic) ---deriveSafeCopy 1 'base ''Log--instance SafeCopy a => SafeCopy (Log a) where- putCopy (Exp arg_afqB)- = contain- (do { safePut_a_afqC <- getSafePut;- safePut_a_afqC arg_afqB;- return () })- getCopy- = contain- (label- "Numeric.Log.Log:"- (do { safeGet_a_afqD <- getSafeGet;- ((return Exp) <*> safeGet_a_afqD) }))- version = 1- kind = base- errorTypeName _ = "Numeric.Log.Log"- instance (Floating a, Show a) => Show (Log a) where showsPrec d (Exp a) = T.showsPrec d (exp a) @@ -345,7 +325,7 @@ fromInteger = Exp . log . fromInteger {-# INLINE fromInteger #-} -instance (Precise a, RealFloat a, Eq a) => Fractional (Log a) where+instance (Precise a, RealFloat a) => Fractional (Log a) where -- n/0 == infinity is handled seamlessly for us, as is 0/0 and infinity/infinity NaNs, and 0/infinity == 0. Exp a / Exp b = Exp (a-b) {-# INLINE (/) #-}@@ -370,7 +350,7 @@ instance (RealFloat a, Unbox a) => Unbox (Log a) -instance (RealFloat a, Unbox a) => M.MVector U.MVector (Log a) where+instance Unbox a => M.MVector U.MVector (Log a) where {-# INLINE basicLength #-} {-# INLINE basicUnsafeSlice #-} {-# INLINE basicOverlaps #-}@@ -421,21 +401,27 @@ data Acc1 a = Acc1 {-# UNPACK #-} !Int64 !a -instance (Precise a, RealFloat a) => Monoid (Log a) where- mempty = Exp negInf- {-# INLINE mempty #-}- mappend = (+)- {-# INLINE mappend #-}- mconcat [] = 0- mconcat (Exp z:zs) = Exp $ case List.foldl' step1 (Acc1 0 z) zs of+instance (Precise a, RealFloat a) => Semigroup (Log a) where+ (<>) = (+)+ {-# INLINE (<>) #-}+ sconcat (Exp z :| zs) = Exp $ case List.foldl' step1 (Acc1 0 z) zs of Acc1 nm1 a | isInfinite a -> a | otherwise -> a + log1p (List.foldl' (step2 a) 0 zs + fromIntegral nm1) where step1 (Acc1 n y) (Exp x) = Acc1 (n + 1) (max x y) step2 a r (Exp x) = r + expm1 (x - a)- {-# INLINE mconcat #-}+ {-# INLINE sconcat #-} +instance (Precise a, RealFloat a) => Monoid (Log a) where+ mempty = Exp negInf+ {-# INLINE mempty #-}+#if !(MIN_VERSION_base(4,11,0))+ mappend = (<>)+#endif+ mconcat [] = 0+ mconcat (x:xs) = sconcat (x :| xs)+ logMap :: Floating a => (a -> a) -> Log a -> Log a logMap f = Exp . log . f . exp . ln {-# INLINE logMap #-}@@ -460,7 +446,7 @@ -- True -- -- /NB:/ This does require two passes over the data.-sum :: (RealFloat a, Ord a, Precise a, Foldable f) => f (Log a) -> Log a+sum :: (RealFloat a, Precise a, Foldable f) => f (Log a) -> Log a sum xs = Exp $ case Foldable.foldl' step1 None xs of None -> negInf Acc nm1 a
src/Numeric/Log/Signed.hs view
@@ -80,7 +80,7 @@ instance (Show a, RealFloat a, Eq a, Fractional a) => Show (SignedLog a) where showsPrec d (SLExp s a) = (if not s && a /= negInf && not (isNaN a) then T.showChar '-' else id) . T.showsPrec d (exp a) -instance (Precise a, RealFloat a, Fractional a, Read a) => Read (SignedLog a) where+instance (Precise a, RealFloat a, Read a) => Read (SignedLog a) where readPrec = (realToFrac :: a -> SignedLog a) <$> step T.readPrec nxor :: Bool -> Bool -> Bool