mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 07:10:40 +01:00
[poincare] Complete Matrix class to prepare for parsing
This commit is contained in:
@@ -68,9 +68,12 @@ class Matrix : public Expression {
|
||||
template<typename T> friend class MatrixComplexNode;
|
||||
friend class GlobalContext;
|
||||
public:
|
||||
static Matrix EmptyMatrix() {
|
||||
return Matrix(TreePool::sharedPool()->createTreeNode<MatrixNode>());
|
||||
}
|
||||
Matrix() : Expression() {}
|
||||
Matrix(const MatrixNode * node) : Expression(node) {}
|
||||
Matrix() : Expression(TreePool::sharedPool()->createTreeNode<MatrixNode>()) {}
|
||||
Matrix(Expression e) : Matrix() {
|
||||
Matrix(Expression e) : Matrix(TreePool::sharedPool()->createTreeNode<MatrixNode>()) {
|
||||
addChildAtIndexInPlace(e, 0, 0);
|
||||
setDimensions(1,1);
|
||||
}
|
||||
@@ -80,8 +83,9 @@ public:
|
||||
int numberOfColumns() const { return node()->numberOfColumns(); }
|
||||
void addChildAtIndexInPlace(TreeByValue t, int index, int currentNumberOfChildren) {
|
||||
Expression::addChildAtIndexInPlace(t, index, currentNumberOfChildren);
|
||||
setDimensions(1, currentNumberOfChildren + 1);
|
||||
}
|
||||
|
||||
void addChildrenAsRowInPlace(TreeByValue t, int i);
|
||||
Expression matrixChild(int i, int j) { return childAtIndex(i*numberOfColumns()+j); }
|
||||
|
||||
/* Operation on matrix */
|
||||
|
||||
@@ -97,13 +97,26 @@ Evaluation<T> MatrixNode::templatedApproximate(Context& context, Preferences::An
|
||||
// MATRIX
|
||||
|
||||
void Matrix::setDimensions(int rows, int columns) {
|
||||
if (node()->type() != ExpressionNode::Type::AllocationFailure) {
|
||||
assert(rows * columns == node()->numberOfChildren());
|
||||
}
|
||||
setNumberOfRows(rows);
|
||||
setNumberOfColumns(columns);
|
||||
}
|
||||
|
||||
void Matrix::addChildrenAsRowInPlace(TreeByValue t, int i) {
|
||||
if (t.isAllocationFailure()) {
|
||||
replaceWithAllocationFailureInPlace(numberOfChildren());
|
||||
return;
|
||||
}
|
||||
int previousNumberOfColumns = numberOfColumns();
|
||||
if (previousNumberOfColumns > 0) {
|
||||
assert(t.numberOfChildren() == numberOfColumns());
|
||||
}
|
||||
int previousNumberOfRows = numberOfRows();
|
||||
for (int i = 0; i < t.numberOfChildren(); i++) {
|
||||
addChildAtIndexInPlace(t.childAtIndex(i), numberOfChildren(), numberOfChildren());
|
||||
}
|
||||
setDimensions(previousNumberOfRows + 1, previousNumberOfColumns == 0 ? t.numberOfChildren() : previousNumberOfColumns);
|
||||
}
|
||||
|
||||
int Matrix::rank(Context & context, Preferences::AngleUnit angleUnit) {
|
||||
Matrix m = rowCanonize(context, angleUnit);
|
||||
int rank = m.numberOfRows();
|
||||
|
||||
Reference in New Issue
Block a user