use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testSum.
/**
*/
public void testSum() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
IgniteCache<Integer, Double> cache = getCache();
CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
double sum;
initMatrix(cacheMatrix);
sum = cacheMatrix.sum();
assertTrue(Double.compare(sum, 0d) == 0);
cacheMatrix.assign(1d);
sum = cacheMatrix.sum();
assertTrue(Double.compare(sum, rows * cols) == 0);
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testGetSet.
/**
*/
public void testGetSet() throws Exception {
MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
IgniteCache<Integer, Double> cache = getCache();
CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
double v = Math.random();
cacheMatrix.set(i, j, v);
assert Double.compare(v, cacheMatrix.get(i, j)) == 0;
assert Double.compare(v, cache.get(keyMapper.apply(i, j))) == 0;
}
}
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testMinMax.
/**
*/
public void testMinMax() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
IgniteCache<Integer, Double> cache = getCache();
final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) cacheMatrix.set(i, j, i * rows + j);
assertEquals(0.0, cacheMatrix.minValue(), 0.0);
assertEquals(rows * cols - 1, cacheMatrix.maxValue(), 0.0);
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testExternalization.
/**
*/
public void testExternalization() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
IgniteCache<Integer, Double> cache = getCache();
final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
ExternalizeTest<CacheMatrix<Integer, Double>> externalizeTest = new ExternalizeTest<CacheMatrix<Integer, Double>>() {
/**
* {@inheritDoc}
*/
@Override
public void externalizeTest() {
super.externalizeTest(cacheMatrix);
}
};
externalizeTest.externalizeTest();
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testMap.
/**
*/
public void testMap() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
IgniteCache<Integer, Double> cache = getCache();
final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
initMatrix(cacheMatrix);
cacheMatrix.map(value -> value + 10);
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) assertEquals(10.0, cacheMatrix.getX(i, j), 0.0);
}
Aggregations