#19705 Fix handling of addition and multiplication of Dimensions for get_dimensional_dependencies

Merged Michael Greminger mgreminger
Coverage Reach
polys/domains/domain.py polys/domains/gaussiandomains.py polys/domains/pythonrational.py polys/domains/old_polynomialring.py polys/domains/expressiondomain.py polys/domains/modularinteger.py polys/domains/mpelements.py polys/domains/quotientring.py polys/domains/old_fractionfield.py polys/domains/polynomialring.py polys/domains/fractionfield.py polys/domains/algebraicfield.py polys/domains/realfield.py polys/domains/complexfield.py polys/domains/finitefield.py polys/domains/gmpyintegerring.py polys/domains/gmpyrationalfield.py polys/domains/ring.py polys/domains/pythonintegerring.py polys/domains/pythonrationalfield.py polys/domains/field.py polys/domains/__init__.py polys/domains/groundtypes.py polys/domains/integerring.py polys/domains/rationalfield.py polys/domains/compositedomain.py polys/domains/pythonfinitefield.py polys/domains/gmpyfinitefield.py polys/domains/characteristiczero.py polys/domains/simpledomain.py polys/domains/domainelement.py polys/polytools.py polys/rings.py polys/polyclasses.py polys/rootisolation.py polys/subresultants_qq_zz.py polys/compatibility.py polys/ring_series.py polys/agca/modules.py polys/agca/homomorphisms.py polys/agca/ideals.py polys/agca/extensions.py polys/agca/__init__.py polys/modulargcd.py polys/factortools.py polys/galoistools.py polys/euclidtools.py polys/polyroots.py polys/numberfields.py polys/rootoftools.py polys/densearith.py polys/densebasic.py polys/densetools.py polys/fields.py polys/polyoptions.py polys/groebnertools.py polys/polyutils.py polys/monomials.py polys/distributedmodules.py polys/constructor.py polys/sqfreetools.py polys/specialpolys.py polys/partfrac.py polys/orthopolys.py polys/polyfuncs.py polys/multivariate_resultants.py polys/polymatrix.py polys/orderings.py polys/polyerrors.py polys/solvers.py polys/polyquinticconst.py polys/fglmtools.py polys/heuristicgcd.py polys/dispersion.py polys/polyconfig.py polys/rationaltools.py polys/__init__.py integrals/rubi/constraints.py integrals/rubi/utility_function.py integrals/rubi/parsetools/parse.py integrals/rubi/parsetools/generate_tests.py integrals/rubi/parsetools/generate_rules.py integrals/rubi/rubimain.py integrals/rubi/symbol.py integrals/meijerint.py integrals/manualintegrate.py integrals/transforms.py integrals/risch.py integrals/integrals.py integrals/prde.py integrals/intpoly.py integrals/heurisch.py integrals/rde.py integrals/rationaltools.py integrals/quadrature.py integrals/trigonometry.py integrals/deltafunctions.py integrals/meijerint_doc.py integrals/singularityfunctions.py integrals/__init__.py physics/quantum/spin.py physics/quantum/gate.py physics/quantum/cg.py physics/quantum/pauli.py physics/quantum/hilbert.py physics/quantum/qubit.py physics/quantum/state.py physics/quantum/represent.py physics/quantum/sho1d.py physics/quantum/identitysearch.py physics/quantum/operator.py physics/quantum/tensorproduct.py physics/quantum/matrixutils.py physics/quantum/circuitplot.py physics/quantum/circuitutils.py physics/quantum/cartesian.py physics/quantum/qexpr.py physics/quantum/operatorordering.py physics/quantum/qasm.py physics/quantum/commutator.py physics/quantum/boson.py physics/quantum/qft.py physics/quantum/operatorset.py physics/quantum/shor.py physics/quantum/qapply.py physics/quantum/fermion.py physics/quantum/density.py physics/quantum/grover.py physics/quantum/anticommutator.py physics/quantum/innerproduct.py physics/quantum/matrixcache.py physics/quantum/piab.py physics/quantum/constants.py physics/quantum/dagger.py physics/quantum/__init__.py physics/vector/frame.py physics/vector/vector.py physics/vector/functions.py physics/vector/dyadic.py physics/vector/printing.py physics/vector/point.py physics/vector/fieldfunctions.py physics/vector/__init__.py physics/mechanics/kane.py physics/mechanics/linearize.py physics/mechanics/functions.py physics/mechanics/lagrange.py physics/mechanics/system.py physics/mechanics/models.py physics/mechanics/rigidbody.py physics/mechanics/particle.py physics/mechanics/body.py physics/mechanics/__init__.py physics/units/dimensions.py physics/units/systems/si.py physics/units/systems/length_weight_time.py physics/units/systems/cgs.py physics/units/systems/mksa.py physics/units/systems/mks.py physics/units/systems/natural.py physics/units/systems/__init__.py physics/units/definitions/unit_definitions.py physics/units/definitions/dimension_definitions.py physics/units/definitions/__init__.py physics/units/unitsystem.py physics/units/prefixes.py physics/units/quantities.py physics/units/util.py physics/units/__init__.py physics/secondquant.py physics/continuum_mechanics/beam.py physics/continuum_mechanics/__init__.py physics/optics/utils.py physics/optics/gaussopt.py physics/optics/waves.py physics/optics/medium.py physics/optics/polarization.py physics/optics/__init__.py physics/hep/gamma_matrices.py physics/wigner.py physics/paulialgebra.py physics/matrices.py physics/hydrogen.py physics/qho_1d.py physics/pring.py physics/sho.py physics/gaussopt.py physics/__init__.py core/numbers.py core/expr.py core/mul.py core/function.py core/power.py core/evalf.py core/exprtools.py core/add.py core/basic.py core/relational.py core/symbol.py core/operations.py core/facts.py core/logic.py core/compatibility.py core/sympify.py core/containers.py core/mod.py core/assumptions.py core/decorators.py core/trace.py core/cache.py core/multidimensional.py core/core.py core/singleton.py core/__init__.py core/parameters.py core/rules.py core/_print_helpers.py core/backend.py core/coreerrors.py core/alphabets.py printing/pretty/pretty.py printing/pretty/stringpict.py printing/pretty/pretty_symbology.py printing/pretty/__init__.py printing/latex.py printing/mathml.py printing/str.py printing/pycode.py printing/fcode.py printing/ccode.py printing/codeprinter.py printing/octave.py printing/julia.py printing/llvmjitcode.py printing/repr.py printing/glsl.py printing/rust.py printing/tableform.py printing/theanocode.py printing/preview.py printing/rcode.py printing/tensorflow.py printing/mathematica.py printing/maple.py printing/jscode.py printing/lambdarepr.py printing/precedence.py printing/printer.py printing/cxxcode.py printing/dot.py printing/python.py printing/conventions.py printing/tree.py printing/__init__.py printing/gtk.py printing/defaults.py functions/elementary/trigonometric.py functions/elementary/hyperbolic.py functions/elementary/exponential.py functions/elementary/piecewise.py functions/elementary/complexes.py functions/elementary/miscellaneous.py functions/elementary/integers.py functions/special/error_functions.py functions/special/bessel.py functions/special/gamma_functions.py functions/special/hyper.py functions/special/polynomials.py functions/special/elliptic_integrals.py functions/special/zeta_functions.py functions/special/delta_functions.py functions/special/bsplines.py functions/special/tensor_functions.py functions/special/spherical_harmonics.py functions/special/singularity_functions.py functions/special/mathieu_functions.py functions/special/beta_functions.py functions/combinatorial/numbers.py functions/combinatorial/factorials.py functions/__init__.py solvers/ode/ode.py solvers/ode/single.py solvers/ode/systems.py solvers/ode/subscheck.py solvers/ode/__init__.py solvers/solvers.py solvers/diophantine/diophantine.py solvers/diophantine/__init__.py solvers/solveset.py solvers/inequalities.py solvers/recurr.py solvers/pde.py solvers/bivariate.py solvers/polysys.py solvers/deutils.py solvers/decompogen.py solvers/__init__.py parsing/autolev/_antlr/autolevparser.py parsing/autolev/_antlr/autolevlexer.py parsing/autolev/_antlr/autolevlistener.py parsing/autolev/_listener_autolev_antlr.py parsing/autolev/_parse_autolev_antlr.py parsing/autolev/__init__.py parsing/latex/_antlr/latexparser.py parsing/latex/_antlr/latexlexer.py parsing/latex/_parse_latex_antlr.py parsing/latex/_build_latex_antlr.py parsing/latex/__init__.py parsing/latex/errors.py parsing/sympy_parser.py parsing/c/c_parser.py parsing/mathematica.py parsing/fortran/fortran_parser.py parsing/fortran/__init__.py parsing/sym_expr.py parsing/ast_parser.py parsing/maxima.py parsing/__init__.py matrices/expressions/matexpr.py matrices/expressions/blockmatrix.py matrices/expressions/matmul.py matrices/expressions/hadamard.py matrices/expressions/kronecker.py matrices/expressions/permutation.py matrices/expressions/diagonal.py matrices/expressions/applyfunc.py matrices/expressions/matpow.py matrices/expressions/matadd.py matrices/expressions/slice.py matrices/expressions/trace.py matrices/expressions/inverse.py matrices/expressions/transpose.py matrices/expressions/factorizations.py matrices/expressions/funcmatrix.py matrices/expressions/determinant.py matrices/expressions/companion.py matrices/expressions/adjoint.py matrices/expressions/dotproduct.py matrices/expressions/fourier.py matrices/expressions/__init__.py matrices/matrices.py matrices/common.py matrices/sparse.py matrices/eigen.py matrices/dense.py matrices/decompositions.py matrices/solvers.py matrices/determinant.py matrices/inverse.py matrices/sparsetools.py matrices/densesolve.py matrices/reductions.py matrices/immutable.py matrices/normalforms.py matrices/densetools.py matrices/subspaces.py matrices/densearith.py matrices/utilities.py matrices/graph.py matrices/__init__.py combinatorics/perm_groups.py combinatorics/permutations.py combinatorics/fp_groups.py combinatorics/free_groups.py combinatorics/coset_table.py combinatorics/tensor_can.py combinatorics/homomorphisms.py combinatorics/rewritingsystem.py combinatorics/partitions.py combinatorics/pc_groups.py combinatorics/generators.py combinatorics/util.py combinatorics/subsets.py combinatorics/prufer.py combinatorics/testutil.py combinatorics/named_groups.py combinatorics/polyhedron.py combinatorics/graycode.py combinatorics/schur_number.py combinatorics/group_constructs.py combinatorics/rewritingsystem_fsm.py combinatorics/__init__.py simplify/hyperexpand.py simplify/simplify.py simplify/fu.py simplify/trigsimp.py simplify/radsimp.py simplify/sqrtdenest.py simplify/powsimp.py simplify/cse_main.py simplify/gammasimp.py simplify/epathtools.py simplify/ratsimp.py simplify/combsimp.py simplify/cse_opts.py simplify/__init__.py simplify/traversaltools.py simplify/hyperexpand_doc.py stats/crv_types.py stats/stochastic_process_types.py stats/rv.py stats/crv.py stats/frv.py stats/drv.py stats/joint_rv_types.py stats/symbolic_probability.py stats/joint_rv.py stats/drv_types.py stats/frv_types.py stats/symbolic_multivariate_probability.py stats/random_matrix_models.py stats/rv_interface.py stats/error_prop.py stats/stochastic_process.py stats/random_matrix.py stats/__init__.py utilities/codegen.py utilities/iterables.py utilities/_compilation/compilation.py utilities/_compilation/util.py utilities/_compilation/runners.py utilities/_compilation/availability.py utilities/_compilation/__init__.py utilities/autowrap.py utilities/lambdify.py utilities/enumerative.py utilities/misc.py utilities/decorator.py utilities/matchpy_connector.py utilities/timeutils.py utilities/memoization.py utilities/exceptions.py utilities/mathml/__init__.py utilities/source.py utilities/pkgdata.py utilities/magic.py utilities/__init__.py utilities/benchmarking.py utilities/pytest.py utilities/tmpfiles.py utilities/runtests.py utilities/quality_unicode.py utilities/randtest.py tensor/tensor.py tensor/array/ndim_array.py tensor/array/arrayop.py tensor/array/array_comprehension.py tensor/array/sparse_ndim_array.py tensor/array/dense_ndim_array.py tensor/array/mutable_ndim_array.py tensor/array/__init__.py tensor/indexed.py tensor/index_methods.py tensor/toperators.py tensor/functions.py tensor/__init__.py ntheory/factor_.py ntheory/residue_ntheory.py ntheory/generate.py ntheory/primetest.py ntheory/elliptic_curve.py ntheory/ecm.py ntheory/continued_fraction.py ntheory/partitions_.py ntheory/multinomial.py ntheory/modular.py ntheory/egyptian_fraction.py ntheory/bbp_pi.py ntheory/digits.py ntheory/__init__.py geometry/polygon.py geometry/line.py geometry/ellipse.py geometry/point.py geometry/plane.py geometry/util.py geometry/entity.py geometry/parabola.py geometry/curve.py geometry/__init__.py geometry/exceptions.py sets/sets.py sets/handlers/intersection.py sets/handlers/functions.py sets/handlers/issubset.py sets/handlers/union.py sets/handlers/power.py sets/handlers/add.py sets/handlers/mul.py sets/fancysets.py sets/ordinals.py sets/conditionset.py sets/setexpr.py sets/powerset.py sets/contains.py sets/__init__.py series/formal.py series/sequences.py series/gruntz.py series/fourier.py series/order.py series/limits.py series/limitseq.py series/series_class.py series/approximants.py series/residues.py series/acceleration.py series/__init__.py series/kauers.py series/aseries.py series/series.py assumptions/handlers/matrices.py assumptions/handlers/sets.py assumptions/handlers/order.py assumptions/handlers/ntheory.py assumptions/handlers/common.py assumptions/handlers/calculus.py assumptions/handlers/__init__.py assumptions/cnf.py assumptions/ask.py assumptions/refine.py assumptions/sathandlers.py assumptions/satask.py assumptions/assume.py assumptions/ask_generated.py assumptions/__init__.py codegen/array_utils.py codegen/ast.py codegen/fnodes.py codegen/cfunctions.py codegen/approximations.py codegen/rewriting.py codegen/algorithms.py codegen/cnodes.py codegen/futils.py codegen/matrix_nodes.py codegen/pyutils.py codegen/cxxnodes.py codegen/cutils.py codegen/__init__.py plotting/plot.py plotting/intervalmath/lib_interval.py plotting/intervalmath/interval_arithmetic.py plotting/intervalmath/interval_membership.py plotting/intervalmath/__init__.py plotting/experimental_lambdify.py plotting/plot_implicit.py plotting/textplot.py plotting/__init__.py holonomic/holonomic.py holonomic/recurrence.py holonomic/numerical.py holonomic/linearsolver.py holonomic/holonomicerrors.py holonomic/__init__.py logic/boolalg.py logic/algorithms/dpll2.py logic/algorithms/dpll.py logic/algorithms/pycosat_wrapper.py logic/inference.py logic/utilities/dimacs.py logic/utilities/__init__.py logic/__init__.py concrete/summations.py concrete/expr_with_limits.py concrete/products.py concrete/guess.py concrete/delta.py concrete/gosper.py concrete/expr_with_intlimits.py concrete/__init__.py vector/coordsysrect.py vector/vector.py vector/basisdependent.py vector/functions.py vector/operators.py vector/orienters.py vector/dyadic.py vector/integrals.py vector/parametricregion.py vector/point.py vector/scalar.py vector/deloperator.py vector/__init__.py testing/runtests.py testing/benchmarking.py testing/pytest.py testing/randtest.py testing/quality_unicode.py testing/tmpfiles.py testing/matrices.py testing/__init__.py categories/diagram_drawing.py categories/baseclasses.py categories/__init__.py liealgebras/weyl_group.py liealgebras/type_e.py liealgebras/type_d.py liealgebras/type_c.py liealgebras/type_f.py liealgebras/type_b.py liealgebras/type_a.py liealgebras/root_system.py liealgebras/cartan_type.py liealgebras/type_g.py liealgebras/cartan_matrix.py liealgebras/dynkin_diagram.py liealgebras/__init__.py calculus/util.py calculus/finite_diff.py calculus/singularities.py calculus/euler.py calculus/__init__.py crypto/crypto.py crypto/__init__.py diffgeom/diffgeom.py diffgeom/rn.py diffgeom/__init__.py interactive/printing.py interactive/session.py interactive/ipythonprinting.py interactive/__init__.py strategies/branch/core.py strategies/branch/traverse.py strategies/branch/tools.py strategies/branch/__init__.py strategies/core.py strategies/rl.py strategies/traverse.py strategies/tree.py strategies/tools.py strategies/util.py strategies/__init__.py discrete/transforms.py discrete/convolutions.py discrete/recurrences.py discrete/__init__.py multipledispatch/dispatcher.py multipledispatch/utils.py multipledispatch/conflict.py multipledispatch/core.py multipledispatch/__init__.py algebras/quaternion.py algebras/__init__.py unify/core.py unify/usympy.py unify/rewrite.py unify/__init__.py __init__.py external/importtools.py external/__init__.py abc.py sandbox/indexed_integrals.py deprecated/class_registry.py deprecated/__init__.py this.py galgebra.py release.py

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 2 files from the diff.

