Consistently use ordering rows, cols everywhere.

Changing the order of logical operators, etc is just to make searching for actual bugs easier.
This commit is contained in:
Jacob Young
2017-08-31 17:41:59 -04:00
parent 6a0e280168
commit 303120c7e2
7 changed files with 19 additions and 17 deletions

View File

@@ -8,7 +8,7 @@ namespace Poincare {
class ExpressionMatrix : public Matrix {
public:
ExpressionMatrix(MatrixData * matrixData);
ExpressionMatrix(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
ExpressionMatrix(Expression ** newOperands, int numberOfOperands, int m_numberOfRows, int m_numberOfColumns, bool cloneOperands);
~ExpressionMatrix();
ExpressionMatrix(const Matrix& other) = delete;
ExpressionMatrix(Matrix&& other) = delete;

View File

@@ -12,7 +12,7 @@ class Complex;
class MatrixData {
public:
MatrixData(ListData * listData, bool clone);
MatrixData(Expression ** newOperands, int numberOfOperands, int m_numberOfColumns, int m_numberOfRows, bool cloneOperands);
MatrixData(Expression ** newOperands, int numberOfOperands, int m_numberOfRows, int m_numberOfColumns, bool cloneOperands);
~MatrixData();
MatrixData(const MatrixData& other) = delete;
MatrixData(MatrixData&& other) = delete;

View File

@@ -18,8 +18,8 @@ ComplexMatrix<T>::ComplexMatrix(const Complex<T> * complexes, int numberOfRows,
m_numberOfColumns(numberOfColumns)
{
assert(complexes != nullptr);
m_values = new Complex<T>[numberOfColumns*numberOfRows];
for (int i = 0; i < numberOfColumns*numberOfRows; i++) {
m_values = new Complex<T>[numberOfRows*numberOfColumns];
for (int i = 0; i < numberOfRows*numberOfColumns; i++) {
m_values[i] = complexes[i];
}
}
@@ -31,7 +31,7 @@ ComplexMatrix<T>::~ComplexMatrix() {
template<typename T>
T ComplexMatrix<T>::toScalar() const {
if (m_numberOfColumns != 1 || m_numberOfRows != 1) {
if (m_numberOfRows != 1 || m_numberOfColumns != 1) {
return NAN;
}
if (m_values[0].b() != 0) {
@@ -87,8 +87,8 @@ Evaluation<T> * ComplexMatrix<T>::createIdentity(int dim) {
template<typename T>
template <class U>
Evaluation<U> * ComplexMatrix<T>::templatedEvaluate(Context& context, Expression::AngleUnit angleUnit) const {
Complex<U> * values = new Complex<U>[m_numberOfColumns*m_numberOfRows];
for (int i = 0; i < m_numberOfColumns*m_numberOfRows; i++) {
Complex<U> * values = new Complex<U>[m_numberOfRows*m_numberOfColumns];
for (int i = 0; i < m_numberOfRows*m_numberOfColumns; i++) {
values[i] = Complex<U>::Cartesian(m_values[i].a(), m_values[i].b());
}
Evaluation<U> * result = new ComplexMatrix<U>(values, m_numberOfRows, m_numberOfColumns);

View File

@@ -31,7 +31,7 @@ const Expression * Evaluation<T>::operand(int i) const {
template<typename T>
Evaluation<T> * Evaluation<T>::createTrace() const {
if (numberOfColumns() != numberOfRows()) {
if (numberOfRows() != numberOfColumns()) {
return new Complex<T>(Complex<T>::Float(NAN));
}
int dim = numberOfRows();
@@ -45,7 +45,7 @@ Evaluation<T> * Evaluation<T>::createTrace() const {
template<typename T>
// TODO: implement determinant for complex matrix?
Evaluation<T> * Evaluation<T>::createDeterminant() const {
if (numberOfColumns() != numberOfRows()) {
if (numberOfRows() != numberOfColumns()) {
return new Complex<T>(Complex<T>::Float(NAN));
}
int dim = numberOfRows();
@@ -107,7 +107,7 @@ Evaluation<T> * Evaluation<T>::createDeterminant() const {
template<typename T>
Evaluation<T> * Evaluation<T>::createInverse() const {
if (numberOfColumns() != numberOfRows()) {
if (numberOfRows() != numberOfColumns()) {
return new Complex<T>(Complex<T>::Float(NAN));
}
int dim = numberOfRows();
@@ -175,6 +175,7 @@ Evaluation<T> * Evaluation<T>::createInverse() const {
delete[] inv[i];
}
delete[] inv;
// Intentionally swapping dimensions for inverse, although it doesn't make a difference because it is square
Evaluation<T> * matrix = new ComplexMatrix<T>(operands, numberOfColumns(), numberOfRows());
delete[] operands;
return matrix;
@@ -188,6 +189,7 @@ Evaluation<T> * Evaluation<T>::createTranspose() const {
operands[j*numberOfRows()+i] = *(complexOperand(i*numberOfColumns()+j));
}
}
// Intentionally swapping dimensions for transpose
Evaluation<T> * matrix = new ComplexMatrix<T>(operands, numberOfColumns(), numberOfRows());
delete[] operands;
return matrix;

View File

@@ -16,9 +16,9 @@ ExpressionMatrix::ExpressionMatrix(MatrixData * matrixData) :
{
}
ExpressionMatrix::ExpressionMatrix(Expression ** newOperands, int numberOfOperands, int numberOfColumns, int numberOfRows, bool cloneOperands)
ExpressionMatrix::ExpressionMatrix(Expression ** newOperands, int numberOfOperands, int numberOfRows, int numberOfColumns, bool cloneOperands)
{
m_matrixData = new MatrixData(newOperands, numberOfOperands, numberOfColumns, numberOfRows, cloneOperands);
m_matrixData = new MatrixData(newOperands, numberOfOperands, numberOfRows, numberOfColumns, cloneOperands);
}
ExpressionMatrix::~ExpressionMatrix() {
@@ -60,7 +60,7 @@ Expression::Type ExpressionMatrix::type() const {
Expression * ExpressionMatrix::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(newOperands != nullptr);
return new ExpressionMatrix(newOperands, numberOfOperands, numberOfColumns(), numberOfRows(), cloneOperands);
return new ExpressionMatrix(newOperands, numberOfOperands, numberOfRows(), numberOfColumns(), cloneOperands);
}
template<typename T>

View File

@@ -23,13 +23,13 @@ MatrixData::MatrixData(ListData * listData, bool clone) :
}
}
MatrixData::MatrixData(Expression ** newOperands, int numberOfOperands, int numberOfColumns, int numberOfRows, bool cloneOperands) :
MatrixData::MatrixData(Expression ** newOperands, int numberOfOperands, int numberOfRows, int numberOfColumns, bool cloneOperands) :
m_numberOfRows(numberOfRows),
m_numberOfColumns(numberOfColumns)
{
assert(newOperands != nullptr);
m_operands = new Expression *[m_numberOfRows*m_numberOfColumns];
for (int i = 0; i < m_numberOfColumns*m_numberOfRows; i++) {
for (int i = 0; i < m_numberOfRows*m_numberOfColumns; i++) {
if (cloneOperands) {
m_operands[i] = i < numberOfOperands ? newOperands[i]->clone() : defaultExpression();
} else {
@@ -44,7 +44,7 @@ Complex<double> * MatrixData::defaultExpression() {
}
MatrixData::~MatrixData() {
for (int i=0; i<m_numberOfColumns*m_numberOfRows; i++) {
for (int i=0; i<m_numberOfRows*m_numberOfColumns; i++) {
// Warning: avoid deleting the defaultExpression
if (m_operands[i] != defaultExpression()) {
delete m_operands[i];

View File

@@ -65,7 +65,7 @@ Complex<T> Power::compute(const Complex<T> c, const Complex<T> d) {
}
template<typename T> Evaluation<T> * Power::templatedComputeOnComplexMatrixAndComplex(Evaluation<T> * m, const Complex<T> * d) const {
if (m->numberOfColumns() != m->numberOfRows()) {
if (m->numberOfRows() != m->numberOfColumns()) {
return new Complex<T>(Complex<T>::Float(NAN));
}
T power = d->toScalar();