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.
- Parameters
obj1, obj2 : {array-like,
Quantity}The object to compare. If
obj2isNone, assume it to be dimensionlesserror_message : str, optional
An error message that is used in the DimensionMismatchError
error_quantities : dict mapping str to
Quantity, optionalQuantities in this dictionary will be converted using the
_short_strhelper method and inserted into theerror_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 inerror_messsageis that converting large quantity arrays to strings can be rather costly and we don’t want to do it if no error occured.- Returns
dim1, dim2 :
Dimension,DimensionThe physical dimensions of the two arguments (so that later code does not need to get the dimensions again).
Raises
DimensionMismatchErrorIf the dimensions of
obj1andobj2do not match (or, ifobj2isNone, in caseobj1is not dimensionsless).
Notes
Implements special checking for
0, treating it as having “any dimensions”.