def test_equal(self): x = self.q.magnitude u = self.Q_(np.ones(x.shape)) self.assertSequenceEqual(u, u) self.assertSequenceEqual(u == u, u.magnitude == u.magnitude) self.assertSequenceEqual(u == 1, u.magnitude == 1)
def test_reversible_op(self): """ """ x = self.q.magnitude u = self.Q_(np.ones(x.shape)) self.assertSequenceEqual(x / self.q, u * x / self.q) self.assertSequenceEqual(x * self.q, u * x * self.q) self.assertSequenceEqual(x + u, u + x) self.assertSequenceEqual(x - u, -(u - x))
def test_reversible_op(self): """This fails because x / self.q returns an array, not Quantity. Division is handled by the ndarray code. """ x = self.q.magnitude u = self.Q_(np.ones(x.shape)) self.assertSequenceEqual(x / self.q, u * x / self.q) self.assertSequenceEqual(x * self.q, u * x * self.q) self.assertSequenceEqual(x + u, u + x) self.assertSequenceEqual(x - u, -(u - x))
def test_issue39(self): x = np.matrix([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) ureg = UnitRegistry() q = ureg.meter * x self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) q = x * ureg.meter self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) m = np.matrix(2 * np.ones(3, 3)) qq = q * m self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units) qq = m * q self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units)
def test_issue37(self): x = np.ma.masked_array([1, 2, 3], mask=[True, True, False]) ureg = UnitRegistry() q = ureg.meter * x self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) q = x * ureg.meter self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) m = np.ma.masked_array(2 * np.ones(3, 3)) qq = q * m self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units) qq = m * q self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units)
def test_issue39(self): x = np.matrix([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) ureg = UnitRegistry() q = ureg.meter * x self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) q = x * ureg.meter self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) m = np.matrix(2 * np.ones(3,3)) qq = q * m self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units) qq = m * q self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units)
def test_issue37(self): x = np.ma.masked_array([1, 2, 3], mask=[True, True, False]) ureg = UnitRegistry() q = ureg.meter * x self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) q = x * ureg.meter self.assertIsInstance(q, ureg.Quantity) self.assertSequenceEqual(q.magnitude, x) self.assertEquals(q.units, ureg.meter.units) m = np.ma.masked_array(2 * np.ones(3,3)) qq = q * m self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units) qq = m * q self.assertIsInstance(qq, ureg.Quantity) self.assertSequenceEqual(qq.magnitude, x * m) self.assertEquals(qq.units, ureg.meter.units)