Search in sources :

Example 26 with IdentityValueMapper

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));
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Example 27 with IdentityValueMapper

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));
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Example 28 with IdentityValueMapper

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.
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 29 with IdentityValueMapper

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);
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Example 30 with IdentityValueMapper

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);
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Aggregations

IdentityValueMapper (org.apache.ignite.ml.math.IdentityValueMapper)37 UnsupportedOperationException (org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)8 Vector (org.apache.ignite.ml.math.Vector)5 Ignite (org.apache.ignite.Ignite)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 ValueMapper (org.apache.ignite.ml.math.distributed.ValueMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ExternalizeTest (org.apache.ignite.ml.math.ExternalizeTest)1 MatrixKeyMapper (org.apache.ignite.ml.math.distributed.MatrixKeyMapper)1 VectorKeyMapper (org.apache.ignite.ml.math.distributed.VectorKeyMapper)1 CacheMatrix (org.apache.ignite.ml.math.impls.matrix.CacheMatrix)1 CacheVector (org.apache.ignite.ml.math.impls.vector.CacheVector)1