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; }
/** * Returns the indices of non-zero element of the vector * * @return indices in Databuffer * */ @Override public DataBuffer getVectorCoordinates() { int idx; if (isRowVector()) { idx = 1; } else if (isColumnVector()) { idx = 0; } else { throw new UnsupportedOperationException(); } // FIXME: int cast int[] temp = new int[(int) length()]; for (int i = 0; i < length(); i++) { temp[i] = getUnderlyingIndicesOf(i).getInt(idx); } return Nd4j.createBuffer(temp); }
/** * Return the index of the value corresponding to the indexes * @param indexes * @return index of the value * */ public int reverseIndexes(int... indexes) { long[] idx = translateToPhysical(ArrayUtil.toLongArray(indexes)); sort(); // FIXME: int cast return indexesBinarySearch(0, (int) length(), ArrayUtil.toInts(idx)); }
/** * Remove an element of the ndarray * @param idx the index of the element to be removed * @return the ndarray * */ public INDArray removeEntry(int idx) { values = shiftLeft(values, idx + 1, 1, length()); indices = shiftLeft(indices, (int) (idx * shape.length() + shape.length()), (int) shape.length(), indices.length()); return this; }
@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); }