use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.
the class SGDNesterovUpdate method copy.
// Assumption dest is zero-ed out.
private static void copy(MatrixBlock src, double[] dest) {
if (src.isInSparseFormat()) {
Iterator<IJV> iter = src.getSparseBlockIterator();
while (iter.hasNext()) {
IJV ijv = iter.next();
dest[ijv.getI() * ijv.getJ()] = ijv.getV();
}
} else {
double[] denseBlock = src.getDenseBlockValues();
if (denseBlock != null) {
// If not empty block
System.arraycopy(denseBlock, 0, dest, 0, dest.length);
}
}
}
use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.
the class DataConverter method convertToLongVector.
public static long[] convertToLongVector(MatrixBlock mb) {
int rows = mb.getNumRows();
int cols = mb.getNumColumns();
// 0-initialized
long[] ret = new long[rows * cols];
if (mb.isEmptyBlock(false))
return ret;
if (mb.isInSparseFormat()) {
Iterator<IJV> iter = mb.getSparseBlockIterator();
while (iter.hasNext()) {
IJV cell = iter.next();
ret[cell.getI() * cols + cell.getJ()] = (int) cell.getV();
}
} else {
// memcopy row major representation if at least 1 non-zero
for (int i = 0, cix = 0; i < rows; i++) for (int j = 0; j < cols; j++, cix++) ret[cix] = (int) (mb.getValueDenseUnsafe(i, j));
}
return ret;
}
use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.
the class DataConverter method convertToDenseBlock.
public static DenseBlock convertToDenseBlock(MatrixBlock mb, boolean deep) {
int rows = mb.getNumRows();
int cols = mb.getNumColumns();
DenseBlock ret = (!mb.isInSparseFormat() && mb.isAllocated() && !deep) ? mb.getDenseBlock() : // 0-initialized
DenseBlockFactory.createDenseBlock(rows, cols);
if (!mb.isEmptyBlock(false)) {
if (mb.isInSparseFormat()) {
Iterator<IJV> iter = mb.getSparseBlockIterator();
while (iter.hasNext()) {
IJV cell = iter.next();
ret.set(cell.getI(), cell.getJ(), cell.getV());
}
} else if (deep) {
ret.set(mb.getDenseBlock());
}
}
return ret;
}
use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.
the class DataConverter method convertToIntVector.
public static int[] convertToIntVector(MatrixBlock mb) {
int rows = mb.getNumRows();
int cols = mb.getNumColumns();
// 0-initialized
int[] ret = new int[rows * cols];
if (mb.isEmptyBlock(false))
return ret;
if (mb.isInSparseFormat()) {
Iterator<IJV> iter = mb.getSparseBlockIterator();
while (iter.hasNext()) {
IJV cell = iter.next();
ret[cell.getI() * cols + cell.getJ()] = (int) cell.getV();
}
} else {
// memcopy row major representation if at least 1 non-zero
for (int i = 0, cix = 0; i < rows; i++) for (int j = 0; j < cols; j++, cix++) ret[cix] = (int) (mb.getValueDenseUnsafe(i, j));
}
return ret;
}
use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.
the class DataConverter method convertToBooleanVector.
public static boolean[] convertToBooleanVector(MatrixBlock mb) {
int rows = mb.getNumRows();
int cols = mb.getNumColumns();
// false-initialized
boolean[] ret = new boolean[rows * cols];
if (mb.getNonZeros() > 0) {
if (mb.isInSparseFormat()) {
Iterator<IJV> iter = mb.getSparseBlockIterator();
while (iter.hasNext()) {
IJV cell = iter.next();
ret[cell.getI() * cols + cell.getJ()] = (cell.getV() != 0.0);
}
} else {
for (int i = 0, cix = 0; i < rows; i++) for (int j = 0; j < cols; j++, cix++) ret[cix] = (mb.getValueDenseUnsafe(i, j) != 0.0);
}
}
return ret;
}
Aggregations