neclib.utils.math_utils#
Utility functions for arithmetic operations.
- discretize(value, start=0.0, step=1.0, *, method='nearest')[source]#
Convert
value
to nearest element of arithmetic sequence.- Parameters:
value (float) – Parameter to discretize.
start (float) – First element of element of arithmetic sequence.
step (float) – Difference between the consecutive 2 elements of the sequence.
method (Literal['nearest', 'ceil', 'floor']) – Discretizing method.
- Return type:
float
Examples
>>> neclib.utils.discretize(3.141592) 3 >>> neclib.utils.discretize(3.141592, step=10) 0 >>> neclib.utils.discretize(3.141592, method="ceil") 4 >>> neclib.utils.discretize(3.141592, start=2.5, step=0.7) 3.2
- counter(stop=None, allow_infty=False)[source]#
Generate integers from 0 to
stop
.- Parameters:
stop (Optional[int]) – Number of yielded values.
allow_infty (bool) – If
True
, the counter counts up to infinity. Listing such object will cause memory leak, so use caution.
- Return type:
Generator[int, None, None]
Examples
>>> list(neclib.utils.counter(5)) [0, 1, 2, 3, 4] >>> list(neclib.utils.counter()) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...] # -> memory leak