コード例 #1
0
 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]))
コード例 #2
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]))
コード例 #3
0
 def test_1d_range(self):
     a = np.arange(6)
     self.assertEqual(self.struct_from_arr(a),
                      ArrayStructure(1, list(range(6))))
コード例 #4
0
 def test_3d_ones(self):
     a = np.ones([10, 2, 1])
     self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, [1]))
コード例 #5
0
 def test_1d_len_1(self):
     a = np.arange(1)
     self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, a))
コード例 #6
0
 def test_1d(self):
     a = np.array([-1, 3, 1, 2])
     self.assertEqual(self.struct_from_arr(a), ArrayStructure(1, a))
コード例 #7
0
 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))
コード例 #8
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]))
コード例 #9
0
 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))
コード例 #10
0
 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))
コード例 #11
0
 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))
コード例 #12
0
 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']])
コード例 #13
0
 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, [])
コード例 #14
0
 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']])
コード例 #15
0
 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"]])