numhask-space 0.8.1.0 → 0.9.0.0
raw patch · 10 files changed
+82/−185 lines, 10 filesdep ~containersdep ~numhaskdep ~random
Dependency ranges changed: containers, numhask, random, tdigest, vector
Files
- ChangeLog.md +9/−0
- numhask-space.cabal +47/−66
- src/NumHask/Space.hs +0/−2
- src/NumHask/Space/Histogram.hs +7/−1
- src/NumHask/Space/Point.hs +1/−5
- src/NumHask/Space/Range.hs +1/−1
- src/NumHask/Space/Rect.hs +1/−1
- src/NumHask/Space/Time.hs +3/−2
- src/NumHask/Space/Types.hs +13/−6
- src/NumHask/Space/XY.hs +0/−101
ChangeLog.md view
@@ -1,3 +1,12 @@+0.9.0+===+* added emptyHistogram+* fixes for numhask-0.9++0.8.2+===+* replaced space1 partial with unsafeSpace1 + total space1+ 0.8.1 === * GHC 9.0.1 support
numhask-space.cabal view
@@ -1,81 +1,62 @@-cabal-version: 2.4-name: numhask-space-version: 0.8.1.0-synopsis:- Numerical spaces.+cabal-version: 2.4+name: numhask-space+version: 0.9.0.0+synopsis: Numerical spaces. description:- @numhask-space@ provides support for spaces where [space](https://en.wikipedia.org/wiki/Space_(mathematics\)) is defined as a set of numbers with a lower and upper bound.- .- == Usage- .- >>> {-# LANGUAGE RebindableSyntax #-}- >>> import NumHask.Prelude- >>> import NumHask.Space- .+ @numhask-space@ provides support for spaces where [space](https://en.wikipedia.org/wiki/Space_(mathematics\)) is defined as a set of numbers with a lower and upper bound.+ .+ == Usage+ .+ >>> {-# LANGUAGE RebindableSyntax #-}+ >>> import NumHask.Prelude+ >>> import NumHask.Space+ . -category:- mathematics-homepage:- https://github.com/tonyday567/numhask-space#readme-bug-reports:- https://github.com/tonyday567/numhask-space/issues-author:- Tony Day-maintainer:- tonyday567@gmail.com-copyright:- Tony Day-license:- BSD-3-Clause-license-file:- LICENSE-build-type:- Simple-tested-with:- GHC ==8.8.4- || ==8.10.4- || ==9.0.1- || ==9.2.0.20210821-extra-source-files:- ChangeLog.md+category: mathematics+homepage: https://github.com/tonyday567/numhask-space#readme+bug-reports: https://github.com/tonyday567/numhask-space/issues+author: Tony Day+maintainer: tonyday567@gmail.com+copyright: Tony Day+license: BSD-3-Clause+license-file: LICENSE+build-type: Simple+tested-with: GHC ==8.8.4 || ==8.10.7 || ==9.2.1+extra-source-files: ChangeLog.md+ source-repository head- type:- git- location:- https://github.com/tonyday567/numhask-space+ type: git+ location: https://github.com/tonyday567/numhask-space library- hs-source-dirs:- src+ hs-source-dirs: src ghc-options:- -Wall- -Wcompat- -Wincomplete-record-updates- -Wincomplete-uni-patterns- -Wredundant-constraints- -fwrite-ide-info+ -Wall -Wcompat -Wincomplete-record-updates+ -Wincomplete-uni-patterns -Wredundant-constraints -fwrite-ide-info -hiedir=.hie+ default-extensions: build-depends:- adjunctions >=4.0 && <5,- base >=4.7 && <5,- containers >= 0.6 && < 0.7,- distributive >=0.2.2 && <1,- numhask >= 0.8.1 && < 0.9,- random >= 1.2 && < 1.3,- semigroupoids >=5 && <5.4,- tdigest >= 0.2.1 && < 0.3,- text >= 1.2.3.1 && <2,- time >= 1.9.1 && <1.12,- vector >= 0.12 && < 0.13,+ , adjunctions >=4.0 && <5+ , base >=4.7 && <5+ , containers ^>=0.6+ , distributive >=0.2.2 && <1+ , numhask ^>=0.9.0+ , random ^>=1.2+ , semigroupoids >=5 && <5.4+ , tdigest ^>=0.2.1+ , text >=1.2.3.1 && <2+ , time >=1.9.1 && <1.12+ , vector ^>=0.12+ exposed-modules: NumHask.Space- NumHask.Space.Types+ NumHask.Space.Histogram+ NumHask.Space.Point NumHask.Space.Range NumHask.Space.Rect- NumHask.Space.Point NumHask.Space.Time- NumHask.Space.Histogram- NumHask.Space.XY+ NumHask.Space.Types+ other-modules:- default-language: Haskell2010+ default-language: Haskell2010
src/NumHask/Space.hs view
@@ -30,7 +30,6 @@ module NumHask.Space.Rect, module NumHask.Space.Time, module NumHask.Space.Histogram,- module NumHask.Space.XY, ) where @@ -40,7 +39,6 @@ import NumHask.Space.Rect hiding () import NumHask.Space.Time hiding () import NumHask.Space.Types hiding ()-import NumHask.Space.XY hiding () -- $setup --
src/NumHask/Space/Histogram.hs view
@@ -7,6 +7,7 @@ -- | A histogram, if you squint, is a series of contiguous 'Range's, annotated with values. module NumHask.Space.Histogram ( Histogram (..),+ emptyHistogram, DealOvers (..), fill, cutI,@@ -43,6 +44,10 @@ } deriving (Show, Eq) +-- | A histogram with no cuts nor data.+emptyHistogram :: Histogram+emptyHistogram = Histogram V.empty Map.empty+ -- | Whether or not to ignore unders and overs. If overs and unders are dealt with, IncludeOvers supplies an assumed width for the outer buckets. data DealOvers = IgnoreOvers | IncludeOvers Double @@ -80,9 +85,10 @@ -- >>> regular 4 [0..100] -- Histogram {cuts = [0.0,25.0,50.0,75.0,100.0], values = fromList [(1,25.0),(2,25.0),(3,25.0),(4,25.0),(5,1.0)]} regular :: Int -> [Double] -> Histogram+regular _ [] = emptyHistogram regular n xs = fill cs xs where- cs = grid OuterPos (space1 xs :: Range Double) n+ cs = grid OuterPos (unsafeSpace1 xs :: Range Double) n -- | Transform a Histogram to Rects --
src/NumHask/Space/Point.hs view
@@ -61,7 +61,7 @@ -- -- This is used extensively in [chart-svg](https://hackage.haskell.org/package/chart-svg) to ergonomically obtain chart areas. ----- > space1 [Point 1 0, Point 0 1] :: Rect Double+-- > unsafeSpace1 [Point 1 0, Point 0 1] :: Rect Double -- Rect 0.0 1.0 0.0 1.0 data Point a = Point { _x :: a,@@ -141,19 +141,15 @@ instance (Additive a) => AdditiveAction (Point a) a where (.+) a (Point x y) = Point (a + x) (a + y)- (+.) (Point x y) a = Point (a + x) (a + y) instance (Subtractive a) => SubtractiveAction (Point a) a where (.-) a (Point x y) = Point (a - x) (a - y)- (-.) (Point x y) a = Point (x - a) (y - a) instance (Multiplicative a) => MultiplicativeAction (Point a) a where (.*) a (Point x y) = Point (a * x) (a * y)- (*.) (Point x y) a = Point (a * x) (a * y) instance (Divisive a) => DivisiveAction (Point a) a where (./) a (Point x y) = Point (a / x) (a / y)- (/.) (Point x y) a = Point (x / a) (y / a) instance Representable Point where type Rep Point = Bool
src/NumHask/Space/Range.hs view
@@ -147,7 +147,7 @@ (<>) a b = getUnion (Union a <> Union b) instance (Additive a, Eq a, Ord a) => Additive (Range a) where- (Range l u) + (Range l' u') = space1 [l + l', u + u']+ (Range l u) + (Range l' u') = unsafeSpace1 [l + l', u + u'] zero = Range zero zero instance (Subtractive a, Eq a, Ord a) => Subtractive (Range a) where
src/NumHask/Space/Rect.hs view
@@ -270,7 +270,7 @@ -- >>> rotationBound (pi/4) one -- Rect -0.7071067811865475 0.7071067811865475 -0.7071067811865475 0.7071067811865475 rotationBound :: (TrigField a, Ord a) => a -> Rect a -> Rect a-rotationBound d = space1 . fmap (rotate d |.) . corners4+rotationBound d = unsafeSpace1 . fmap (rotate d |.) . corners4 -- | Create Rects for a formulae y = f(x) across an x range where the y range is Range 0 y --
src/NumHask/Space/Time.hs view
@@ -238,9 +238,10 @@ -- >>> placedTimeLabelDiscontinuous PosIncludeBoundaries (Just (pack "%d %b")) 2 [UTCTime (fromGregorian 2017 12 6) (toDiffTime 0), UTCTime (fromGregorian 2017 12 29) (toDiffTime 0), UTCTime (fromGregorian 2018 1 31) (toDiffTime 0), UTCTime (fromGregorian 2018 3 3) (toDiffTime 0)] -- ([(0,"06 Dec"),(1,"31 Dec"),(2,"28 Feb"),(3,"03 Mar")],[]) placedTimeLabelDiscontinuous :: PosDiscontinuous -> Maybe Text -> Int -> [UTCTime] -> ([(Int, Text)], [UTCTime])+placedTimeLabelDiscontinuous _ _ _ [] = ([], []) placedTimeLabelDiscontinuous posd format n ts = (zip (fst <$> inds') labels, rem') where- r@(Range l u) = space1 ts+ r@(Range l u) = unsafeSpace1 ts (grain, tps) = sensibleTimeGrid InnerPos n r tps' = case posd of PosInnerOnly -> tps@@ -296,7 +297,7 @@ Just f -> unpack f Nothing -> autoFormat grain labels = pack . formatTime defaultTimeLocale fmt <$> tps'- (Range l' u') = space1 tps'+ (Range l' u') = unsafeSpace1 tps' r' = fromNominalDiffTime $ diffUTCTime u' l' tpsd = (/ r') . fromNominalDiffTime . flip diffUTCTime l <$> tps'
src/NumHask/Space/Types.hs view
@@ -18,6 +18,7 @@ project, Pos (..), space1,+ unsafeSpace1, randomS, randomSM, randomSs,@@ -199,7 +200,7 @@ -- | a space that can be divided neatly ----- > space1 (grid OuterPos s g) == s+-- > unsafeSpace1 (grid OuterPos s g) == s -- > getUnion (sconcat (Union <$> (gridSpace s g))) == s class (Space s, Field (Element s)) => FieldSpace s where type Grid s :: Type@@ -244,15 +245,21 @@ project s0 s1 p = ((p - lower s0) / (upper s0 - lower s0)) * (upper s1 - lower s1) + lower s1 --- | the containing space of a non-empty Traversable+-- | the containing space of a non-empty Traversable. ----- > all $ space1 a `contains` <$> a-space1 :: (Space s, Traversable f) => f (Element s) -> s-space1 = P.foldr1 union . fmap singleton+-- partial function.+--+-- > all $ unsafeSpace1 a `contains` <$> a+unsafeSpace1 :: (Space s, Traversable f) => f (Element s) -> s+unsafeSpace1 = P.foldr1 union . fmap singleton +-- | Maybe containing space of a traversable.+space1 :: (Space s, Traversable f) => f (Element s) -> Maybe s+space1 s = bool (Just $ unsafeSpace1 s) Nothing (null s)+ -- | lift a monotone function (increasing or decreasing) over a given space monotone :: (Space a, Space b) => (Element a -> Element b) -> a -> b-monotone f s = space1 [f (lower s), f (upper s)]+monotone f s = unsafeSpace1 [f (lower s), f (upper s)] -- | a small space eps ::
− src/NumHask/Space/XY.hs
@@ -1,101 +0,0 @@-{-# LANGUAGE DeriveFunctor #-}-{-# LANGUAGE PatternSynonyms #-}-{-# LANGUAGE RebindableSyntax #-}-{-# LANGUAGE StrictData #-}---- | Unification of 'Point' and 'Rect'.-module NumHask.Space.XY- ( XY (..),- pattern P,- pattern R,- toRect,- toPoint,- projectOn,- projectTo,- )-where--import qualified Data.List.NonEmpty as NonEmpty-import GHC.Show (show)-import NumHask.Prelude hiding (show)-import NumHask.Space.Point-import NumHask.Space.Rect-import NumHask.Space.Types---- $setup--- >>> import NumHask.Prelude--- >>> import NumHask.Space---- | unification of a point and rect on the plane-data XY a- = PointXY (Point a)- | RectXY (Rect a)- deriving (Eq, Functor)--instance (Show a) => Show (XY a) where- show (PointXY (Point x y)) = "P " <> show x <> " " <> show y- show (RectXY (Rect x z y w)) = "R " <> show x <> " " <> show z <> " " <> show y <> " " <> show w---- | make an XY from a point-pattern P :: a -> a -> XY a-pattern P x y = PointXY (Point x y)--{-# COMPLETE P #-}---- | make an XY from a rectangle-pattern R :: a -> a -> a -> a -> XY a-pattern R x z y w = RectXY (Rect x z y w)--{-# COMPLETE R #-}--instance (Additive a) => Additive (XY a) where- PointXY (Point x y) + PointXY (Point x' y') = PointXY (Point (x + x') (y + y'))- PointXY (Point x' y') + RectXY (Rect x z y w) = RectXY $ Rect (x + x') (z + x') (y + y') (w + y')- RectXY (Rect x z y w) + PointXY (Point x' y') = RectXY $ Rect (x + x') (z + x') (y + y') (w + y')- RectXY (Rect x z y w) + RectXY (Rect x' z' y' w') =- RectXY $ Rect (x + x') (z + z') (y + y') (w + w')- zero = PointXY (Point zero zero)--instance (Ord a, Field a) => Multiplicative (XY a) where- x * y = RectXY $ toRect x * toRect y- one = RectXY one--instance (Ord a, Subtractive a) => Subtractive (XY a) where- negate (PointXY (Point x y)) = PointXY (Point (negate x) (negate y))- negate (RectXY (Rect x z y w)) = RectXY (Rect (negate x) (negate z) (negate y) (negate w))--instance (Ord a, Field a, Signed a) => Signed (XY a) where- abs x = PointXY $ abs <$> toPoint x- sign x = PointXY $ sign <$> toPoint x---- * Natural transformations---- | Convert an XY to a Rect-toRect :: XY a -> Rect a-toRect (PointXY (Point x y)) = Rect x x y y-toRect (RectXY a) = a---- | Convert an XY to a Point-toPoint :: (Ord a, Field a) => XY a -> Point a-toPoint (PointXY (Point x y)) = Point x y-toPoint (RectXY (Ranges x y)) = Point (mid x) (mid y)--instance (Ord a) => Semigroup (XY a) where- (<>) a b = RectXY (toRect a `union` toRect b)---- | project an XY from one Rect to another, preserving relative position.------ >>> projectOn one (Rect 0 1 0 1) zero--- P -0.5 -0.5-projectOn :: Rect Double -> Rect Double -> XY Double -> XY Double-projectOn new old (PointXY p) = PointXY $ projectOnP new old p-projectOn new old (RectXY r) = RectXY $ projectOnR new old r---- | project an [XY a] from it's enclosing space to the given space------ >>> projectTo one (zipWith P [0..2] [0..2])--- [P -0.5 -0.5,P 0.0 0.0,P 0.5 0.5]-projectTo :: Rect Double -> [XY Double] -> [XY Double]-projectTo _ [] = []-projectTo vb (x : xs) =- projectOn vb (toRect $ sconcat (x NonEmpty.:| xs)) <$> (x : xs)