Skip to content

Feat/reshape: Add evaluate_shape to reshape.rs to allow for variable#148

Open
orangmuda wants to merge 1 commit into
masterfrom
rework-reshape
Open

Feat/reshape: Add evaluate_shape to reshape.rs to allow for variable#148
orangmuda wants to merge 1 commit into
masterfrom
rework-reshape

Conversation

@orangmuda

@orangmuda orangmuda commented Oct 19, 2021

Copy link
Copy Markdown

…reshape inputs. Update examples to use isize and variable batch_size.

What does this PR accomplish?

  • 🦚 Feature

Changes proposed by this PR:

Notes to reviewer:

📜 Checklist

  • Test coverage is excellent
  • All unit tests pass
  • The juice-examples run just fine
  • Documentation is thorough, extensive and explicit

…reshape inputs. Update examples to use isize and variable batch_size.
@drahnr

drahnr commented Oct 19, 2021

Copy link
Copy Markdown
Member

Hey @oxctdev :) thanks for opening this PR. The commit seems to be in need of some additional attention, I'll add comments inline.

Comment on lines +226 to +227
dbg!(&network);
panic!("End");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray dbg statement, this should not end up in master, not even in a test.


fn main() {
env_logger::builder().filter_level(log::LevelFilter::Info).init();
env_logger::builder().filter_level(log::LevelFilter::Trace).init();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Info was picked intentionally to not flood first time users with lot's of overwhelming (=useless) info.

Comment thread juice/Cargo.toml
num = "0.4"
capnp = "0.14"
timeit = "0.1"
anyhow = "1.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a library, thiserror is the preferred approach. Anyhow is for applications.

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")),
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@drahnr

drahnr commented Sep 12, 2022

Copy link
Copy Markdown
Member

Gentle ping?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants