improved index out of range diagnostics

This commit is contained in:
2025-11-16 09:25:09 +01:00
parent 898645ed94
commit 5f74028ab6
3 changed files with 18 additions and 0 deletions

8
mat.h
View File

@@ -744,6 +744,7 @@ template <typename T>
inline T* NRMat<T>::operator[](const int i) {
#ifdef DEBUG
if (_LA_count_check && *count != 1) laerror("matrix with *count>1 used as l-value");
if(i<0||i>=nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<std::endl;
if (i < 0) laerror("Mat [] out of range - low");
if (i >= nn) laerror("Mat [] out of range - high");
if (!v) laerror("unallocated matrix");
@@ -762,6 +763,7 @@ inline T* NRMat<T>::operator[](const int i) {
template <typename T>
inline const T* NRMat<T>::operator[](const int i) const {
#ifdef DEBUG
if(i<0||i>=nn) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<std::endl;
if (i < 0) laerror("index out of range - low");
if (i >= nn) laerror("index out of range - high");
if (!v) laerror("unallocated matrix");
@@ -785,6 +787,7 @@ template <typename T>
inline T& NRMat<T>::operator()(const int i, const int j){
#ifdef DEBUG
if (_LA_count_check && *count != 1) laerror("NRMat::operator(,) used as l-value for a matrix with count > 1");
if(i<0||i>=nn||j<0||j>mm) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<mm-1<<std::endl;
if (i < 0) laerror("first index out of range - low");
if (i >= nn) laerror("first index out of range - high");
if (j < 0) laerror("second index out of range - low");
@@ -809,6 +812,7 @@ template <typename T>
inline const T& NRMat<T>::operator()(const int i, const int j) const{
T ret;
#ifdef DEBUG
if(i<0||i>=nn||j<0||j>mm) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<mm-1<<std::endl;
if (i < 0) laerror("first index out of range - low");
if (i >= nn) laerror("first index out of range - high");
if (j < 0) laerror("second index out of range - low");
@@ -833,6 +837,7 @@ template <typename T>
inline const T NRMat<T>::get_ij(const int i, const int j) const{
T ret;
#ifdef DEBUG
if(i<0||i>=nn||j<0||j>mm) std::cout<<"INDEX PROBLEM "<<0<<" "<<i<<" "<<nn-1<<" "<<0<<" "<<j<<" "<<mm-1<<std::endl;
if (i < 0) laerror("first index out of range - low");
if (i >= nn) laerror("first index out of range - high");
if (j < 0) laerror("second index out of range - low");
@@ -1399,6 +1404,7 @@ public:
inline const T& operator() (const int i, const int j) const {
#ifdef DEBUG
if(i<=0||i>NRMat<T>::nn||j<=0||j>NRMat<T>::mm) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRMat<T>::mm<<std::endl;
if (i < 1) laerror("first index out of range - low");
if (i > NRMat<T>::nn) laerror("first index out of range - high");
if (j < 1) laerror("second index out of range - low");
@@ -1416,6 +1422,7 @@ public:
inline T& operator() (const int i, const int j) {
#ifdef DEBUG
if (_LA_count_check && *NRMat<T>::count != 1) laerror("matrix with *count > 1 used as l-value");
if(i<=0||i>NRMat<T>::nn||j<=0||j>NRMat<T>::mm) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRMat<T>::mm<<std::endl;
if (i < 1) laerror("first index out of range - low");
if (i > NRMat<T>::nn) laerror("first index out of range - high");
if (j < 1) laerror("second index out of range - low");
@@ -1433,6 +1440,7 @@ public:
inline const T get_ij(const int i, const int j) const {
T ret;
#ifdef DEBUG
if(i<=0||i>NRMat<T>::nn||j<=0||j>NRMat<T>::mm) std::cout<<"INDEX PROBLEM "<<1<<" "<<i<<" "<<NRMat<T>::nn<<" "<<1<<" "<<j<<" "<<NRMat<T>::mm<<std::endl;
if (i < 1) laerror("first index out of range - low");
if (i > NRMat<T>::nn) laerror("first index out of range - high");
if (j < 1) laerror("second index out of range - low");