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);
}
}
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);
}
}
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.
}
}
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);
});
}
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) {
}
}
Aggregations