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
220225template <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
234239template <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
244249template <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
269274template <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
339344template <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
350355template <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
367372template <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
576581template <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 ());
0 commit comments