MCPcopy Create free account
hub / github.com/numpy/numpy / test_edge_paths

Method test_edge_paths

numpy/core/tests/test_einsum.py:1143–1185  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1141 (0, 5), (1, 4), (3, 4), (1, 3), (1, 2), (0, 1)])
1142
1143 def test_edge_paths(self):
1144 # Difficult edge cases
1145
1146 # Edge test1
1147 edge_test1 = self.build_operands('eb,cb,fb->cef')
1148 path, path_str = np.einsum_path(*edge_test1, optimize='greedy')
1149 self.assert_path_equal(path, ['einsum_path', (0, 2), (0, 1)])
1150
1151 path, path_str = np.einsum_path(*edge_test1, optimize='optimal')
1152 self.assert_path_equal(path, ['einsum_path', (0, 2), (0, 1)])
1153
1154 # Edge test2
1155 edge_test2 = self.build_operands('dd,fb,be,cdb->cef')
1156 path, path_str = np.einsum_path(*edge_test2, optimize='greedy')
1157 self.assert_path_equal(path, ['einsum_path', (0, 3), (0, 1), (0, 1)])
1158
1159 path, path_str = np.einsum_path(*edge_test2, optimize='optimal')
1160 self.assert_path_equal(path, ['einsum_path', (0, 3), (0, 1), (0, 1)])
1161
1162 # Edge test3
1163 edge_test3 = self.build_operands('bca,cdb,dbf,afc->')
1164 path, path_str = np.einsum_path(*edge_test3, optimize='greedy')
1165 self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 2), (0, 1)])
1166
1167 path, path_str = np.einsum_path(*edge_test3, optimize='optimal')
1168 self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 2), (0, 1)])
1169
1170 # Edge test4
1171 edge_test4 = self.build_operands('dcc,fce,ea,dbf->ab')
1172 path, path_str = np.einsum_path(*edge_test4, optimize='greedy')
1173 self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 1), (0, 1)])
1174
1175 path, path_str = np.einsum_path(*edge_test4, optimize='optimal')
1176 self.assert_path_equal(path, ['einsum_path', (1, 2), (0, 2), (0, 1)])
1177
1178 # Edge test5
1179 edge_test4 = self.build_operands('a,ac,ab,ad,cd,bd,bc->',
1180 size_dict={"a": 20, "b": 20, "c": 20, "d": 20})
1181 path, path_str = np.einsum_path(*edge_test4, optimize='greedy')
1182 self.assert_path_equal(path, ['einsum_path', (0, 1), (0, 1, 2, 3, 4, 5)])
1183
1184 path, path_str = np.einsum_path(*edge_test4, optimize='optimal')
1185 self.assert_path_equal(path, ['einsum_path', (0, 1), (0, 1, 2, 3, 4, 5)])
1186
1187 def test_path_type_input(self):
1188 # Test explicit path handling

Callers

nothing calls this directly

Calls 2

build_operandsMethod · 0.95
assert_path_equalMethod · 0.95

Tested by

no test coverage detected