cutcutcodec.utils

Pythonic tools.

Classes

MetaSingleton

For share memory inside the current session.

Functions

get_compilation_rules()

Return the extra compilation rules.

get_project_root()

Return the absolute project root folder.

mround(number[, nbits])

Round the mentissa of a floating number.

Details

class cutcutcodec.utils.MetaSingleton[source]

For share memory inside the current session.

Notes

The arguments needs to be hashable.

Examples

>>> from cutcutcodec.utils import MetaSingleton
>>> class A:
...     pass
...
>>> class B(metaclass=MetaSingleton):
...     pass
...
>>> class C(metaclass=MetaSingleton):
...     def __init__(self, *args, **kwargs):
...         self.args = args
...         self.kwargs = kwargs
...
>>> A() is A()
False
>>> B() is B()
True
>>> C(0) is C(0)
True
>>> C(0) is C(1)
False
>>>
cutcutcodec.utils.get_compilation_rules() dict[source]

Return the extra compilation rules.

cutcutcodec.utils.get_project_root() Path[source]

Return the absolute project root folder.

Examples

>>> from cutcutcodec.utils import get_project_root
>>> root = get_project_root()
>>> root.is_dir()
True
>>> root.name
'cutcutcodec'
>>> sorted(p.name for p in root.iterdir())  
['__init__.py', '__main__.py', ...]
>>>
cutcutcodec.utils.mround(number: Real, nbits: int = 8) float[source]

Round the mentissa of a floating number.

Parameters

number: float

The number to be rounded.

nbits: int, default=4

The number of bit to keep in the mantissa.

Returns

float

The rounded number.

Examples

>>> from cutcutcodec.utils import mround
>>> mround(1/3)
0.34375
>>>