Feat/reshape: Add evaluate_shape to reshape.rs to allow for variable#148
Open
orangmuda wants to merge 1 commit into
Open
Feat/reshape: Add evaluate_shape to reshape.rs to allow for variable#148orangmuda wants to merge 1 commit into
orangmuda wants to merge 1 commit into
Conversation
…reshape inputs. Update examples to use isize and variable batch_size.
Member
|
Hey @oxctdev :) thanks for opening this PR. The commit seems to be in need of some additional attention, I'll add comments inline. |
drahnr
reviewed
Oct 19, 2021
Comment on lines
+226
to
+227
| dbg!(&network); | ||
| panic!("End"); |
Member
There was a problem hiding this comment.
Stray dbg statement, this should not end up in master, not even in a test.
drahnr
reviewed
Oct 19, 2021
|
|
||
| fn main() { | ||
| env_logger::builder().filter_level(log::LevelFilter::Info).init(); | ||
| env_logger::builder().filter_level(log::LevelFilter::Trace).init(); |
Member
There was a problem hiding this comment.
Info was picked intentionally to not flood first time users with lot's of overwhelming (=useless) info.
drahnr
reviewed
Oct 19, 2021
| num = "0.4" | ||
| capnp = "0.14" | ||
| timeit = "0.1" | ||
| anyhow = "1.0" |
Member
There was a problem hiding this comment.
Since this is a library, thiserror is the preferred approach. Anyhow is for applications.
drahnr
reviewed
Oct 19, 2021
Comment on lines
+40
to
71
| fn evaluate_shape(&self, input_shape: &TensorDesc) -> Result<Vec<usize>> { | ||
| dbg!(&self.shape); | ||
| dbg!(input_shape); | ||
| let unknown_dimensions: usize = self.shape.iter().filter(|x| **x == -1).count(); | ||
| let invalid_dimensions: usize = self.shape.iter().filter(|x| **x < -1).count(); | ||
| if invalid_dimensions > 0 { | ||
| return Err(anyhow!("Invalid elements provided to Reshape")) | ||
| } | ||
| return match unknown_dimensions { | ||
| 0 => Ok(self.shape.clone().into_iter().map(|x| x as usize).collect()), | ||
| 1 => { | ||
| let total_prior_elements: usize = input_shape.iter().product(); | ||
| let known_elements: usize = self.shape.iter().filter(|x| **x > -1).product::<isize>() as usize; | ||
| dbg!(total_prior_elements); | ||
| dbg!(known_elements); | ||
| if total_prior_elements != (total_prior_elements / known_elements * known_elements) { | ||
| Err(anyhow!( | ||
| "Dimensions {:?} do not cleanly reshape into {:?}", | ||
| input_shape, self.shape | ||
| )) | ||
| } else { | ||
| let unknown_element: usize = total_prior_elements / known_elements; | ||
| Ok(self.shape | ||
| .iter() | ||
| .map(|x| if *x == -1 { unknown_element } else { *x as usize }) | ||
| .collect()) | ||
| } | ||
| } | ||
| _ => Err(anyhow!("More than 2 unknown elements provided to Reshape")), | ||
| } | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Is in need of bunch of tests :) and also has stray dbg! statements and requires some love for the Err types (or the lack of those).
Member
|
Gentle ping? |
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.
…reshape inputs. Update examples to use isize and variable batch_size.
What does this PR accomplish?
Changes proposed by this PR:
Notes to reviewer:
📜 Checklist
juice-examplesrun just fine