fail_for_dimension_mismatch function

(Shortest import: from brian2.units.fundamentalunits import fail_for_dimension_mismatch)

brian2.units.fundamentalunits.fail_for_dimension_mismatch(obj1, obj2=None, error_message=None, **error_quantities)[source]

Compare the dimensions of two objects.


obj1, obj2 : {array-like, Quantity}

The object to compare. If obj2 is None, assume it to be dimensionless

error_message : str, optional

An error message that is used in the DimensionMismatchError

error_quantities : dict mapping str to Quantity, optional

Quantities in this dictionary will be converted using the _short_str helper method and inserted into the error_message (which should have placeholders with the corresponding names). The reason for doing this in a somewhat complicated way instead of directly including all the details in error_messsage is that converting large quantity arrays to strings can be rather costly and we don’t want to do it if no error occured.


dim1, dim2 : Dimension, Dimension

The physical dimensions of the two arguments (so that later code does not need to get the dimensions again).


If the dimensions of obj1 and obj2 do not match (or, if obj2 is None, in case obj1 is not dimensionsless).


Implements special checking for 0, treating it as having “any dimensions”.