use of org.apache.sysml.runtime.util.LongLongDoubleHashMap in project incubator-systemml by apache.
the class SparseBlockGetSet method runSparseBlockGetSetTest.
/**
* @param sparseM1
* @param sparseM2
* @param instType
*/
private void runSparseBlockGetSetTest(SparseBlock.Type btype, double sparsity, InitType itype) {
try {
// data generation
double[][] A = getRandomMatrix(rows, cols, -10, 10, sparsity, 7654321);
// init sparse block
SparseBlock sblock = null;
if (itype == InitType.BULK) {
MatrixBlock mbtmp = DataConverter.convertToMatrixBlock(A);
SparseBlock srtmp = mbtmp.getSparseBlock();
switch(btype) {
case MCSR:
sblock = new SparseBlockMCSR(srtmp);
break;
case CSR:
sblock = new SparseBlockCSR(srtmp);
break;
case COO:
sblock = new SparseBlockCOO(srtmp);
break;
}
} else if (itype == InitType.SEQ_SET || itype == InitType.RAND_SET) {
switch(btype) {
case MCSR:
sblock = new SparseBlockMCSR(rows, cols);
break;
case CSR:
sblock = new SparseBlockCSR(rows, cols);
break;
case COO:
sblock = new SparseBlockCOO(rows, cols);
break;
}
if (itype == InitType.SEQ_SET) {
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) sblock.append(i, j, A[i][j]);
} else if (itype == InitType.RAND_SET) {
LongLongDoubleHashMap map = new LongLongDoubleHashMap();
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) map.addValue(i, j, A[i][j]);
Iterator<ADoubleEntry> iter = map.getIterator();
while (iter.hasNext()) {
// random hash order
ADoubleEntry e = iter.next();
sblock.set((int) e.getKey1(), (int) e.getKey2(), e.value);
}
}
}
// check basic meta data
if (sblock.numRows() != rows)
Assert.fail("Wrong number of rows: " + sblock.numRows() + ", expected: " + rows);
// check for correct number of non-zeros
int[] rnnz = new int[rows];
int nnz = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) rnnz[i] += (A[i][j] != 0) ? 1 : 0;
nnz += rnnz[i];
}
if (nnz != sblock.size())
Assert.fail("Wrong number of non-zeros: " + sblock.size() + ", expected: " + nnz);
// check correct isEmpty return
for (int i = 0; i < rows; i++) if (sblock.isEmpty(i) != (rnnz[i] == 0))
Assert.fail("Wrong isEmpty(row) result for row nnz: " + rnnz[i]);
// check correct values
for (int i = 0; i < rows; i++) if (!sblock.isEmpty(i))
for (int j = 0; j < cols; j++) {
double tmp = sblock.get(i, j);
if (tmp != A[i][j])
Assert.fail("Wrong get value for cell (" + i + "," + j + "): " + tmp + ", expected: " + A[i][j]);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
use of org.apache.sysml.runtime.util.LongLongDoubleHashMap in project systemml by apache.
the class SparseBlockGetSet method runSparseBlockGetSetTest.
/**
* @param sparseM1
* @param sparseM2
* @param instType
*/
private void runSparseBlockGetSetTest(SparseBlock.Type btype, double sparsity, InitType itype) {
try {
// data generation
double[][] A = getRandomMatrix(rows, cols, -10, 10, sparsity, 7654321);
// init sparse block
SparseBlock sblock = null;
if (itype == InitType.BULK) {
MatrixBlock mbtmp = DataConverter.convertToMatrixBlock(A);
SparseBlock srtmp = mbtmp.getSparseBlock();
switch(btype) {
case MCSR:
sblock = new SparseBlockMCSR(srtmp);
break;
case CSR:
sblock = new SparseBlockCSR(srtmp);
break;
case COO:
sblock = new SparseBlockCOO(srtmp);
break;
}
} else if (itype == InitType.SEQ_SET || itype == InitType.RAND_SET) {
switch(btype) {
case MCSR:
sblock = new SparseBlockMCSR(rows, cols);
break;
case CSR:
sblock = new SparseBlockCSR(rows, cols);
break;
case COO:
sblock = new SparseBlockCOO(rows, cols);
break;
}
if (itype == InitType.SEQ_SET) {
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) sblock.append(i, j, A[i][j]);
} else if (itype == InitType.RAND_SET) {
LongLongDoubleHashMap map = new LongLongDoubleHashMap();
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) map.addValue(i, j, A[i][j]);
Iterator<ADoubleEntry> iter = map.getIterator();
while (iter.hasNext()) {
// random hash order
ADoubleEntry e = iter.next();
sblock.set((int) e.getKey1(), (int) e.getKey2(), e.value);
}
}
}
// check basic meta data
if (sblock.numRows() != rows)
Assert.fail("Wrong number of rows: " + sblock.numRows() + ", expected: " + rows);
// check for correct number of non-zeros
int[] rnnz = new int[rows];
int nnz = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) rnnz[i] += (A[i][j] != 0) ? 1 : 0;
nnz += rnnz[i];
}
if (nnz != sblock.size())
Assert.fail("Wrong number of non-zeros: " + sblock.size() + ", expected: " + nnz);
// check correct isEmpty return
for (int i = 0; i < rows; i++) if (sblock.isEmpty(i) != (rnnz[i] == 0))
Assert.fail("Wrong isEmpty(row) result for row nnz: " + rnnz[i]);
// check correct values
for (int i = 0; i < rows; i++) if (!sblock.isEmpty(i))
for (int j = 0; j < cols; j++) {
double tmp = sblock.get(i, j);
if (tmp != A[i][j])
Assert.fail("Wrong get value for cell (" + i + "," + j + "): " + tmp + ", expected: " + A[i][j]);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
use of org.apache.sysml.runtime.util.LongLongDoubleHashMap in project systemml by apache.
the class SparseBlockAppendSort method runSparseBlockAppendSortTest.
/**
* @param sparseM1
* @param sparseM2
* @param instType
*/
private void runSparseBlockAppendSortTest(SparseBlock.Type btype, double sparsity, InitType itype) {
try {
// data generation
double[][] A = getRandomMatrix(rows, cols, -10, 10, sparsity, 7654321);
// init sparse block
SparseBlock sblock = null;
switch(btype) {
case MCSR:
sblock = new SparseBlockMCSR(rows, cols);
break;
case CSR:
sblock = new SparseBlockCSR(rows, cols);
break;
case COO:
sblock = new SparseBlockCOO(rows, cols);
break;
}
if (itype == InitType.SEQ_SET) {
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) sblock.append(i, j, A[i][j]);
} else if (itype == InitType.RAND_SET) {
LongLongDoubleHashMap map = new LongLongDoubleHashMap();
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) map.addValue(i, j, A[i][j]);
Iterator<ADoubleEntry> iter = map.getIterator();
while (iter.hasNext()) {
// random hash order
ADoubleEntry e = iter.next();
sblock.append((int) e.getKey1(), (int) e.getKey2(), e.value);
}
}
// sort appended values
sblock.sort();
// check for correct number of non-zeros
int[] rnnz = new int[rows];
int nnz = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) rnnz[i] += (A[i][j] != 0) ? 1 : 0;
nnz += rnnz[i];
}
if (nnz != sblock.size())
Assert.fail("Wrong number of non-zeros: " + sblock.size() + ", expected: " + nnz);
// check correct isEmpty return
for (int i = 0; i < rows; i++) if (sblock.isEmpty(i) != (rnnz[i] == 0))
Assert.fail("Wrong isEmpty(row) result for row nnz: " + rnnz[i]);
// check correct values
for (int i = 0; i < rows; i++) if (!sblock.isEmpty(i))
for (int j = 0; j < cols; j++) {
double tmp = sblock.get(i, j);
if (tmp != A[i][j])
Assert.fail("Wrong get value for cell (" + i + "," + j + "): " + tmp + ", expected: " + A[i][j]);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
use of org.apache.sysml.runtime.util.LongLongDoubleHashMap in project incubator-systemml by apache.
the class SparseBlockAppendSort method runSparseBlockAppendSortTest.
/**
* @param sparseM1
* @param sparseM2
* @param instType
*/
private void runSparseBlockAppendSortTest(SparseBlock.Type btype, double sparsity, InitType itype) {
try {
// data generation
double[][] A = getRandomMatrix(rows, cols, -10, 10, sparsity, 7654321);
// init sparse block
SparseBlock sblock = null;
switch(btype) {
case MCSR:
sblock = new SparseBlockMCSR(rows, cols);
break;
case CSR:
sblock = new SparseBlockCSR(rows, cols);
break;
case COO:
sblock = new SparseBlockCOO(rows, cols);
break;
}
if (itype == InitType.SEQ_SET) {
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) sblock.append(i, j, A[i][j]);
} else if (itype == InitType.RAND_SET) {
LongLongDoubleHashMap map = new LongLongDoubleHashMap();
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) map.addValue(i, j, A[i][j]);
Iterator<ADoubleEntry> iter = map.getIterator();
while (iter.hasNext()) {
// random hash order
ADoubleEntry e = iter.next();
sblock.append((int) e.getKey1(), (int) e.getKey2(), e.value);
}
}
// sort appended values
sblock.sort();
// check for correct number of non-zeros
int[] rnnz = new int[rows];
int nnz = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) rnnz[i] += (A[i][j] != 0) ? 1 : 0;
nnz += rnnz[i];
}
if (nnz != sblock.size())
Assert.fail("Wrong number of non-zeros: " + sblock.size() + ", expected: " + nnz);
// check correct isEmpty return
for (int i = 0; i < rows; i++) if (sblock.isEmpty(i) != (rnnz[i] == 0))
Assert.fail("Wrong isEmpty(row) result for row nnz: " + rnnz[i]);
// check correct values
for (int i = 0; i < rows; i++) if (!sblock.isEmpty(i))
for (int j = 0; j < cols; j++) {
double tmp = sblock.get(i, j);
if (tmp != A[i][j])
Assert.fail("Wrong get value for cell (" + i + "," + j + "): " + tmp + ", expected: " + A[i][j]);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
Aggregations