vcorelib.math package#
Subpackages#
Submodules#
vcorelib.math.constants module#
A module defining some useful constants.
vcorelib.math.time module#
Math utilities involving units of time and other conversions.
- class vcorelib.math.time.Timer[source]#
Bases:
object
A class for measuring and logging how long events take.
- log(log: Logger | LoggerAdapter[Any], message: str, *args, level: int = 20, reminder: bool = False, **kwargs) Iterator[None] [source]#
Log how long the caller’s context took to execute.
- vcorelib.math.time.byte_count_str(byte_count: int) str [source]#
Get a string representing a number of bytes.
- vcorelib.math.time.nano_str(nanos: int, is_time: bool = False, max_prefix: int = 3, unit: UnitSystem = (['n', 'u', 'm', '', 'k', 'M', 'G', 'T'], 1000), prefix_space: bool = False, iteration: int = 0) str [source]#
Convert an arbitrary value in a 10^-9 domain into as concise of a string as possible.
vcorelib.math.unit module#
A module for working with units.
- class vcorelib.math.unit.UnitSystem(prefixes: Sequence[str], divisor: int)[source]#
Bases:
NamedTuple
A pairing of prefixes defining a unit, and the amount that indicates the multiplicative step-size between them.
- divisor: int#
Alias for field number 1
- prefixes: Sequence[str]#
Alias for field number 0
- vcorelib.math.unit.unit_traverse(val: int, unit: UnitSystem = (['n', 'u', 'm', '', 'k', 'M', 'G', 'T'], 1000), max_prefix: int = 3, iteration: int = 0) Tuple[int, int, str] [source]#
Given an initial value, traverse a unit system to get the largest representative unit prefix. Also return a fractional component, in units of the next-smallest prefix.
Module contents#
Math utilities.
- class vcorelib.math.FloatBuffer(depth: int = 10, initial: float = 0.0)[source]#
Bases:
object
A class implementing a simple circular buffer for floats.
- class vcorelib.math.MovingAverage(depth: int = 10, initial: float = 0.0)[source]#
Bases:
object
A class for managing a moving average of floats.
- class vcorelib.math.MovingSum(depth: int = 10, initial: float = 0.0)[source]#
Bases:
FloatBuffer
A simple moving sum implementation.
- class vcorelib.math.RateLimiter(period_ns: int, **kwargs)[source]#
Bases:
object
A class for limiting the rate of runtime work.
- property rate_hz: float#
Get the underlying rate that this limiter is governing. This is useful to determine if the rate limitation is or isn’t impacting the rate of some task.
- class vcorelib.math.RateTracker(**kwargs)[source]#
Bases:
object
A class for managing rate information for some data channel.
- measure(value: float = 1.0, timer: ~vcorelib.math.time.Timer = <vcorelib.math.time.Timer object>) Iterator[None] [source]#
Track the time that the caller’s context takes.
- property value: float#
An accessor for the underlying value.
- class vcorelib.math.Timer[source]#
Bases:
object
A class for measuring and logging how long events take.
- log(log: Logger | LoggerAdapter[Any], message: str, *args, level: int = 20, reminder: bool = False, **kwargs) Iterator[None] [source]#
Log how long the caller’s context took to execute.
- class vcorelib.math.UnitSystem(prefixes: Sequence[str], divisor: int)[source]#
Bases:
NamedTuple
A pairing of prefixes defining a unit, and the amount that indicates the multiplicative step-size between them.
- divisor: int#
Alias for field number 1
- prefixes: Sequence[str]#
Alias for field number 0
- class vcorelib.math.WeightedAverage(depth: int = 10)[source]#
Bases:
object
A class implementing a weighted average.
- property depth: int#
This average’s depth.
- vcorelib.math.byte_count_str(byte_count: int) str [source]#
Get a string representing a number of bytes.
- vcorelib.math.from_nanos(nanos: int) float [source]#
Convert a number in nano counts to a regular floating-point number.
- vcorelib.math.nano_str(nanos: int, is_time: bool = False, max_prefix: int = 3, unit: UnitSystem = (['n', 'u', 'm', '', 'k', 'M', 'G', 'T'], 1000), prefix_space: bool = False, iteration: int = 0) str [source]#
Convert an arbitrary value in a 10^-9 domain into as concise of a string as possible.
- vcorelib.math.seconds_str(seconds: int) Tuple[str, int] [source]#
Attempt to characterize a large amount of seconds into a string describing hours and minutes, returning the string (may be empty) and the seconds left over.
- vcorelib.math.to_nanos(value: float) int [source]#
Convert a number to the same number but in nano counts.
- vcorelib.math.unit_traverse(val: int, unit: UnitSystem = (['n', 'u', 'm', '', 'k', 'M', 'G', 'T'], 1000), max_prefix: int = 3, iteration: int = 0) Tuple[int, int, str] [source]#
Given an initial value, traverse a unit system to get the largest representative unit prefix. Also return a fractional component, in units of the next-smallest prefix.