packages feed

quantizer 0.2.0.0 → 0.2.1.0

raw patch · 4 files changed

+101/−5 lines, 4 filesdep ~subGPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: subG

API changes (from Hackage documentation)

+ ListQuantizer: foldableQuantizerGL :: (Ord a, Floating a, Integral a) => Bool -> ([a] -> a -> Ordering) -> [a] -> [a] -> [a]
+ ListQuantizer: foldableQuantizerGML :: (Ord a, Floating a, Integral a, Monad m) => Bool -> ([a] -> a -> m Ordering) -> [a] -> [a] -> m [a]
+ ListQuantizer: round2GL :: Ord a => Bool -> ([a] -> a -> Ordering) -> [a] -> a -> Maybe a
+ ListQuantizer: round2GML :: (Ord a, Monad m) => Bool -> ([a] -> a -> m Ordering) -> [a] -> a -> m (Maybe a)

Files

CHANGELOG.md view
@@ -3,3 +3,14 @@ ## 0.1.0.0 -- 2022-09-13  * First version. Released on an unsuspecting world.++## 0.2.0.0 -- 2023-01-24++* Second version. Updated the dependencies bounaries.++## 0.2.1.0 -- 2023-01-25++* Second version revised A. Applied the ideas of the foldl package and added a new module+ListQuantizer to be used in case of lists instead of FoldableQuantizer. Some documentation+improvements.+
FoldableQuantizer.hs view
@@ -8,6 +8,8 @@ -- A module to provide the extended variants to convert a 'S.InsertLeft' instance structure with -- some values to another one with the values from the pre-defined structure. Similar to  -- the measurement of the quantum state observables with the discrete spectrum.+-- For performance reasons it is better to use module ListQuantizer whenever possible (especially if the+-- given 'F.Foldable' and 'S.InsertLeft' instances are just lists).  {-# LANGUAGE NoImplicitPrelude #-} @@ -39,7 +41,7 @@  | otherwise = Just (case f xs z of { GT -> u; LT -> t; EQ -> if bool then u else t })    where (x, y) = fromJust . minMax11 $ xs          (ts,us) = S.span (<z) xs-         t = fromJust . S.safeLastG $ ts+         t = fromJust . S.safeLastG $ ts -- This can cause some perfarmance downgrade because of the general implementation being not optimized.          u = fromJust . S.safeHeadG $ us  foldableQuantizerG @@ -69,7 +71,7 @@      case q of { GT -> return u; LT -> return t; EQ -> return (if bool then u else t)}    where (x, y) = fromJust . minMax11 $ xs          (ts,us) = S.span (<z) xs-         t = S.safeLastG ts+         t = S.safeLastG ts --  This can cause some perfarmance downgrade because of the general implementation being not optimized.          u = S.safeHeadG us  foldableQuantizerGM 
+ ListQuantizer.hs view
@@ -0,0 +1,83 @@+-- |+-- Module      :  ListQuantizer+-- Copyright   :  (c) OleksandrZhabenko 2023+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  oleksandr.zhabenko@yahoo.com+--+-- A module to provide the extended variants to convert a list with+-- some values to another one with the values from the pre-defined another list. Similar to +-- the measurement of the quantum state observables with the discrete spectrum.++{-# LANGUAGE NoImplicitPrelude #-}++module ListQuantizer where++import GHC.Base+import GHC.List+import GHC.Real+import GHC.Float+import GHC.Num+import Data.Maybe+import qualified TwoQuantizer as Q (meanF2)+import Data.MinMax (minMax11)++-- | A better suited variant for 'FoldableQuantizer.round2G' for lists. +round2GL+ :: (Ord a) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. + -> ([a] -> a -> Ordering) + -> [a] + -> a + -> Maybe a -- ^ The @a@ value (in 'Just' case) can be equal just to the one of the two first @a@ arguments.+round2GL bool f xs z + | z `elem` xs = Just z+ | length xs < 2 = Nothing+ | z < x || z > y = Nothing+ | null ts = Just u+ | null us = Just t+ | otherwise = Just (case f xs z of { GT -> u; LT -> t; EQ -> if bool then u else t })+     where (x, y) = fromJust . minMax11 $ xs+           (ts,us) = span (<z) xs+           t = last ts+           u = head us++foldableQuantizerGL + :: (Ord a, Floating a, Integral a) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value.+ -> ([a] -> a -> Ordering) + -> [a] + -> [a]+ -> [a]+foldableQuantizerGL ctrl f needs xs = map (fromJust . round2GL ctrl f needs) ys+  where k = Q.meanF2 needs 0 0 / Q.meanF2 xs 0 0+        ys = foldr (\t ts -> t * k : ts) [] xs++round2GML + :: (Ord a, Monad m) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. + -> ([a] -> a -> m Ordering) + -> [a] + -> a + -> m (Maybe a)+round2GML bool f xs z + | z `elem` xs = return . Just $ z+ | length xs < 2 = return Nothing+ | z < x || z > y = return Nothing+ | null ts = return u+ | null us = return t+ | otherwise = do+     q <- f xs z+     case q of { GT -> return u; LT -> return t; EQ -> return (if bool then u else t)}+   where (x, y) = fromJust . minMax11 $ xs+         (ts,us) = span (<z) xs+         t = if null ts then Nothing else Just . last $ ts+         u = if null us then Nothing else Just . head $ us++foldableQuantizerGML + :: (Ord a, Floating a, Integral a, Monad m) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. + -> ([a] -> a -> m Ordering) + -> [a] + -> [a] + -> m [a]+foldableQuantizerGML ctrl f needs xs = mapM (fmap fromJust . round2GML ctrl f needs) ys+  where k = Q.meanF2 needs 0 0  / Q.meanF2 xs 0 0+        ys = foldr (\u us -> u * k : us) [] xs+
quantizer.cabal view
@@ -1,5 +1,5 @@ name:                quantizer-version:             0.2.0.0+version:             0.2.1.0 synopsis:            Library to provide the behaviour similar to quantum states superposition.  description:         Has two modules with similar functionality. The functions provide the somewhat generalized way to round the numbers based on some data. homepage:            https://hackage.haskell.org/package/quantizer@@ -14,9 +14,9 @@ cabal-version:       >=1.10  library-  exposed-modules:     TwoQuantizer, FoldableQuantizer+  exposed-modules:     TwoQuantizer, ListQuantizer, FoldableQuantizer   -- other-modules:   -- other-extensions: -  build-depends:       base >=4.13 && <5, subG == 0.6.0.0, uniqueness-periods-vector-stats == 0.4.0.0+  build-depends:       base >=4.13 && <5, subG == 0.6.1.0, uniqueness-periods-vector-stats == 0.4.0.0   -- hs-source-dirs:   default-language:    Haskell2010