Utilities: msmbuilder.utils¶
- msmbuilder.utils.check_assignment_array_input(assignments, check_ndarray=True, check_integer=True, ndim=2)[source]¶
Check if input is an appropriate data type for assignments.
Parameters: assignments : ndarray
Assignment data whose format will be checked.
check_ndarray : bool, optional
Default True; set False to skip checking for ndarray type
check_integer : bool, optional
Default True; set False to skip checking for integer dtype
ndim : int, optional
Default is 2, which is the correct value for an assignment array.
Notes
Checks if type is Numpy array, if dtype is int-like, and if ndim is ndim (2 by default).
- msmbuilder.utils.deprecated(replacement=None, removal_version=None)[source]¶
A decorator which can be used to mark functions as deprecated. replacement is a callable that will be called with the same args as the decorated function.
Code adapted from http://code.activestate.com/recipes/577819-deprecated-decorator/, MIT license
>>> @deprecated() ... def foo(x): ... return x ... >>> ret = foo(1) DeprecationWarning: foo is deprecated >>> ret 1 >>> >>> >>> def newfun(x): ... return 0 ... >>> @deprecated(newfun) ... def foo(x): ... return x ... >>> ret = foo(1) DeprecationWarning: foo is deprecated; use newfun instead >>> ret 0 >>>
- msmbuilder.utils.format_block(block)[source]¶
Format the given block of text, trimming leading/trailing empty lines and any leading whitespace that is common to all lines. The purpose is to let us list a code block as a multiline, triple-quoted Python string, taking care of indentation concerns.
- msmbuilder.utils.future_warning(func)[source]¶
This is a decorator which can be used to mark functions as to-be deprecated. It will result in a warning being emitted when the function is used.
- msmbuilder.utils.highlight(text, color='Red', bold=False)[source]¶
Return a highlighted string using color or bold.
@param[in] text The string that the printout is based upon. This function will return the highlighted string.
@param[in] color String or number corresponding to the color. 1 red
2 green
3 yellow
4 blue
5 magenta
6 cyan
7 white
@param[in] bold Whether to use bold print
- msmbuilder.utils.keynat(string)[source]¶
A natural sort helper function for sort() and sorted() without using regular expression.
>>> items = ('Z', 'a', '10', '1', '9') >>> sorted(items) ['1', '10', '9', 'Z', 'a'] >>> sorted(items, key=keynat) ['1', '9', '10', 'Z', 'a']
- msmbuilder.utils.lru_cache(maxsize=100)[source]¶
Least-recently-used cache decorator.
Arguments to the cached function must be hashable. Cache performance statistics stored in f.hits and f.misses. Clear the cache with f.clear(). http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used