@Override public void write(DataOutputStream out) throws IOException { if (length() >= Integer.MAX_VALUE) throw new IllegalArgumentException("Length of data buffer can not be >= Integer.MAX_VALUE on output"); // log.info("Saving dType: {}", dataType().name()); out.writeUTF(allocationMode.name()); out.writeLong(length()); out.writeUTF(dataType().name()); if (dataType() == Type.DOUBLE) { for (int i = 0; i < length(); i++) out.writeDouble(getDouble(i)); } else if (dataType() == Type.LONG) { for (int i = 0; i < length(); i++) out.writeLong(getLong(i)); } else if (dataType() == Type.INT) { for (int i = 0; i < length(); i++) out.writeInt(getInt(i)); } else if (dataType() == Type.HALF) { for (int i = 0; i < length(); i++) { out.writeShort(getShort(i)); } } else { for (int i = 0; i < length(); i++) { out.writeFloat(getFloat(i)); } } }
@Override public String toString() { StringBuilder ret = new StringBuilder(); ret.append("["); int max; if (TO_STRING_MAX >= 0) { max = (int)Math.min(length(), TO_STRING_MAX); } else { max = (int)Math.min(length(), Integer.MAX_VALUE); } for (int i = 0; i < max; i++) { ret.append(getNumber(i)); if (i < max - 1) ret.append(","); } if(max < length()){ ret.append(",<") .append(length()-max) .append(" more elements>"); } ret.append("]"); return ret.toString(); }
@Override public void setData(double[] data) { for (int i = 0; i < data.length; i++) { put(i, data[i]); } }
@Override public byte[] asBytes() { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); if (dataType() == Type.DOUBLE) { for (int i = 0; i < length(); i++) { try { dos.writeDouble(getDouble(i)); } catch (IOException e) { e.printStackTrace(); } } } else { for (int i = 0; i < length(); i++) { try { dos.writeFloat(getFloat(i)); } catch (IOException e) { e.printStackTrace(); } } } return bos.toByteArray(); }
private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); write(out); }
@Override public int[] asInt() { if (length >= Integer.MAX_VALUE) throw new IllegalArgumentException("Unable to create array of length " + length); int[] ret = new int[(int) length]; for (int i = 0; i < length; i++) ret[i] = getInt(i); return ret; }
@Override public float[] asFloat() { if (length >= Integer.MAX_VALUE) throw new IllegalArgumentException("Unable to create array of length " + length); float[] ret = new float[(int) length]; for (int i = 0; i < length; i++) ret[i] = getFloat(i); return ret; }
@Override public double[] asDouble() { if (length >= Integer.MAX_VALUE) throw new IllegalArgumentException("Unable to create array of length " + length); double[] ret = new double[(int) length]; for (int i = 0; i < length; i++) ret[i] = getDouble(i); return ret; }
@Override public void copyAtStride(DataBuffer buf, long n, long stride, long yStride, long offset, long yOffset) { if (dataType() == Type.FLOAT) { for (int i = 0; i < n; i++) { put(offset + i * stride, buf.getFloat(yOffset + i * yStride)); } } else { for (int i = 0; i < n; i++) { put(offset + i * stride, buf.getDouble(yOffset + i * yStride)); } } }
@Override public Number getNumber(long i) { allocator.synchronizeHostData(this); return super.getNumber(i); }
for (int e = 0; e < op.getRealArguments().size(); e++) { idx = realPos + (i * op.maxRealArguments()); sPtr.put(idx + e, BaseDataBuffer.fromFloat(op.getRealArguments().get(e).floatValue()));
@Override public byte[] asBytes() { allocator.synchronizeHostData(this); return super.asBytes(); }
@Override public double[] asDouble() { allocator.synchronizeHostData(this); return super.asDouble(); }
@Override public float[] asFloat() { allocator.synchronizeHostData(this); return super.asFloat(); }