/** * Inplace compression of INDArray * * @param array */ @Override public void compressi(INDArray array) { // TODO: lift this restriction if (array.isView()) throw new UnsupportedOperationException("Impossible to apply inplace compression on View"); array.setData(compress(array.data())); array.markAsCompressed(true); }
/** * Convert an ndarray to an unsafe buffer * for use by aeron * @param arr the array to convert * @return the unsafebuffer representation of this array */ public static ByteBuffer toByteBuffer(INDArray arr) { //subset and get rid of 1 off non 1 element wise stride cases if (arr.isView()) arr = arr.dup(); if (!arr.isCompressed()) { ByteBuffer b3 = ByteBuffer.allocateDirect(byteBufferSizeFor(arr)).order(ByteOrder.nativeOrder()); doByteBufferPutUnCompressed(arr, b3, true); return b3; } //compressed array else { ByteBuffer b3 = ByteBuffer.allocateDirect(byteBufferSizeFor(arr)).order(ByteOrder.nativeOrder()); doByteBufferPutCompressed(arr, b3, true); return b3; } }
@Override public void serialize(INDArray array, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { if (array.isView()) { array = array.dup(); } double[] dArr = array.data().asDouble(); jsonGenerator.writeObject(dArr); } }
/** * Write an ndarray to the specified outputstream * * @param arr the array to write * @param dataOutputStream the data output stream to write to * @throws IOException */ public static void write(INDArray arr, DataOutputStream dataOutputStream) throws IOException { //BaseDataBuffer.write(...) doesn't know about strides etc, so dup (or equiv. strategy) is necessary here //Furthermore, because we only want to save the *actual* data for a view (not the full data), the shape info // (mainly strides, offset, element-wise stride) may be different in the duped array vs. the view array if (arr.isView()) arr = arr.dup(); arr.shapeInfoDataBuffer().write(dataOutputStream); arr.data().write(dataOutputStream); }
public BaseNDArrayProxy(INDArray anInstance) { if (anInstance.isView()) { anInstance = anInstance.dup(anInstance.ordering()); } this.arrayShape = anInstance.shape(); this.length = anInstance.length(); this.arrayOrdering = anInstance.ordering(); this.data = anInstance.data(); }
@Override public void serialize(INDArray indArray, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { if (indArray.isView()) indArray = indArray.dup(indArray.ordering()); jsonGenerator.writeStartObject();
public AssignRequestMessage(@NonNull Integer key, @NonNull INDArray array) { this(); this.key = key; this.payload = array.isView() ? array.dup(array.ordering()) : array; }
public AssignRequestMessage(@NonNull Integer key, @NonNull INDArray array) { this(); this.key = key; this.payload = array.isView() ? array.dup(array.ordering()) : array; }
public VectorCompleteMessage(long taskId, @NonNull INDArray vector) { this(); this.taskId = taskId; this.payload = vector.isView() ? vector.dup(vector.ordering()) : vector; } }
public VectorCompleteMessage(long taskId, @NonNull INDArray vector) { this(); this.taskId = taskId; this.payload = vector.isView() ? vector.dup(vector.ordering()) : vector; } }
public VectorAggregation(long taskId, short aggregationWidth, short shardIndex, INDArray array) { super(taskId, aggregationWidth, shardIndex); this.payload = array.isView() ? array.dup(array.ordering()) : array; addToChunks(payload); }
private static INDArray toCOrder(INDArray arr) { if (arr.isView() || arr.ordering() != 'c' || !Shape.strideDescendingCAscendingF(arr)) { arr = arr.dup('c'); } return arr; }
public VectorAggregation(long taskId, short aggregationWidth, short shardIndex, INDArray array) { super(taskId, aggregationWidth, shardIndex); this.payload = array.isView() ? array.dup(array.ordering()) : array; addToChunks(payload); }
/** * Inplace compression of INDArray * * @param array */ @Override public void compressi(INDArray array) { // TODO: lift this restriction if (array.isView()) throw new UnsupportedOperationException("Impossible to apply inplace compression on View"); array.setData(compress(array.data())); array.markAsCompressed(true); }
@Override public void serialize(INDArray array, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { if (array.isView()) { array = array.dup(); } double[] dArr = array.data().asDouble(); jsonGenerator.writeObject(dArr); } }
/** * This method converts Single/Double precision databuffer to Half-precision databuffer * * @param typeSrc * @param source * @param typeDst @return */ @Override public INDArray convertDataEx(DataBuffer.TypeEx typeSrc, INDArray source, DataBuffer.TypeEx typeDst) { if (source.isView()) throw new UnsupportedOperationException("Impossible to compress View. Consider using dup() before. "); DataBuffer buffer = convertDataEx(typeSrc, source.data(), typeDst); source.setData(buffer); if (buffer instanceof CompressedDataBuffer) source.markAsCompressed(true); else source.markAsCompressed(false); return source; }
public BaseNDArrayProxy(INDArray anInstance) { if (anInstance.isView()) { anInstance = anInstance.dup(anInstance.ordering()); } this.arrayShape = anInstance.shape(); this.length = anInstance.length(); this.arrayOrdering = anInstance.ordering(); this.data = anInstance.data(); }
/** * Write an ndarray to the specified outputstream * * @param arr the array to write * @param dataOutputStream the data output stream to write to * @throws IOException */ public static void write(INDArray arr, DataOutputStream dataOutputStream) throws IOException { //BaseDataBuffer.write(...) doesn't know about strides etc, so dup (or equiv. strategy) is necessary here //Furthermore, because we only want to save the *actual* data for a view (not the full data), the shape info // (mainly strides, offset, element-wise stride) may be different in the duped array vs. the view array if (arr.isView()) arr = arr.dup(); arr.shapeInfoDataBuffer().write(dataOutputStream); arr.data().write(dataOutputStream); }
protected void applyDropOutIfNecessary(boolean training) { if (layerConf().getDropOut() > 0 && !conf.isUseDropConnect() && training && !dropoutApplied) { if (Nd4j.getWorkspaceManager().checkIfWorkspaceExists(ComputationGraph.workspaceExternal)) { try (MemoryWorkspace ws = Nd4j.getWorkspaceManager() .getWorkspaceForCurrentThread(ComputationGraph.workspaceExternal) .notifyScopeBorrowed()) { input = input.isView() ? input.dup() : input.unsafeDuplication(); } } else input = input.isView() ? input.dup() : input.unsafeDuplication(); Dropout.applyDropout(input, layerConf().getDropOut()); dropoutApplied = true; } }