def test_1d_over_2d_first_dim_manual(self): sub = np.array([10, 10, 20, 20]) self.assertEqual(self.struct_from_arr(sub), ArrayStructure(2, [10, 20]))
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]))
def test_1d_range(self): a = np.arange(6) self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, list(range(6))))
def test_3d_ones(self): a = np.ones([10, 2, 1]) self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, [1]))
def test_1d_len_1(self): a = np.arange(1) self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, a))
def test_1d(self): a = np.array([-1, 3, 1, 2]) self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, a))
def test_len_1_3d(self): # Setup a case which triggers an IndexError when identifying # the stride, but the result should still be correct. sub = np.arange(2) a = construct_nd(sub, 1, (1, 1, 1)) self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, sub))
def test_not_an_array(self): # Support lists as an argument. self.assertEqual(ArrayStructure.from_array([1, 2, 3]), ArrayStructure(1, [1, 2, 3]))
def test_1d_over_3d_second_dim(self): sub = np.array([-1, 3, 1, 2]) a = construct_nd(sub, 1, (2, 4, 3)) self.assertEqual(self.struct_from_arr(a), ArrayStructure(3, sub))
def test_1d_over_3d_third_dim(self): sub = np.array([-1, 3, 1, 2]) a = construct_nd(sub, 2, (3, 2, 4)) self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, sub))
def test_1d_over_3d_first_dim(self): sub = np.array([-1, 3, 1, 2]) a = construct_nd(sub, 0, (4, 2, 3)) self.assertEqual(self.struct_from_arr(a), ArrayStructure(6, sub))
def test_multiple_potentials(self): # More than one potential dimension for dim 1. array_structures = regular_array_structures((4, 2, 3)) array_structures['shared b'] = ArrayStructure(4, [-10, 4]) self.assert_potentials(24, array_structures, [['a', 'b', 'c'], ['a', 'shared b', 'c']])
def test_non_viable_element(self): # One 2d potential as well as one 3d, using the same first dimension. array_structures = regular_array_structures((4, 2, 3)) array_structures.pop('c') array_structures['strange_length'] = ArrayStructure(4, np.arange(5)) self.assert_potentials(24, array_structures, [])
def test_shared_first_dimension(self): # One 2d potential as well as one 3d, using the same first dimension. array_structures = regular_array_structures((4, 2, 3)) array_structures['bc combined'] = ArrayStructure(4, np.arange(6)) self.assert_potentials(24, array_structures, [['a', 'bc combined'], ['a', 'b', 'c']])
def test_multiple_potentials(self): # More than one potential dimension for dim 1. array_structures = regular_array_structures((4, 2, 3)) array_structures["shared b"] = ArrayStructure(4, [-10, 4]) self.assert_potentials(24, array_structures, [["a", "b", "c"], ["a", "shared b", "c"]])