static StridedSliceArgs mergeIndexes()

in tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/op/core/StridedSliceHelper.java [57:120]


  static StridedSliceArgs mergeIndexes(Index[] indices) {
    int[] begin = new int[indices.length];
    int[] end = new int[indices.length];
    int[] strides = new int[indices.length];
    long beginMask = 0;
    long endMask = 0;
    long ellipsisMask = 0;
    long newAxisMask = 0;
    long shrinkAxisMask = 0;

    for (int i = 0; i < indices.length; i++) {
      Index idx = indices[i];

      if (idx == null) {
        idx = Indices.all();
      }

      if (!idx.isStridedSlicingCompliant()) {
        throw new UnsupportedOperationException("Index " + idx + " is not supported for Tensors");
      }

      begin[i] = (int) idx.begin();
      if (begin[i] != idx.begin()) {
        throw new IllegalArgumentException(
            "Can't convert long begin value to int for index " + idx + ": Out of bounds");
      }

      end[i] = (int) idx.end();
      if (end[i] != idx.end()) {
        throw new IllegalArgumentException("Can't convert long end value to int for index " + idx + ": Out of bounds");
      }

      strides[i] = (int) idx.stride();
      if (strides[i] != idx.stride()) {
        throw new IllegalArgumentException(
            "Can't convert long stride value to int for index " + idx + ": Out of bounds");
      }

      if (idx.beginMask()) {
        beginMask |= 1L << i;
      }

      if (idx.endMask()) {
        endMask |= 1L << i;
      }

      if (idx.isEllipsis()) {
        if (ellipsisMask != 0) {
          throw new IllegalArgumentException("Can not have two ellipsis in a slice");
        }
        ellipsisMask |= 1L << i;
      }

      if (idx.isNewAxis()) {
        newAxisMask |= 1L << i;
      }

      if (idx.isPoint()) {
        shrinkAxisMask |= 1L << i;
      }
    }

    return new StridedSliceArgs(begin, end, strides, beginMask, endMask, ellipsisMask, newAxisMask, shrinkAxisMask);
  }