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
obj2
isNone
, 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_str
helper 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_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.- Returns:
dim1, dim2 :
Dimension
,Dimension
The physical dimensions of the two arguments (so that later code does not need to get the dimensions again).
Raises
DimensionMismatchError
If the dimensions of
obj1
andobj2
do not match (or, ifobj2
isNone
, in caseobj1
is not dimensionsless).
Notes
Implements special checking for
0
, treating it as having “any dimensions”.