37 #include <boost/core/ignore_unused.hpp>
45 unsigned int subDiags,
unsigned int superDiags)
52 if( diags != std::numeric_limits<unsigned int>::max() )
56 else if( totalRows > 0 )
72 unsigned int totalColumns,
73 unsigned int row,
unsigned int column,
74 unsigned int sub,
unsigned int super)
76 boost::ignore_unused(totalColumns);
81 unsigned int elementColumn = column;
87 return std::numeric_limits<unsigned int>::max();
92 std::tuple<unsigned int, unsigned int>
94 const unsigned int curRow,
const unsigned int curColumn)
96 boost::ignore_unused(totalRows, totalColumns);
97 unsigned int nextRow = curRow;
98 unsigned int nextColumn = curColumn;
100 return std::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
111 boost::ignore_unused(totalColumns);
112 return curColumn*totalRows + curRow;
116 std::tuple<unsigned int, unsigned int>
118 const unsigned int curRow,
const unsigned int curColumn)
120 unsigned int nextRow = curRow;
121 unsigned int nextColumn = curColumn;
123 if( nextRow < totalRows )
128 if( nextRow >= totalRows )
134 if( nextColumn >= totalColumns )
136 nextRow = std::numeric_limits<unsigned int>::max();
137 nextColumn = std::numeric_limits<unsigned int>::max();
140 return std::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
146 ASSERTL0(rows==columns,
"Triangular matrices must be square.");
147 return rows*(rows+1)/2;
152 if( curRow <= curColumn )
154 return curRow + curColumn*(curColumn+1)/2;
158 return std::numeric_limits<unsigned int>::max();
162 std::tuple<unsigned int, unsigned int>
164 const unsigned int curRow,
const unsigned int curColumn)
166 boost::ignore_unused(totalRows);
168 ASSERTL1(totalRows == totalColumns,
"Triangular matrices must be square.");
169 ASSERTL1(curRow < totalRows,
"Attemping to iterate through an element on row " +
170 std::to_string(curRow) +
" of a (" +
171 std::to_string(totalRows) +
", " +
172 std::to_string(totalColumns) +
" upper triangular matrix.");
173 ASSERTL1(curColumn < totalColumns,
"Attemping to iterate through an element on row " +
174 std::to_string(curColumn) +
" of a (" +
175 std::to_string(totalRows) +
", " +
176 std::to_string(totalColumns) +
" upper triangular matrix.");
177 ASSERTL1(curRow <= curColumn,
"Attemping to iterate through element (" +
178 std::to_string(curRow) +
", " +
179 std::to_string(curColumn) +
") of a (" +
180 std::to_string(totalRows) +
", " +
181 std::to_string(totalColumns) +
" upper triangular matrix.");
183 unsigned int nextRow = curRow;
184 unsigned int nextColumn = curColumn;
186 if( nextRow <= nextColumn )
191 if( nextRow > nextColumn )
197 if( nextColumn >= totalColumns )
199 nextRow = std::numeric_limits<unsigned int>::max();
200 nextColumn = std::numeric_limits<unsigned int>::max();
203 return std::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
209 if( curRow >= curColumn )
211 return curRow + (2*totalColumns - curColumn - 1)*(curColumn)/2;
215 return std::numeric_limits<unsigned int>::max();
219 std::tuple<unsigned int, unsigned int>
221 const unsigned int curRow,
const unsigned int curColumn,
224 ASSERTL1(totalRows == totalColumns,
"Triangular matrices must be square.");
225 ASSERTL1(curRow < totalRows,
"Attemping to iterate through an element on row " +
226 std::to_string(curRow) +
" of a (" +
227 std::to_string(totalRows) +
", " +
228 std::to_string(totalColumns) +
" lower triangular matrix.");
229 ASSERTL1(curColumn < totalColumns,
"Attemping to iterate through an element on row " +
230 std::to_string(curColumn) +
" of a (" +
231 std::to_string(totalRows) +
", " +
232 std::to_string(totalColumns) +
" lower triangular matrix.");
233 ASSERTL1(curRow >= curColumn,
"Attemping to iterate through element (" +
234 std::to_string(curRow) +
", " +
235 std::to_string(curColumn) +
") of a (" +
236 std::to_string(totalRows) +
", " +
237 std::to_string(totalColumns) +
" lower triangular matrix.");
239 if( transpose ==
'T' )
242 totalColumns, totalRows, curColumn, curRow);
245 unsigned int nextRow = curRow;
246 unsigned int nextColumn = curColumn;
248 if( nextRow < totalRows )
253 if( nextRow >= totalRows )
256 nextRow = nextColumn;
259 if( nextColumn >= totalColumns )
261 nextRow = std::numeric_limits<unsigned int>::max();
262 nextColumn = std::numeric_limits<unsigned int>::max();
265 return std::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
271 if( curRow <= curColumn )
273 return curRow + curColumn*(curColumn+1)/2;
277 return curColumn + curRow*(curRow + 1)/2;
281 std::tuple<unsigned int, unsigned int>
283 const unsigned int curRow,
const unsigned int curColumn)
285 ASSERTL1(totalRows == totalColumns,
"Symmetric matrices must be square.");
286 ASSERTL1(curRow < totalRows,
"Attemping to iterate through an element on row " +
287 std::to_string(curRow) +
" of a (" +
288 std::to_string(totalRows) +
", " +
289 std::to_string(totalColumns) +
" symmetric matrix.");
290 ASSERTL1(curColumn < totalColumns,
"Attemping to iterate through an element on row " +
291 std::to_string(curColumn) +
" of a (" +
292 std::to_string(totalRows) +
", " +
293 std::to_string(totalColumns) +
" symmetric matrix.");
295 unsigned int nextRow = curRow;
296 unsigned int nextColumn = curColumn;
298 if( nextRow < totalRows )
303 if( nextRow >= totalRows )
309 if( nextColumn >= totalColumns )
311 nextRow = std::numeric_limits<unsigned int>::max();
312 nextColumn = std::numeric_limits<unsigned int>::max();
315 return std::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
318 std::tuple<unsigned int, unsigned int>
320 const unsigned int curRow,
const unsigned int curColumn)
322 boost::ignore_unused(totalColumns);
324 ASSERTL0(curRow == curColumn,
"Iteration of a diagonal matrix is only valid along the diagonal.");
326 unsigned int nextRow = curRow;
327 unsigned int nextColumn = curColumn;
329 if( nextRow < totalRows )
335 if( nextRow >= totalRows )
337 nextRow = std::numeric_limits<unsigned int>::max();
338 nextColumn = std::numeric_limits<unsigned int>::max();
341 return std::tuple<unsigned int, unsigned int>(nextRow, nextColumn);
346 ASSERTL0(rows==columns,
"Diagonal matrices must be square.");
358 return std::numeric_limits<unsigned int>::max();
363 unsigned int nSubSuperDiags)
365 ASSERTL0(rows==columns,
"Triangular matrices must be square.");
366 return (nSubSuperDiags+1)*columns;
370 unsigned int nSuperDiags)
372 if( curRow <= curColumn )
374 if( (curColumn - curRow) <= nSuperDiags )
376 unsigned int elementRow = nSuperDiags - (curColumn - curRow);
377 unsigned int elementColumn = curColumn;
379 return elementRow + elementColumn*(nSuperDiags+1);
383 return std::numeric_limits<unsigned int>::max();
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
The above copyright notice and this permission notice shall be included.
static unsigned int CalculateNumberOfRows(unsigned int totalRows, unsigned int subDiags, unsigned int superDiags)
static unsigned int CalculateIndex(unsigned int totalRows, unsigned int totalColumns, unsigned int row, unsigned int column, unsigned int sub, unsigned int super)
static unsigned int CalculateNumberOfDiags(unsigned int totalRows, unsigned int diags)
static unsigned int GetRequiredStorageSize(unsigned int totalRows, unsigned int totalColumns, unsigned int subDiags, unsigned int superDiags)
Calculates and returns the storage size required.
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)
static unsigned int CalculateIndex(unsigned int row, unsigned int col)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static unsigned int CalculateIndex(unsigned int totalRows, unsigned int totalColumns, unsigned int curRow, unsigned int curColumn)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn, char transpose='N')
static unsigned int CalculateIndex(unsigned int totalColumns, unsigned int curRow, unsigned int curColumn)
static unsigned int CalculateIndex(unsigned int curRow, unsigned int curColumn, unsigned int nSuperDiags)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static unsigned int CalculateIndex(unsigned int curRow, unsigned int curColumn)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns, unsigned int nSubSuperDiags)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static unsigned int CalculateIndex(unsigned int curRow, unsigned int curColumn)