-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
check sizes of arguments in dot; fixes #28617 #28666
base: master
Are you sure you want to change the base?
Conversation
I think the check should actually be |
I thought custom indices should only be some kind of simplification for special purposes. Thus, I would not forbid having two arrays of the same size but with different axes and calculating the dot product of them. Could you please explain why we should disallow something as
|
The idea is that the indices of |
Thank you for the explanation. If this is the basic idea behind the checks (and |
stdlib/LinearAlgebra/src/generic.jl
Outdated
Compute the dot product between two vectors. For complex vectors, the first | ||
vector is conjugated. When the vectors have equal lengths, calling `dot` is | ||
semantically equivalent to `sum(dot(vx,vy) for (vx,vy) in zip(x, y))`. | ||
Compute the dot product between two arrays of the same size as if they were |
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.
"of the same size" -> "with the same axes" ? The "equal sizes" language is also used a few lines below...
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.
I will change that.
@@ -206,7 +206,9 @@ end | |||
# Frobenius dot/inner product: trace(A'B) | |||
function dot(A::SparseMatrixCSC{T1,S1},B::SparseMatrixCSC{T2,S2}) where {T1,T2,S1,S2} | |||
m, n = size(A) | |||
size(B) == (m,n) || throw(DimensionMismatch("matrices must have the same dimensions")) | |||
if size(B) != (m,n) |
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.
Is axes
purposely not used here for some reason?
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.
I thought SparseMatrixCSC
uses definitely classical indexing as in line 208. Thus, I've just used size
instead of axes
. Should I change that?
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.
For now, the SparseArrays
code has not been modified to support arbitrary indices.
I suppose it would be generally less useful than for dense arrays.
We should note somewhere that these changes are breaking. Since the |
I guess the question is whether we consider this to be a bugfix or a change in the documented API. |
Following the discussion above, it seems that most people see this as a bugfix. Should I modify this PR in some way before it can be merged? |
This is not a simple bug fix.
It works exactly like documented. We can't label things bugfixes just because we change what we like about the behavior. Also, master is currently closed for breaking changes. |
Okay. Do I have to anything now in that case? |
This LGTM so I think this can rest for a while until we open up master or implement versioning in for the stdlibs. |
Bump. Any chance this qualifies as a "minor change"? |
I've marked it as a "minor change" and put the "triage" label on it and 1.1 milestone; we can discuss whether to include it on Thursday's triage call. |
I'm not sure this is useful at all --- it just adds errors to more cases. Very much not sure it's worth the potential breakage. |
Also not obvious to me whether comparing axes or just sizes is the right thing. |
The general triage sentiment is that by default we need to lean heavily in favor of not breaking code. So this could happen but the burden is on those proposing this that this is (a) the right thing to do and (b) that it won't break any packages or applications. Running PkgEval on this branch would be a good first step to inform that decision—if nothing breaks, we can consider it. |
Triage says 👍 but we need a PkgEval run. |
I'm for the behavior in this PR. Also, It should be marked as fixing #32395 (which I opened). |
@ararslan Would you be able to run PkgEval here? |
I won't likely be able to get to it for a while. |
@nanosoldier |
Your test job has completed - possible new issues were detected. A full report can be found here. cc @maleadt |
Ok, this does indeed cause some package test failures. That matches my intuition that, given that we allow passing arbitrary iterators to |
I just read through the error logs here and I think we have drawn the wrong conclusion from them. Most of the failures are unrelated to this PR. They are either segfaults or look intermittent. Then three of them fail because of an unfortunate |
5d48509
to
2bdedc1
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Third time's the charm (and comes with a @nanosoldier |
Your package evaluation job has completed - possible new issues were detected. A full report can be found here. |
I've tried to summarize the reason for the failures in the table below. No packages rely on dotting arrays of different shape except for singleton dimensions. A few packages rely on dotting one column matrix with a vector and a few packages dots a one row matrix with a vector. There are also some numerical differences which might be because some calls now use our dot instead of the dot from BLAS. We can revert that but I think the tests might just be too strict and that it would be better to go through the packages and adjust the tests. I think it's unfortunate that we don't provide an error in the motivating example in #28617 but maybe it's not a sufficiently common case to warrant the the effort required for introducing the check.
|
As discussed in #28617 and https://discourse.julialang.org/t/efficient-trace-of-product-of-matrices/13313/12,
dot(A::AbstractArray, B::AbstractArray)
should check whethersize(A) == size(B)
instead oflength(A) == length(B)
.