Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __div__(self, other):
assert_isinstance(other, Dimensionality)
return self.__truediv__(other)
def __pow__(self, other):
try:
assert np.isscalar(other)
except AssertionError:
raise TypeError('exponent must be a scalar, got %r' % other)
if other == 0:
return Dimensionality()
new = Dimensionality(self)
for i in new:
new[i] *= other
return new
def __truediv__(self, other):
assert_isinstance(other, Dimensionality)
new = Dimensionality(self)
for unit, power in other.items():
try:
new[unit] -= power
if new[unit] == 0:
new.pop(unit)
except KeyError:
new[unit] = -power
return new
def __itruediv__(self, other):
assert_isinstance(other, Dimensionality)
for unit, power in other.items():
try:
self[unit] -= power
if self[unit] == 0:
self.pop(unit)
except KeyError:
self[unit] = -power
return self
def copy(self):
return Dimensionality(self)
def _d_trig(q1, out=None):
try:
assert q1.units == unit_registry['radian']
except AssertionError:
raise ValueError(
'expected units of radians, got "%s"' % q1._dimensionality
)
return Dimensionality()
p_dict[np.sin] = _d_trig
def __pow__(self, other):
try:
assert np.isscalar(other)
except AssertionError:
raise TypeError('exponent must be a scalar, got %r' % other)
if other == 0:
return Dimensionality()
new = Dimensionality(self)
for i in new:
new[i] *= other
return new
def __array_finalize__(self, obj):
self._dimensionality = getattr(obj, 'dimensionality', Dimensionality())
def dimensionless(value):
"""Test for dimensionlessness of input."""
if type(value) is Quantity:
if value.dimensionality == Dimensionality({}):
value = value.base.item()
else:
raise TypeError("Score value %s must be dimensionless" % value)
return value