@Override public double getDouble(int... indices) { int valIdx = reverseIndexes(indices); if (valIdx == -1) { return 0; } else { return values.getDouble(valIdx); } }
public DataBuffer shiftLeft(DataBuffer buffer, int from, int offset, long datalength) { for (int i = from; i < datalength; i++) { buffer.put(i - offset, buffer.getDouble(i)); } return buffer; }
@Override public double getDoubleUnsafe(long offset) { return data().getDouble(offset); }
/** * Returns a scalar (individual element) * of a scalar ndarray * * @return the individual item in this ndarray */ @Override public Object element() { if (!isScalar()) throw new IllegalStateException("Unable to getScalar the element of a non scalar"); long idx = linearIndex(0); return Nd4j.createDouble(data.getDouble(idx), data.getDouble(idx + 1)); }
@Override public void assign(long[] offsets, long[] strides, long n, DataBuffer... buffers) { if (offsets.length != strides.length || strides.length != buffers.length) throw new IllegalArgumentException( "Unable to assign buffers, please specify equal lengths strides, offsets, and buffers"); int count = 0; for (int i = 0; i < buffers.length; i++) { //note here that the final put will take care of the offset for (long j = offsets[i]; j < buffers[i].length(); j += strides[i]) { put(count++, buffers[i].getDouble(j)); } } if (count != n) throw new IllegalArgumentException("Strides and offsets didn't match up to length " + n); }
/** * Returns a scalar (individual element) * of a scalar ndarray * * @return the individual item in this ndarray */ @Override public Object element() { if (!isScalar()) throw new IllegalStateException("Unable to retrieve element from non scalar matrix"); if (data.dataType() == DataBuffer.Type.FLOAT) return data.getFloat(0); return data.getDouble(0); }
public static double getDouble(INDArray arr, long... indices) { long offset = getOffset(arr.shapeInfo(), indices); return arr.data().getDouble(offset); }
@Override public boolean equals(Object o) { // FIXME: this is BAD. it takes too long to work, and it breaks general equals contract if (o instanceof DataBuffer) { DataBuffer d = (DataBuffer) o; if (d.length() != length()) return false; for (int i = 0; i < length(); i++) { double eps = Math.abs(getDouble(i) - d.getDouble(i)); if (eps > 1e-12) return false; } } return true; }
@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)); } } }
/** * Get a double based on the array and given indices * * @param arr the array to retrieve the double from * @param indices the indices to iterate over * @return the double at the specified index */ public static double getDouble(INDArray arr, int[] indices) { long offset = getOffset(arr.shapeInfo(), ArrayUtil.toLongArray(indices)); return arr.data().getDouble(offset); }
@Override public void assign(DataBuffer data) { if (data.length() != length()) throw new IllegalArgumentException("Unable to assign buffer of length " + data.length() + " to this buffer of length " + length()); for (int i = 0; i < data.length(); i++) { put(i, data.getDouble(i)); } }
/** * Returns the double data * for this buffer. * If possible (the offset is 0 representing the whole buffer) * it will return a direct reference to the underlying array * @param buf the ndarray to get the data for * @return the double data for this buffer */ public static double[] getDoubleData(DataBuffer buf) { if (buf.allocationMode() == DataBuffer.AllocationMode.HEAP) return buf.asDouble(); else { double[] ret = new double[(int) buf.length()]; for (int i = 0; i < buf.length(); i++) ret[i] = buf.getDouble(i); return ret; } }
val.add(values.getDouble(i));
@Override public double getDouble(long i) { Nd4j.getCompressor().autoDecompress(this); if (i >= length()) { throw new IllegalArgumentException("Unable to get linear index >= " + length()); } autoProcessScalarCall(); if (i == 0) return data().getDouble(i); long[] dimensions = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); Shape.assertShapeLessThan(dimensions, shape()); return getDouble(dimensions); }
@Override public double getDouble(long i) { if (i >= length()) { throw new IllegalArgumentException("Unable to get linear index >= " + length()); } if (Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.DISABLED && Nd4j.getExecutioner().getProfilingMode() != OpExecutioner.ProfilingMode.SCOPE_PANIC) OpProfiler.getInstance().processScalarCall(); if (i == 0) return data().getDouble(i); long[] dimensions = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); Shape.assertShapeLessThan(dimensions, shape()); return getDouble(dimensions); }
/** * Converts the sparse ndarray into a dense one * @return a dense ndarray */ @Override public INDArray toDense() { // TODO support view conversion INDArray result = Nd4j.zeros(shape()); switch (data().dataType()) { case DOUBLE: for (int i = 0; i < length; i++) { int[] idx = getUnderlyingIndicesOf(i).asInt(); double value = values.getDouble(i); result.putScalar(idx, value); } break; case FLOAT: for (int i = 0; i < length; i++) { int[] idx = getUnderlyingIndicesOf(i).asInt(); float value = values.getFloat(i); result.putScalar(idx, value); } break; default: throw new UnsupportedOperationException(); } return result; }
@Override public double getDouble(long... indices) { autoProcessScalarCall(); Nd4j.getCompressor().autoDecompress(this); for (int i = 0; i < indices.length; i++) { if (indices[i] < 0) indices[i] += rank(); } if (indices.length == 1) { if (rank() == 1) return Shape.getDouble(this, indices[0]); else if (isRowVector()) return Shape.getDouble(this, 0, indices[0]); else if (isColumnVector()) return Shape.getDouble(this, indices[0], 0); else if (isScalar() && indices[0] == 0) return data().getDouble(0); else throw new IllegalStateException("Indexes length must be > 1 for non vectors and scalars"); } return Shape.getDouble(this, indices); }
/** * Returns the elements at the the specified indices * * @param indices the indices to get * @return the array with the specified elements */ @Override public double getDouble(int... indices) { autoProcessScalarCall(); Nd4j.getCompressor().autoDecompress(this); for (int i = 0; i < indices.length; i++) { if (indices[i] < 0) indices[i] += rank(); } if (indices.length == 1) { if (rank() == 1) return Shape.getDouble(this, indices[0]); else if (isRowVector()) return Shape.getDouble(this, 0, indices[0]); else if (isColumnVector()) return Shape.getDouble(this, indices[0], 0); else if (isScalar() && indices[0] == 0) return data().getDouble(0); else throw new IllegalStateException("Indexes length must be > 1 for non vectors and scalars"); } return Shape.getDouble(this, indices); }
jsonGenerator.writeArrayFieldStart("dataBuffer"); for (int i = 0; i < view.length(); i++) { jsonGenerator.writeNumber(view.getDouble(i));
for (int i = 0; i < ret.length(); i++) { ret.data().put(i, toConcat[currBuffer].data() .getDouble(toConcat[currBuffer].offset() + currBufferOffset++)); if (currBufferOffset >= toConcat[currBuffer].length()) { currBuffer++;