예제 #1
0
    def test_setitem(self):
        self.assertRaises(ValueError, self.q.__setitem__, (0,0), 1)
        self.assertRaises(ValueError, self.q.__setitem__, (0,0), 1*self.ureg.J)
        self.assertRaises(ValueError, self.q.__setitem__, 0, 1)
        self.assertRaises(ValueError, self.q.__setitem__, 0, np.ndarray([1, 2]))
        self.assertRaises(ValueError, self.q.__setitem__, 0, 1*self.ureg.J)

        q = self.q.copy()
        q[0] = 1*self.ureg.m
        self.assertQuantityEqual(q, [[1,1],[3,4]]*self.ureg.m)

        q = self.q.copy()
        q.__setitem__(Ellipsis, 1*self.ureg.m)
        self.assertQuantityEqual(q, [[1,1],[1,1]]*self.ureg.m)

        q = self.q.copy()
        q[:] = 1*self.ureg.m
        self.assertQuantityEqual(q, [[1,1],[1,1]]*self.ureg.m)

        # check and see that dimensionless num  bers work correctly
        q = [0,1,2,3]*self.ureg.dimensionless
        q[0] = 1
        self.assertQuantityEqual(q, np.asarray([1,1,2,3]))
        q[0] = self.ureg.m/self.ureg.mm
        self.assertQuantityEqual(q, np.asarray([1000, 1,2,3]))

        q = [0.,1.,2.,3.] * self.ureg.m / self.ureg.mm
        q[0] = 1.
        self.assertQuantityEqual(q, [0.001,1,2,3]*self.ureg.m / self.ureg.mm)
예제 #2
0
    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)
예제 #3
0
파일: test_issues.py 프로젝트: itmeson/pint
    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

        self.assertSequenceEqual(q1 == q2, v1 == v2)
        self.assertSequenceEqual(q1 != q2, v1 != v2)

        q2s = np.asarray([0.003, 0.002, 0.001]) * ureg.s
        v2s = q2s.to('ms').magnitude

        self.assertSequenceEqual(q1 == q2s, v1 == v2s)
        self.assertSequenceEqual(q1 != q2s, v1 != v2s)
예제 #4
0
    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, ),)
예제 #5
0
    def test_issue74(self):
        ureg = UnitRegistry()
        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)
예제 #6
0
 def qi(self):
     return np.asarray([1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j]) * self.ureg.m
예제 #7
0
 def qm(self):
     return np.asarray([1., 2., 3., 4.]) * self.ureg.m
예제 #8
0
 def qm(self):
     return np.asarray([1., 2., 3., 4.]) * self.ureg.m
예제 #9
0
 def qless(self):
     return np.asarray([1, 2, 3, 4], dtype=np.uint8) * self.ureg.dimensionless
예제 #10
0
 def test_ndarray_downcast_with_dtype(self):
     with self.assertWarns(UnitStrippedWarning):
         qarr = np.asarray(self.q, dtype=np.float64)
         self.assertEqual(qarr.dtype, np.float64)
예제 #11
0
 def test_ndarray_downcast(self):
     with self.assertWarns(UnitStrippedWarning):
         np.asarray(self.q)
예제 #12
0
 def test_issue483(self):
     ureg = self.ureg
     a = np.asarray([1, 2, 3])
     q = [1, 2, 3] * ureg.dimensionless
     p = (q ** q).m
     np.testing.assert_array_equal(p, a ** a)
예제 #13
0
 def test_issue171_T(self):
     a = np.asarray([[1.0, 2.0, 3.0, 4.0], [4.0, 3.0, 2.0, 1.0]])
     q1 = a * self.ureg.meter
     q2 = a.T * self.ureg.meter
     self.assertQuantityEqual(q1.T, q2)
예제 #14
0
파일: test_numpy.py 프로젝트: wiki01/pint
 def test_ndarray_downcast_with_dtype(self):
     with pytest.warns(UnitStrippedWarning):
         qarr = np.asarray(self.q, dtype=np.float64)
         assert qarr.dtype == np.float64
예제 #15
0
 def qi(self):
     return np.asarray([1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j]) * self.ureg.m
예제 #16
0
 def test_issue171_T(self):
     a = np.asarray([[1., 2., 3., 4.],[4., 3., 2., 1.]])
     q1 = a * self.ureg.meter
     q2 = a.T * self.ureg.meter
     self.assertQuantityEqual(q1.T, q2)
예제 #17
0
 def test_issue483(self):
     ureg = self.ureg
     a = np.asarray([1, 2, 3])
     q = [1, 2, 3] * ureg.dimensionless
     p = (q ** q).m
     np.testing.assert_array_equal(p, a ** a)
예제 #18
0
 def qless(self):
     return np.asarray([1, 2, 3, 4], dtype=np.uint8) * self.ureg.dimensionless
예제 #19
0
 def qm(self):
     return np.asarray([1, 2, 3, 4], dtype=np.uint8) * self.ureg.m
예제 #20
0
 def qless(self):
     return np.asarray([1., 2., 3., 4.]) * self.ureg.dimensionless
예제 #21
0
 def qm(self):
     return np.asarray([1, 2, 3, 4], dtype=np.uint8) * self.ureg.m
예제 #22
0
 def qless(self):
     return np.asarray([1., 2., 3., 4.]) * self.ureg.dimensionless