Search in sources :

Example 6 with UnsupportedOperationException

use of org.apache.ignite.ml.math.exceptions.UnsupportedOperationException in project ignite by apache.

the class SingleElementVectorConstructorTest method basicTest.

/**
 */
private void basicTest(int size, int idx) {
    final Double expVal = (double) (size - idx);
    Vector v = new SingleElementVector(size, idx, expVal);
    assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size, expVal.equals(v.get(idx)));
    final double delta = 1.0;
    v.set(idx, expVal - delta);
    assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size, expVal.equals(v.get(idx) + delta));
    final Double zero = 0.0;
    for (int i = 0; i < size; i++) {
        if (i == idx)
            continue;
        assertTrue("Expect zero at index " + i + " for size " + size, zero.equals(v.get(i)));
        boolean eCaught = false;
        try {
            v.set(i, 1.0);
        } catch (UnsupportedOperationException uoe) {
            eCaught = true;
        }
        assertTrue("Expect " + java.lang.UnsupportedOperationException.class.getSimpleName() + " at index " + i + " for size " + size, eCaught);
    }
}
Also used : Vector(org.apache.ignite.ml.math.Vector) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 7 with UnsupportedOperationException

use of org.apache.ignite.ml.math.exceptions.UnsupportedOperationException in project ignite by apache.

the class SingleElementVectorViewConstructorTest method basicTest.

/**
 */
private void basicTest(int size, int idx) {
    final Double expVal = (double) (size - idx);
    Vector orig = helper.newSample(size, idx, expVal);
    SingleElementVectorView svv = new SingleElementVectorView(orig, idx);
    assertEquals("Size differs from expected", size, svv.size());
    assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size, expVal.equals(svv.get(idx)));
    final double delta = 1.0;
    svv.set(idx, expVal - delta);
    assertTrue("Expect value " + expVal + " at index " + idx + " for size " + size, expVal.equals(orig.get(idx) + delta));
    final Double zero = 0.0;
    for (int i = 0; i < size; i++) {
        if (i == idx)
            continue;
        assertTrue("Expect zero at index " + i + " for size " + size, zero.equals(svv.get(i)));
        boolean eCaught = false;
        try {
            svv.set(i, 1.0);
        } catch (UnsupportedOperationException uoe) {
            eCaught = true;
        }
        assertTrue("Expect " + UnsupportedOperationException.class.getSimpleName() + " at index " + i + " for size " + size, eCaught);
    }
}
Also used : Vector(org.apache.ignite.ml.math.Vector) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 8 with UnsupportedOperationException

use of org.apache.ignite.ml.math.exceptions.UnsupportedOperationException 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 9 with UnsupportedOperationException

use of org.apache.ignite.ml.math.exceptions.UnsupportedOperationException in project ignite by apache.

the class MatrixImplementationsTest method testLike.

/**
 */
@Test
public void testLike() {
    consumeSampleMatrix((m, desc) -> {
        Class<? extends Matrix> cls = likeMatrixType(m);
        if (cls != null) {
            Matrix like = m.like(m.rowSize(), m.columnSize());
            assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected rows.", like.rowSize(), m.rowSize());
            assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected columns.", like.columnSize(), m.columnSize());
            assertEquals("Wrong \"like\" matrix for " + desc + "; Unexpected class: " + like.getClass().toString(), cls, like.getClass());
            return;
        }
        boolean expECaught = false;
        try {
            m.like(1, 1);
        } catch (UnsupportedOperationException uoe) {
            expECaught = true;
        }
        assertTrue("Expected exception was not caught for " + desc, expECaught);
    });
}
Also used : Matrix(org.apache.ignite.ml.math.Matrix) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException) Test(org.junit.Test) ExternalizeTest(org.apache.ignite.ml.math.ExternalizeTest)

Example 10 with UnsupportedOperationException

use of org.apache.ignite.ml.math.exceptions.UnsupportedOperationException 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)

Aggregations

UnsupportedOperationException (org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)13 IdentityValueMapper (org.apache.ignite.ml.math.IdentityValueMapper)8 Vector (org.apache.ignite.ml.math.Vector)5 ExternalizeTest (org.apache.ignite.ml.math.ExternalizeTest)2 Matrix (org.apache.ignite.ml.math.Matrix)2 Test (org.junit.Test)2 DenseLocalOffHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector)1 DenseLocalOnHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)1 RandomVector (org.apache.ignite.ml.math.impls.vector.RandomVector)1 SparseLocalVector (org.apache.ignite.ml.math.impls.vector.SparseLocalVector)1