コード例 #1
0
ファイル: test_ArrayStructure.py プロジェクト: fionaRust/iris
 def test_single_vector(self):
     orig = construct_nd(np.array([1, 2]), 0, (2, 1, 3))
     flattened = orig.flatten(order=self.order)
     struct = ArrayStructure.from_array(flattened)
     array, dims = struct.nd_array_and_dims(flattened, (2, 1, 3), order=self.order)
     self.assertArrayEqual(array, [1, 2])
     self.assertEqual(dims, (0,))
コード例 #2
0
ファイル: test_ArrayStructure.py プロジェクト: zmaalick/iris
 def test_single_vector(self):
     orig = construct_nd(np.array([1, 2]), 0, (2, 1, 3))
     flattened = orig.flatten(order=self.order)
     struct = ArrayStructure.from_array(flattened)
     array, dims = struct.nd_array_and_dims(flattened, (2, 1, 3),
                                            order=self.order)
     self.assertArrayEqual(array, [1, 2])
     self.assertEqual(dims, (0, ))
コード例 #3
0
    def test_structure_creation(self):
        # Test that the appropriate dictionary containing ArrayStructures is
        # computed when constructing a GroupStructure from_component_arrays.
        array = np.arange(6)
        expected_structure = {'a': ArrayStructure.from_array(array)}

        grp = GroupStructure.from_component_arrays({'a': array})

        self.assertEqual(grp.length, 6)
        self.assertEqual(grp._cmpt_structure, expected_structure)
コード例 #4
0
    def test_structure_creation(self):
        # Test that the appropriate dictionary containing ArrayStructures is
        # computed when constructing a GroupStructure from_component_arrays.
        array = np.arange(6)
        expected_structure = {'a': ArrayStructure.from_array(array)}

        grp = GroupStructure.from_component_arrays({'a': array})

        self.assertEqual(grp.length, 6)
        self.assertEqual(grp._cmpt_structure, expected_structure)
コード例 #5
0
ファイル: test_ArrayStructure.py プロジェクト: fionaRust/iris
    def test_single_vector_extra_dimension(self):
        orig = construct_nd(np.array([1, 2]), 1, (3, 2))
        flattened = orig.flatten(order=self.order)

        struct = ArrayStructure.from_array(flattened)

        # Add another dimension on flattened, making it a (6, 2).
        input_array = np.vstack([flattened, flattened + 100]).T

        array, dims = struct.nd_array_and_dims(input_array, (3, 1, 2, 1), order=self.order)
        self.assertArrayEqual(array, [[1, 101], [2, 102]])
        self.assertEqual(dims, (2,))
コード例 #6
0
ファイル: test_ArrayStructure.py プロジェクト: zmaalick/iris
    def test_single_vector_extra_dimension(self):
        orig = construct_nd(np.array([1, 2]), 1, (3, 2))
        flattened = orig.flatten(order=self.order)

        struct = ArrayStructure.from_array(flattened)

        # Add another dimension on flattened, making it a (6, 2).
        input_array = np.vstack([flattened, flattened + 100]).T

        array, dims = struct.nd_array_and_dims(input_array, (3, 1, 2, 1),
                                               order=self.order)
        self.assertArrayEqual(array, [[1, 101], [2, 102]])
        self.assertEqual(dims, (2, ))
コード例 #7
0
ファイル: test_ArrayStructure.py プロジェクト: zmaalick/iris
 def test_3d_first_dimension(self):
     flattened = np.array([1, 1, 1, 2, 2, 2])
     self.assertEqual(ArrayStructure.from_array(flattened),
                      ArrayStructure(3, [1, 2]))
コード例 #8
0
ファイル: test_ArrayStructure.py プロジェクト: zmaalick/iris
 def struct_from_arr(self, nd_array):
     return ArrayStructure.from_array(nd_array.flatten())
コード例 #9
0
ファイル: test_ArrayStructure.py プロジェクト: zmaalick/iris
 def test_multi_dim_array(self):
     with self.assertRaises(ValueError):
         ArrayStructure.from_array(np.arange(12).reshape(3, 4))
コード例 #10
0
ファイル: test_ArrayStructure.py プロジェクト: zmaalick/iris
 def test_not_an_array(self):
     # Support lists as an argument.
     self.assertEqual(ArrayStructure.from_array([1, 2, 3]),
                      ArrayStructure(1, [1, 2, 3]))
コード例 #11
0
 def test_3d_first_dimension(self):
     flattened = np.array([1, 1, 1, 2, 2, 2])
     self.assertEqual(ArrayStructure.from_array(flattened),
                      ArrayStructure(3, [1, 2]))
コード例 #12
0
 def struct_from_arr(self, nd_array):
     return ArrayStructure.from_array(nd_array.flatten())
コード例 #13
0
 def test_multi_dim_array(self):
     with self.assertRaises(ValueError):
         ArrayStructure.from_array(np.arange(12).reshape(3, 4))
コード例 #14
0
 def test_not_an_array(self):
     # Support lists as an argument.
     self.assertEqual(ArrayStructure.from_array([1, 2, 3]),
                      ArrayStructure(1, [1, 2, 3]))