@@ -411,6 +411,11 @@
Loading
411 411
        return self.args[2]
412 412
413 413
    def _get_dimensional_dependencies_for_name(self, name):
414 +
        if isinstance(name, Dimension):
415 +
            name = name.name
416 +
417 +
        if isinstance(name, str):
418 +
            name = Symbol(name)
414 419
415 420
        if name.is_Symbol:
416 421
            # Dimensions not included in the dependencies are considered
@@ -430,6 +435,12 @@
Loading
430 435
                    ret[k] += v
431 436
            return {k: v for (k, v) in ret.items() if v != 0}
432 437
438 +
        if name.is_Add:
439 +
            dicts = [get_for_name(i) for i in name.args]
440 +
            if all([d == dicts[0] for d in dicts[1:]]):
441 +
                return dicts[0]
442 +
            raise TypeError("Only equivalent dimensions can be added or subtracted.")
443 +
433 444
        if name.is_Pow:
434 445
            dim = get_for_name(name.base)
435 446
            return {k: v*name.exp for (k, v) in dim.items()}
@@ -446,12 +457,9 @@
Loading
446 457
            else:
447 458
                return get_for_name(result)
448 459
449 -
    def get_dimensional_dependencies(self, name, mark_dimensionless=False):
450 -
        if isinstance(name, Dimension):
