NumSharp
NumSharp copied to clipboard
Mixing indices and slices in NDArray[...]
Is it possible to suppor mixed index/ slice? This is what numpy doing:

Currently, it doesn't support:

label[i][Slice.Index(yind), Slice.Index(xind), Slice.Index(iou_mast), new Slice(0, 4)] = bbox_xywh;
or
label[i][$"{yind}, {xind}, {iou_mast}, 0:4"] = bbox_xywh;
Btw: we could try implicitly convert from int to Slice.Index(int)
Worth mentioning that using a string inside a loop or O(n) will affect performance. Regex parsing is not lightning fast.
The iou_mask is NDArray.

It means we use different ways in different dimension to select elements.
One approach my idea is:
Define a IIndex interface, NDArray and Slice implement IIndex.
update
NDArray this[params IIndex[] selectors]
{
get; set;
}
Too messy, plus it won't solve your problem.. you can't implement implicit cast from int to IIndex.
Having index nd[int, int, NDArray, Slice] doesn't make sense. Our algorithm accepts either only slices or only ints.
nd[NDArray[]] is not for Indexing, it is for Masking.
Right now use Slice.Index, in the future I'll implement implicit castings to Slice.
We might have to extend the slicing algorithm to accept a mask (i.e. Slice.Mask(boolean_array)). He is porting Python code so it seems Python allows mixing of indices and masks.
Masking has a complete separate algorithm from slicing. In fact they don't have anything in common (function-wise).
Not only for masking, but also for any 1d array. We don’t have to have int to IIndex implicitly, we can use np.array(1) as alternative.
The goal is having people can use 1d or Slice, Scalar to select and mask elements in appropriate dimensions.
@henon This situation doesn't work:
iou_mask is NDArray, yind and xind are int:


I know, @Nucs is removing the int[] indexer in favor of an object[] indexer so that implicit conversion operators don't get in the way and we can reliably forward the different use cases into the right implementatons ( slicing if no NDarrays are part of the params and index extraction/masking otherwise)
@Oceania2018 Please verify if it works on master branch.