extern "C" { #include #include } #include #include #include "layout/grid_layout.h" #include "layout/bracket_layout.h" #include #include #include namespace Poincare { template ComplexMatrix::ComplexMatrix(const Complex * complexes, int numberOfRows, int numberOfColumns) : m_numberOfRows(numberOfRows), m_numberOfColumns(numberOfColumns) { assert(complexes != nullptr); m_values = new Complex[numberOfRows*numberOfColumns]; for (int i = 0; i < numberOfRows*numberOfColumns; i++) { m_values[i] = complexes[i]; } } template ComplexMatrix::~ComplexMatrix() { delete[] m_values; } template T ComplexMatrix::toScalar() const { if (m_numberOfRows != 1 || m_numberOfColumns != 1) { return NAN; } if (m_values[0].b() != 0) { return NAN; } return m_values[0].a(); } template int ComplexMatrix::numberOfRows() const { return m_numberOfRows; } template int ComplexMatrix::numberOfColumns() const { return m_numberOfColumns; } template const Complex * ComplexMatrix::complexOperand(int i) const { return &m_values[i]; } template ComplexMatrix * ComplexMatrix::clone() const { return new ComplexMatrix(m_values, m_numberOfRows, m_numberOfColumns); } template ComplexMatrix * ComplexMatrix::cloneWithDifferentOperands(Expression** newOperands, int numberOfOperands, bool cloneOperands) const { assert(newOperands != nullptr); return new ComplexMatrix((Complex *)newOperands[0], m_numberOfRows, m_numberOfColumns); } template Evaluation * ComplexMatrix::createIdentity(int dim) { Complex * operands = new Complex [dim*dim]; for (int i = 0; i < dim; i++) { for (int j = 0; j < dim; j++) { if (i == j) { operands[i*dim+j] = Complex::Float(1.0); } else { operands[i*dim+j] = Complex::Float(0.0); } } } Evaluation * matrix = new ComplexMatrix(operands, dim, dim); delete [] operands; return matrix; } template template Evaluation * ComplexMatrix::templatedEvaluate(Context& context, Expression::AngleUnit angleUnit) const { Complex * values = new Complex[m_numberOfRows*m_numberOfColumns]; for (int i = 0; i < m_numberOfRows*m_numberOfColumns; i++) { values[i] = Complex::Cartesian(m_values[i].a(), m_values[i].b()); } Evaluation * result = new ComplexMatrix(values, m_numberOfRows, m_numberOfColumns); delete [] values; return result; } template class Poincare::ComplexMatrix; template class Poincare::ComplexMatrix; }