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;
}
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;
}
Aggregations