(self)
| 2053 | assert_almost_equal(out, A.dot(B).dot(C).dot(D)) |
| 2054 | |
| 2055 | def test_dynamic_programming_logic(self): |
| 2056 | # Test for the dynamic programming part |
| 2057 | # This test is directly taken from Cormen page 376. |
| 2058 | arrays = [np.random.random((30, 35)), |
| 2059 | np.random.random((35, 15)), |
| 2060 | np.random.random((15, 5)), |
| 2061 | np.random.random((5, 10)), |
| 2062 | np.random.random((10, 20)), |
| 2063 | np.random.random((20, 25))] |
| 2064 | m_expected = np.array([[0., 15750., 7875., 9375., 11875., 15125.], |
| 2065 | [0., 0., 2625., 4375., 7125., 10500.], |
| 2066 | [0., 0., 0., 750., 2500., 5375.], |
| 2067 | [0., 0., 0., 0., 1000., 3500.], |
| 2068 | [0., 0., 0., 0., 0., 5000.], |
| 2069 | [0., 0., 0., 0., 0., 0.]]) |
| 2070 | s_expected = np.array([[0, 1, 1, 3, 3, 3], |
| 2071 | [0, 0, 2, 3, 3, 3], |
| 2072 | [0, 0, 0, 3, 3, 3], |
| 2073 | [0, 0, 0, 0, 4, 5], |
| 2074 | [0, 0, 0, 0, 0, 5], |
| 2075 | [0, 0, 0, 0, 0, 0]], dtype=int) |
| 2076 | s_expected -= 1 # Cormen uses 1-based index, python does not. |
| 2077 | |
| 2078 | s, m = _multi_dot_matrix_chain_order(arrays, return_costs=True) |
| 2079 | |
| 2080 | # Only the upper triangular part (without the diagonal) is interesting. |
| 2081 | assert_almost_equal(np.triu(s[:-1, 1:]), |
| 2082 | np.triu(s_expected[:-1, 1:])) |
| 2083 | assert_almost_equal(np.triu(m), np.triu(m_expected)) |
| 2084 | |
| 2085 | def test_too_few_input_arrays(self): |
| 2086 | assert_raises(ValueError, multi_dot, []) |
nothing calls this directly
no test coverage detected