Skip to content

Commit 33607cc

Browse files
committed
More standards fixups
1 parent 726a5f9 commit 33607cc

3 files changed

Lines changed: 28 additions & 51 deletions

File tree

src/core/matrix.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ class SingularMatrixException final : public std::runtime_error {
3434
~SingularMatrixException() noexcept override = default;
3535
};
3636

37-
template <class T> Vector<T> operator*(const Vector<T> &, const Matrix<T> &);
38-
3937
template <class T> class Matrix {
40-
friend Vector<T> operator* <>(const Vector<T> &, const Matrix &);
41-
4238
RectArray<T> m_data;
4339

4440
public:
@@ -115,7 +111,7 @@ template <class T> class Matrix {
115111
void CMultiply(const Vector<T> &, Vector<T> &) const;
116112
/// "in-place" row (transposed) multiply
117113
void RMultiply(const Vector<T> &, Vector<T> &) const;
118-
Matrix operator*(const Matrix<T> &) const;
114+
Matrix operator*(const Matrix &) const;
119115
Vector<T> operator*(const Vector<T> &) const;
120116
Matrix operator*(const T &) const;
121117
Matrix &operator*=(const T &);
@@ -138,57 +134,53 @@ template <class T> class Matrix {
138134

139135
template <class T> Vector<T> operator*(const Vector<T> &, const Matrix<T> &);
140136

141-
template <class T> template <class Vector> void Matrix<T>::GetColumn(int col, Vector &v) const
137+
template <class T> template <class V> void Matrix<T>::GetColumn(int col, V &v) const
142138
{
143139
if (col < MinCol() || col > MaxCol()) {
144140
throw std::out_of_range("Index out of range in Matrix::GetColumn");
145141
}
146142
if (!CheckColumn(v)) {
147143
throw DimensionException();
148144
}
149-
150145
for (int i = MinRow(); i <= MaxRow(); ++i) {
151146
v[i] = (*this)(i, col);
152147
}
153148
}
154149

155-
template <class T> template <class Vector> void Matrix<T>::SetColumn(int col, const Vector &v)
150+
template <class T> template <class V> void Matrix<T>::SetColumn(int col, const V &v)
156151
{
157152
if (col < MinCol() || col > MaxCol()) {
158153
throw std::out_of_range("Index out of range in Matrix::SetColumn");
159154
}
160155
if (!CheckColumn(v)) {
161156
throw DimensionException();
162157
}
163-
164158
for (int i = MinRow(); i <= MaxRow(); ++i) {
165159
(*this)(i, col) = v[i];
166160
}
167161
}
168162

169-
template <class T> template <class Vector> void Matrix<T>::GetRow(int row, Vector &v) const
163+
template <class T> template <class V> void Matrix<T>::GetRow(int row, V &v) const
170164
{
171165
if (row < MinRow() || row > MaxRow()) {
172166
throw std::out_of_range("Index out of range in Matrix::GetRow");
173167
}
174168
if (!CheckRow(v)) {
175169
throw DimensionException();
176170
}
177-
178171
for (int j = MinCol(); j <= MaxCol(); ++j) {
179172
v[j] = (*this)(row, j);
180173
}
181174
}
182175

183-
template <class T> template <class Vector> void Matrix<T>::SetRow(int row, const Vector &v)
176+
template <class T> template <class V> void Matrix<T>::SetRow(int row, const V &v)
184177
{
185178
if (row < MinRow() || row > MaxRow()) {
186179
throw std::out_of_range("Index out of range in Matrix::SetRow");
187180
}
188181
if (!CheckRow(v)) {
189182
throw DimensionException();
190183
}
191-
192184
for (int j = MinCol(); j <= MaxCol(); ++j) {
193185
(*this)(row, j) = v[j];
194186
}

src/core/matrix.imp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ template <class T> void Matrix<T>::RMultiply(const Vector<T> &in, Vector<T> &out
184184
}
185185

186186
// transposed (row) vector*matrix multiplication operator
187-
// a friend function of Matrix
188187
template <class T> Vector<T> operator*(const Vector<T> &v, const Matrix<T> &M)
189188
{
190189
if (!M.CheckColumn(v)) {

src/core/recarray.h

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,46 @@ template <class T> class RectArray {
4545
/// @name Lifecycle
4646
//@{
4747
RectArray() : m_minrow(1), m_maxrow(0), m_mincol(1), m_maxcol(0), m_storage() {}
48-
RectArray(unsigned int nrows, unsigned int ncols);
49-
RectArray(int minr, int maxr, int minc, int maxc)
50-
: m_minrow(minr), m_maxrow(maxr), m_mincol(minc), m_maxcol(maxc),
51-
m_storage((maxr >= minr && maxc >= minc) ? (maxr - minr + 1) * (maxc - minc + 1) : 0)
48+
RectArray(const size_t nrows, const size_t ncols) : RectArray(1, nrows, 1, ncols) {}
49+
RectArray(const int minrow, const int maxrow, const int mincol, const int maxcol)
50+
: m_minrow(minrow), m_maxrow(maxrow), m_mincol(mincol), m_maxcol(maxcol),
51+
m_storage((maxrow >= minrow && maxcol >= mincol)
52+
? (maxrow - minrow + 1) * (maxcol - mincol + 1)
53+
: 0)
5254
{
5355
}
5456
RectArray(const RectArray &) = default;
5557
RectArray(RectArray &&) noexcept = default;
56-
57-
virtual ~RectArray() = default;
58+
~RectArray() = default;
5859

5960
RectArray &operator=(const RectArray &) = default;
6061
RectArray &operator=(RectArray &&) noexcept = default;
6162
//@}
6263

64+
/// @name Range checking functions; returns true only if valid index/size
65+
//@{
6366
/// check array for same row and column boundaries
6467
bool CheckBounds(const RectArray<T> &m) const
6568
{
6669
return (m_minrow == m.m_minrow && m_maxrow == m.m_maxrow && m_mincol == m.m_mincol &&
6770
m_maxcol == m.m_maxcol);
6871
}
69-
/// @name Range checking functions; returns true only if valid index/size
70-
//@{
7172
/// check for correct row index
72-
bool CheckRow(int row) const { return (m_minrow <= row && row <= m_maxrow); }
73+
bool CheckRow(const int row) const { return (m_minrow <= row && row <= m_maxrow); }
7374
/// check row vector for correct column boundaries
74-
template <class Vector> bool CheckRow(const Vector &v) const
75+
template <class V> bool CheckRow(const V &v) const
7576
{
76-
return (v.front_index() == m_mincol && v.back_index() == m_maxcol);
77+
return v.front_index() == m_mincol && v.back_index() == m_maxcol;
7778
}
7879
/// check for correct column index
79-
bool CheckColumn(int col) const { return (m_mincol <= col && col <= m_maxcol); }
80+
bool CheckColumn(const int col) const { return (m_mincol <= col && col <= m_maxcol); }
8081
/// check column vector for correct row boundaries
81-
template <class Vector> bool CheckColumn(const Vector &v) const
82+
template <class V> bool CheckColumn(const V &v) const
8283
{
8384
return (v.front_index() == m_minrow && v.back_index() == m_maxrow);
8485
}
8586
/// check row and column indices
86-
bool Check(int row, int col) const { return CheckRow(row) && CheckColumn(col); }
87+
bool Check(const int row, const int col) const { return CheckRow(row) && CheckColumn(col); }
8788

8889
//@}
8990
/// @name General data access
@@ -131,7 +132,7 @@ template <class T> class RectArray {
131132
return;
132133
}
133134

134-
auto stride = row_stride();
135+
const auto stride = row_stride();
135136
const size_t ai = index(i, m_mincol);
136137
const size_t aj = index(j, m_mincol);
137138
for (size_t k = 0; k < stride; ++k) {
@@ -145,15 +146,6 @@ template <class T> class RectArray {
145146
//@}
146147
};
147148

148-
//------------------------------------------------------------------------
149-
// RectArray<T>: Constructors, destructor, constructive operators
150-
//------------------------------------------------------------------------
151-
152-
template <class T>
153-
RectArray<T>::RectArray(unsigned int rows, unsigned int cols) : RectArray(1, rows, 1, cols)
154-
{
155-
}
156-
157149
//------------------------------------------------------------------------
158150
// RectArray<T>: Row and column rotation
159151
//------------------------------------------------------------------------
@@ -163,12 +155,9 @@ template <class T> void RectArray<T>::RotateUp(int lo, int hi)
163155
if (lo < m_minrow || hi < lo || m_maxrow < hi) {
164156
throw std::out_of_range("Index out of range in RectArray");
165157
}
166-
167-
auto stride = row_stride();
168-
169-
size_t first = index(lo, m_mincol);
170-
size_t last = index(hi + 1, m_mincol);
171-
158+
const auto stride = row_stride();
159+
const size_t first = index(lo, m_mincol);
160+
const size_t last = index(hi + 1, m_mincol);
172161
std::rotate(m_storage.begin() + first, m_storage.begin() + first + stride,
173162
m_storage.begin() + last);
174163
}
@@ -178,12 +167,9 @@ template <class T> void RectArray<T>::RotateDown(int lo, int hi)
178167
if (lo < m_minrow || hi < lo || m_maxrow < hi) {
179168
throw std::out_of_range("Index out of range in RectArray");
180169
}
181-
182-
auto stride = row_stride();
183-
184-
size_t first = index(lo, m_mincol);
185-
size_t last = index(hi + 1, m_mincol);
186-
170+
const auto stride = row_stride();
171+
const size_t first = index(lo, m_mincol);
172+
const size_t last = index(hi + 1, m_mincol);
187173
std::rotate(m_storage.begin() + first, m_storage.begin() + last - stride,
188174
m_storage.begin() + last);
189175
}
@@ -200,7 +186,7 @@ template <class T> template <class Vector> void RectArray<T>::GetRow(int row, Ve
200186
if (!CheckRow(v)) {
201187
throw DimensionException();
202188
}
203-
size_t base = index(row, m_mincol);
189+
const size_t base = index(row, m_mincol);
204190
for (int c = m_mincol; c <= m_maxcol; ++c) {
205191
v[c] = m_storage[base + (c - m_mincol)];
206192
}

0 commit comments

Comments
 (0)