Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def qless(self):
return np.asarray([1, 2, 3, 4], dtype=np.uint8) * self.ureg.dimensionless
def q1(self):
return np.asarray([1, 2, 3, 4], dtype=np.uint8) * self.ureg.J
def qm(self):
return np.asarray([1, 2, 3, 4], dtype=np.uint8) * self.ureg.m
def test_issue74(self):
ureg = UnitRegistry()
v1 = np.asarray([1., 2., 3.])
v2 = np.asarray([3., 2., 1.])
q1 = v1 * ureg.ms
q2 = v2 * ureg.ms
np.testing.assert_array_equal(q1 < q2, v1 < v2)
np.testing.assert_array_equal(q1 > q2, v1 > v2)
np.testing.assert_array_equal(q1 <= q2, v1 <= v2)
np.testing.assert_array_equal(q1 >= q2, v1 >= v2)
q2s = np.asarray([0.003, 0.002, 0.001]) * ureg.s
v2s = q2s.to('ms').magnitude
np.testing.assert_array_equal(q1 < q2s, v1 < v2s)
np.testing.assert_array_equal(q1 > q2s, v1 > v2s)
def qm(self):
return np.asarray([1., 2., 3., 4.]) * self.ureg.m
def qm(self):
return np.asarray([1., 2., 3., 4.]) * self.ureg.m
def test_issue75(self):
ureg = UnitRegistry()
v1 = np.asarray([1., 2., 3.])
v2 = np.asarray([3., 2., 1.])
q1 = v1 * ureg.ms
q2 = v2 * ureg.ms
np.testing.assert_array_equal(q1 == q2, v1 == v2)
np.testing.assert_array_equal(q1 != q2, v1 != v2)
q2s = np.asarray([0.003, 0.002, 0.001]) * ureg.s
v2s = q2s.to('ms').magnitude
np.testing.assert_array_equal(q1 == q2s, v1 == v2s)
np.testing.assert_array_equal(q1 != q2s, v1 != v2s)
def test_issue74(self):
ureg = UnitRegistry()
v1 = np.asarray([1., 2., 3.])
v2 = np.asarray([3., 2., 1.])
q1 = v1 * ureg.ms
q2 = v2 * ureg.ms
np.testing.assert_array_equal(q1 < q2, v1 < v2)
np.testing.assert_array_equal(q1 > q2, v1 > v2)
np.testing.assert_array_equal(q1 <= q2, v1 <= v2)
np.testing.assert_array_equal(q1 >= q2, v1 >= v2)
q2s = np.asarray([0.003, 0.002, 0.001]) * ureg.s
v2s = q2s.to('ms').magnitude
np.testing.assert_array_equal(q1 < q2s, v1 < v2s)
np.testing.assert_array_equal(q1 > q2s, v1 > v2s)
np.testing.assert_array_equal(q1 <= q2s, v1 <= v2s)
np.testing.assert_array_equal(q1 >= q2s, v1 >= v2s)
def test_power(self):
"""This is not supported as different elements might end up with different units
eg. ([1, 1] * m) ** [2, 3]
Must force exponent to single value
"""
self._test2(np.power, self.q1,
(self.qless, np.asarray([1., 2, 3, 4])),
(self.q2, ),)
def test_issue74(self):
v1 = np.asarray([1.0, 2.0, 3.0])
v2 = np.asarray([3.0, 2.0, 1.0])
q1 = v1 * ureg.ms
q2 = v2 * ureg.ms
np.testing.assert_array_equal(q1 < q2, v1 < v2)
np.testing.assert_array_equal(q1 > q2, v1 > v2)
np.testing.assert_array_equal(q1 <= q2, v1 <= v2)
np.testing.assert_array_equal(q1 >= q2, v1 >= v2)
q2s = np.asarray([0.003, 0.002, 0.001]) * ureg.s
v2s = q2s.to("ms").magnitude
np.testing.assert_array_equal(q1 < q2s, v1 < v2s)
np.testing.assert_array_equal(q1 > q2s, v1 > v2s)
np.testing.assert_array_equal(q1 <= q2s, v1 <= v2s)
np.testing.assert_array_equal(q1 >= q2s, v1 >= v2s)