Search in sources :

Example 1 with UnsupportedOperationException

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

the class CacheMatrixTest method testLike.

/**
 */
public void testLike() 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.like(rows, 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 2 with UnsupportedOperationException

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

the class CacheMatrixTest method testCopy.

/**
 */
public void testCopy() 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());
    fillMatrix(cacheMatrix);
    try {
        cacheMatrix.copy();
        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 3 with UnsupportedOperationException

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

the class FunctionMatrixConstructorTest method basicTest.

/**
 */
private void basicTest(int rows, int cols) {
    double[][] data = new double[rows][cols];
    for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) data[row][col] = row * cols + row;
    Matrix mReadOnly = new FunctionMatrix(rows, cols, (i, j) -> data[i][j]);
    assertEquals("Rows in matrix.", rows, mReadOnly.rowSize());
    assertEquals("Cols in matrix.", cols, mReadOnly.columnSize());
    for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) {
        assertEquals("Unexpected value at " + row + "x" + col, data[row][col], mReadOnly.get(row, col), 0d);
        boolean expECaught = false;
        try {
            mReadOnly.set(row, col, 0.0);
        } catch (UnsupportedOperationException uoe) {
            expECaught = true;
        }
        assertTrue("Expected exception wasn't thrown at " + row + "x" + col, expECaught);
    }
    Matrix m = new FunctionMatrix(rows, cols, (i, j) -> data[i][j], (i, j, val) -> data[i][j] = val);
    assertEquals("Rows in matrix, with setter function.", rows, m.rowSize());
    assertEquals("Cols in matrix, with setter function.", cols, m.columnSize());
    for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) {
        assertEquals("Unexpected value at " + row + "x" + col, data[row][col], m.get(row, col), 0d);
        m.set(row, col, -data[row][col]);
    }
    for (int row = 0; row < rows; row++) for (int col = 0; col < cols; col++) assertEquals("Unexpected value set at " + row + "x" + col, -(row * cols + row), m.get(row, col), 0d);
    assertTrue("Incorrect copy for empty matrix.", m.copy().equals(m));
}
Also used : Matrix(org.apache.ignite.ml.math.Matrix) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 4 with UnsupportedOperationException

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

the class MatrixImplementationsTest method testLikeVector.

/**
 */
@Test
public void testLikeVector() {
    consumeSampleMatrix((m, desc) -> {
        if (likeVectorTypesMap().containsKey(m.getClass())) {
            Vector likeVector = m.likeVector(m.columnSize());
            assertNotNull(likeVector);
            assertEquals("Unexpected value for " + desc, likeVector.size(), m.columnSize());
            return;
        }
        boolean expECaught = false;
        try {
            m.likeVector(1);
        } catch (UnsupportedOperationException uoe) {
            expECaught = true;
        }
        assertTrue("Expected exception was not caught for " + desc, expECaught);
    });
}
Also used : RandomVector(org.apache.ignite.ml.math.impls.vector.RandomVector) DenseLocalOffHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector) Vector(org.apache.ignite.ml.math.Vector) SparseLocalVector(org.apache.ignite.ml.math.impls.vector.SparseLocalVector) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException) Test(org.junit.Test) ExternalizeTest(org.apache.ignite.ml.math.ExternalizeTest)

Example 5 with UnsupportedOperationException

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

the class CacheVectorTest method testLikeMatrix.

/**
 */
public void testLikeMatrix() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    IdentityValueMapper valMapper = new IdentityValueMapper();
    CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
    try {
        cacheVector.likeMatrix(size, 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)

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