451 -
            name = name.name
452 -
        if isinstance(name, str):
453 -
            name = Symbol(name)
460 +
        raise TypeError("Type {0} not implemented for get_dimensional_dependencies".format(type(name)))
454 461
462 +
    def get_dimensional_dependencies(self, name, mark_dimensionless=False):
455 463
        dimdep = self._get_dimensional_dependencies_for_name(name)
456 464
        if mark_dimensionless and dimdep == {}:
457 465
            return {'dimensionless': 1}

Learn more Showing 15 files with coverage changes found.

Changes in sympy/polys/densebasic.py
-2
+1
+1
Loading file...
Changes in sympy/core/evalf.py
-3
+1
+2
Loading file...
Changes in sympy/concrete/summations.py
-2
+1
+1
Loading file...
Changes in sympy/core/mul.py
New
Loading file...
Changes in sympy/printing/printer.py
New
Loading file...
Changes in sympy/sets/handlers/union.py
-1
+1
Loading file...
Changes in sympy/combinatorics/perm_groups.py
-1
-2
+3
Loading file...
Changes in sympy/physics/secondquant.py
-5
+4
+1
Loading file...
Changes in sympy/combinatorics/coset_table.py
-1
-1
+2
Loading file...
Changes in sympy/functions/elementary/exponential.py
-2
-2
+4
Loading file...
Changes in sympy/tensor/indexed.py
-1
-1
+2
Loading file...
Changes in sympy/physics/units/dimensions.py
-3
+3
Loading file...
Changes in sympy/ntheory/primetest.py
-1
-2
+3
Loading file...
Changes in sympy/vector/parametricregion.py
+33
+1
Loading file...
Changes in sympy/vector/integrals.py
-5
+11
Loading file...
Files Coverage
sympy 0.017% 75.695%
Project Totals (658 files) 75.695%
Loading