You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's currently impossible to implement for example From<[usize; 1]> into TensorDesc or Into<TensorDesc> for [usize; 1] since TensorDesc is a type alias for Vec. Vec, [usize; N], From, Into are defined outside of collenchyma, so it's not possible to define an impl inside. There are some solutions:
Wrap Vec completely with struct TensorDesc (Vec<usize>) and then proxy all required methods and interfaces to internal Vec. AFAIK there is no way to do it automatically, so that means tons of boilerplate if we want to support everything Vec supports.
Use From<_> for Vec<_> traits already defined in stdlib. There is one useful impl: From<&[T]> for Vec<T>. That's good, but &[T; N] doesn't automatically dereference into &[T] for function like fn new<D: Into<Vec<usize>>>(xs: T). It's possible to call new(&[2, 3][..]) or new([2, 3].as_ref()) but both are not pleasant.
Change function signature to new(xs: &[usize]) and pay price of redundant allocation if user already has Vec that could be reowned by TensorDesc.
Leave things as they are and require users to import IntoTensorDesc trait. Right now InfoTensorDesc::into is not consuming, so overhead is the same as for option 3. But I think it's possible to change it into a consuming version.
Actually overhead of Vec allocation is small and users aren't supposed to create millions of tensors per second, so I think it's better to go with options 3 or 4 for better code readability.
Using
Into<TensorDesc>
instead of aIntoTensorDesc
would be much more rust-y :)The text was updated successfully, but these errors were encountered: