packages feed

quantizer 0.3.1.0 → 0.4.0.0

raw patch · 6 files changed

+67/−68 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -35,3 +35,7 @@  * Third version revised C. Switched to more lightweight dependencies of minmax and monoid-insertleft.  Added Git repository with bug-tracking. +## 0.4.0.0 -- 2024-09-28++* Fourth version. Fixed incorrect definitions of the structures traversions that led to incorrect results in general. Added explicit error messages.+
FoldableQuantizer.hs view
@@ -13,7 +13,7 @@ -- TwoQuantizer module, the results  in every function  here depend not just on the two values,  -- which the point is located in between, but on the whole structure. Defined for just positive real numbers of 'Double' type. -{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE NoImplicitPrelude, BangPatterns #-}  module FoldableQuantizer where @@ -42,9 +42,9 @@  | F.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) = IL.span (<z) xs-         t = fromJust . IL.safeLastG $ ts -- This can cause some perfarmance downgrade because of the general implementation being not optimized.-         u = fromJust . IL.safeHeadG $ us+         (ts,us) = IL.partitionG (<z) xs+         t = F.maximum ts+         u = F.minimum us  foldableQuantizerG   :: (Ord a, Floating a, IL.InsertLeft t1 a, Monoid (t1 a), F.Foldable t2) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -53,7 +53,10 @@  -> t2 a  -> [a] foldableQuantizerG ctrl f needs xs = map (fromJust . round2G ctrl f needs) ys-  where k = Q.meanF2 (F.toList needs) 0 0 / Q.meanF2 (F.toList xs) 0 0+  where !k +          | y == 0 = error "FoldableQuantizer.foldableQuantizerG: division by zero!"+          | otherwise = Q.meanF2 (F.toList needs) 0 0 / y+                where !y = Q.meanF2 (F.toList xs) 0 0         ys = F.foldr (\t ts -> t * k : ts) [] xs  round2GM @@ -66,15 +69,15 @@  | z `F.elem` xs = return . Just $ z  | F.length xs < 2 = return Nothing  | z < x || z > y = return Nothing- | F.null ts = return u- | F.null us = return t+ | F.null ts = return . Just $ u+ | F.null us = return . Just $ t  | otherwise = do      q <- f xs z-     case q of { GT -> return u; LT -> return t; EQ -> return (if bool then u else t)}+     case q of { GT -> return . Just $ u; LT -> return . Just $ t; EQ -> return . Just $ if bool then u else t}    where (x, y) = fromJust . minMax11 $ xs-         (ts,us) = IL.span (<z) xs-         t = IL.safeLastG ts --  This can cause some perfarmance downgrade because of the general implementation being not optimized.-         u = IL.safeHeadG us+         (ts,us) = IL.partitionG (<z) xs+         t = F.maximum ts +         u = F.minimum us  foldableQuantizerGM   :: (Ord a, Floating a, Monad m, IL.InsertLeft t1 a, Monoid (t1 a), F.Foldable t2) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -83,6 +86,9 @@  -> t2 a   -> m [a] foldableQuantizerGM ctrl f needs xs = mapM (fmap fromJust . round2GM ctrl f needs) ys-  where k = Q.meanF2 (F.toList needs) 0 0  / Q.meanF2 (F.toList xs) 0 0+  where !k +           | y == 0 = error "FoldableQuantizer.foldableQuantizerGM: division by zero!"+           | otherwise = Q.meanF2 (F.toList needs) 0 0  / y+               where !y = Q.meanF2 (F.toList xs) 0 0          ys = F.foldr (\u us -> u * k : us) [] xs 
ListQuantizer.hs view
@@ -12,7 +12,7 @@ -- which the point is located in between, but on the whole list. Defined for just positive real numbers of 'Double' type.  -{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE NoImplicitPrelude, BangPatterns #-}  module ListQuantizer where @@ -24,6 +24,7 @@ import Data.Maybe import qualified TwoQuantizer as Q (meanF2) import Data.MinMax1 (minMax11)+import Data.List (partition)   -- | A better suited variant for 'FoldableQuantizer.round2G' for lists.  round2GL@@ -32,7 +33,7 @@  -> [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 +round2GL bool f xs@(w:_:_) z   | z `elem` xs = Just z  | length xs < 2 = Nothing  | z < x || z > y = Nothing@@ -40,9 +41,9 @@  | 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+           (ts,us) = partition (<z) xs+           t = maximum ts+           u = minimum us  foldableQuantizerGL   :: (Ord a, Floating a) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -50,8 +51,10 @@  -> [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+foldableQuantizerGL ctrl f needs xs = map (fromJust . round2GL ctrl f needs . (*k)) xs+  where !k +           | Q.meanF2 xs 0 0 == 0 = error "ListQuantizer.foldableQuantizerGL: division by zero!"+           | otherwise = Q.meanF2 needs 0 0 / Q.meanF2 xs 0 0         ys = foldr (\t ts -> t * k : ts) [] xs  round2GML @@ -70,9 +73,9 @@      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+         (ts,us) = partition (<z) xs+         t = if null ts then Nothing else Just . maximum $ ts+         u = if null us then Nothing else Just . minimum $ us  foldableQuantizerGML   :: (Ord a, Floating a, Monad m) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -80,7 +83,9 @@  -> [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+foldableQuantizerGML ctrl f needs xs = mapM (fmap fromJust . round2GML ctrl f needs . (*k)) xs+  where !k +           | Q.meanF2 xs 0 0 == 0 = error "ListQuantizer.foldableQuantizerGML: division by zero!"+           | otherwise = Q.meanF2 needs 0 0  / Q.meanF2 xs 0 0         ys = foldr (\u us -> u * k : us) [] xs 
README.md view
@@ -2,26 +2,7 @@ Uses some rounding techniques and recaps about quantum states superposition  (therefore, the package's name). - Devotion- ========--The author would like to devote this project to support the [Foundation Gastrostars](https://gastrostars.nl).--On the 21/02/2024 there is an International Mother Tongue Day — that is Ukrainian for the author of the package. --On the 12/03/2024 there was a Birthday of Emma Kok, she turned 16. Therefore, the release 0.3.1.0 is dedicated i.e. tributed to her.--Besides, you can support Ukrainian people in various forms.+You can support Ukrainian people in various forms.  All support is welcome, including donations for the needs of the Ukrainian army, IDPs and refugees. --If you would like to share some financial support with the Foundation Gastrostars, please, contact the mentioned foundation-using the URL:--[Contact Foundation GASTROSTARS](https://gastrostars.nl/hou-mij-op-de-hoogte)--or --[Donation Page](https://gastrostars.nl/doneren)- 
TwoQuantizer.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  TwoQuantizer--- Copyright   :  (c) OleksandrZhabenko 2022-2023+-- Copyright   :  (c) OleksandrZhabenko 2022-2024 -- License     :  MIT -- Stability   :  Experimental -- Maintainer  :  oleksandr.zhabenko@yahoo.com@@ -10,7 +10,7 @@ -- ListQuantizer module, the results  in every function  here depend on the two values,  -- which the point is located in between. Defined for just positive real numbers of 'Double' type. -{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE NoImplicitPrelude, BangPatterns #-}  module TwoQuantizer where @@ -21,7 +21,7 @@ import GHC.Float import GHC.Real import GHC.List-+import Data.List (partition)   round2    :: Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is when the square of the third paremeter is equal to  the product of the second one and the fourth one. @@ -45,18 +45,19 @@  | null us = y0  | x < y = fromJust . round2 ctrl y0 y $ x  | otherwise = y-  where (ks, us) = span (<x) ts-        y = head us-        y0 = last ks+  where (ks, us) = partition (<x) ts+        y = minimum us+        y0 = maximum ks  twoQuantizer   :: Bool  -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value.   -> [Double]   -> [Double]   -> [Double]-twoQuantizer ctrl needs xs = map (round2L ctrl needs) ys-  where k = meanD needs / meanD xs-        ys = map (*k) xs+twoQuantizer ctrl needs xs = map ((round2L ctrl needs) . (*k)) xs+  where !k +           | meanD xs == 0 = error "TwoQuantizer.twoQuantizer: division by zero!"+           | otherwise = meanD needs / meanD xs  round2G   :: (Ord a) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -83,9 +84,9 @@  | null us = y0  | x < y = fromJust . round2G ctrl f y0 y $ x  | otherwise = y-  where (ks, us) = span (<x) ts-        y = head us-        y0 = last ks+  where (ks, us) = partition (<x) ts+        y = minimum us+        y0 = maximum ks  twoQuantizerG   :: (Ord a, Floating a) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -93,9 +94,10 @@  -> [a]   -> [a]   -> [a]-twoQuantizerG ctrl f needs xs = map (round2GL ctrl f needs) ys-  where k = meanF2 needs 0 0 / meanF2 xs 0 0-        ys = map (*k) xs+twoQuantizerG ctrl f needs xs = map ((round2GL ctrl f needs) . (*k)) xs+  where !k +           | meanF2 xs 0 0 == 0 = error "TwoQuantizer.twoQuantizerG: division by zero!"+           | otherwise = meanF2 needs 0 0 / meanF2 xs 0 0  round2GM   :: (Ord a, Monad m) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -124,9 +126,9 @@  | null us = return y0  | x < y = fmap fromJust . round2GM ctrl f y0 y $ x   | otherwise = return y-  where (ks, us) = span (<x) ts-        y = head us-        y0 = last ks+  where (ks, us) = partition (<x) ts+        y = minimum us+        y0 = maximum ks  -- | Simple arithmetic mean. Is vulnerable to floating point rounding error so if possible use just -- for double-precision values.@@ -135,8 +137,8 @@  -> a   -> a   -> a-meanF2 (t:ts) s l = meanF2 ts (s + t) (l + 1) -meanF2 _ s l = s / l+meanF2 (!t:ts) !s !l = meanF2 ts (s + t) (l + 1) +meanF2 _ !s !l = s / l  twoQuantizerGM   :: (Ord a, Floating a, Monad m) => Bool -- ^ If 'True' then the function rounds the result in the ambiguous situation to the greater value. The ambigous situation is defined by the second argument.@@ -144,7 +146,8 @@  -> [a]   -> [a]   -> m [a]-twoQuantizerGM ctrl f needs xs = mapM (round2GLM ctrl f needs) ys-  where k = meanF2 needs 0 0  / meanF2 xs 0 0-        ys = map (*k) xs+twoQuantizerGM ctrl f needs xs = mapM ((round2GLM ctrl f needs) . (*k)) xs+  where !k +           | meanF2 xs 0 0 == 0 = error "TwoQuantizer.twoQuantizerGM: division by zero!"+           | otherwise = meanF2 needs 0 0  / meanF2 xs 0 0 
quantizer.cabal view
@@ -1,5 +1,5 @@ name:                quantizer-version:             0.3.1.0+version:             0.4.0.0 synopsis:            Library to provide the behaviour similar to quantum states superposition.  description:         Has three 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