3.8.5. qupulse.utils.types

Functions

has_type_interface(obj, type_obj)

Return true if all public attributes of the class are attributes of the object

time_from_float(value[, absolute_error])

See TimeType.from_float().

time_from_fraction(numerator, denominator)

See TimeType.from_float().

Classes

DocStringABCMeta(classname, bases, cls_dict)

Metaclass that copies/refers to docstrings of the super class.

HashableNumpyArray

Make numpy arrays hashable.

SequenceProxy(inner)

SingletonABCMeta(classname, bases, cls_dict)

Metaclass that enforces singletons

TimeType([value, denominator])

This type represents a rational number with arbitrary precision.

class DocStringABCMeta(classname, bases, cls_dict)[source]

Bases: ABCMeta

Metaclass that copies/refers to docstrings of the super class.

class HashableNumpyArray[source]

Bases: ndarray

Make numpy arrays hashable.

Deprecated since 0.6. This is a bad idea.

Example usage: my_array = np.zeros([1, 2, 3, 4]) hashable = my_array.view(HashableNumpyArray)

class SequenceProxy(inner: Sequence)[source]

Bases: Sequence

count(value) integer -- return number of occurrences of value[source]
index(value[, start[, stop]]) integer -- return first index of value.[source]

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

class SingletonABCMeta(classname, bases, cls_dict)[source]

Bases: DocStringABCMeta

Metaclass that enforces singletons

class TimeType(value: Rational | int = 0.0, denominator: int | None = None)[source]

Bases: object

This type represents a rational number with arbitrary precision.

Internally it uses gmpy2.mpq() which is considered an implementation detail.

Parameters:
  • value – interpreted as Rational if denominator is None. interpreted as numerator otherwise

  • denominator – Denominator of the Fraction if not None

classmethod as_comparable(other: TimeType | Any)[source]
property denominator
classmethod from_float(value: float, absolute_error: float | None = None) TimeType[source]

Convert a floating point number to a TimeType using one of three modes depending on absolute_error.

The default str(value) guarantees that all floats have a different result with sensible rounding. This was chosen as default because it is the expected behaviour most of the time if the user defined the float from a literal in code.

Parameters:
  • value – Floating point value to convert to arbitrary precision TimeType

  • absolute_error

    • None: Use str(value) as a proxy to get consistent precision

    • 0: Return the exact value of the float i.e. float(0.8) == 3602879701896397 / 4503599627370496

    • 0 < absolute_error <= 1: Return the best approximation to value within (value - absolute_error, value + absolute_error). The best approximation is defined as the fraction with the smallest denominator.

Raises:

ValueError – If absolute_error is not None and not 0 <= absolute_error <= 1

classmethod from_fraction(numerator: int, denominator: int) TimeType[source]

Convert a fraction to a TimeType.

Parameters:
  • numerator – Numerator of the time fraction

  • denominator – Denominator of the time fraction

classmethod from_sympy(num: Expr)[source]
property numerator
time_from_float(value: float, absolute_error: float | None = None) TimeType[source]

See TimeType.from_float().