public static long lengthOfBuffer(@NonNull long[] shape, @NonNull long[] stride){
        Preconditions.checkArgument(shape.length == stride.length, "Shape and strides must be same length: shape %s, stride %s",
                shape, stride);
        //Length is simply 1 + the buffer index of the last element
        long length = 1;
        for(int i=0; i<shape.length; i++ ){
            length += (shape[i]-1) * stride[i];
        }
        return length;
    }
public static long lengthOfBuffer ( @ NonNull long [ ] shape , @ NonNull long [ ] stride ) { Preconditions . checkArgument ( shape . length == stride . length , "Shape and strides must be same length: shape %s, stride %s" , shape , stride ) ; long length = 1 ; for ( int i = 0 ; i < shape . length ; i ++ ) { length += ( shape [ i ] - 1 ) * stride [ i ] ; } return length ; }
Calculate the length of the buffer required to store the given shape with the given strides

@param shape  Shape of the array
@param stride Strides
@return Length of the buffer