def test_build_arrays_unstructured_ndim_c_order(self): # Passing an unstructured array to build_arrays, should result in the # appropriately shaped array, plus any trailing dimensions. grp = GroupStructure(6, {'a': None}, array_order='c') orig = np.array([1, 2, 3, 4, 5, 6]).reshape(2, 3) orig = np.dstack([orig, orig + 10]) r = grp.build_arrays((2, 3), {'a': orig.reshape((-1, 2), order='c')}) self.assert_built_array('a', r, (orig, (0, 1)))
def test_structured_array_not_applicable(self): # Just because an array has a possible structure, does not mean it # gets used. Check that 'd' which would make a good 1D array, doesn't # get used in a specific shape. elements = regular_array_structures((2, 2, 3)) elements['d'] = ArrayStructure(3, range(4)) grp = GroupStructure(12, elements, array_order='f') d = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]).reshape((3, 4), order='f') expected = np.array([[[0, 1, 2], [0, 2, 3]], [[0, 1, 3], [1, 2, 3]]]) r = grp.build_arrays((2, 2, 3), {'a': np.arange(12), 'b': np.arange(12), 'c': np.arange(12), 'd': d.flatten(order='f')}) self.assert_built_array('d', r, (expected, (0, 1, 2)))
def test_build_arrays_regular_f_order(self): # Construct simple orthogonal 1d array structures, adding a trailing # dimension to the second, and assert the result of build_arrays # produces the required result. elements = regular_array_structures((2, 3)) a = elements['a'].construct_array(6) b = elements['b'].construct_array(6) # Make b 2 dimensional. b = np.vstack([b, b + 100]).T grp = GroupStructure(6, elements, array_order='f') result = grp.build_arrays((2, 3), {'a': a, 'b': b}) self.assert_built_array('a', result, ([0, 1], (0,))) self.assert_built_array('b', result, ([[0, 100], [1, 101], [2, 102]], (1,)))
def test_build_arrays_regular_f_order(self): # Construct simple orthogonal 1d array structures, adding a trailing # dimension to the second, and assert the result of build_arrays # produces the required result. elements = regular_array_structures((2, 3)) a = elements['a'].construct_array(6) b = elements['b'].construct_array(6) # Make b 2 dimensional. b = np.vstack([b, b + 100]).T grp = GroupStructure(6, elements, array_order='f') result = grp.build_arrays((2, 3), {'a': a, 'b': b}) self.assert_built_array('a', result, ([0, 1], (0, ))) self.assert_built_array('b', result, ([[0, 100], [1, 101], [2, 102]], (1, )))
def test_structured_array_not_applicable(self): # Just because an array has a possible structure, does not mean it # gets used. Check that 'd' which would make a good 1D array, doesn't # get used in a specific shape. elements = regular_array_structures((2, 2, 3)) elements['d'] = ArrayStructure(3, np.arange(4)) grp = GroupStructure(12, elements, array_order='f') d = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]).reshape((3, 4), order='f') expected = np.array([[[0, 1, 2], [0, 2, 3]], [[0, 1, 3], [1, 2, 3]]]) r = grp.build_arrays( (2, 2, 3), { 'a': np.arange(12), 'b': np.arange(12), 'c': np.arange(12), 'd': d.flatten(order='f') }) self.assert_built_array('d', r, (expected, (0, 1, 2)))
def test_build_arrays_unstructured(self): # Check that an unstructured array gets reshaped appropriately. grp = GroupStructure(6, {'a': None}, array_order='c') orig = np.array([1, 2, 3, 4, 5, 6]).reshape(2, 3) r = grp.build_arrays((2, 3), {'a': orig.flatten(order='c')}) self.assert_built_array('a', r, (orig, (0, 1)))