use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testPlus.
/**
*/
public void testPlus() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
double plusVal = 2;
MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
IgniteCache<Integer, Double> cache = getCache();
CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
initMatrix(cacheMatrix);
cacheMatrix.plus(plusVal);
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) assertEquals(plusVal, cacheMatrix.get(i, j));
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testAssignSingleValue.
/**
*/
public void testAssignSingleValue() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
double initVal = 1;
MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
IgniteCache<Integer, Double> cache = getCache();
CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
initMatrix(cacheMatrix);
cacheMatrix.assign(initVal);
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) assertEquals(initVal, cacheMatrix.get(i, j));
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testLikeVector.
/**
*/
public void testLikeVector() 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());
try {
cacheMatrix.likeVector(cols);
fail("UnsupportedOperationException expected");
} catch (UnsupportedOperationException e) {
// No-op.
}
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheVectorTest method testGetSet.
/**
*/
public void testGetSet() throws Exception {
IdentityValueMapper valMapper = new IdentityValueMapper();
CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
for (int i = 0; i < size; i++) {
double random = Math.random();
cacheVector.set(i, random);
assertEquals("Unexpected value.", random, cacheVector.get(i), 0d);
}
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheVectorTest method testTimes.
/**
*/
public void testTimes() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
final int size = MathTestConstants.STORAGE_SIZE;
IdentityValueMapper valMapper = new IdentityValueMapper();
CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
initVector(cacheVector);
cacheVector.assign(1d);
cacheVector.times(2d);
for (int i = 0; i < size; i++) assertEquals("Unexpected value.", cacheVector.get(i), 2d, 0d);
}
Aggregations