Skip to content
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

Merged
merged 7 commits into from
Jan 9, 2018

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Jan 3, 2018

This pull request is the next step in the #5332 series after #24969, #25083, #25125, #25148, and #25217. Specifically, this pull request makes adjoint/transpose uniformly lazy and extends collect copy for materialization.

Remaining tasks, for this or a downstream pull request:

  1. Transform most Adjoint/Transpose calls to adjoint/transpose. done here
  2. Lower ' directly to adjoint (thereby fixing method overwrites during build). done here
  3. Make Adjoint/Transpose behave like proper constructors.

Let's see what CI says. Thanks and best!

@@ -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
Copy link
Sponsor Member

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 collecting 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.

Copy link
Member Author

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.

@@ -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])
Copy link
Sponsor Member

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?

Copy link
Member Author

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
Copy link
Sponsor Member

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.

Copy link
Member Author

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 :).

Copy link
Sponsor Member

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.

@Sacha0 Sacha0 force-pushed the lowercase branch 3 times, most recently from ab71b79 to e2faff7 Compare January 4, 2018 05:36
@Sacha0 Sacha0 added the status:triage This should be discussed on a triage call label Jan 4, 2018
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 4, 2018

(Marking triage for collect discussion.)

@Sacha0 Sacha0 mentioned this pull request Jan 4, 2018
@Sacha0 Sacha0 force-pushed the lowercase branch 2 times, most recently from f1b9de8 to 375d957 Compare January 4, 2018 19:09
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 4, 2018

From discussion on triage, there was some consensus to go with the following:

  • deprecate collect name:
    • use Array constructor instead in some cases (usually for realizing lazy operations like iterators)
    • use copy in other cases (probably most of these)
      • define copy(x::AbstractArray) = Array(x) (or some equivalent like copyto!(similar(Array, x), x))
      • encourage specializations of copy when there's a better definition which can fold away extra wrappers or, failing that, can return an object of the same type

@Sacha0 Sacha0 removed the status:triage This should be discussed on a triage call label Jan 5, 2018
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 5, 2018

Rebased and completed rewrites to adjoint/transpose in base, test, and stdlib. Passing sparse, linalg, and stdlib test suites locally. So this pull request should be in shape after a sweep to replace collect methods/calls with copy as per triage. Best!

@Sacha0 Sacha0 force-pushed the lowercase branch 2 times, most recently from a6ea332 to e842f27 Compare January 5, 2018 20:54
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 5, 2018

Rebased, squashed out all intermediate commits in the adjoint/transpose lazification process, and added a commit transforming collect to copy as per triage. The last commit is #25418, which I will drop once #25418 merges. Passed all impacted test suites locally. Best!

@Sacha0 Sacha0 force-pushed the lowercase branch 2 times, most recently from 3663550 to 27aaaf3 Compare January 6, 2018 00:12
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 6, 2018

Added a commit lowering ' directly to adjoint and further cleaned up the commit history; the lowering change incidentally fixes the method overwrite warning during build mentioned in #25212. I plan to make the Adjoint/Transpose constructor changes in a separate pull request. So this pull request should now be in shape. Best!

@Sacha0 Sacha0 changed the title [WIP] adjoint/transpose transcend material concerns adjoint/transpose transcend material concerns Jan 6, 2018
Copy link
Sponsor Member

@mbauman mbauman left a 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])
Copy link
Sponsor Member

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).

Copy link
Member Author

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 😉.

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 6, 2018

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! :)

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 8, 2018

Rebased out conflict. Absent objections I plan to merge these changes once CI clears. Best!

@Sacha0
Copy link
Member Author

Sacha0 commented Jan 9, 2018

(AV and FreeBSD failures are timeouts without apparent issue prior.)

@Sacha0 Sacha0 merged commit 09f7213 into JuliaLang:master Jan 9, 2018
@Sacha0 Sacha0 deleted the lowercase branch January 9, 2018 01:31
@Sacha0
Copy link
Member Author

Sacha0 commented Jan 9, 2018

Thanks all! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants