e48fb30ea6f7eb0c3092ca3b55bdc75176be272a,brian2/stateupdaters/exact.py,,get_linear_system,#Any#,20

Before Change


    
    symbols = [Symbol(name, real=True) for name in diff_eq_names]
    // Coefficients
    wildcards = [Wild("c_" + name, exclude=symbols) for name in diff_eq_names]
    
    //Additive constant
    constant_wildcard = Wild("c", exclude=symbols)
    
    pattern = reduce(operator.add, [c * s for c, s in zip(wildcards, symbols)])
    pattern += constant_wildcard
    
    coefficients = sp.zeros(len(diff_eq_names))
    constants = sp.zeros((len(diff_eq_names), 1))
    
    for row_idx, (name, expr) in enumerate(diff_eqs):
        s_expr = expr.sympy_expr.expand()
        pattern_matches = s_expr.match(pattern)
        if pattern_matches is None:
            raise ValueError(("The expression "%s", defining the variable %s, "
                             "could not be separated into linear components") %
                             (expr, name))

After Change


        s_expr = expr.sympy_expr.expand()

        current_s_expr = s_expr
        for col_idx, (name, symbol) in enumerate(zip(eqs.diff_eq_names, symbols)):
            current_s_expr = current_s_expr.collect(symbol)
            constant_wildcard = Wild("c", exclude=[symbol])
            factor_wildcard = Wild("c_"+name, exclude=symbols)
            one_pattern = factor_wildcard*symbol + constant_wildcard
            matches = current_s_expr.match(one_pattern)
            if matches is None:
                raise ValueError(("The expression "%s", defining the variable %s, "
                                 "could not be separated into linear components") %
                                 (expr, name))

            coefficients[row_idx, col_idx] = matches[factor_wildcard]
            current_s_expr = matches[constant_wildcard]

        // The remaining constant should be a true constant
        constants[row_idx] = current_s_expr

    return (diff_eq_names, coefficients, constants)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 10

Instances


Project Name: brian-team/brian2
Commit Name: e48fb30ea6f7eb0c3092ca3b55bdc75176be272a
Time: 2013-10-11
Author: marcel.stimberg@ens.fr
File Name: brian2/stateupdaters/exact.py
Class Name:
Method Name: get_linear_system


Project Name: OpenMined/Grid
Commit Name: d51dd50f93232f5542df1a8ccb2d91cee17c52d8
Time: 2020-07-08
Author: hericles.me@gmail.com
File Name: grid/app/main/sfl/cycles/cycle_manager.py
Class Name: CycleManager
Method Name: _average_plan_diffs


Project Name: dmlc/gluon-nlp
Commit Name: f19ace982075ea009af81f5e9f687cc2276f50ea
Time: 2020-01-20
Author: 50716238+MoisesHer@users.noreply.github.com
File Name: scripts/bert/fp16_utils.py
Class Name:
Method Name: grad_global_norm