means.util package¶
Submodules¶
-
class
means.util.memoisation.
MemoisableObject
[source]¶ Bases:
object
A wrapper around objects that support
memoised_property
decorator. It overrides the __getstate__ method to prevent pickling cached values.
MEANS Helpers¶
This part of the package provides a function to generate all mixed and “pure” raw and :class:`~means.core.descriptor.Moment`s up to a maximal_order.
-
means.util.moment_counters.
generate_n_and_k_counters
(max_order, species, central_symbols_prefix='M_', raw_symbols_prefix='x_')[source]¶ Makes a counter for central moments (n_counter) and a counter for raw moment (k_counter). Each is a list of
Moments
is represented by both a vector of integer and a symbol.Parameters: - max_order – the maximal order of moment to be computer (will generate a list of moments up to max_order + 1)
- species – the name of the species
Returns: a pair of lists of :class:`~means.core.descriptors.Moment`s corresponding to central,
and raw moments, respectively. :rtype: (list[
Moment
],list[Moment
])
Sympy Helpers¶
This part of the package provides functions to extend the functionality of sympy, or to make MEANS compatible with different versions of sympy.
-
means.util.sympyhelpers.
assert_sympy_expressions_equal
(expr1, expr2)[source]¶ Raises AssertionError if expr1 is not equal to expr2.
Parameters: - expr1 – first expression
- expr2 – second expression
Returns: None
-
means.util.sympyhelpers.
quick_solve
(expr, var)[source]¶ A function that tries to solve a very simple equation in the quickest way. For instance, an expression like :math: 2*a + 3*b + c == 0 needed to be solved for :math: c may be simply solved by stating :math: c = -(2*a + 3*b). The function checks if the right hand side does not contain :math: c. If it does, then, the classic sympy.solve() method is used. sympy.solve() uses simplify in the background (i.e. is slow), it is therefore preferable to avoid using it.
Parameters: - expr – an expression like implicitly equal to 0
- var – a variable to solve for
Returns: the solution for var
-
means.util.sympyhelpers.
substitute_all
(sp_object, pairs)[source]¶ Performs multiple substitutions in an expression :param expr: a sympy matrix or expression :param pairs: a list of pairs (a,b) where each a_i is to be substituted with b_i :return: the substituted expression
-
means.util.sympyhelpers.
sympy_empirical_equal
(expr1, expr2)[source]¶ Compare long , complex, expressions by replacing all symbols by a set of arbitrary expressions
Parameters: - expr1 – first expression
- expr2 – second expression
Returns: True if expressions are empirically equal, false otherwise
-
means.util.sympyhelpers.
sympy_expressions_equal
(expr1, expr2)[source]¶ Compare two sympy expressions that are not necessarily expanded. :param expr1: a first expression :param expr2: a second expression :return: True if the expressions are similar, False otherwise
Module contents¶
Utilities¶
This package contains helper functions that did not fit into any other packages.
These functions include helper functions for common operations when dealing with sympy
,
as well as functions that help with memoisation of CPU intensive function results.
These functions are designed to be package-specific. The users of the software are generally discouraged to use any of these functions.