utils
Modules:
| Name | Description |
|---|---|
classUtils |
|
decorators |
|
string |
|
Modules
classUtils
Functions:
| Name | Description |
|---|---|
singleton |
This decorator can be used to create a singleton out of a class. |
cached_class |
Decorator to cache class instances by constructor arguments. |
Functions
singleton(cls)
This decorator can be used to create a singleton out of a class.
Usage::
@singleton
class MySingleton:
def __init__():
'''Init function.'''
pass
cached_class(klass)
Decorator to cache class instances by constructor arguments.
This results in a class that behaves like a singleton for each
set of constructor arguments, ensuring efficiency.
Note that this should be used for *immutable classes only*.
Having a cached mutable class makes very little sense. For
efficiency, avoid using this decorator for situations where
there are many constructor arguments permutations.
The keywords argument dictionary is converted to a tuple because
dicts are mutable; keywords themselves are strings and so are
always hashable, but if any arguments (keyword or positional)
are non- hashable, that set of arguments is not cached.
decorators
Classes:
| Name | Description |
|---|---|
memoized |
Decorator. |
Functions:
| Name | Description |
|---|---|
counted |
Count how many times a function has been called. |
time_it |
Times a function and reports the time either to the class' log or |
deprecated |
This is a decorator which can be used to mark functions as |
Classes
memoized(func)
Decorator.
Caches a function's return value each time it is called. If called later with the same arguments, the cached value is returned (not reevaluated).
Methods:
| Name | Description |
|---|---|
__get__ |
Support instance methods. |
Functions
__get__(obj, objtype)
Support instance methods.
Functions
counted(func)
Count how many times a function has been called.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
Function to be counted. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., Any]
|
Wrapped function with a |
time_it(func)
Times a function and reports the time either to the class' log or the base logger :param func: function to be timed :return: callable function with timer.
deprecated(func)
This is a decorator which can be used to mark functions as deprecated.
It will result in a warning being emitted when the function is used.
Modules
string
Functions:
| Name | Description |
|---|---|
transformation_to_string |
Convenience method. |
Functions
transformation_to_string(matrix, translation_vec=(0, 0, 0), components=('x', 'y', 'z'), c='', delim=',')
Convenience method.
Given matrix returns string, e.g. x+2y+1/4
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
Any
|
Transformation matrix. |
required |
translation_vec
|
tuple[Any, Any, Any]
|
By default, (0, 0, 0). |
(0, 0, 0)
|
components
|
tuple[str, str, str]
|
Either ('x', 'y', 'z') or ('a', 'b', 'c'). By default, ('x', 'y', 'z'). |
('x', 'y', 'z')
|
c
|
str
|
Optional additional character to print (used for magmoms). By default, ''. |
''
|
delim
|
str
|
Delimiter. By default, ','. |
','
|
Returns:
| Type | Description |
|---|---|
str
|
Xyz string. |