Search in sources :

Example 1 with OpenMapRealMatrix

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

the class SparseArrayExpr method toRealMatrix.

/**
 * {@inheritDoc}
 */
@Override
public RealMatrix toRealMatrix() {
    if (fDimension.length == 2 && fDimension[0] > 0 && fDimension[1] > 0) {
        try {
            OpenMapRealMatrix result = new OpenMapRealMatrix(fDimension[0], fDimension[1]);
            if (!fDefaultValue.isZero()) {
                double d = fDefaultValue.evalDouble();
                for (int i = 0; i < fDimension[0]; i++) {
                    for (int j = 0; j < fDimension[1]; j++) {
                        result.setEntry(i, j, d);
                    }
                }
            }
            for (TrieNode<int[], IExpr> entry : fData.nodeSet()) {
                int[] key = entry.getKey();
                IExpr value = entry.getValue();
                result.setEntry(key[0] - 1, key[1] - 1, value.evalDouble());
            }
            return result;
        } catch (ArgumentTypeException rex) {
        }
    }
    return null;
}
Also used : IExpr(org.matheclipse.core.interfaces.IExpr) OpenMapRealMatrix(org.hipparchus.linear.OpenMapRealMatrix) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Aggregations

OpenMapRealMatrix (org.hipparchus.linear.OpenMapRealMatrix)1 ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)1 IExpr (org.matheclipse.core.interfaces.IExpr)1