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