Beispiel #1
0
 def test_not_complex(self):
     """Test that result is not a complex object."""
     modes = np.array([[1, 1j], [-1j, 3 - 1j]]).reshape((1, 2, 2, 1))
     phidot = np.array([1, 1]).reshape((1, 2, 1))
     axis = 1
     arr = adiabatic.Pr_spectrum(phidot, modes, axis)
     assert_((not np.iscomplexobj(arr)))
Beispiel #2
0
 def test_imaginary(self):
     """Test calculation with complex values."""
     modes = np.array([[1, 1j], [-1j, 3 - 1j]]).reshape((1, 2, 2, 1))
     phidot = np.array([1, 1]).reshape((1, 2, 1))
     axis = 1
     arr = adiabatic.Pr_spectrum(phidot, modes, axis)
     desired = np.array([[11 / 4.0]]).reshape((1, 1))
     assert_almost_equal(arr, desired)
Beispiel #3
0
 def test_one_by_two_by_two_by_one(self):
     """Test that 1x2x2x1 calculation works."""
     modes = np.array([[1, 3], [2, 5]]).reshape((1, 2, 2, 1))
     phidot = np.array([7, 9]).reshape((1, 2, 1))
     axis = 1
     arr = adiabatic.Pr_spectrum(phidot, modes, axis)
     desired = np.array([[4981.0 / 16900.0]]).reshape((1, 1))
     assert_almost_equal(arr, desired)
Beispiel #4
0
 def test_floatdivision(self):
     """Test that float division is used."""
     modes = np.array([[1, 3], [2, 5]]).reshape((1, 2, 2, 1))
     phidot = np.array([7, 9]).reshape((1, 2, 1))
     axis = 1
     arr = adiabatic.Pr_spectrum(phidot, modes, axis)
     desired = np.array([[4981.0 / 16900.0]]).reshape((1, 1))
     assert_almost_equal(arr, desired)
Beispiel #5
0
 def test_singlefield(self):
     """Test single field calculation."""
     modes = np.array([[[7]]])
     phidot = 1.7
     axis = 0
     actual = np.array([49 / (1.7)**2])
     arr = adiabatic.Pr_spectrum(phidot, modes, axis)
     assert_almost_equal(arr, actual)
Beispiel #6
0
 def test_shape(self):
     """Test whether the rhodots are shaped correctly."""
     arr = adiabatic.Pr_spectrum(self.phidot, self.modes, self.axis)
     result = arr.shape
     newshape = list(self.Vphi.shape)
     del newshape[self.axis]
     actual = tuple(newshape)
     assert_(
         result == actual, "Result shape %s, but desired shape is %s" %
         (str(result), str(actual)))