Numworks Epsilon  1.4.1
Graphing Calculator Operating System
matrix_transpose.cpp
Go to the documentation of this file.
2 #include <poincare/matrix.h>
3 #include <poincare/complex.h>
4 #include <poincare/division.h>
5 extern "C" {
6 #include <assert.h>
7 }
8 #include <cmath>
9 
10 namespace Poincare {
11 
13  return Type::MatrixTranspose;
14 }
15 
18  return a;
19 }
20 
21 Expression * MatrixTranspose::shallowReduce(Context& context, AngleUnit angleUnit) {
22  Expression * e = Expression::shallowReduce(context, angleUnit);
23  if (e != this) {
24  return e;
25  }
26  Expression * op = editableOperand(0);
27 #if MATRIX_EXACT_REDUCING
28  if (op->type() == Type::Matrix) {
29  Matrix * transpose = static_cast<Matrix *>(op)->createTranspose();
30  return replaceWith(transpose, true);
31  }
32  if (!op->recursivelyMatches(Expression::IsMatrix)) {
33  return replaceWith(op, true);
34  }
35  return this;
36 #else
37  return replaceWith(op, true);
38 #endif
39 }
40 
41 template<typename T>
42 Expression * MatrixTranspose::templatedApproximate(Context& context, AngleUnit angleUnit) const {
43  Expression * input = operand(0)->approximate<T>(context, angleUnit);
44  Expression * result = nullptr;
45  if (input->type() == Type::Complex) {
46  result = input->clone();
47  } else {
48  assert(input->type() == Type::Matrix);
49  result = static_cast<Matrix *>(input)->createTranspose();
50  }
51  delete input;
52  return result;
53 }
54 
55 }
#define assert(e)
Definition: assert.h:9
Expression * replaceWith(Expression *newOperand, bool deleteAfterReplace=true)
Definition: expression.cpp:85
Expression * approximate(Context &context, AngleUnit angleUnit=AngleUnit::Default) const
Definition: expression.cpp:338
static bool IsMatrix(const Expression *e, Context &context)
Definition: expression.cpp:198
#define T(x)
Definition: events.cpp:26
Expression * editableOperand(int i)
Definition: expression.h:176
Expression * clone() const override
const Expression * m_operands[T]
friend class Matrix
Definition: expression.h:73
friend class MatrixTranspose
Definition: expression.h:59
const Expression * operand(int i) const
Definition: expression.cpp:78
Type type() const override