-
-
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
there is no full #24147
there is no full #24147
Conversation
@@ -426,7 +426,7 @@ scale!(c::Number, A::Union{UpperTriangular,LowerTriangular}) = scale!(A,c) | |||
+(A::UnitLowerTriangular, B::LowerTriangular) = LowerTriangular(tril(A.data, -1) + B.data + I) | |||
+(A::UnitUpperTriangular, B::UnitUpperTriangular) = UpperTriangular(triu(A.data, 1) + triu(B.data, 1) + 2I) | |||
+(A::UnitLowerTriangular, B::UnitLowerTriangular) = LowerTriangular(tril(A.data, -1) + tril(B.data, -1) + 2I) | |||
+(A::AbstractTriangular, B::AbstractTriangular) = full(A) + full(B) | |||
+(A::AbstractTriangular, B::AbstractTriangular) = copy!(similar(parent(A)), A) + copy!(similar(parent(B)), B) |
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 definition could be simplified by widening only one of the arguments and then redispatching. That approach would likely be an improvement in any case.
base/linalg/triangular.jl
Outdated
@@ -436,15 +436,15 @@ scale!(c::Number, A::Union{UpperTriangular,LowerTriangular}) = scale!(A,c) | |||
-(A::UnitLowerTriangular, B::LowerTriangular) = LowerTriangular(tril(A.data, -1) - B.data + I) | |||
-(A::UnitUpperTriangular, B::UnitUpperTriangular) = UpperTriangular(triu(A.data, 1) - triu(B.data, 1)) | |||
-(A::UnitLowerTriangular, B::UnitLowerTriangular) = LowerTriangular(tril(A.data, -1) - tril(B.data, -1)) | |||
-(A::AbstractTriangular, B::AbstractTriangular) = full(A) - full(B) | |||
-(A::AbstractTriangular, B::AbstractTrianglar) = copy!(similar(parent(A)), A) - copy!(similar(parent(B)), B) |
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.
Likewise here, this definition could be simplified by widening only one of the arguments and then redispatching. That approach would likely be an improvement in any case.
Thanks |
Pleased that someone caught the reference! :D |
Thanks all! |
Sorry for the delay. Have had a bit of a backlog. I don't like this. A poorly named slightly ambiguously defined generic function is still better than repeated use of |
No worries re. the delay! :) Some abstraction over Till we have that abstraction in all its glory and splendour, I suggest we carry through #24137 (comment) (the Best! :) |
After #24137, #24138, and the long series of prior
full
disambiguations/rewrites, only thirteenfull
calls remain. All such calls are on[Unit](Upper|Lower)Triangular
/Symmetric
/Hermitian
matrices and unambiguously meancopy!(similar(parent(A)), A)
. A number of options for eliminating these calls follow below.This pull request implements the simplest, most conservative option: replace the remaining calls with
copy!(similar(parent(A)), A)
.Another option is to introduce the generic function discussed in #23270. #24148 provides a sketch of this option. (After some thought, that generic function has (in an abstract sense) the semantics of
widen
. So presently #24148 extendswiden
instead of introducing a new exported name.) But this approach seems heavy handed now: Thirteen calls tocopy!(similar(parent(A)), A)
in a specific context don't alone seem worth exporting a new generic name from Base (nor worth extending an existing Base export in a major way). The generic function in #23270/#24148 may find other uses, but playing with those other uses / carefully vetting behavior prior to introducing such functionality seems wise. And we can introduce such functionality after 1.0, but we can't change or remove it in the 1.x series if we inject it now.In any case,
copy!(similar(parent(A)), A)
isn't bad to write on the few occasions one needs to, is quite clear, and provides more opportunity for optimization than existing alternatives. So at this point I err on the (conservative) side of the approach in this pull request. If we really need a new name, we can introduce it later. Best!(Also note: In #24137 (comment) Andreas and I discuss fleshing out the (unexported)
full!(A::Union{[Unit](Upper|Lower)Triangular,Symmetric,Hermitian})
(which fillsA
's parent withA
's contents and returns the parent) and renaming it to better reflect is semantics (e.g. tofillparent!(A)
). Then one could write eithercopy!(similar(parent(A)), A)
orfillparent!(copy(A))
for this operation. And if it proves necessary, introducing an unexportedfilledparent(A)
or so would then be natural.)