drake
drake copied to clipboard
Improve speed of symbolic::Polynomial::EvaluatePartial
trafficstars
Currently computing symbolic::Polynomial::EvaluatePartial is very slow. I have a mathematical program that takes 6 minutes to solve, but it takes 10 minutes to retrieve the solution when I use symbolic::Polynomial::EvaluatePartial.
Here is an example illustrating the issue.
- I construct the polynomial as
p(x) = m(x)ᵀ * S * m(x), wherem(x)is a vector containing all my monomial basis,Sis a matrix of decision variables. - I create a
symbolic::Environmentobject that contains the value ofS, set toS_val. - I call
p(x).EvaluatePartial(env). This takes 10 minutes. - I tried the alternative approach to compute
m(x)ᵀ * S_val * m(x), which gives me the same result as in step 3, but only takes 16 seconds.
I do expect step 3 to be slower than step 4, but I didn't expect that much slow.
I put my example in the branch https://github.com/hongkai-dai/drake/tree/benchmark_polynomial. You could see the comparison in bazel run common/symbolic/benchmarking:benchmark_polynomial.