Search in sources :

Example 31 with IdentityValueMapper

use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.

the class CacheVectorTest method testPlusVec.

/**
 */
public void testPlusVec() {
    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());
    try {
        cacheVector.plus(testVec);
        TestCase.fail();
    } catch (UnsupportedOperationException ignored) {
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) Vector(org.apache.ignite.ml.math.Vector) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 32 with IdentityValueMapper

use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.

the class CacheVectorTest method testTimesVector.

/**
 */
public void testTimesVector() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    IdentityValueMapper valMapper = new IdentityValueMapper();
    CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
    cacheVector.assign(1d);
    Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
    try {
        cacheVector.times(testVec);
        TestCase.fail();
    } catch (UnsupportedOperationException ignored) {
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) Vector(org.apache.ignite.ml.math.Vector) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 33 with IdentityValueMapper

use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.

the class CacheVectorTest method testLike.

/**
 */
public void testLike() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    IdentityValueMapper valMapper = new IdentityValueMapper();
    CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
    try {
        cacheVector.like(size);
        TestCase.fail("Unsupported case");
    } catch (UnsupportedOperationException ignored) {
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 34 with IdentityValueMapper

use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.

the class CacheVectorTest method testExternalize.

/**
 */
public void testExternalize() throws IOException, ClassNotFoundException {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    IdentityValueMapper valMapper = new IdentityValueMapper();
    CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
    cacheVector.set(1, 1.0);
    ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objOutputStream = new ObjectOutputStream(byteArrOutputStream);
    objOutputStream.writeObject(cacheVector);
    ByteArrayInputStream byteArrInputStream = new ByteArrayInputStream(byteArrOutputStream.toByteArray());
    ObjectInputStream objInputStream = new ObjectInputStream(byteArrInputStream);
    CacheVector objRestored = (CacheVector) objInputStream.readObject();
    assertTrue(MathTestConstants.VAL_NOT_EQUALS, cacheVector.equals(objRestored));
    assertEquals(MathTestConstants.VAL_NOT_EQUALS, objRestored.get(1), 1.0, 0.0);
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 35 with IdentityValueMapper

use of org.apache.ignite.ml.math.IdentityValueMapper in project ignite by apache.

the class CacheVectorTest method testMin.

/**
 */
public void testMin() {
    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);
    assertEquals("Unexpected value.", cacheVector.minValue(), 0d, 0d);
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) Vector(org.apache.ignite.ml.math.Vector)

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