improved out of range diagnostics

This commit is contained in:
2025-11-15 20:57:57 +01:00
parent 5505d39b99
commit 898645ed94
3 changed files with 58 additions and 19 deletions

38
mat.h
View File

@@ -744,7 +744,8 @@ 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) laerror("Mat [] out of range");
if (i < 0) laerror("Mat [] out of range - low");
if (i >= nn) laerror("Mat [] out of range - high");
if (!v) laerror("unallocated matrix");
#endif
#ifdef MATPTR
@@ -761,7 +762,8 @@ 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) laerror("index out of range");
if (i < 0) laerror("index out of range - low");
if (i >= nn) laerror("index out of range - high");
if (!v) laerror("unallocated matrix");
#endif
NOT_GPU(*this);
@@ -783,7 +785,10 @@ 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 && nn > 0 || j < 0 || j >= mm && mm > 0) laerror("index out of range");
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");
if (j >= mm) laerror("second index out of range - high");
if (!v) laerror("unallocated matrix");
#endif
NOT_GPU(*this);
@@ -804,7 +809,10 @@ 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 && nn>0 || j<0 || j>=mm && mm>0) laerror("index out of range");
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");
if (j >= mm) laerror("second index out of range - high");
if (!v) laerror("unallocated matrix");
#endif
NOT_GPU(*this);
@@ -825,7 +833,10 @@ 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) laerror("index out of range");
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");
if (j >= mm) laerror("second index out of range - high");
if (!v) laerror("unallocated matrix");
#endif
#ifdef CUDALA
@@ -1388,8 +1399,11 @@ public:
inline const T& operator() (const int i, const int j) const {
#ifdef DEBUG
if (i<1 || i>NRMat<T>::nn || j<1 || j>NRMat<T>::mm) laerror("index out of range");
if (!NRMat<T>::v) laerror("unallocated matrix");
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");
if (j > NRMat<T>::mm) laerror("second index out of range - high");
if (!NRMat<T>::v) laerror("unallocated matrix");
#endif
NOT_GPU(*this);
#ifdef MATPTR
@@ -1402,7 +1416,10 @@ 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<1 || i>NRMat<T>::nn || j<1 || j>NRMat<T>::mm) laerror("index out of range");
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");
if (j > NRMat<T>::mm) laerror("second index out of range - high");
if (!NRMat<T>::v) laerror("unallocated matrix");
#endif
NOT_GPU(*this);
@@ -1416,7 +1433,10 @@ public:
inline const T get_ij(const int i, const int j) const {
T ret;
#ifdef DEBUG
if (i<1 || i>NRMat<T>::nn || j<1 || j>NRMat<T>::mm) laerror("index out of range");
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");
if (j > NRMat<T>::mm) laerror("second index out of range - high");
if (!NRMat<T>::v) laerror("unallocated matrix");
#endif
#ifdef CUDALA

27
smat.h
View File

@@ -626,7 +626,8 @@ template <typename T>
inline T& NRSMat<T>::operator[](const size_t ij) {
#ifdef DEBUG
if(_LA_count_check && *count != 1) laerror("T& NRSMat<T>::operator[] used for matrix with count>1");
if(ij<0 || ij>=NN2) laerror("T& NRSMat<T>::operator[] out of range");
if(ij<0) laerror("T& NRSMat<T>::operator[] out of range - low");
if(ij>=NN2) laerror("T& NRSMat<T>::operator[] out of range - high");
if(!v) laerror("T& NRSMat<T>::operator[] used for unallocated NRSmat<T> object");
#endif
NOT_GPU(*this);
@@ -645,7 +646,8 @@ inline T& NRSMat<T>::operator[](const size_t ij) {
template <typename T>
inline const T & NRSMat<T>::operator[](const size_t ij) const {
#ifdef DEBUG
if(ij<0 || ij>=NN2) laerror("T& NRSMat<T>::operator[] out of range");
if(ij<0) laerror("T& NRSMat<T>::operator[] out of range - low");
if(ij>=NN2) laerror("T& NRSMat<T>::operator[] out of range - high");
if(!v) laerror("T& NRSMat<T>::operator[] used for unallocated NRSmat<T> object");
#endif
NOT_GPU(*this);
@@ -752,7 +754,10 @@ template <typename T>
inline T & NRSMat<T>::operator()(const int i, const int j) {
#ifdef DEBUG
if(_LA_count_check && *count != 1) laerror("T & NRSMat<T>::operator()(const int, const int) used for matrix with count > 1");
if(i<0 || i>=nn || j<0 || j>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) out of range");
if(i<0) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - low");
if(i>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - high");
if(j<0) laerror("T & NRSMat<T>::operator()(const int, const int) second index out of range - low");
if(j>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) second index out of range - high");
if(!v) laerror("T & NRSMat<T>::operator()(const int, const int) used for unallocated NRSmat<T> object");
#endif
NOT_GPU(*this);
@@ -770,7 +775,11 @@ inline T & NRSMat<T>::operator()(const int i, const int j) {
template <typename T>
inline const T & NRSMat<T>::operator()(const int i, const int j) const {
#ifdef DEBUG
if(i<0 || i>=nn || j<0 || j>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) out of range");
if(i<0) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - low");
if(i>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) first index out of range - high");
if(j<0) laerror("T & NRSMat<T>::operator()(const int, const int) second index out of range - low");
if(j>=nn) laerror("T & NRSMat<T>::operator()(const int, const int) second index out of range - high");
if(!v) laerror("T & NRSMat<T>::operator()(const int, const int) used for unallocated NRSmat<T> object");
if(!v) laerror("T & NRSMat<T>::operator()(const int, const int) used for unallocated NRSmat<T> object");
#endif
NOT_GPU(*this);
@@ -1304,14 +1313,20 @@ public:
inline const T& operator() (const int i, const int j) const {
#ifdef DEBUG
if(i<=0||j<=0||i>NRSMat<T>::nn||j>NRSMat<T>::nn) laerror("index in const T& NRSMat<T>::operator() (const int, const int) out of range");
if(i<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - low");
if(i>NRSMat<T>::nn) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - high");
if(j<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) second index out of range - low");
if(j>NRSMat<T>::nn) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) second index out of range - high");
#endif
return NRSMat<T>::v[SMat_index_1(i,j)];
}
inline T& operator() (const int i, const int j){
#ifdef DEBUG
if(i<=0||j<=0||i>NRSMat<T>::nn||j>NRSMat<T>::nn) laerror("index in T& NRSMat<T>::operator() (const int, const int) out of range");
if(i<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - low");
if(i>NRSMat<T>::nn) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) first indexout of range - high");
if(j<=0) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) second index out of range - low");
if(j>NRSMat<T>::nn) laerror("index in const T& NRSMat_from1<T>::operator() (const int, const int) second index out of range - high");
#endif
return NRSMat<T>::v[SMat_index_1(i,j)];
}

12
vec.h
View File

@@ -620,7 +620,8 @@ template <typename T>
inline T& NRVec_from1<T>::operator[](const int i) {
#ifdef DEBUG
if(_LA_count_check && *NRVec<T>::count != 1) laerror("possible use of NRVec[] with count>1 as l-value");
if(i < 1 || i > NRVec<T>::nn) laerror("out of range");
if(i < 1) laerror("out of range - low");
if(i > NRVec<T>::nn) laerror("out of range - high");
if(!NRVec<T>::v) laerror("unallocated NRVec");
#endif
NOT_GPU(*this);
@@ -637,7 +638,8 @@ inline T& NRVec_from1<T>::operator[](const int i) {
template <typename T>
inline const T& NRVec_from1<T>::operator[](const int i) const {
#ifdef DEBUG
if(i < 1 || i > NRVec<T>::nn) laerror("out of range");
if(i < 1) laerror("out of range - low");
if(i > NRVec<T>::nn) laerror("out of range - high");
if(!NRVec<T>::v) laerror("unallocated NRVec");
#endif
NOT_GPU(*this);
@@ -1080,7 +1082,8 @@ template <typename T>
inline T& NRVec<T>::operator[](const int i) {
#ifdef DEBUG
if(_LA_count_check && *count != 1) laerror("possible use of NRVec[] with count>1 as l-value");
if(i < 0 || i >= nn) laerror("out of range");
if(i < 0) laerror("out of range - low");
if(i >= nn) laerror("out of range - high");
if(!v) laerror("unallocated NRVec");
#endif
NOT_GPU(*this);
@@ -1097,7 +1100,8 @@ inline T& NRVec<T>::operator[](const int i) {
template <typename T>
inline const T& NRVec<T>::operator[](const int i) const {
#ifdef DEBUG
if(i < 0 || i >= nn) laerror("out of range");
if(i < 0) laerror("out of range - low");
if(i >= nn) laerror("out of range - high");
if(!v) laerror("unallocated NRVec");
#endif
NOT_GPU(*this);