Skip to content

Conversation

@ivarflakstad
Copy link
Member

Currently when we chain math with Result<Tensor> we have to write code like

(&(&(&x.powf(2.0)? * 3.0)? - &x * 4.0)? + 5.0)?

Given that we change all our methods to return the newtype TensorResult instead of Result<Tensor>, we could simply write

(x.powf(2.0) * 3.0 - x * 4.0 + 5.0).ok()?;

Where .ok() does TensorResult -> Result<Tensor>

The only unanswered question is what to do when we have two Err results.
My proposed solution is to simply aggregate them. Either via a new candle_core::Error enum type that wraps two, or by simply using Error::context (e1.context(e2)).

Ref #691

@EricLBuehler
Copy link
Member

Looks awesome.

The only unanswered question is what to do when we have two Err results.
My proposed solution is to simply aggregate them. Either via a new candle_core::Error enum type that wraps two, or by simply using Error::context (e1.context(e2)).

I think a new Error variant would be better, since the .context might not exactly match expectations.

Maybe this can tie in with some of our specialized backend work?

@sempervictus
Copy link

Big fan of explicit error-typing for maintainability and security reasons. Convenience tucks of types into others can later be abused for type-confusion logic by red team even though Rust itself is thought to be safe from such things.

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.

4 participants