3.9.5. qupulse.utils.types¶
Functions
|
|
|
This is decorator to convert the other argument and the result into a |
|
Return true if all public attributes of the class are attributes of the object |
|
|
|
Classes
|
Metaclass that copies/refers to docstrings of the super class. |
Make numpy arrays hashable. |
|
|
|
|
Metaclass that enforces singletons |
|
This type represents a rational number with arbitrary precision. |
|
This is non mutable, hashable dict. |
|
Immutable dict like type. |
- class qupulse.utils.types.DocStringABCMeta(classname, bases, cls_dict)[source]¶
Bases:
abc.ABCMeta
Metaclass that copies/refers to docstrings of the super class.
- class qupulse.utils.types.HashableNumpyArray[source]¶
Bases:
numpy.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 qupulse.utils.types.SequenceProxy(inner: Sequence)[source]¶
Bases:
collections.abc.Sequence
- class qupulse.utils.types.SingletonABCMeta(classname, bases, cls_dict)[source]¶
Bases:
qupulse.utils.types.DocStringABCMeta
Metaclass that enforces singletons
- class qupulse.utils.types.TimeType(value: Union[numbers.Rational, int] = 0.0, denominator: Optional[int] = None)[source]¶
Bases:
object
This type represents a rational number with arbitrary precision.
Internally it uses
gmpy2.mpq()
(if available) orfractions.Fraction
- Parameters
value – interpreted as Rational if denominator is None. interpreted as numerator otherwise
denominator – Denominator of the Fraction if not None
- __init__(value: Union[numbers.Rational, int] = 0.0, denominator: Optional[int] = None)[source]¶
- 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: Union[qupulse.utils.types.TimeType, Any])[source]¶
- property denominator¶
- classmethod from_float(value: float, absolute_error: Optional[float] = None) qupulse.utils.types.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 precision0: 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) qupulse.utils.types.TimeType [source]¶
Convert a fraction to a TimeType.
- Parameters
numerator – Numerator of the time fraction
denominator – Denominator of the time fraction
- property numerator¶
- class qupulse.utils.types.frozendict¶
Bases:
object
An immutable version of dict.
frozendict.frozendict() -> returns an empty immutable dictionary frozendict.frozendict(mapping) -> returns an immutable dictionary initialized from a mapping object’s
(key, value) pairs
- frozendict.frozendict(iterable) -> returns an immutable dictionary, equivalent to:
- d = {}
for k, v in iterable: d[k] = v frozendict.frozendict(d)
- frozendict.frozendict(**kwargs) -> returns an immutable dictionary initialized with the name=value pairs
in the keyword argument list. For example: frozendict.frozendict(one=1, two=2)
- copy() a shallow copy of D ¶
- delete(key, /)¶
Returns a copy of the dictionary without the item of the corresponding key.
- fromkeys(value=None, /)¶
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)¶
Return the value for key if key is in the dictionary, else default.
- item()¶
Get the (key, value) item at the specified index (insertion order). If index is not passed, it defaults to 0. If index is negative, returns the item at position size + index.
- items() a set-like object providing a view on D's items ¶
- key()¶
Get the key at the specified index (insertion order). If index is not passed, it defaults to 0. If index is negative, returns the key at position size + index.
- keys() a set-like object providing a view on D's keys ¶
- set(key, value, /)¶
Returns a copy of the dictionary with the new (key, value) item.
- setdefault()¶
set($self, key[, default], /) –
If key is in the dictionary, it returns the dictionary unchanged. Otherwise, it returns a copy of the dictionary with the new (key, default) item; default argument is optional and is None by default.
- value()¶
Get the value at the specified index (insertion order). If index is not passed, it defaults to 0. If index is negative, returns the value at position size + index.
- values() an object providing a view on D's values ¶