ocl icon indicating copy to clipboard operation
ocl copied to clipboard

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

Open charles-r-earp opened this issue 4 years ago • 0 comments

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

charles-r-earp avatar Jul 10 '20 01:07 charles-r-earp