Add Support for NDArrays with Zero elements#8621
Merged
danking merged 10 commits intohail-is:masterfrom Apr 28, 2020
Merged
Conversation
…l (may restore correct version in future)
1fe3d69 to
b6abd99
Compare
Contributor
Author
|
Alright, adjusted this to also make sure we don't pass a 0 into |
patrick-schultz
previously requested changes
Apr 28, 2020
Member
patrick-schultz
left a comment
There was a problem hiding this comment.
Nice! Just a couple small things.
| (hypercube.reshape((5, 7, 9, 3)).reshape((7, 9, 3, 5)), np_hypercube.reshape((7, 9, 3, 5))), | ||
| (hypercube.reshape(hl.tuple([5, 7, 9, 3])), np_hypercube.reshape((5, 7, 9, 3))) | ||
| (hypercube.reshape(hl.tuple([5, 7, 9, 3])), np_hypercube.reshape((5, 7, 9, 3))), | ||
| (shape_zero.reshape((0, 5)), np_shape_zero.reshape((0, 5))) |
Member
There was a problem hiding this comment.
Can we add a case shape_zero.reshape((-1, 5)), and also assert an error is thrown in shape_zero.reshape((0, -1))?
| Code(newShapeVars.zip(requestedShape).map { case (variable, shapeElement) => | ||
| variable := (shapeElement ceq -1L).mux(quotient, shapeElement) | ||
| }) | ||
| (runningProduct ceq 0L).mux( |
Member
There was a problem hiding this comment.
I think the logic here could be cleaned up a bit. How about
Code(
hasNegativeOne.mux(
(runningProduct ceq 0) || (numElements % runningProduct) > 0L,
numElements cne runningProduct
).orEmpty(Code._fatal[Unit]("Can't reshape since requested shape is incompatible with number of elements")),
quotient := (runningProduct ceq 0).mux(0, numElements / runningProduct),
Code(newShapeVars.zip(requestedShape).map { case (variable, shapeElement) =>
variable := (shapeElement ceq -1L).mux(quotient, shapeElement)
})
patrick-schultz
approved these changes
Apr 28, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR: