Blame view

Giac_maj/epsilon-giac/poincare/src/expression_matrix.cpp 2.33 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  extern "C" {
  #include <assert.h>
  #include <stdlib.h>
  }
  #include <poincare/expression_matrix.h>
  #include <poincare/complex_matrix.h>
  #include <poincare/complex.h>
  #include <cmath>
  #include <float.h>
  #include <string.h>
  
  namespace Poincare {
  
  ExpressionMatrix::ExpressionMatrix(MatrixData * matrixData) :
    m_matrixData(matrixData)
  {
  }
  
  ExpressionMatrix::ExpressionMatrix(Expression ** newOperands, int numberOfOperands, int numberOfRows, int numberOfColumns, bool cloneOperands)
  {
    m_matrixData = new MatrixData(newOperands, numberOfOperands, numberOfRows, numberOfColumns, cloneOperands);
  }
  
  ExpressionMatrix::~ExpressionMatrix() {
    delete m_matrixData;
  }
  
  bool ExpressionMatrix::hasValidNumberOfArguments() const {
    for (int i = 0; i < numberOfOperands(); i++) {
      if (!operand(i)->hasValidNumberOfArguments()) {
        return false;
      }
    }
    return true;
  }
  
  
  int ExpressionMatrix::numberOfRows() const {
    return m_matrixData->numberOfRows();
  }
  
  int ExpressionMatrix::numberOfColumns() const {
    return m_matrixData->numberOfColumns();
  }
  
  const Expression * ExpressionMatrix::operand(int i) const {
    assert(i >= 0);
    assert(i < numberOfOperands());
    return m_matrixData->operands()[i];
  }
  
  Expression * ExpressionMatrix::clone() const {
    return this->cloneWithDifferentOperands(m_matrixData->operands(), numberOfOperands(), true);
  }
  
  Expression::Type ExpressionMatrix::type() const {
    return Type::ExpressionMatrix;
  }
  
  Expression * ExpressionMatrix::cloneWithDifferentOperands(Expression** newOperands,
      int numberOfOperands, bool cloneOperands) const {
    assert(newOperands != nullptr);
    return new ExpressionMatrix(newOperands, numberOfOperands, numberOfRows(), numberOfColumns(), cloneOperands);
  }
  
  template<typename T>
  Evaluation<T> * ExpressionMatrix::templatedEvaluate(Context& context, AngleUnit angleUnit) const {
    Complex<T> * operands = new Complex<T>[numberOfOperands()];
    for (int i = 0; i < numberOfOperands(); i++) {
      Evaluation<T> * operandEvaluation = operand(i)->evaluate<T>(context, angleUnit);
      if (operandEvaluation->numberOfOperands() != 1) {
        operands[i] = Complex<T>::Float(NAN);
      } else {
        operands[i] = *(operandEvaluation->complexOperand(0));
      }
      delete operandEvaluation;
    }
    Evaluation<T> * matrix = new ComplexMatrix<T>(operands, numberOfRows(), numberOfColumns());
    delete[] operands;
    return matrix;
  }
  
  }