hexrd.utils.decorators module

Decorators that don’t go anywhere else.

This module contains decorators that don’t really go with another module in hexrd.utils. Before putting something here please see if it should go into another topical module in hexrd.utils.

hexrd.utils.decorators.limit_numba_threads(max_threads)[source]
hexrd.utils.decorators.memoize(func=None, maxsize=2)[source]

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).

This uses an LRU cache, where, before the maxsize is exceeded, the least recently used item will be removed.

Numpy array arguments will be hashed for use in the cache.

We are not using functools.lru_cache() only because it requires hashed arguments. Here, we can create hashes for the arguments on our own, and still pass the unhashed arguments to the function.

hexrd.utils.decorators.numba_njit_if_available(func=None, *args, **kwargs)[source]
hexrd.utils.decorators.undoc(func)[source]

Mark a function or class as undocumented. This is found by inspecting the AST, so for now it must be used directly as @undoc, not as e.g. @decorators.undoc