cogciprocate / ocl

OpenCL for Rust
Other
721 stars 75 forks source link

Change Spatial Dims From<isize> to be consistent with other types. Impl FromPrimitive for SpatialDims. #187

Closed charles-r-earp closed 2 years ago

charles-r-earp commented 4 years ago

Currently SpatialDims::from(n: isize) would assert n > 0. This would disallow a 0 sized offset, and was only for isize, not for any other type. I changed this to call to_usize on signed types and a cast to usize for unsigned types. Also implemented FromPrimitive by mapping the ToPrimitive::to_usize implementation. I checked that the issue on my end was fixed by either forcing 0 as usize or the changes here.

To reproduce:

use ocl::SpatialDims;
SpatialDims::from(0 as i32); // fine 
SpatialDims::from(0 as usize); // fine
SpatialDims::from(0 as isize); // panics