crop function

VARP crop(
  1. VARP images,
  2. VARP size,
  3. int axis,
  4. List<int> offset,
)

Crop images.

Args:

  • images: 4-D variable of NC4HW4 format.
  • size: A variable. It takes the shape of size as output cropped variable's shape while omits the values/format of size.
  • axis: A int indicating the dimention to crop. Must be >=2. All dimensions up to but excluding axis are preserved, while the dimensions including and trailing axis are cropped.
  • offset: A vector of int indicating the offsets. length(offset) must be >=1 and <=2. If length(offset) is 1, then all dimensions are offset by this amount.Otherwise, the number of offsets must equal the number of cropped axes in each dimension accordingly.

Returns:

  • The cropped 4-D variable of NC4HW4 format.

Implementation

VARP crop(VARP images, VARP size, int axis, List<int> offset) {
  final (offsetPtr, offsetSize) = offset.toNativeArrayI32();
  final rval = VARP.fromPointer(C.mnn_expr_Crop(images.ptr, size.ptr, axis, offsetPtr.cast(), offsetSize));
  calloc.free(offsetPtr);
  return rval;
}