Skip to content

Commit df4de2f

Browse files
committed
Add missing header for std::negate
1 parent a45d075 commit df4de2f

2 files changed

Lines changed: 27 additions & 22 deletions

File tree

src/core/matrix.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#ifndef GAMBIT_CORE_MATRIX_H
2424
#define GAMBIT_CORE_MATRIX_H
2525

26+
#include <functional>
27+
2628
#include "recarray.h"
2729
#include "vector.h"
2830
#include "rational.h"
@@ -98,10 +100,13 @@ template <class T> class Matrix {
98100
template <class V> void SetColumn(int j, const V &);
99101
template <class V> void GetRow(int row, V &) const;
100102
template <class V> void SetRow(int row, const V &);
101-
// vector helpers used internally
102-
template <class V> bool CheckRow(const V &v) const { return m_data.CheckRow(v); }
103-
template <class V> bool CheckColumn(const V &v) const { return m_data.CheckColumn(v); }
104-
bool CheckBounds(const Matrix &M) const { return m_data.CheckBounds(M.m_data); }
103+
104+
/// @brief Test whether a vector conforms to the matrix row shape
105+
template <class V> bool ConformsToRow(const V &v) const { return m_data.ConformsToRow(v); }
106+
/// @brief Test whether a vector conforms to the matrix column shape
107+
template <class V> bool ConformsToColumn(const V &v) const { return m_data.ConformsToColumn(v); }
108+
/// @brief Test whether another matrix conforms to the shape of this matrix
109+
bool ConformsTo(const Matrix &M) const { return m_data.ConformsTo(M.m_data); }
105110
///@}
106111

107112
/// @name Comparison operators
@@ -219,7 +224,7 @@ template <class T> Matrix<T> &Matrix<T>::operator=(const T &c)
219224

220225
template <class T> bool Matrix<T>::operator==(const Matrix &M) const
221226
{
222-
if (!this->CheckBounds(M)) {
227+
if (!this->ConformsTo(M)) {
223228
throw DimensionException();
224229
}
225230
return std::equal(m_data.elements_begin(), m_data.elements_end(), M.m_data.elements_begin());
@@ -233,7 +238,7 @@ template <class T> bool Matrix<T>::operator==(const T &c) const
233238

234239
template <class T> Matrix<T> &Matrix<T>::operator+=(const Matrix &M)
235240
{
236-
if (!this->CheckBounds(M)) {
241+
if (!this->ConformsTo(M)) {
237242
throw DimensionException();
238243
}
239244
std::transform(m_data.elements_begin(), m_data.elements_end(), M.m_data.elements_begin(),
@@ -243,7 +248,7 @@ template <class T> Matrix<T> &Matrix<T>::operator+=(const Matrix &M)
243248

244249
template <class T> Matrix<T> &Matrix<T>::operator-=(const Matrix &M)
245250
{
246-
if (!this->CheckBounds(M)) {
251+
if (!this->ConformsTo(M)) {
247252
throw DimensionException();
248253
}
249254
std::transform(m_data.elements_begin(), m_data.elements_end(), M.m_data.elements_begin(),
@@ -268,7 +273,7 @@ template <class T> Matrix<T> &Matrix<T>::operator*=(const T &c)
268273

269274
template <class T> Matrix<T> &Matrix<T>::operator/=(const T &c)
270275
{
271-
if (c == static_cast<T>(0)) {
276+
if (c == T{0}) {
272277
throw ZeroDivideException();
273278
}
274279
std::transform(m_data.elements_begin(), m_data.elements_end(), m_data.elements_begin(),
@@ -285,7 +290,7 @@ template <class T> template <class V> void Matrix<T>::GetColumn(int col, V &v) c
285290
if (col < MinCol() || col > MaxCol()) {
286291
throw std::out_of_range("Index out of range in Matrix::GetColumn");
287292
}
288-
if (!CheckColumn(v)) {
293+
if (!ConformsToColumn(v)) {
289294
throw DimensionException();
290295
}
291296
for (int i = MinRow(); i <= MaxRow(); ++i) {
@@ -298,7 +303,7 @@ template <class T> template <class V> void Matrix<T>::SetColumn(int col, const V
298303
if (col < MinCol() || col > MaxCol()) {
299304
throw std::out_of_range("Index out of range in Matrix::SetColumn");
300305
}
301-
if (!CheckColumn(v)) {
306+
if (!ConformsToColumn(v)) {
302307
throw DimensionException();
303308
}
304309
for (int i = MinRow(); i <= MaxRow(); ++i) {
@@ -311,7 +316,7 @@ template <class T> template <class V> void Matrix<T>::GetRow(int row, V &v) cons
311316
if (row < MinRow() || row > MaxRow()) {
312317
throw std::out_of_range("Index out of range in Matrix::GetRow");
313318
}
314-
if (!CheckRow(v)) {
319+
if (!ConformsToRow(v)) {
315320
throw DimensionException();
316321
}
317322
for (int j = MinCol(); j <= MaxCol(); ++j) {
@@ -324,7 +329,7 @@ template <class T> template <class V> void Matrix<T>::SetRow(int row, const V &v
324329
if (row < MinRow() || row > MaxRow()) {
325330
throw std::out_of_range("Index out of range in Matrix::SetRow");
326331
}
327-
if (!CheckRow(v)) {
332+
if (!ConformsToRow(v)) {
328333
throw DimensionException();
329334
}
330335
for (int j = MinCol(); j <= MaxCol(); ++j) {
@@ -338,7 +343,7 @@ template <class T> template <class V> void Matrix<T>::SetRow(int row, const V &v
338343

339344
template <class T> void Matrix<T>::CMultiply(const Vector<T> &p_input, Vector<T> &p_output) const
340345
{
341-
if (!this->CheckRow(p_input) || !this->CheckColumn(p_output)) {
346+
if (!this->ConformsToRow(p_input) || !this->ConformsToColumn(p_output)) {
342347
throw DimensionException();
343348
}
344349
for (int i = MinRow(); i <= MaxRow(); ++i) {
@@ -349,7 +354,7 @@ template <class T> void Matrix<T>::CMultiply(const Vector<T> &p_input, Vector<T>
349354

350355
template <class T> void Matrix<T>::RMultiply(const Vector<T> &p_input, Vector<T> &p_output) const
351356
{
352-
if (!this->CheckColumn(p_input) || !this->CheckRow(p_output)) {
357+
if (!this->ConformsToColumn(p_input) || !this->ConformsToRow(p_output)) {
353358
throw DimensionException();
354359
}
355360

@@ -366,7 +371,7 @@ template <class T> void Matrix<T>::RMultiply(const Vector<T> &p_input, Vector<T>
366371

367372
template <class T> Vector<T> Matrix<T>::operator*(const Vector<T> &v) const
368373
{
369-
if (!this->CheckRow(v)) {
374+
if (!this->ConformsToRow(v)) {
370375
throw DimensionException();
371376
}
372377
Vector<T> tmp(MinRow(), MaxRow());
@@ -575,7 +580,7 @@ template <class T> T Matrix<T>::Determinant() const
575580
/// @sa Matrix<T>::RMultiply
576581
template <class T> Vector<T> operator*(const Vector<T> &v, const Matrix<T> &M)
577582
{
578-
if (!M.CheckColumn(v)) {
583+
if (!M.ConformsToColumn(v)) {
579584
throw DimensionException();
580585
}
581586
Vector<T> tmp(M.MinCol(), M.MaxCol());

src/core/recarray.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,22 @@ template <class T> class RectArray {
156156
/// @name Range checking functions; returns true only if valid index/size
157157
//@{
158158
/// check array for same row and column boundaries
159-
bool CheckBounds(const RectArray<T> &m) const
159+
bool ConformsTo(const RectArray &m) const
160160
{
161161
return (m_minrow == m.m_minrow && m_maxrow == m.m_maxrow && m_mincol == m.m_mincol &&
162162
m_maxcol == m.m_maxcol);
163163
}
164164
/// check for correct row index
165165
bool CheckRow(const int row) const { return (m_minrow <= row && row <= m_maxrow); }
166166
/// check row vector for correct column boundaries
167-
template <class V> bool CheckRow(const V &v) const
167+
template <class V> bool ConformsToRow(const V &v) const
168168
{
169169
return v.front_index() == m_mincol && v.back_index() == m_maxcol;
170170
}
171171
/// check for correct column index
172172
bool CheckColumn(const int col) const { return (m_mincol <= col && col <= m_maxcol); }
173173
/// check column vector for correct row boundaries
174-
template <class V> bool CheckColumn(const V &v) const
174+
template <class V> bool ConformsToColumn(const V &v) const
175175
{
176176
return (v.front_index() == m_minrow && v.back_index() == m_maxrow);
177177
}
@@ -292,7 +292,7 @@ template <class T> template <class Vector> void RectArray<T>::GetRow(int row, Ve
292292
if (!CheckRow(row)) {
293293
throw std::out_of_range("Index out of range in RectArray");
294294
}
295-
if (!CheckRow(v)) {
295+
if (!ConformsToRow(v)) {
296296
throw DimensionException();
297297
}
298298
const size_t base = index(row, m_mincol);
@@ -310,7 +310,7 @@ template <class T> template <class Vector> void RectArray<T>::GetColumn(int col,
310310
if (!CheckColumn(col)) {
311311
throw std::out_of_range("Index out of range in RectArray");
312312
}
313-
if (!CheckColumn(v)) {
313+
if (!ConformsToColumn(v)) {
314314
throw DimensionException();
315315
}
316316
for (int r = m_minrow; r <= m_maxrow; ++r) {
@@ -323,7 +323,7 @@ template <class T> template <class Vector> void RectArray<T>::SetColumn(int col,
323323
if (!CheckColumn(col)) {
324324
throw std::out_of_range("Index out of range in RectArray");
325325
}
326-
if (!CheckColumn(v)) {
326+
if (!ConformsToColumn(v)) {
327327
throw DimensionException();
328328
}
329329
for (int r = m_minrow; r <= m_maxrow; ++r) {

0 commit comments

Comments
 (0)