Closed HammerBu closed 3 years ago
@HammerBu Sorry about the delay, I have been on leave and then sick for past few weeks.
When writing generic functions, you need to add certain bounds for user defined functions based on the set of functions that are used from arrayfire crate so that all trait bounds required by this set is satisfied by the user defined generic function. This is true in general for any rust generic function.
In your case, you can look at the imax_all documentation to see the bounds. The error you showed itself also very clearly indicates the trait bound required. For you reference, given below is the version of GetMax
with trait bounds added.
fn GetMax<T: HasAfEnum>(a: &Array<T>)
where
T: HasAfEnum,
<<T as HasAfEnum>::InType as HasAfEnum>::BaseType: HasAfEnum + Fromf64
{
let v_max = imax_all(&a).0;
println!("Max value: {:?}", v_max);
}
Closing as the issue has been addressed. If you have any follow up questions, feel free to post them on slack channel too.
imax_all works well in main function.
output:
However, failed when use typed function
error:
What should i do to use imax_all in the function for different types array(u8, f16, f32)