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

Return a value from with #34

Merged
merged 2 commits into from
Dec 29, 2020
Merged

Return a value from with #34

merged 2 commits into from
Dec 29, 2020

Conversation

emilk
Copy link
Contributor

@emilk emilk commented Dec 25, 2020

Thanks for a very cool library! I hope it is OK that I come with an unsolicited PR.

I changed the entry with function to return the value of the FnOnce it encapsulates. This is an ergonomic win as it allows us to return a value from a with-scope like so:

let nd_array = autograd::with(|g| {
    let tensor = ...
    tensor.eval(&[])
});

I demonstrate its use in fn test_deconv.

@@ -481,11 +481,11 @@ fn test_deconv() {
)
.unwrap();

crate::with::<f32, _>(|s| {
let out_val = crate::with(|s: &mut crate::Graph<f32>| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

crate::with::<f32, _> no longer compiles (this PR introduces a slight breaking change), so this either needed to be changed to crate::with::<f32, _, _>, or changed to take an explicit argument (and I chose the latter).

@raskr
Copy link
Owner

raskr commented Dec 26, 2020

Thank you for your proposal!

This is an ergonomic win as it allows us to return a value from a with-scope

Yes I think so too, but as you mentioned, this is a breaking change. How about introducing it as a new function (e.g. ag::run) during v1.x ?

@emilk
Copy link
Contributor Author

emilk commented Dec 28, 2020

A new run method had been added, keeping the old with as it were. Would you like me to update all examples to use the new run instead, or should we hold off on that for a bit?

@raskr
Copy link
Owner

raskr commented Dec 29, 2020

@emilk Thank you for the fix!

Would you like me to update all examples to use the new run instead, or should we hold off on that for a bit?

I choose the latter to avoid confusion, and I think the doc of with is explaining about the new function well enough 👍

@raskr raskr merged commit cdd82ab into raskr:master Dec 29, 2020
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.

2 participants