tch-rs icon indicating copy to clipboard operation
tch-rs copied to clipboard

Revise TryFrom impls and make ndarray optional

Open jerry73204 opened this issue 4 years ago • 2 comments

TryFrom now receives a referenced type instead of owned type. The move is unnecessary because it always copies the data.

TryInto impls are removed in flavor of TryFrom. That's because TryFrom implies TryInto, but it does not in vice versa.

The ndarray crate becomes an optional but enabled by default feature to avoid bloating. It helps reducing compiling time for those who does not need this feature.

jerry73204 avatar Dec 07 '20 22:12 jerry73204

BTW, I noticed the inconsistency of TryFrom<Vec<T>> and From<&[T]>. The latter does not follow the guideline that From<_> should not fail.

Also. regarding to #281, we have lots of From<T> for Tensor that could panic. However, moving to TryFrom is a breaking change. How do you think @LaurentMazare?

jerry73204 avatar Dec 07 '20 23:12 jerry73204

I rebase the patch and upgrade ndarray to 0.14. To recap, the PR made following changes:

  • Replace TryInto to TryFrom as suggested by std doc
  • ndarray becomes an optional but enabled by default cargo feature, to reduce bloating
  • Update to 0.14

The only breaking change is ndarray version update to 0.14.

jerry73204 avatar Jan 14 '21 04:01 jerry73204