Esempio n. 1
0
 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,))
Esempio n. 2
0
 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, ))
    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)
Esempio n. 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)
Esempio n. 5
0
    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,))
Esempio n. 6
0
    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, ))
Esempio n. 7
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]))
Esempio n. 8
0
 def struct_from_arr(self, nd_array):
     return ArrayStructure.from_array(nd_array.flatten())
Esempio n. 9
0
 def test_multi_dim_array(self):
     with self.assertRaises(ValueError):
         ArrayStructure.from_array(np.arange(12).reshape(3, 4))
Esempio n. 10
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]))
Esempio n. 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]))
Esempio n. 12
0
 def struct_from_arr(self, nd_array):
     return ArrayStructure.from_array(nd_array.flatten())
Esempio n. 13
0
 def test_multi_dim_array(self):
     with self.assertRaises(ValueError):
         ArrayStructure.from_array(np.arange(12).reshape(3, 4))
Esempio n. 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]))