<commit_before>
import sympy

from matrix_normal_forms import normal_hnf_col, hnf_col, is_hnf_col, smf
from ode_system import ODESystem
from tex_tools import matrix_to_tex

def _int_inv(matrix_):
    ''' Given an integer matrix, return the inverse, ensuring we do it right in the integers

    >>> matrix_ = sympy.Matrix([[5, 2, -2],
    ...                         [-7, -3, 3],
    ...                         [17, 8, -7]])
    >>> _int_inv(matrix_)
    Matrix([
    [ 3, 2, 0],
    [-2, 1, 1],
    [ 5, 6, 1]])
    '''
    if abs(matrix_.det()) != 1:
        raise ValueError('Nonunimodular matrix with det {} cannot be inverted over the integers.'.format(matrix_.det()))
    sympy_inverse = sympy.Matrix(matrix_).inv()
    return sympy_inverse

class ODETranslation(object):
    '''
    An object used for translating between systems of ODEs according to a scaling matrix.
    The key data are :attr:`~scaling_matrix` and :attr:`~herm_mult`, which together contain all the information needed
    (along with a variable order) to reduce an :class:`ode_system.ODESystem`.

    Args:
        scaling_matrix (sympy.Matrix): Matrix that defines the torus action on the system.
        variables_domain (iter of sympy.Symbol, optional): An ordering of the variables we expect to act upon.
            If this is not given, we will act on a system according to the position of the variables in
            :attr:`ode_system.ODESystem.variables`, as long as there is the correct number of variables.
        hermite_multiplier (sympy.Matrix, optional): User-defined Hermite multiplier, that puts :attr:`~scaling_matrix` into
            column Hermite normal form.
            If not given, the normal Hermite multiplier will be calculated.
    '''
    def __init__(self, scaling_matrix, variables_domain=None, hermite_multiplier=None):
        scaling_matrix = scaling_matrix.copy()

        self._scaling_matrix = scaling_matrix
        self._variables_domain = variables_domain
        if (variables_domain is not None) and (self.n != len(self.variables_domain)):
            raise ValueError('{} variables given but we have {} actions'.format(len(self.variables_domain), self.n))

        self._scaling_matrix_hnf, self._herm_mult = normal_hnf_col(scaling_matrix)<commit_msg>Fix links to methods in docstrings<commit_after>
import sympy

from matrix_normal_forms import normal_hnf_col, hnf_col, is_hnf_col, smf
from ode_system import ODESystem
from tex_tools import matrix_to_tex

def _int_inv(matrix_):
    ''' Given an integer matrix, return the inverse, ensuring we do it right in the integers

    >>> matrix_ = sympy.Matrix([[5, 2, -2],
    ...                         [-7, -3, 3],
    ...                         [17, 8, -7]])
    >>> _int_inv(matrix_)
    Matrix([
    [ 3, 2, 0],
    [-2, 1, 1],
    [ 5, 6, 1]])
    '''
    if abs(matrix_.det()) != 1:
        raise ValueError('Nonunimodular matrix with det {} cannot be inverted over the integers.'.format(matrix_.det()))
    sympy_inverse = sympy.Matrix(matrix_).inv()
    return sympy_inverse

class ODETranslation(object):
    '''
    An object used for translating between systems of ODEs according to a scaling matrix.
    The key data are :attr:`~desr.ode_translation.ODETranslation.scaling_matrix` and
    :attr:`~desr.ode_translation.ODETranslation.herm_mult`, which together contain all the information needed
    (along with a variable order) to reduce an :class:`~desr.ode_system.ODESystem`.

    Args:
        scaling_matrix (sympy.Matrix): Matrix that defines the torus action on the system.
        variables_domain (iter of sympy.Symbol, optional): An ordering of the variables we expect to act upon.
            If this is not given, we will act on a system according to the position of the variables in
            :attr:`~desr.ode_system.ODESystem.variables`, as long as there is the correct number of variables.
        hermite_multiplier (sympy.Matrix, optional): User-defined Hermite multiplier, that puts
            :attr:`~desr.ode_translation.ODETranslation.scaling_matrix` into
            column Hermite normal form.
            If not given, the normal Hermite multiplier will be calculated.
    '''
    def __init__(self, scaling_matrix, variables_domain=None, hermite_multiplier=None):
        scaling_matrix = scaling_matrix.copy()

        self._scaling_matrix = scaling_matrix
        self._variables_domain = variables_domain
        if (variables_domain is not None) and (self.n != len(self.variables_domain)):
            raise ValueError('{} variables given but we have {} actions'.format(len(self.variables_domain), self.n))

        self._scaling_matrix_hnf, self._herm_mult = normal_hnf_col(scaling_matrix)
{'fraction_non_alphanumeric': 0.09458023379383634, 'fraction_numerical': 0.008501594048884165, 'mean_word_length': 3.131694468832309, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1514887', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1329, 'n_words': 456}