Search in sources :

Example 1 with ArrayFieldVector

use of org.hipparchus.linear.ArrayFieldVector in project symja_android_library by axkr.

the class Convert method list2Vector.

/**
 * Returns a FieldVector if possible.
 *
 * @param expr
 * @return <code>null</code> if the conversion isn't possible.
 * @throws ClassCastException
 */
public static FieldVector<IExpr> list2Vector(final IExpr expr) throws ClassCastException {
    if (expr == null) {
        return null;
    }
    int dim = expr.isVector();
    if (dim <= 0) {
        return null;
    }
    if (expr.isSparseArray()) {
        ISparseArray array = (ISparseArray) expr;
        return array.toFieldVector(false);
    }
    if (expr.isList()) {
        final int rowSize = expr.argSize();
        IAST list = (IAST) expr;
        final IExpr[] elements = new IExpr[rowSize];
        for (int i = 0; i < rowSize; i++) {
            elements[i] = list.get(i + 1);
        }
        return new ArrayFieldVector<IExpr>(elements, false);
    }
    return null;
}
Also used : ArrayFieldVector(org.hipparchus.linear.ArrayFieldVector) ISparseArray(org.matheclipse.core.interfaces.ISparseArray) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 2 with ArrayFieldVector

use of org.hipparchus.linear.ArrayFieldVector in project symja_android_library by axkr.

the class Convert method list2ComplexVector.

public static FieldVector<Complex> list2ComplexVector(IExpr expr) throws ClassCastException {
    if (expr == null) {
        return null;
    }
    int dim = expr.isVector();
    if (dim <= 0) {
        return null;
    }
    if (expr.isSparseArray()) {
        // ISparseArray array = (ISparseArray) expr;
        // return array.toFieldVector(false);
        expr = ((ISparseArray) expr).normal(false);
    }
    if (expr.isList()) {
        try {
            final int rowSize = expr.argSize();
            IAST list = (IAST) expr;
            final Complex[] elements = new Complex[rowSize];
            for (int i = 0; i < rowSize; i++) {
                elements[i] = list.get(i + 1).evalComplex();
            }
            return new ArrayFieldVector<Complex>(elements, false);
        } catch (ValidateException vex) {
        // pass
        }
    }
    return null;
}
Also used : ArrayFieldVector(org.hipparchus.linear.ArrayFieldVector) ValidateException(org.matheclipse.core.eval.exception.ValidateException) IAST(org.matheclipse.core.interfaces.IAST) Complex(org.hipparchus.complex.Complex)

Aggregations

ArrayFieldVector (org.hipparchus.linear.ArrayFieldVector)2 IAST (org.matheclipse.core.interfaces.IAST)2 Complex (org.hipparchus.complex.Complex)1 ValidateException (org.matheclipse.core.eval.exception.ValidateException)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 ISparseArray (org.matheclipse.core.interfaces.ISparseArray)1