Blame view

epsilon-master/poincare/src/matrix_dimension.cpp 1.84 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  #include <poincare/matrix_dimension.h>
  #include <poincare/matrix.h>
  extern "C" {
  #include <assert.h>
  }
  #include <cmath>
  
  namespace Poincare {
  
  Expression::Type MatrixDimension::type() const {
    return Type::MatrixDimension;
  }
  
  Expression * MatrixDimension::clone() const {
    MatrixDimension * a = new MatrixDimension(m_operands, true);
    return a;
  }
  
  Expression * MatrixDimension::shallowReduce(Context& context, AngleUnit angleUnit) {
    Expression * e = Expression::shallowReduce(context, angleUnit);
    if (e != this) {
      return e;
    }
  #if MATRIX_EXACT_REDUCING
    Expression * op = editableOperand(0);
    if (op->type() == Type::Matrix) {
      Matrix * m = static_cast<Matrix *>(op);
      const Expression * newOperands[2] = {new Rational(m->numberOfRows()), new Rational(m->numberOfColumns())};
      return replaceWith(new Matrix(newOperands, 1, 2, false), true);
    }
    if (!op->recursivelyMatches(Expression::IsMatrix)) {
      const Expression * newOperands[2] = {new Rational(1), new Rational(1)};
      return replaceWith(new Matrix(newOperands, 1, 2, false), true);
    }
    return this;
  #else
    const Expression * newOperands[2] = {new Rational(1), new Rational(1)};
    return replaceWith(new Matrix(newOperands, 1, 2, false), true);
  #endif
  }
  
  template<typename T>
  Evaluation<T> * MatrixDimension::templatedApproximate(Context& context, AngleUnit angleUnit) const {
    Evaluation<T> * input = operand(0)->privateApproximate(T(), context, angleUnit);
    std::complex<T> operands[2];
    if (input->type() == Evaluation<T>::Type::MatrixComplex) {
      operands[0] = std::complex<T>(static_cast<MatrixComplex<T> *>(input)->numberOfRows());
      operands[1] = std::complex<T>(static_cast<MatrixComplex<T> *>(input)->numberOfColumns());
    } else {
      operands[0] = std::complex<T>(1.0);
      operands[1] = std::complex<T>(1.0);
    }
    delete input;
    return new MatrixComplex<T>(operands, 1, 2);
  }
  
  
  }