-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
evalpoly
is broken for matrices
#1161
Comments
Also, in a separate code path, for |
Seems like a |
It's just a matter of how the sum is initialized — it should be initialized by (Note that it should be |
However, I experimented with this and it seems like we need a completely separate method when (Also, a specialized method for matrix So, for now, the fact that it throws an error is a good thing — better than giving the wrong answer. |
Here is a generic implementation that we can use as a fallback, which should handle most matrix types AFAICT: # non-inplace fallback
function _evalpoly(X::AbstractMatrix, p)
Base.require_one_based_indexing(p)
p0 = isempty(p) ? Base.reduce_empty_iter(+, p) : p[end]
Xone = one(X)
S = Base.promote_op(*, typeof(Xone), typeof(Xone))(Xone) * p0
for i = length(p)-1:-1:1
S = X * S + @inbounds(p[i] isa AbstractMatrix ? p[i] : p[i] * I)
end
return S
end
evalpoly(X::AbstractMatrix, p::Tuple) = _evalpoly(X, p)
evalpoly(X::AbstractMatrix, p::AbstractVector) = _evalpoly(X, p) It would be nice to have an optimized implementation when |
A generic in place version could work using |
You can't just use I also agree that for |
I was thinking of |
You also run into trouble for matrices of matrices, but I guess those aren't well-supported in linear algebra anyway right now. e.g. |
The text was updated successfully, but these errors were encountered: