-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix range bugs for matrix multiply/solve #13833
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
Conversation
@@ -633,6 +633,10 @@ end | |||
./(r::FloatRange, x::Real) = FloatRange(r.start/x, r.step/x, r.len, r.divisor) | |||
./(r::LinSpace, x::Real) = LinSpace(r.start / x, r.stop / x, r.len, r.divisor) | |||
|
|||
# Matrix multiplication/solve on ranges, A*r should treat r as collected vector | |||
*(A::AbstractArray, r::Range) = A*collect(r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just AbstractMatrix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, will do.
Switched to Previous commit caused Travis to break. Not sure why, as it said the Mac environment failed, and I can't reproduce it on my Mac, which is where everything had passed tests to begin with. |
It turns out I had a poor choice of matrix for unit test; changed to something simpler and now everything works. Rebased for clean commit. |
I think the deeper problems are different for |
It seems reasonable for Meanwhile, I don't think there is a rush to fix this, because the person who reported it was complaining about having to do |
@artkuo Any news on a general fix of this? If not, I think we can just merge this for now. |
I am close to having a more correct fix, but it has become complicated. As you predicted, both multiply and divide have deeper issues. These are, however, somewhat delicate to deal with. There are cases where Also, one of the problems is missing fall-back for My ultimate fix is something of an omnibus. It deals with a bunch of these issues at once, and I need to write some more tests against side-effects like accidentally messing up sparse methods. I have been toying with breaking it into multiple, bite-size PRs, but it's a bit complicated because some things overlap, so I can't necessarily find an easy way to make the commits fully independent. Omnibus is easier for me to put together, but almost certainly harder for the community to digest, and at greater risk for rejection. It may be sensible to merge the present PR, with the understanding that it's temporary. It's actually not a terrible fix, but it leaves some other bugs unaddressed. If/when the "real" fix is performed, then the |
Please do this. If you need design guidance on how to split things up, perhaps a new issue with links to the prospective branch would be best so you can get feedback by a means other than opening an overly-large PR. |
Okay I'll start with a small one on |
Merging this for now as it fixes the problem. Looking forward to the more general fix. |
fix range bugs for matrix multiply/solve
This seems to cause a problem when building Julia v0.5: WARNING: New definition
\(Base.LinAlg.Diagonal, AbstractArray{T<:Any, 1}) at linalg/diagonal.jl:170
is ambiguous with:
\(AbstractArray{#T<:Any, 2}, Base.Range) at range.jl:652.
To fix, define
\(Base.LinAlg.Diagonal{#T<:Any}, Base.Range)
before the new definition. |
I wasn't sure to make of this ambiguity, because the evaluation |
There should be time left in this release cycle to find a more general fix and the users who complained about the range issue should and probably will stay on 0.4 meanwhile. Therefore, I think we should just revert this commit and wait for your more general fix. |
Sounds good, the fix for |
Reverted in 7cda13f |
This is a combined bug fix and workaround for ranges not behaving properly when pre-multiplied by a matrix. In the user forum an error was reported for
A*r
whereA
is a matrix andr
is a range, which should just like a vector. The fix is to define matrix multiplication by aRange
as including acollect
first.A second problem is that
A\r
can fail, with the workaround also being to do acollect
onr
. I call this a workaround as opposed to a bug fix, because the problem may come from intricacies ofconvert
, and not necessarily a failure tocollect
, asA\r
doesn't fail universally but only for some/most combinations of types forA
andr
. I didn't trace down far enough to figure that out, and someone more knowledgeable might know whether there is a deeper bug lurking somewhere. Nevertheless this PR seems to work and pass all tests including the added ones.Finally, I left the definitions very broad here with
AbstractArray
. I would appreciate advice if these should be something more specific such asAbstractMatrix
or such. My thinking was that the details on types get figured out by matmul.jl so there's no need to deal with it beforehand, but I'm not sure if this could potentially slow things down.