Reference🔗
berhoel.helper 🔗
Misc helper.
Modules:
-
check_args–Proccess arguments flexible.
-
machar–Determine machine-specific parameters affecting floating-point arithmetic.
-
set_version–Set lib version from
pyproject.toml. -
tests–
Classes:
-
SwirlSelect–Selector for swirl style.
Functions:
-
count_with_msg–Count variable with start value and message.
-
process_msg_context–Provide a context for calling routines and reporting entering and exit.
-
swirl–Retrun generator to show a swirling life indicator.
-
timed_process_msg_context–Provide a context for calling routines and reporting entering and exit.
Classes🔗
berhoel.helper.SwirlSelect 🔗
Selector for swirl style.
Functions🔗
berhoel.helper.count_with_msg 🔗
Count variable with start value and message.
>>> c = count_with_msg("msg", 5)
>>> print([i for _, i in zip(range(5), c)] == [5, 6, 7, 8, 9])
msg 1 ...msg 2 ...msg 3 ...msg 4 ...msg 5 ...True
>>>
Parameters:
Returns:
-
Generator–counter with message.
Source code in src/berhoel/helper/__init__.py
berhoel.helper.process_msg_context 🔗
Provide a context for calling routines and reporting entering and exit.
Parameters:
Returns:
-
Generator–bracing message.
Source code in src/berhoel/helper/__init__.py
berhoel.helper.swirl 🔗
swirl(style: SwirlSelect = LINES) -> Generator
Retrun generator to show a swirling life indicator.
>>> sw = swirl()
>>> a = [_ for _ in zip(range(5), sw)]
\...|.../...-...\...
>>> sw = swirl(SwirlSelect.DOTS)
>>> a = [_ for _ in zip(range(8), sw)]
⠇...⡆...⣄...⣠...⢰...⠸...⠙...⠋...
Returns:
-
Generator–printing running indicator.
Source code in src/berhoel/helper/__init__.py
berhoel.helper.timed_process_msg_context 🔗
Provide a context for calling routines and reporting entering and exit.
Report spent time.
>>> with timed_process_msg_context("do something"):
... time.sleep(1)
do something......do something...done (0:00:01)
>>> with timed_process_msg_context(
... "do something", lambda t: "{:d}s".format(int(t))
... ):
... time.sleep(1)
do something......do something...done (1s)
>>>
Parameters:
-
(msg🔗str) –message for bracing process.
-
(time_form🔗Callable | None, default:None) –function formatting druntime.
Returns:
-
Generator–bracing message.
Source code in src/berhoel/helper/__init__.py
berhoel.helper.machar 🔗
Determine machine-specific parameters affecting floating-point arithmetic.
Function to determine machine-specific parameters affecting floating-point arithmetic.
- This is build after “NUMERICAL RECIPES in C”, second edition, Reprinted 1996, pp. 889.
Functions:
-
machar–Determine and returns machine-spec. paras affecting floating-point arithmetic.
Attributes:
-
eps–eps(float) -
epsneg–epsneg(float) -
ibeta–ibeta(int) -
iexp–iexp(int) -
irnd–irnd(int) -
it–it(int) -
machdep–machep(int) -
maxexp–maxexp(int) -
minexp–minexp(int) -
negep–negep(int) -
ngrd–ngrd(int) -
xmax–xmax(float) -
xmin–xmin(float)
Attributes🔗
berhoel.helper.machar.eps module-attribute 🔗
eps (float) Is the floating-point number ibeta ** machdep, loosly referred to as the floating-point precision.
berhoel.helper.machar.epsneg module-attribute 🔗
epsneg (float) Is ibeta ** negep, another way of defining floating-point precision. Not infrequently epsneg is 0.5 times eps; occasionally eps and epsneg are equal.
berhoel.helper.machar.ibeta module-attribute 🔗
ibeta (int) The radix in which numbers are represented, almost always 2, but occasionally 16, or even 10
berhoel.helper.machar.iexp module-attribute 🔗
iexp (int) Is the number of bits in the exponent (including its sign or bias)
berhoel.helper.machar.irnd module-attribute 🔗
irnd (int) Returns a code in the range 0…5, giving information on what kind of rounding is done in addition, and on how underflow is handled.
If irnd returns 2 or 5, then your computer is compilant with the IEEE standard for rounding. If it returns 1 or 4, then it is doing some kind of rounding, but not the IEEE standard. If irnd returns 0 or 3, then it is truncating the result, not rounding it.
berhoel.helper.machar.it module-attribute 🔗
it (int) The number of base-ibeta digits in the floating point mantissa
berhoel.helper.machar.machdep module-attribute 🔗
machep (int) Is the exponent of the smallest (most negative) power if ibeta that, added to 1.0 gives something different from 1.0.
berhoel.helper.machar.maxexp module-attribute 🔗
maxexp (int) Is the smallest (positive) power of ibeta that causes overflow.
berhoel.helper.machar.minexp module-attribute 🔗
minexp (int) Is the smallest (most negative) power if ibeta consistent with there no leading zeros in the mantissa.
berhoel.helper.machar.negep module-attribute 🔗
negep (int) Is the exponenet of the smalles power of ibeta that, subtracted from 1.0, gives something different from 1.0.
berhoel.helper.machar.ngrd module-attribute 🔗
ngrd (int) Is the number of guard digits used when truncating the product of two mantissas to fit the representation”
berhoel.helper.machar.xmax module-attribute 🔗
xmax (float) Is (1 - epsneg) x ibeta ** maxexp, generally the largest (in magnitude) usable floating value.
berhoel.helper.machar.xmin module-attribute 🔗
xmin (float) Is the floating-point number ibeta ** minexp, generally the smallest (in magnitude) usable floating value
Functions🔗
berhoel.helper.machar.machar 🔗
Determine and returns machine-spec. paras affecting floating-point arithmetic.
Returns🔗
dict: Values in result dictionary are:
ibeta(int): The radix in which numbers are represented, almost always 2, but occasionally 16, or even 10it(int): The number of base-ibetadigits in the floating point mantissamachep(int): Is the exponent of the smallest (most negative) power ifibetathat, added to 1.0 gives something different from 1.0.eps(float): Is the floating-point numberibeta**machdep, loosly referred to as the floating-point precision.negep(int): Is the exponenet of the smalles power ofibetathat, subtracted from 1.0, gives something different from 1.0.epsneg(float): Isibeta**negep, another way of defining floating-point precision. Not infrequentlyepsnegis 0.5 timeseps; occasionallyepsandepsnegare equal.iexp(int): Is the number of bits in the exponent (including its sign or bias)minexp(int): Is the smallest (most negative) power ifibetaconsistent with there no leading zeros in the mantissa.xmin(float): Is the floating-point numberibeta**minexp, generally the smallest (in magnitude) usable floating valuemaxexp(int): Is the smallest (positive) power ofibetathat causes overflow.xmax(float): Is (1 -epsneg) xibeta**maxexp, generally the largest (in magnitude) usable floating value.-
irnd(int): Returns a code in the range 0…5, giving information on what kind of rounding is done in addition, and on how underflow is handled.If
irndreturns 2 or 5, then your computer is compilant with the IEEE standard for rounding. If it returns 1 or 4, then it is doing some kind of rounding, but not the IEEE standard. Ifirndreturns 0 or 3, then it is truncating the result, not rounding it. -ngrd(int): Is the number of guard digits used when truncating the product of two mantissas to fit the representation
This is taken from “NUMERICAL RECIPES in C”, second edition, Reprinted 1996.
Source code in src/berhoel/helper/machar.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
berhoel.helper.check_args 🔗
Proccess arguments flexible.
This module provides a class named CheckArgs and a function named check_args.
The class CheckArgs is ment to be used as base class for own classes. After the __init__ method is called a dictionary args is added to the local namespace.
The init mathod has four arguments.
The first is, as usual, the self handler. The second is a list or tuples holding the allowed keyword arguments as first tuple element and their default values as remaining tuple elements.
The third and forth argument are the *data and **kw arguments from the implemented class.
Example
>>> from .check_args import CheckArgs
>>> class samp(CheckArgs):
... default = (("A", "A"), ("B", "B"), ("C", ("C", 1, 2)))
...
... def __init__(self, *data, **kw):
... CheckArgs.__init__(self, *data, **kw)
... print(self.args["A"], self.args["B"], self.args["C"])
>>> A = samp(A=34)
34 B ('C', 1, 2)
>>> A = samp(34, "HALLO")
34 HALLO ('C', 1, 2)
>>>
The function check_args provides similar funtionality for functions. It also takes four arguments.
The first to third argument are simlar to the second to forth element of the class. The forth element of the function is the functions name.
Example
Classes:
Functions:
-
check_args–Check arguments for function.
Classes🔗
berhoel.helper.check_args.ArgError 🔗
Error from the argument checking.
berhoel.helper.check_args.CheckArgs 🔗
Functions🔗
berhoel.helper.check_args.check_args 🔗
check_args(
default: Iterable[tuple[str, object]], data: tuple, kw: dict, name: str
) -> dict[str, object]
Check arguments for function.
Parameters:
-
(default🔗tuple[tuple[str, object]]) –argument names and default values for function call.
-
(data🔗tuple) –arguments to function call.
-
(kw🔗dict) –keyword arguments to function call.
-
(name🔗str) –name for reporting.
Returns:
Source code in src/berhoel/helper/check_args.py
berhoel.helper.set_version 🔗
Set lib version from pyproject.toml.
Deprecated: 1.3.6
Use:
instead
This library allows for setting the version number for a library from the pyproject.toml file.
Add to your pyproject.toml add a new section:
Generate the version file:
In the library __init__.py just use:
Functions:
-
build–Create version files with version number from
pyproject.toml. -
build_parser–Build cli parser.
Functions🔗
berhoel.helper.set_version.build 🔗
Create version files with version number from pyproject.toml.
Source code in src/berhoel/helper/set_version.py
berhoel.helper.set_version.build_parser 🔗
build_parser() -> ArgumentParser
Build cli parser.