nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/indexing/Indices.java
public static long[] offsets(long[] shape, INDArrayIndex... indices) {
        //offset of zero for every new axes
        long[] ret = new long[shape.length];

        if (indices.length == shape.length) {
            for (int i = 0; i < indices.length; i++) {
                if (indices[i] instanceof NDArrayIndexEmpty)
                    ret[i] = 0;
                else {
                    ret[i] = indices[i].offset();
                }

            }

            if (ret.length == 1) {
                ret = new long[] {ret[0], 0};
            }
        }

        else {
            int numPoints = NDArrayIndex.numPoints(indices);
            if (numPoints > 0) {
                List<Long> nonZeros = new ArrayList<>();
                for (int i = 0; i < indices.length; i++)
                    if (indices[i].offset() > 0)
                        nonZeros.add(indices[i].offset());
                if (nonZeros.size() > shape.length)
                    throw new IllegalStateException("Non zeros greater than shape unable to continue");
                else {
                    //push all zeros to the back
                    for (int i = 0; i < nonZeros.size(); i++)
                        ret[i] = nonZeros.get(i);
                }
            } else {
                int shapeIndex = 0;
                for (int i = 0; i < indices.length; i++) {
                    if (indices[i] instanceof NDArrayIndexEmpty)
                        ret[i] = 0;
                    else {
                        ret[i] = indices[shapeIndex++].offset();
                    }

                }
            }


            if (ret.length == 1) {
                ret = new long[] {ret[0], 0};
            }
        }



        return ret;
    }
public static long[] offsets(long[] shape, INDArrayIndex... indices) {
        //offset of zero for every new axes
        long[] ret = new long[shape.length];

        if (indices.length == shape.length) {
            for (int i = 0; i < indices.length; i++) {
                if (indices[i] instanceof NDArrayIndexEmpty)
                    ret[i] = 0;
                else {
                    ret[i] = indices[i].offset();
                }

            }

            if (ret.length == 1) {
                ret = new long[] {ret[0], 0};
            }
        }

        else {
            int numPoints = NDArrayIndex.numPoints(indices);
            if (numPoints > 0) {
                List<Long> nonZeros = new ArrayList<>();
                for (int i = 0; i < indices.length; i++)
                    if (indices[i].offset() > 0)
                        nonZeros.add(indices[i].offset());
                if (nonZeros.size() > shape.length)
                    throw new IllegalStateException("Non zeros greater than shape unable to continue");
                else {
                    //push all zeros to the back
                    for (int i = 0; i < nonZeros.size(); i++)
                        ret[i] = nonZeros.get(i);
                }
            } else {
                int shapeIndex = 0;
                for (int i = 0; i < indices.length; i++) {
                    if (indices[i] instanceof NDArrayIndexEmpty)
                        ret[i] = 0;
                    else {
                        ret[i] = indices[shapeIndex++].offset();
                    }

                }
            }


            if (ret.length == 1) {
                ret = new long[] {ret[0], 0};
            }
        }



        return ret;
    }
The offsets (begin index) for each index

@param indices the indices
@return the offsets for the given set of indices