예제 #1
0
    def test_h5_illegal_dtype(self):
        with h5py.File(file_path, mode='r') as h5_f:
            with self.assertRaises(TypeError):
                _ = dtype_utils.flatten_complex_to_real(h5_f['real'])

            with self.assertRaises(TypeError):
                _ = dtype_utils.flatten_complex_to_real(h5_f['compound'])
예제 #2
0
 def test_compound_illegal(self):
     num_elems = 5
     structured_array = np.zeros(shape=num_elems, dtype=struc_dtype)
     structured_array['r'] = np.random.random(size=num_elems)
     structured_array['g'] = np.random.randint(0, high=1024, size=num_elems)
     structured_array['b'] = np.random.random(size=num_elems)
     with self.assertRaises(TypeError):
         _ = dtype_utils.flatten_complex_to_real(structured_array)
예제 #3
0
 def test_nd_array_dask(self):
     complex_array = 5 * np.random.rand(2, 3, 5, 7) + 7j * np.random.rand(2, 3, 5, 7)
     da_comp = da.from_array(complex_array, chunks=complex_array.shape)
     actual = dtype_utils.flatten_complex_to_real(da_comp)
     self.assertIsInstance(actual, da.core.Array)
     actual = actual.compute()
     expected = np.concatenate([np.real(complex_array), np.imag(complex_array)], axis=3)
     self.assertTrue(np.allclose(actual, expected))
예제 #4
0
 def test_complex_to_real_nd_array(self):
     complex_array = 5 * np.random.rand(2, 3, 5, 7) + 7j * np.random.rand(
         2, 3, 5, 7)
     actual = dtype_utils.flatten_complex_to_real(complex_array)
     expected = np.concatenate(
         [np.real(complex_array),
          np.imag(complex_array)], axis=3)
     self.assertTrue(np.allclose(actual, expected))
예제 #5
0
 def base_h5_legal(self, lazy):
     with h5py.File(file_path, mode='r') as h5_f:
         h5_comp = h5_f['complex']
         actual = dtype_utils.flatten_complex_to_real(h5_comp, lazy=lazy)
         if lazy:
             self.assertIsInstance(actual, da.core.Array)
             actual = actual.compute()
         expected = np.concatenate([np.real(h5_comp[()]), np.imag(h5_comp[()])], axis=len(h5_comp.shape) - 1)
         self.assertTrue(np.allclose(actual, expected))
예제 #6
0
 def test_complex_to_real_h5_legal(self):
     with h5py.File(file_path, mode='r') as h5_f:
         h5_comp = h5_f['complex']
         actual = dtype_utils.flatten_complex_to_real(h5_comp)
         expected = np.concatenate(
             [np.real(h5_comp[()]),
              np.imag(h5_comp[()])],
             axis=len(h5_comp.shape) - 1)
         self.assertTrue(np.allclose(actual, expected))
예제 #7
0
 def test_real_in(self):
     with self.assertRaises(TypeError):
         _ = dtype_utils.flatten_complex_to_real(np.arange(4))
예제 #8
0
 def test_2d_array(self):
     complex_array = 5 * np.random.rand(2, 3) + 7j * np.random.rand(2, 3)
     actual = dtype_utils.flatten_complex_to_real(complex_array)
     expected = np.hstack([np.real(complex_array), np.imag(complex_array)])
     self.assertTrue(np.allclose(actual, expected))