-
-
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
adjoint/transpose transcend material concerns #25364
Conversation
base/linalg/bitarray.jl
Outdated
@@ -123,7 +123,7 @@ end | |||
|
|||
## Structure query functions | |||
|
|||
issymmetric(A::BitMatrix) = size(A, 1)==size(A, 2) && count(!iszero, A - transpose(A))==0 | |||
issymmetric(A::BitMatrix) = size(A, 1)==size(A, 2) && count(!iszero, A - collect(A'))==0 |
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.
Just curious: is your rationale for collect
ing here to ensure we still hit an optimized -(::BitMatrix, ::BitMatrix)
method? If that's the case it may be worth keeping note of this so we can revisit this PR for more ::Adjoint
method specializations in the future.
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.
Partly, yes :). During the relevant transformation pass, preserving behavior was my primary concern. And for some array types, the rewrite above was strictly necessary to preserve behavior. (For example, S + Adjoint(S)
for sparse matrix S
hits an AbstractArray
+
fallback yielding an Array
rather than the former S + adjoint(S)
's SparseMatrixCSC
. Hence the transformation S + adjoint(S)
-> S + collect(S')
rather than S + S'
, though S + S'
should work eventually.) And indeed, after the gross functionality is complete quite a bit of cleanup will be in order :). #25331 is my present breadcrumb for this particular issue.
base/linalg/generic.jl
Outdated
@@ -986,7 +986,7 @@ function ishermitian(A::AbstractMatrix) | |||
return false | |||
end | |||
for i = indsn, j = i:last(indsn) | |||
if A[i,j] != adjoint(A[j,i]) | |||
if A[i,j] != Adjoint(A[j,i]) |
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.
Why are you favoring the uppercase constructors in these cases?
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.
The simple answer is that this pull request presently represents an intermediate state which will change substantially on next push. Specifically, most uppercase calls should then disappear :).
base/number.jl
Outdated
first(x::Number) = x | ||
last(x::Number) = x | ||
copy(x::Number) = x # some code treats numbers as collection-like | ||
copy(x::Number) = x | ||
collect(x::Number) = x |
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.
This may be worth calling out and thinking through a bit more. I expected collect(1)
to return [1]
since numbers are iterable "collections". In fact, right now collect(1) = fill(1)
(that is, a zero-d array).
I get why this change is needed, but I'm not entirely sold that it's the right answer.
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.
Agreed, I'm not entirely sold on it either :).
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'm also -1 on this definition.
ab71b79
to
e2faff7
Compare
(Marking triage for |
f1b9de8
to
375d957
Compare
From discussion on triage, there was some consensus to go with the following:
|
Rebased and completed rewrites to |
a6ea332
to
e842f27
Compare
3663550
to
27aaaf3
Compare
Added a commit lowering |
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.
LGTM! Very nice work.
@@ -122,7 +122,7 @@ mutable struct Graph | |||
adjdict[p0][p1] = j1 | |||
|
|||
bm = trues(spp[p1], spp[p0]) | |||
bmt = adjoint(bm) | |||
bmt = trues(spp[p0], spp[p1]) |
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.
Wow, your re-write here is way better. Bravo for not just zoning out (like I did when this change caught me off guard).
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.
One small step towards atonement for the horde of ghastly transformations I introduced in #24969 😉.
Rebased out the last commit with #25418 in. With Matt and CI approving, absent objections or requests for time I plan to merge these changes Sunday evening PT or later. Best! :) |
Rebased out conflict. Absent objections I plan to merge these changes once CI clears. Best! |
(AV and FreeBSD failures are timeouts without apparent issue prior.) |
Thanks all! :) |
This pull request is the next step in the JuliaLang/LinearAlgebra.jl#57 series after #24969, #25083, #25125, #25148, and #25217. Specifically, this pull request makes
adjoint
/transpose
uniformly lazy and extendscollect
copy
for materialization.Remaining tasks, for this or a downstream pull request:
Transform mostdone hereAdjoint
/Transpose
calls toadjoint
/transpose
.Lowerdone here'
directly toadjoint
(thereby fixing method overwrites during build).Adjoint
/Transpose
behave like proper constructors.Let's see what CI says. Thanks and best!