コード例 #1
0
ファイル: test_ArrayStack.py プロジェクト: gdementen/biggus
 def test_multidim_stack_multidim(self):
     # Multidim stack of arrays shape (4, 6)
     arrays = np.array([[ConstantArray((), i) for i in range(6)] for
                        i in range(4)])
     msg = 'multidimensional stacks not yet supported'
     with self.assertRaisesRegexp(ValueError, msg):
         ArrayStack.multidim_array_stack(arrays, (3, 2, 4))
コード例 #2
0
 def test_multidim_stack_multidim(self):
     # Multidim stack of arrays shape (4, 6)
     arrays = np.array([[ConstantArray((), i) for i in range(6)]
                        for i in range(4)])
     msg = 'multidimensional stacks not yet supported'
     with self.assertRaisesRegexp(ValueError, msg):
         ArrayStack.multidim_array_stack(arrays, (3, 2, 4))
コード例 #3
0
 def test_order_incorrect_order(self):
     # Specifying an unknown order.
     array1 = fake_array(0)
     array2 = fake_array(0)
     with self.assertRaisesRegexp(TypeError, 'order not understood'):
         ArrayStack.multidim_array_stack([array1, array2], (1, 2),
                                         order='random')
コード例 #4
0
 def test_order_incorrect_order(self):
     # Specifying an unknown order.
     array1 = fake_array(0)
     array2 = fake_array(0)
     with self.assertRaisesRegexp(TypeError, 'order not understood'):
         ArrayStack.multidim_array_stack([array1, array2], (1, 2),
                                         order='random')
コード例 #5
0
 def test_stack_order_fortran_t1(self):
     # Fortran index ordering
     # 1D stack of arrays shape (6,)
     res = ArrayStack.multidim_array_stack(self.arrays, (3, 2), order='F')
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (3, 2), order='F')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #6
0
 def test_stack_order_default(self):
     # 1D stack of arrays shape (6,)
     # Ensure that the default index ordering corresponds to C.
     res = ArrayStack.multidim_array_stack(self.arrays, (3, 2))
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (3, 2), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #7
0
 def test_stack_order_c_list(self):
     # 1D stack of arrays length  6
     res = ArrayStack.multidim_array_stack(self.arrays.tolist(), (3, 2),
                                           order='C')
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (3, 2), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #8
0
 def test_stack_order_c_numpy_array_t2(self):
     # 1D stack of arrays shape (6,)
     # alternate shape
     res = ArrayStack.multidim_array_stack(self.arrays, (2, 3), order='C')
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (2, 3), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #9
0
ファイル: test_ArrayStack.py プロジェクト: gdementen/biggus
 def test_stack_order_c_list(self):
     # 1D stack of arrays length  6
     res = ArrayStack.multidim_array_stack(self.arrays.tolist(), (3, 2),
                                           order='C')
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (3, 2), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #10
0
 def test_stack_order_c_numpy_array_t2(self):
     # 1D stack of arrays shape (6,)
     # alternate shape
     res = ArrayStack.multidim_array_stack(self.arrays, (2, 3), order='C')
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (2, 3), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #11
0
 def test_stack_order_default(self):
     # 1D stack of arrays shape (6,)
     # Ensure that the default index ordering corresponds to C.
     res = ArrayStack.multidim_array_stack(self.arrays, (3, 2))
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (3, 2), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #12
0
 def test_stack_order_fortran_t1(self):
     # Fortran index ordering
     # 1D stack of arrays shape (6,)
     res = ArrayStack.multidim_array_stack(self.arrays, (3, 2), order='F')
     arr = np.array([i for i in range(6)])
     target = np.reshape(arr, (3, 2), order='F')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #13
0
 def data(self):
     if not self._structure_calculated:
         self._calculate_structure()
     if self._data_cache is None:
         data_arrays = [f._data for f in self.fields]
         self._data_cache = ArrayStack.multidim_array_stack(data_arrays, self.vector_dims_shape)
     return self._data_cache
コード例 #14
0
 def test_stack_order_c_multidim(self):
     # 1D stack of 6 arrays each (4, 5)
     arrays = [NumpyArrayAdapter(np.arange(20).reshape(4, 5)) for
               i in range(6)]
     res = ArrayStack.multidim_array_stack(arrays, (2, 3), order='C')
     arr = np.arange(20).reshape(4, 5) * np.ones((6, 4, 5))
     target = np.reshape(arr, (2, 3, 4, 5), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #15
0
 def test_stack_order_c_multidim(self):
     # 1D stack of 6 arrays each (4, 5)
     arrays = [NumpyArrayAdapter(np.arange(20).reshape(4, 5)) for
               i in range(6)]
     res = ArrayStack.multidim_array_stack(arrays, (2, 3), order='C')
     arr = np.arange(20).reshape(4, 5) * np.ones((6, 4, 5))
     target = np.reshape(arr, (2, 3, 4, 5), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #16
0
 def test_stack_order_fortran_t2(self):
     # Fortran index ordering
     # 1D stack of arrays shape (6,)
     # alternate shape
     res = ArrayStack.multidim_array_stack(self.arrays, (2, 3), order='F')
     arr = np.arange(6)
     target = np.reshape(arr, (2, 3), order='F')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #17
0
 def data(self):
     if not self._structure_calculated:
         self._calculate_structure()
     if self._data_cache is None:
         data_arrays = [f._data for f in self.fields]
         self._data_cache = \
             ArrayStack.multidim_array_stack(data_arrays,
                                             self.vector_dims_shape)
     return self._data_cache
コード例 #18
0
 def test_stack_order_c_numpy_array_t1(self):
     # 1D stack of arrays shape (6,)
     res = ArrayStack.multidim_array_stack(self.arrays, (3, 2), order='C')
     arr = np.arange(6)
     target = np.reshape(arr, (3, 2), order='C')
     self.assertTrue(np.array_equal(res.ndarray(), target))
コード例 #19
0
 def test_incompatible_shape(self):
     # 1D stack of arrays shape (6,)
     # Specifying a stack shape that is not feasible.
     msg = 'total size of new array must be unchanged'
     with self.assertRaisesRegexp(ValueError, msg):
         ArrayStack.multidim_array_stack(self.arrays, (3, 1), order='C')
コード例 #20
0
 def test_incompatible_shape(self):
     # 1D stack of arrays shape (6,)
     # Specifying a stack shape that is not feasible.
     msg = 'total size of new array must be unchanged'
     with self.assertRaisesRegexp(ValueError, msg):
         ArrayStack.multidim_array_stack(self.arrays, (3, 1), order='C')