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
I don't think they are just implementation detail. Generic Array trait bounds help with validating the input type statically at compile time. They also help establish what is expected input when a given set of functions are used inside a generic function. The other disadvantage of removing all these trait checks is ArrayFire functions (upstream library) calls will throw a runtime error when invalid inputs are passed to them.
About automatic trait bound addition ?
I am not sure if that is something possible in rust, but I will look into it. I think a comprehensive trait impls for a limited set of combinations should solve the problem for some of these traits. But such brute trick won't help for all cases.
Trait Aliases
That is not a stable feature in rust yet and more importantly it is impractical to define trait aliases to all combinations of traits for user defined generic functions - there is no practical way to know what functions constitute a given user defined generic function.
Generic trait implementation (e.g. Convertable), not implementation for f32, f64 and other types individually.
I don't understand the question. Convertable is one trait that is internal detail but it had to exposed to enable writing generic functions on user end. Ideally and in almost all cases, users are not meant to implement this trait over any other user defined type.
I understand writing a generic function with so many trait bounds takes time to figure out the correct bound check. Let me see what can be done to improve the situation.
Question 2. was about implementation of Convertable using generics, not macros for each types. I wrote that and send PR. I don't know so much about type safety in arrayfire and some trait bounds may not be enough for safety, but I hope you'll get the idea.
I was about to add a modified example of the code stub from your original description to show why I think such usage of traits: Convertable and ImplicitPromote for Array<T> is incorrect.
None of those two traits are meant to be used for defining bounds against Array itself, rather they are for the underlying type of Array.
About trait like alias(I understand they don't need nightly): I am still contemplating as to how helpful such aliases are in general. Also, associated types like UnaryOutType are not meant to be used in such a fashion as T: HasAfEnum<UnaryOutType = T> as that would further restrict the type of Arrays that can be provided as input to function. For example, only types whose UnaryOutType is same as Self will be allowed to this function which is not the intended use case of this or other associated types defined under HasAfEnum trait.
The reason I used a macro to impl Convertable is to restrict the implementation of that traits to the base types of Array generic and not do it for Array<T>.
I have seen the PR and will take a closer look at the generic changes and leave further feedback if required. Thank you for using and contributing to arrayfire-rust!
I think the recent change of Convertible has an unexpected issue with different kind of function. May be it should be reverted but I am not sure yet. Will post an update soon. Incorrect example code was used. please ignore.
Leaving this as a place holder issue to improve generic programming using rust wrapper. Any future user, kindly showcase your use case if facing issues. We will try to improve as more features of traits in rust stabilize.
Note, I have addedHasAfEnum trait bound to most of the other traits to avoid specification of HasAfEnum bound explicitly again in any of user code. Hopefully, that helps some cases.
Activity
9prady9 commentedon Nov 30, 2020
I don't think they are just implementation detail. Generic Array trait bounds help with validating the input type statically at compile time. They also help establish what is expected input when a given set of functions are used inside a generic function. The other disadvantage of removing all these trait checks is ArrayFire functions (upstream library) calls will throw a runtime error when invalid inputs are passed to them.
I am not sure if that is something possible in rust, but I will look into it. I think a comprehensive trait impls for a limited set of combinations should solve the problem for some of these traits. But such brute trick won't help for all cases.
That is not a stable feature in rust yet and more importantly it is impractical to define trait aliases to all combinations of traits for user defined generic functions - there is no practical way to know what functions constitute a given user defined generic function.
I don't understand the question.
Convertableis one trait that is internal detail but it had to exposed to enable writing generic functions on user end. Ideally and in almost all cases, users are not meant to implement this trait over any other user defined type.I understand writing a generic function with so many trait bounds takes time to figure out the correct bound check. Let me see what can be done to improve the situation.
atomicky commentedon Nov 30, 2020
Thanks for your reply 😃
I'm sorry, I didn't explain enough. You're right, traits are NOT implementation detail. Compile-time errors are much better than runtime errors.
However, I think
AfFloatbelow will help users.I wish
af::FloatingPointoraf::RealFloatingwould be used like this. Can we do this?atomicky commentedon Nov 30, 2020
Question 2. was about implementation of
Convertableusing generics, not macros for each types. I wrote that and send PR. I don't know so much about type safety inarrayfireand some trait bounds may not be enough for safety, but I hope you'll get the idea.9prady9 commentedon Nov 30, 2020
I was about to add a modified example of the code stub from your original description to show why I think such usage of traits:
ConvertableandImplicitPromoteforArray<T>is incorrect.UnaryOutTypeare not meant to be used in such a fashion asT: HasAfEnum<UnaryOutType = T>as that would further restrict the type of Arrays that can be provided as input to function. For example, only types whose UnaryOutType is same asSelfwill be allowed to this function which is not the intended use case of this or other associated types defined underHasAfEnumtrait.Convertableis to restrict the implementation of that traits to the base types of Array generic and not do it forArray<T>.I have seen the PR and will take a closer look at the generic changes and leave further feedback if required. Thank you for using and contributing to arrayfire-rust!
9prady9 commentedon Dec 7, 2020
#265 (comment)
9prady9 commentedon Dec 8, 2020
I think the recent change ofIncorrect example code was used. please ignore.Convertiblehas an unexpected issue with different kind of function. May be it should be reverted but I am not sure yet. Will post an update soon.9prady9 commentedon Dec 9, 2020
Leaving this as a place holder issue to improve generic programming using rust wrapper. Any future user, kindly showcase your use case if facing issues. We will try to improve as more features of traits in rust stabilize.
Note, I have added
HasAfEnumtrait bound to most of the other traits to avoid specification ofHasAfEnumbound explicitly again in any of user code. Hopefully, that helps some cases.