Search in sources :

Example 6 with ISparseArray

use of org.matheclipse.core.interfaces.ISparseArray 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)

Aggregations

ISparseArray (org.matheclipse.core.interfaces.ISparseArray)6 IAST (org.matheclipse.core.interfaces.IAST)3 IExpr (org.matheclipse.core.interfaces.IExpr)3 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)2 ISymbol (org.matheclipse.core.interfaces.ISymbol)2 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 DoubleUnaryOperator (java.util.function.DoubleUnaryOperator)1 MathIllegalArgumentException (org.hipparchus.exception.MathIllegalArgumentException)1 ArrayFieldVector (org.hipparchus.linear.ArrayFieldVector)1 IBuiltInSymbol (org.matheclipse.core.interfaces.IBuiltInSymbol)1 IEvaluator (org.matheclipse.core.interfaces.IEvaluator)1 IPatternObject (org.matheclipse.core.interfaces.IPatternObject)1