vcorelib.math
index
/home/vkottler/src/vkottler/workspace/vcorelib/vcorelib/math/__init__.py

Math utilities.

 
Package Contents
       
analysis (package)
constants
time
unit

 
Classes
       
builtins.object
vcorelib.math.analysis.average.MovingAverage
vcorelib.math.analysis.buffer.FloatBuffer
vcorelib.math.analysis.average.MovingSum
vcorelib.math.analysis.rate.RateTracker
vcorelib.math.analysis.rate.limiter.RateLimiter
vcorelib.math.analysis.weighted.WeightedAverage
vcorelib.math.time.Timer
builtins.tuple(builtins.object)
vcorelib.math.unit.UnitSystem

 
class FloatBuffer(builtins.object)
    FloatBuffer(depth: int = 10, initial: float = 0.0) -> None
 
A class implementing a simple circular buffer for floats.
 
  Methods defined here:
__call__(self, value: float) -> float
Insert an element into the buffer and return the oldest value (that
gets overwritten).
__init__(self, depth: int = 10, initial: float = 0.0) -> None
Initialize this instance.
reset(self, initial: float = 0.0) -> None
Reset the buffer.
resize(self, depth: int, initial: float = 0.0) -> None
Set a new depth for this buffer average and reset the values.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class MovingAverage(builtins.object)
    MovingAverage(depth: int = 10, initial: float = 0.0) -> None
 
A class for managing a moving average of floats.
 
  Methods defined here:
__call__(self, value: float) -> float
Add a new value to the dataset and get the average.
__init__(self, depth: int = 10, initial: float = 0.0) -> None
Initialize this moving average.
reset(self, initial: float = 0.0) -> None
Reset the average value.
resize(self, depth: int, initial: float = 0.0) -> None
Set a new depth for this moving average and reset the value.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class MovingSum(vcorelib.math.analysis.buffer.FloatBuffer)
    MovingSum(depth: int = 10, initial: float = 0.0) -> None
 
A simple moving sum implementation.
 
 
Method resolution order:
MovingSum
vcorelib.math.analysis.buffer.FloatBuffer
builtins.object

Methods defined here:
__call__(self, value: float) -> float
Update the moving sum.
__init__(self, depth: int = 10, initial: float = 0.0) -> None
Initialize this instance.
reset(self, initial: float = 0.0) -> None
Reset the buffer and sum.

Methods inherited from vcorelib.math.analysis.buffer.FloatBuffer:
resize(self, depth: int, initial: float = 0.0) -> None
Set a new depth for this buffer average and reset the values.

Data descriptors inherited from vcorelib.math.analysis.buffer.FloatBuffer:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class RateLimiter(builtins.object)
    RateLimiter(period_ns: int, **kwargs) -> None
 
A class for limiting the rate of runtime work.
 
  Methods defined here:
__call__(self, time_ns: int = None, task: Callable[[], NoneType] = None) -> bool
Query the limiter to determine if the current time would allow a
governed task to run.
__init__(self, period_ns: int, **kwargs) -> None
Initialize this rate-limiter.

Readonly properties defined here:
rate_hz
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.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class RateTracker(builtins.object)
    RateTracker(**kwargs) -> None
 
A class for managing rate information for some data channel.
 
  Methods defined here:
__call__(self, time_ns: int = None, value: float = 1.0) -> float
Submit new data to the rate tracker. If this function is called with
default arguments, the returned value will reflect the rate that this
method is being called in hertz.
__init__(self, **kwargs) -> None
Initialize this rate tracker.
measure(self, value: float = 1.0, timer: vcorelib.math.time.Timer = <vcorelib.math.time.Timer object at 0x7f7f560cd850>) -> Iterator[NoneType]
Track the time that the caller's context takes.
poll(self, time_ns: int = None) -> float
Siphon accumulated time and update rate tracking.
reset(self) -> None
Reset this rate tracker.
with_dt(self, delta_s: float, value: float = 1.0) -> None
Update this rate by directly providing the delta-time value.

Readonly properties defined here:
value
An accessor for the underlying value.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class Timer(builtins.object)
    Timer() -&gt; None
 
A class for measuring and logging how long events take.
 
  Methods defined here:
__init__(self) -> None
Initialize this timer.
log(self, log: Union[logging.Logger, logging.LoggerAdapter[Any]], message: str, *args, level: int = 20, reminder: bool = False, **kwargs) -> Iterator[NoneType]
Log how long the caller's context took to execute.
measure_ns(self) -> Iterator[int]
Compute the time that the caller's context takes, provides an integer
token that can be used to query for the result afterwards.
result(self, token: int) -> int
Get the timer result.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
class UnitSystem(builtins.tuple)
    UnitSystem(prefixes: Sequence[str], divisor: int)
 
