Exemple #1
0
 def test_raises_exception_if_mixing_incompatible_units(self):
     a = sp.array([1.0])
     b = sp.array([2.0]) * pq.dimensionless
     c = sp.array([3.0]) * pq.s
     d = sp.array([4.0]) * pq.m
     for p in combinations((a, c, d), 2):
         with self.assertRaises(Exception):
             spq.inner(p)
         with self.assertRaises(Exception):
             spq.inner(p[::-1])
     for p in combinations((b, c, d), 2):
         with self.assertRaises(Exception):
             spq.inner(p)
         with self.assertRaises(Exception):
             spq.inner(p[::-1])
 def test_raises_exception_if_mixing_incompatible_units(self):
     a = sp.array([1.0])
     b = sp.array([2.0]) * pq.dimensionless
     c = sp.array([3.0]) * pq.s
     d = sp.array([4.0]) * pq.m
     for p in combinations((a, c, d), 2):
         with self.assertRaises(Exception):
             spq.inner(p)
         with self.assertRaises(Exception):
             spq.inner(p[::-1])
     for p in combinations((b, c, d), 2):
         with self.assertRaises(Exception):
             spq.inner(p)
         with self.assertRaises(Exception):
             spq.inner(p[::-1])
 def test_works_with_multidimensional_arrays(self):
     a = sp.array([[0.0, 1.0], [2.0, 3.0]]) * pq.s
     b = sp.array([[2.0, 2.0], [3.0, 4.0]]) * pq.s
     expected = sp.array([[2.0, 4.0], [10.0, 18.0]]) * pq.s
     actual = spq.inner(a, b)
     assert_array_almost_equal(expected, actual.rescale(expected.units))
 def test_works_with_normal_and_quantity_arrays_mixed(self):
     a = sp.array([0.0, 1.0, 2.0]) * pq.dimensionless
     b = sp.array([2.0, 2.0, 3.0])
     expected = sp.inner(a, b)
     actual = spq.inner(a, b)
     self.assertAlmostEqual(expected, actual)
 def test_works_with_quantities_arrays(self):
     a = sp.array([0.0, 1.0, 2.0]) * pq.s
     b = sp.array([2000.0, 2000.0, 3000.0]) * pq.ms
     expected = 8.0 * pq.s
     actual = spq.inner(a, b)
     self.assertAlmostEqual(expected, actual.rescale(expected.units))
 def test_works_with_normal_arrays(self):
     a = sp.array([0.0, 1.0, 2.0])
     b = sp.array([2.0, 2.0, 3.0])
     expected = sp.inner(a, b)
     actual = spq.inner(a, b)
     self.assertAlmostEqual(expected, actual)
Exemple #7
0
 def test_works_with_multidimensional_arrays(self):
     a = sp.array([[0.0, 1.0], [2.0, 3.0]]) * pq.s
     b = sp.array([[2.0, 2.0], [3.0, 4.0]]) * pq.s
     expected = sp.array([[2.0, 4.0], [10.0, 18.0]]) * pq.s
     actual = spq.inner(a, b)
     assert_array_almost_equal(expected, actual.rescale(expected.units))
Exemple #8
0
 def test_works_with_normal_and_quantity_arrays_mixed(self):
     a = sp.array([0.0, 1.0, 2.0]) * pq.dimensionless
     b = sp.array([2.0, 2.0, 3.0])
     expected = sp.inner(a, b)
     actual = spq.inner(a, b)
     self.assertAlmostEqual(expected, actual)
Exemple #9
0
 def test_works_with_quantities_arrays(self):
     a = sp.array([0.0, 1.0, 2.0]) * pq.s
     b = sp.array([2000.0, 2000.0, 3000.0]) * pq.ms
     expected = 8.0 * pq.s
     actual = spq.inner(a, b)
     self.assertAlmostEqual(expected, actual.rescale(expected.units))
Exemple #10
0
 def test_works_with_normal_arrays(self):
     a = sp.array([0.0, 1.0, 2.0])
     b = sp.array([2.0, 2.0, 3.0])
     expected = sp.inner(a, b)
     actual = spq.inner(a, b)
     self.assertAlmostEqual(expected, actual)