/*
Reads n number of bytes and return as an array.

@param arr- Array of bytes to read from
@param n- Number of bytes to read
347012
function readBytes(arr, n) {
		var i, ret = [];
		for (i = 0; i < n; i += 1) {
			ret.push(arr.shift());
		}

		return ret;
	}
922672
public static String base64String(INDArray arr) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(bos);
        Nd4j.write(arr, dos);
        String base64 = Base64.encodeBase64String(bos.toByteArray());
        return base64;
    }
749684
public static byte[] add(byte[] arr, int n) {
        int index = binarySearch(arr, n);
        byte[] arr2 = new byte[arr.length + 4];
        System.arraycopy(arr, 0, arr2, 0, index);
        System.arraycopy(arr, index, arr2, index + 4, arr.length - index);
        Bytes.setInt(arr2, n, index);
        return arr2;
    }
527030
public static int[] sort(double[] arr) {
        int[] order = new int[arr.length];
        for (int i = 0; i < order.length; i++) {
            order[i] = i;
        }
        sort(arr, order);
        return order;
    }
914843
public static long bytesToLong(final byte[] arr) {
    long v = 0;
    for (int i = 0; i < 8; i++) {
      v |= (arr[i] & 0XFFL) << (i * 8);
    }
    return v;
  }
392731
function arrayToBuffer(arr) {
    if (arr instanceof ArrayBuffer) {
        return arr;
    }
    var ab = arr.buffer;
    if (arr.byteOffset === 0 && arr.byteLength === ab.byteLength) {
        return ab;
    }
    return arr.buffer.slice(arr.byteOffset, arr.byteOffset + arr.byteLength);
}
1323544
private int readCorner3(int numRows, int numColumns) {
    int currentByte = 0;
    if (readModule(numRows - 1, 0, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(numRows - 1, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 3, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 2, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(1, numColumns - 3, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(1, numColumns - 2, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(1, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    return currentByte;
  }
1350167
public static byte[] asArray(ByteBuffer byteBuffer) {
        ByteBuffer bb = ByteBufferUtil.clone(byteBuffer);
        byte[] bytes = new byte[bb.remaining()];
        bb.get(bytes);
        return bytes;
    }
906512
public int[] asArray() {
	    int arr[] = new int[size()];
	    OrdinalIterator iter = iterator();
	    
	    int ordinal = iter.nextOrdinal();
	    int i = 0;

	    while(ordinal != NO_MORE_ORDINALS) {
	        arr[i++] = ordinal;
	        ordinal = iter.nextOrdinal();
	    }
	    
	    return arr;
	}
374935
public static void writeArrayToDisk(INDArray arr, File toWrite) throws IOException {
        try (FileOutputStream os = new FileOutputStream(toWrite)) {
            FileChannel channel = os.getChannel();
            ByteBuffer buffer = BinarySerde.toByteBuffer(arr);
            channel.write(buffer);
        }
    }
43542
public void readArray(double[] dataR, double[] dataI) throws IOException {
        int size = dataR.length;
        if (size != dataI.length)
            throw new IllegalArgumentException(
                    "All arrays must be of the same size");
        for (int i = 0; i < size; ++i) {
            dataR[i] = getDouble();
            dataI[i] = getDouble();
        }
    }
1093941
public void readArray(long[] data) throws IOException {
        int size = data.length;
        for (int i = 0; i < size; ++i)
            data[i] = getLong();
    }
139937
public float[] get(float[] arr, int offset) {
        arr[offset+0] = (float)m00;
        arr[offset+1] = (float)m01;
        arr[offset+2] = (float)m02;
        arr[offset+3] = (float)m10;
        arr[offset+4] = (float)m11;
        arr[offset+5] = (float)m12;
        arr[offset+6] = (float)m20;
        arr[offset+7] = (float)m21;
        arr[offset+8] = (float)m22;
        return arr;
    }
1025169
public static void shuffle(int[] arr, Random rand) {
        int size = arr.length;
        for (int i = size; i > 1; i--) {
            int tmp = arr[i-1];
            int r = rand.nextInt(i);
            arr[i-1] = arr[r];
            arr[r] = tmp;
        }
    }
132471
private int readExpDigits(CharArr arr, int lim) throws IOException {
    while (--lim>=0) {
      int ch = getChar();
      if (ch>='0' && ch<='9') {
        arr.write(ch);
      } else {
        if (ch!=-1) start--; // back up
        return NUMBER;
      }
    }
    return BIGNUMBER;
  }
387339
def read(self, n=1):
        
        self.offset += n
        return self.data[self.offset - n:self.offset]
275348
public void readArray(int[] data) throws IOException {
        int size = data.length;
        for (int i = 0; i < size; ++i)
            data[i] = getInt();
    }