A pairing of prefixes defining a unit, and the amount that indicates the
multiplicative step-size between them.
 
 
Method resolution order:
UnitSystem
builtins.tuple
builtins.object

Methods defined here:
__getnewargs__(self)
Return self as a plain tuple.  Used by copy and pickle.
__repr__(self)
Return a nicely formatted representation string
_asdict(self)
Return a new dict which maps field names to their values.
_replace(self, /, **kwds)
Return a new UnitSystem object replacing specified fields with new values

Class methods defined here:
_make(iterable) from builtins.type
Make a new UnitSystem object from a sequence or iterable

Static methods defined here:
__new__(_cls, prefixes: Sequence[str], divisor: int)
Create new instance of UnitSystem(prefixes, divisor)

Data descriptors defined here:
prefixes
Alias for field number 0
divisor
Alias for field number 1

Data and other attributes defined here:
__annotations__ = {'divisor': <class 'int'>, 'prefixes': typing.Sequence[str]}
__match_args__ = ('prefixes', 'divisor')
__orig_bases__ = (<function NamedTuple>,)
_field_defaults = {}
_fields = ('prefixes', 'divisor')

Methods inherited from builtins.tuple:
__add__(self, value, /)
Return self+value.
__contains__(self, key, /)
Return bool(key in self).
__eq__(self, value, /)
Return self==value.
__ge__(self, value, /)
Return self>=value.
__getattribute__(self, name, /)
Return getattr(self, name).
__getitem__(self, key, /)
Return self[key].
__gt__(self, value, /)
Return self>value.
__hash__(self, /)
Return hash(self).
__iter__(self, /)
Implement iter(self).
__le__(self, value, /)
Return self<=value.
__len__(self, /)
Return len(self).
__lt__(self, value, /)
Return self<value.
__mul__(self, value, /)
Return self*value.
__ne__(self, value, /)
Return self!=value.
__rmul__(self, value, /)
Return value*self.
count(self, value, /)
Return number of occurrences of value.
index(self, value, start=0, stop=9223372036854775807, /)
Return first index of value.
 
Raises ValueError if the value is not present.

Class methods inherited from builtins.tuple:
__class_getitem__(...) from builtins.type
See PEP 585

 
class WeightedAverage(builtins.object)
    WeightedAverage(depth: int = 10) -&gt; None
 
A class implementing a weighted average.
 
  Methods defined here:
__call__(self, value: float, weight: float = 1.0) -> None
Update tracking, doesn't compute weighted average.
__init__(self, depth: int = 10) -> None
Initialize this weighted average.
average(self) -> float
Compute the overall weighted average.
reset(self) -> None
Reset the average.

Readonly properties defined here:
depth
This average's depth.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Functions
       
byte_count_str(byte_count: int) -> str
Get a string representing a number of bytes.
default_time_ns() -> int
Get a timestamp value using a default method.
from_nanos(nanos: int) -> float
Convert a number in nano counts to a regular floating-point number.
nano_str(nanos: int, is_time: bool = False, max_prefix: int = 3, unit: vcorelib.math.unit.UnitSystem = UnitSystem(prefixes=['n', 'u', 'm', '', 'k', 'M', 'G', 'T'], divisor=1000), prefix_space: bool = False, iteration: int = 0) -> str
Convert an arbitrary value in a 10^-9 domain into as concise of a string
as possible.
rate_str(period_s: float) -> str
Get a string representing a rate in Hz.
seconds_str(seconds: int) -> Tuple[str, int]
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.
to_nanos(value: float) -> int
Convert a number to the same number but in nano counts.
unit_traverse(val: int, unit: vcorelib.math.unit.UnitSystem = UnitSystem(prefixes=['n', 'u', 'm', '', 'k', 'M', 'G', 'T'], divisor=1000), max_prefix: int = 3, iteration: int = 0) -> Tuple[int, int, str]
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.

 
Data
        BILLION = 1000000000
DEFAULT_DEPTH = 10
KIBI_UNITS = UnitSystem(prefixes=['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'], divisor=1024)
LoggerType = typing.Union[logging.Logger, logging.LoggerAdapter[typing.Any]]
MILLION = 1000000
SI_UNITS = UnitSystem(prefixes=['n', 'u', 'm', '', 'k', 'M', 'G', 'T'], divisor=1000)
TIMER = <vcorelib.math.time.Timer object>
__all__ = ['MILLION', 'BILLION', 'from_nanos', 'to_nanos', 'UnitSystem', 'SI_UNITS', 'KIBI_UNITS', 'unit_traverse', 'byte_count_str', 'default_time_ns', 'nano_str', 'seconds_str', 'rate_str', 'LoggerType', 'Timer', 'TIMER', 'DEFAULT_DEPTH', 'MovingAverage', 'RateLimiter', 'RateTracker', ...]