public int[] getPointerEArray() { return pointerE.asInt(); }
public int[] getPointerBArray() { return pointerB.asInt(); }
public boolean isZero(int... indexes) { for (int i = 0; i < length(); i++) { int[] idx = getUnderlyingIndicesOf(i).asInt(); if (Arrays.equals(idx, translateToPhysical(indexes))) { return false; } } return true; }
@Override public INDArray toDense() { // Dummy way - going to use the conversion routines in level2 (?) INDArray result = Nd4j.zeros(shape()); int[] pointersB = pointerB.asInt(); int[] pointersE = pointerE.asInt(); for (int row = 0; row < rows(); row++) { for (int idx = pointersB[row]; idx < pointersE[row]; idx++) { result.put(row, columnsPointers.getInt(idx), values.getNumber(idx)); } } return result; }
private void setIndexes(BaseSparseNDArrayCOO coo, boolean oneBased) { int incr = oneBased ? 1 : 0; int[] idx = coo.getIncludedIndices().asInt(); int[] rows = new int[nnz]; int[] cols = new int[nnz]; for (int i = 0; i < nnz; i++) { rows[i] = idx[i * 2] + incr; cols[i] = idx[(i * 2) + 1] + incr; } rowInd = Nd4j.createBuffer(rows); colInd = Nd4j.createBuffer(cols); }
@Override public int[] toIntVector() { if(!isVector()) { throw new ND4JIllegalStateException("Unable to create a 1d array from a non vector!"); } return dup().data().asInt(); }
/** * Return the position of the idx array into the indexes buffer between the lower and upper bound. * @param idx a set of coordinates * @param lowerBound the lower bound of the position * @param upperBound the upper bound of the position * @return the position of the idx array into the indexes buffers, which corresponds to the position of * the corresponding value in the values data. * */ public int indexesBinarySearch(int lowerBound, int upperBound, int[] idx) { int min = lowerBound; int max = upperBound; int mid = (max + min) / 2; int[] midIdx = getUnderlyingIndicesOf(mid).asInt(); if (Arrays.equals(idx, midIdx)) { return mid; } if (ArrayUtil.lessThan(idx, midIdx)) { max = mid; } if (ArrayUtil.greaterThan(idx, midIdx)) { min = mid; } if (min == max) { return -1; } return indexesBinarySearch(min, max, idx); }
protected DataBuffer reallocate(DataBuffer buffer) { int newSize = (int) buffer.length() * 2; DataBuffer newBuffer = Nd4j.createBuffer(newSize); switch (buffer.dataType()) { case INT: newBuffer.setData(buffer.asInt()); break; case DOUBLE: newBuffer.setData(buffer.asDouble()); break; case FLOAT: newBuffer.setData(buffer.asFloat()); break; case HALF: //TODO throw new UnsupportedOperationException(); case COMPRESSED: //TODO throw new UnsupportedOperationException(); default: throw new UnsupportedOperationException(); } return newBuffer; }
@Override public INDArray put(INDArray indices, INDArray element) { INDArrayIndex[] realIndices = new INDArrayIndex[indices.rank()]; for(int i = 0; i < realIndices.length; i++) { realIndices[i] = new SpecifiedIndex(indices.slice(i).dup().data().asInt()); } return put(realIndices,element); }
/** * 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 void initFromTensorFlow(NodeDef nodeDef, SameDiff initWith, Map<String, AttrValue> attributesForNode, GraphDef graph) { val lastNode = TFGraphMapper.getInstance().getNodeWithNameFromGraph(graph,nodeDef.getInput(nodeDef.getInputCount() - 1)); val arr = TFGraphMapper.getInstance().getNDArrayFromTensor("value",lastNode,graph); if(arr != null) { this.axis = arr.data().asInt(); addArguments(); } }
@Override public void initFromTensorFlow(NodeDef nodeDef, SameDiff initWith, Map<String, AttrValue> attributesForNode, GraphDef graph) { val targetNode = TFGraphMapper.getInstance().getNodeWithNameFromGraph(graph, nodeDef.getInput(1)); val dimArr = TFGraphMapper.getInstance().getNDArrayFromTensor("value", targetNode, graph); if (dimArr != null) { int axis = dimArr.data().asInt()[0]; this.axis = axis; addIArgument(this.axis); } else { this.axis = Integer.MAX_VALUE; addIArgument(this.axis); } }
boolean isIn = true; int idxNotFixed = 0; int[] idx = getUnderlyingIndicesOf(i).asInt(); for (int dim = 0; dim < idx.length; dim++) { if (flags()[dim] == 1) {
/** * Count the number of value that are included in the ndarray (view) according to the sparse offsets and the shape * @return nnz * */ public long countNNZ() { long count = 0; for (int i = 0; i < values.length(); i++) { int[] idx = getUnderlyingIndicesOf(i).asInt(); boolean isIn = true; int idxNotFixed = 0; for (int dim = 0; dim < idx.length; dim++) { if (flags()[dim] == 1) { if (sparseOffsets()[dim] != idx[dim]) { isIn = false; break; } } else { int lowerBound = sparseOffsets()[dim]; long upperBound = sparseOffsets()[dim] + shape()[idxNotFixed]; if (!(idx[dim] >= lowerBound && idx[dim] < upperBound)) { isIn = false; break; } idxNotFixed++; } } count = isIn ? count + 1 : count; } return count; }
setValueFor(fieldType,varArr.data().asInt());
@Override public int[][] toIntMatrix() { if(!isMatrix()) { throw new ND4JIllegalStateException("Unable to create a 2d array from a non matrix!"); } if (this.rows() > Integer.MAX_VALUE || this.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); int[][] ret = new int[(int) rows()][(int) columns()]; for(int i = 0; i < ret.length; i++) { ret[i] = getRow(i).dup().data().asInt(); } return ret; }
int[] specifiedIndex = indices.getColumn(i).dup().data().asInt(); ret.putScalar(i,getDouble(specifiedIndex));
NdIndexIterator ndIndexIterator = new NdIndexIterator(element.shape()); for(int i = 0; i < indices.columns(); i++) { int[] specifiedIndex = indices.getColumn(i).dup().data().asInt(); putScalar(specifiedIndex,element.getDouble(ndIndexIterator.next()));
this.permuteDims = permuteArrayOp.data().asInt(); for (int i = 0; i < permuteDims.length; i++) { addIArgument(permuteDims[i]);