Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Implement
at.eye
using existingOps
#1217base: main
Are you sure you want to change the base?
Implement
at.eye
using existingOps
#1217Changes from 21 commits
6617b69
34acf8f
f28cee4
10472ba
0ec6c10
bf445ab
8a9da62
1738058
5c2442b
e0b5d2e
a14303a
4c095b6
810f5d9
837ec91
2487597
2861abd
4ac63b3
af2dc7d
94ce70d
29991e3
b4d9b7e
4c2a622
b823eec
680179e
5ece747
741a73c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Do we need the last
set_subtensor
(i.e. that appears to fill with0
s if we've already usedzeros
? I think I might know why, but it would be nice to have only oneset_subtensor
.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 second
set_subtenor
is to prevent the diagonal from "wrapping around" the matrix in cases whenm > n
or whenk != 0
. This one-liner almost works:But it fails when
k < -n
ork > m
. In these cases I guess an error could be raised (why is the user asking for an offset greater than the width of the matrix?), but numpy returns the zero matrix for this case and I wanted to be consistent.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 way to match
numpy
and avoid the secondset_subtensor
would be to check the conditions where the zero matrix should be returned and use multiplication:But this was about 5µs slower than the two
set_subtensor
method when I ran%timeit
. Perhaps it's too cute?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.
Here's an implementation that uses scalars and
Composite
: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.
Before I forget, usingOnly applies wheninc_subtensor
withset_instead_of_inc=True
andignore_duplicates=True
might be faster.AdvancedIncSubtensor
is used, and it isn't 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.
We also need an issue for a rewrite that replaces scalar-only sub-graphs with
Composite
s.Done: #1225
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.
Sorry,
Switch
is quite literally the scalar version ofIfElse
—at least in terms of itsOp.c_code
implementation. If anything, we should make invocations ofifelse
returnSwitch
es when the arguments areScalarType
ed.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.
Here's the issue for
ifelse
: #1226.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.
Also, there's no scalar
Op
formax
andmin
?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.
Disregard, obviously this can be done using scalar
switch
.