Search in sources :

Example 6 with CardinalityException

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

the class VectorImplementationsTest method assignVectorWrongCardinality.

/**
 */
private void assignVectorWrongCardinality(Vector v, String desc) {
    boolean expECaught = false;
    try {
        v.assign(new DenseVector(v.size() + 1));
    } catch (CardinalityException ce) {
        expECaught = true;
    }
    assertTrue("Expect exception at too large size in " + desc, expECaught);
    if (v.size() < 2)
        return;
    expECaught = false;
    try {
        v.assign(new DenseVector(v.size() - 1));
    } catch (CardinalityException ce) {
        expECaught = true;
    }
    assertTrue("Expect exception at too small size in " + desc, expECaught);
}
Also used : CardinalityException(org.apache.ignite.ml.math.exceptions.math.CardinalityException) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

Example 7 with CardinalityException

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

the class VectorImplementationsTest method assertWrongCardinality.

/**
 */
private void assertWrongCardinality(Vector v, String desc, BiFunction<Vector, Vector, Vector> vecOperation) {
    boolean expECaught = false;
    try {
        vecOperation.apply(v, new DenseVector(v.size() + 1));
    } catch (CardinalityException ce) {
        expECaught = true;
    }
    assertTrue("Expect exception at too large size in " + desc, expECaught);
    if (v.size() < 2)
        return;
    expECaught = false;
    try {
        vecOperation.apply(v, new DenseVector(v.size() - 1));
    } catch (CardinalityException ce) {
        expECaught = true;
    }
    assertTrue("Expect exception at too small size in " + desc, expECaught);
}
Also used : CardinalityException(org.apache.ignite.ml.math.exceptions.math.CardinalityException) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

Example 8 with CardinalityException

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

the class AbstractMatrix method times.

/**
 * {@inheritDoc}
 */
@Override
public Vector times(Vector vec) {
    int cols = columnSize();
    if (cols != vec.size())
        throw new CardinalityException(cols, vec.size());
    int rows = rowSize();
    Vector res = likeVector(rows);
    Blas.gemv(1, this, vec, 0, res);
    return res;
}
Also used : CardinalityException(org.apache.ignite.ml.math.exceptions.math.CardinalityException) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

Example 9 with CardinalityException

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

the class AbstractMatrix method setRow.

/**
 * {@inheritDoc}
 */
@Override
public Matrix setRow(int row, double[] data) {
    checkRowIndex(row);
    int cols = columnSize();
    if (cols != data.length)
        throw new CardinalityException(cols, data.length);
    // TODO: IGNITE-5777, use Blas for this.
    for (int y = 0; y < cols; y++) setX(row, y, data[y]);
    return this;
}
Also used : CardinalityException(org.apache.ignite.ml.math.exceptions.math.CardinalityException)

Example 10 with CardinalityException

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

the class AbstractMatrix method assignRow.

/**
 * {@inheritDoc}
 */
@Override
public Matrix assignRow(int row, Vector vec) {
    checkRowIndex(row);
    int cols = columnSize();
    if (cols != vec.size())
        throw new CardinalityException(cols, vec.size());
    // TODO: IGNITE-5777, use Blas for this.
    for (int y = 0; y < cols; y++) storageSet(row, y, vec.getX(y));
    return this;
}
Also used : CardinalityException(org.apache.ignite.ml.math.exceptions.math.CardinalityException)

Aggregations

CardinalityException (org.apache.ignite.ml.math.exceptions.math.CardinalityException)12 DenseVector (org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)4 SingularMatrixException (org.apache.ignite.ml.math.exceptions.math.SingularMatrixException)2 Vector (org.apache.ignite.ml.math.primitives.vector.Vector)2 SparseVector (org.apache.ignite.ml.math.primitives.vector.impl.SparseVector)2 FileParsingException (org.apache.ignite.ml.math.exceptions.datastructures.FileParsingException)1 MathIllegalArgumentException (org.apache.ignite.ml.math.exceptions.math.MathIllegalArgumentException)1 NonSquareMatrixException (org.apache.ignite.ml.math.exceptions.math.NonSquareMatrixException)1 VectorizedViewMatrix (org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix)1 LabeledVector (org.apache.ignite.ml.structures.LabeledVector)1 NotNull (org.jetbrains.annotations.NotNull)1