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

fix broadcast! where the destination is a structured matrix #20886

Merged
merged 1 commit into from
Mar 6, 2017

Conversation

Sacha0
Copy link
Member

@Sacha0 Sacha0 commented Mar 4, 2017

Due to an oversight in #19926, broadcast! where the destination is a structured matrix presently fails. This pull request fixes the preceding issue and adds tests to guard against regression.

Some of the tests are @test_broken for the following reason: While Diagonal setindex! (#11582) supports setting off-diagonal entries to zero (and similarly subtypes of AbstractTriangular provide analogous behavior), the other special matrix types (Bidiagonal, Tridiagonal, and SymTridiagonal) do not provide analogous behavior (they always throw, which I'm guessing was an oversight in #15092). That behavior is necessary for a given structured matrix type to function as a destination for AbstractArray broadcast!, hence the broken tests; I have a fix (separate PR) in the works for setindex! over Bidiagonal, Tridiagonal, and SymTridiagonal. Best!

@Sacha0 Sacha0 added bugfix This change fixes an existing bug sparse Sparse arrays labels Mar 4, 2017
@Sacha0 Sacha0 added this to the 0.6.x milestone Mar 4, 2017
@tkelman
Copy link
Contributor

tkelman commented Mar 4, 2017

#15902

wrong issue number?

Does the Symmetric wrapper type support setindex! ? If not, then SymTridiagonal probably shouldn't either.

@Sacha0
Copy link
Member Author

Sacha0 commented Mar 4, 2017

wrong issue number?

Good catch; OP updated.

Does the Symmetric wrapper type support setindex! ? If not, then SymTridiagonal probably shouldn't either.

Symmetric/Hermitian setindex! support assignment only to the diagonal (though I'm not certain why in principle?). On the other hand, SymTridiagonal setindex! supports assignment to the diagonal and also the sub and super diagonals. Making all the special matrix types' setindex! behavior consistent seems worthwhile. Thoughts? Thanks!

@ararslan
Copy link
Member

ararslan commented Mar 4, 2017

Symmetric/Hermitian setindex! support assignment only to the diagonal (though I'm not certain why in principle?)

This behavior was explicitly requested by @andreasnoack in #19228 (comment). The problem with assigning outside of the diagonal for symmetric matrices is that you're modifying two values at once. Only allowing assignment on the diagonal ensures that the behavior of setindex! is consistent in that it only modifies a single value.

@Sacha0
Copy link
Member Author

Sacha0 commented Mar 4, 2017

Much thanks for the pointer! Hm, that's tricky. On the one hand, not allowing setindex! off the diagonal evidently defeats generic programming. On the other hand, setindex! modifying two values might also be a generic programming issue. Are there examples where the modifies-two-values behavior causes problems in practice? Thanks!

@tkelman
Copy link
Contributor

tkelman commented Mar 4, 2017

A[1,2] = 1
Array(A)

would give different results for symmetric A vs non symmetric. For generic programming we could introduce a symmetric setter function that does the same thing on symmetric and non symmetric inputs.

@Sacha0
Copy link
Member Author

Sacha0 commented Mar 4, 2017

would give different results for symmetric A vs non symmetric.

One could argue that behavior is correct though, depending on how one interprets setindex!.

broadcast!(identity, asymtridiagional, anonsymtridiagonal) or equivalently asymtridiagonal .= anonsymtridiagonal with broadcast! dispatching to the AbstractArray code seems a strong example. (The result being unambiguously incorrect, independent of which of the possible results the operation produces.)

So SymTridiagonal setindex! supporting off-diagonal assignment seems like a bug then? (By default I will add a commit to the WIP mentioned above removing (fixing) that behavior.) Thanks!

@tkelman
Copy link
Contributor

tkelman commented Mar 4, 2017

No one has been arguing for any interpretation of setindex on a single entry changing multiple values, multiple people have argued (and written code for Symmetric) to enforce against that. SymTridiagonal is surely a bug/oversight that we should fix asap.

@Sacha0
Copy link
Member Author

Sacha0 commented Mar 4, 2017

No one has been arguing for any interpretation of setindex on a single entry changing multiple values, multiple people have argued (and written code for Symmetric) to enforce against that. SymTridiagonal is surely a bug/oversight that we should fix asap.

Cheers, sounds good, and shall do :). Thanks!

@tkelman
Copy link
Contributor

tkelman commented Mar 6, 2017

there are several broken tests that need switching over here

@Sacha0
Copy link
Member Author

Sacha0 commented Mar 6, 2017

Thanks all! (Ref. #20901 (comment).)

@Sacha0 Sacha0 deleted the bcbangstruc branch March 6, 2017 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants