use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheVectorTest method testAssignRange.
/** */
public void testAssignRange() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
IdentityValueMapper valMapper = new IdentityValueMapper();
CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
cacheVector.assign(IntStream.range(0, size).asDoubleStream().toArray());
for (int i = 0; i < size; i++) assertEquals("Unexpected value.", cacheVector.get(i), i, 0d);
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheVectorTest method testAssignVector.
/** */
public void testAssignVector() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
IdentityValueMapper valMapper = new IdentityValueMapper();
CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
cacheVector.assign(testVec);
for (int i = 0; i < size; i++) assertEquals("Unexpected value.", cacheVector.get(i), testVec.get(i), 0d);
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheVectorTest method testMap.
/** */
public void testMap() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
IdentityValueMapper valMapper = new IdentityValueMapper();
CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
initVector(cacheVector);
cacheVector.map(value -> 110d);
for (int i = 0; i < size; i++) assertEquals("Unexpected value.", cacheVector.get(i), 110d, 0d);
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testAttributes.
/** */
public void testAttributes() {
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());
assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isSequentialAccess());
assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isDense());
assertFalse(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isArrayBased());
assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isRandomAccess());
assertTrue(UNEXPECTED_ATTRIBUTE_VALUE, cacheMatrix.isDistributed());
}
use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.
the class CacheMatrixTest method testDivide.
/** */
public void testDivide() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
double initVal = 1;
double divVal = 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.assign(initVal);
cacheMatrix.divide(divVal);
for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) assertTrue(Double.compare(cacheMatrix.get(i, j), initVal / divVal) == 0);
}
Aggregations