(self)
| 2199 | assert_almost_equal(out, A.dot(B).dot(C).dot(D)) |
| 2200 | |
| 2201 | def test_dynamic_programming_logic(self): |
| 2202 | # Test for the dynamic programming part |
| 2203 | # This test is directly taken from Cormen page 376. |
| 2204 | arrays = [np.random.random((30, 35)), |
| 2205 | np.random.random((35, 15)), |
| 2206 | np.random.random((15, 5)), |
| 2207 | np.random.random((5, 10)), |
| 2208 | np.random.random((10, 20)), |
| 2209 | np.random.random((20, 25))] |
| 2210 | m_expected = np.array([[0., 15750., 7875., 9375., 11875., 15125.], |
| 2211 | [0., 0., 2625., 4375., 7125., 10500.], |
| 2212 | [0., 0., 0., 750., 2500., 5375.], |
| 2213 | [0., 0., 0., 0., 1000., 3500.], |
| 2214 | [0., 0., 0., 0., 0., 5000.], |
| 2215 | [0., 0., 0., 0., 0., 0.]]) |
| 2216 | s_expected = np.array([[0, 1, 1, 3, 3, 3], |
| 2217 | [0, 0, 2, 3, 3, 3], |
| 2218 | [0, 0, 0, 3, 3, 3], |
| 2219 | [0, 0, 0, 0, 4, 5], |
| 2220 | [0, 0, 0, 0, 0, 5], |
| 2221 | [0, 0, 0, 0, 0, 0]], dtype=int) |
| 2222 | s_expected -= 1 # Cormen uses 1-based index, python does not. |
| 2223 | |
| 2224 | s, m = _multi_dot_matrix_chain_order(arrays, return_costs=True) |
| 2225 | |
| 2226 | # Only the upper triangular part (without the diagonal) is interesting. |
| 2227 | assert_almost_equal(np.triu(s[:-1, 1:]), |
| 2228 | np.triu(s_expected[:-1, 1:])) |
| 2229 | assert_almost_equal(np.triu(m), np.triu(m_expected)) |
| 2230 | |
| 2231 | def test_too_few_input_arrays(self): |
| 2232 | assert_raises(ValueError, multi_dot, []) |
nothing calls this directly
no test coverage detected