Esempio n. 1
0
 def test_flatten_to_real_complex_nd(self):
     complex_array = 5 * np.random.rand(2, 3, 5, 7) + 7j * np.random.rand(
         2, 3, 5, 7)
     actual = dtype_utils.flatten_to_real(complex_array)
     expected = np.concatenate(
         [np.real(complex_array),
          np.imag(complex_array)], axis=3)
     self.assertTrue(np.allclose(actual, expected))
Esempio n. 2
0
 def test_compound_single(self):
     num_elems = 1
     structured_array = np.zeros(shape=num_elems, dtype=struc_dtype)
     structured_array['r'] = r_vals = np.random.random(size=num_elems)
     structured_array['g'] = g_vals = np.random.randint(0, high=1024, size=num_elems)
     structured_array['b'] = b_vals = np.random.random(size=num_elems)
     expected = np.concatenate((r_vals, g_vals, b_vals))
     actual = dtype_utils.flatten_to_real(structured_array[0])
     self.assertTrue(np.allclose(actual, expected))
Esempio n. 3
0
 def test_complex_single(self):
     complex_val = 4.32 + 5.67j
     expected = [np.real(complex_val), np.imag(complex_val)]
     actual = dtype_utils.flatten_to_real(complex_val)
     self.assertTrue(np.allclose(actual, expected))
Esempio n. 4
0
 def test_real_nd(self):
     real_array = 5 * np.random.rand(2, 3, 5, 7)
     actual = dtype_utils.flatten_to_real(real_array)
     self.assertTrue(np.allclose(actual, real_array))