From d6bdf33e06705e01b9c24285a78d1ef7ed7004c5 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Wed, 7 Feb 2024 23:28:18 +0100 Subject: [PATCH 1/2] . --- CImg.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CImg.h b/CImg.h index bb95ede5..183b5118 100644 --- a/CImg.h +++ b/CImg.h @@ -17057,11 +17057,11 @@ namespace cimg_library { #define _cimg_mp_interpolation (reserved_label[31]!=~0U?reserved_label[31]:0) #define _cimg_mp_boundary (reserved_label[32]!=~0U?reserved_label[32]:0) #define _cimg_mp_slot_t 17 -#define _cimg_mp_slot_nan 29 -#define _cimg_mp_slot_x 30 -#define _cimg_mp_slot_y 31 -#define _cimg_mp_slot_z 32 -#define _cimg_mp_slot_c 33 +#define _cimg_mp_slot_nan 30 +#define _cimg_mp_slot_x 31 +#define _cimg_mp_slot_y 32 +#define _cimg_mp_slot_z 33 +#define _cimg_mp_slot_c 34 mem.assign(96); for (unsigned int i = 0; i<=10; ++i) mem[i] = (double)i; // mem[0-10] = 0...10 @@ -17079,6 +17079,7 @@ namespace cimg_library { mem[26] = (double)imglist._width; // l mem[27] = std::exp(1.); // e mem[28] = cimg::PI; // pi + mem[29] = DBL_EPSILON; // eps mem[_cimg_mp_slot_nan] = cimg::type::nan(); // nan // Set value property : @@ -17095,7 +17096,7 @@ namespace cimg_library { // reserved_label[0-32] are used to store the memory index of these variables: // [0] = wh, [1] = whd, [2] = whds, [3] = pi, [4] = im, [5] = iM, [6] = ia, [7] = iv, [8] = id, // [9] = is, [10] = ip, [11] = ic, [12] = in, [13] = xm, [14] = ym, [15] = zm, [16] = cm, [17] = xM, - // [18] = yM, [19] = zM, [20] = cM, [21] = i0...[30] = i9, [31] = interpolation, [32] = boundary + // [18] = yM, [19] = zM, [20] = cM, [21] = i0...[30] = i9, [31] = interpolation, [32] = boundary, [33] = eps // Compile expression into a sequence of opcodes. s_op = ""; ss_op = expr._data; @@ -17390,6 +17391,8 @@ namespace cimg_library { } else if (ss3==se) { // Three-chars reserved variable if (*ss=='w' && *ss1=='h' && *ss2=='d') // whd _cimg_mp_return(reserved_label[1]!=~0U?reserved_label[1]:24); + if (*ss=='e' && *ss1=='p' && *ss2=='s') // eps + _cimg_mp_return(reserved_label[33]!=~0U?reserved_label[33]:29); } else if (ss4==se) { // Four-chars reserved variable if (*ss=='w' && *ss1=='h' && *ss2=='d' && *ss3=='s') // whds _cimg_mp_return(reserved_label[2]!=~0U?reserved_label[2]:25); @@ -23866,6 +23869,7 @@ namespace cimg_library { c2 = variable_name[1]; c3 = variable_name[2]; if (c1=='w' && c2=='h' && c3=='d') rp = 1; // whd + else if (c1=='e' && c2=='p' && c3=='s') rp = 33; // eps } else if (variable_name[1] && variable_name[2] && variable_name[3] && !variable_name[4]) { // Four-chars variable c1 = variable_name[0]; From b5482a3133bc36cff06202179a59a69de26056e9 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Fri, 9 Feb 2024 08:03:43 +0100 Subject: [PATCH 2/2] . --- CImg.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/CImg.h b/CImg.h index 183b5118..553733e2 100644 --- a/CImg.h +++ b/CImg.h @@ -31446,9 +31446,9 @@ namespace cimg_library { CImg _get_invert_svd(const float lambda) const { CImg U, S, V; SVD(U,S,V,false); - const Tfloat epsilon = (sizeof(Tfloat)<=4?5.96e-8f:1.11e-16f)*std::max(_width,_height)*S.max(); + const Tfloat eps = (sizeof(Tfloat)<=4?5.96e-8f:1.11e-16f)*std::max(_width,_height)*S.max(); cimg_forX(V,x) { - const Tfloat s = S(x), invs = lambda?1/(lambda + s):s>epsilon?1/s:0; + const Tfloat s = S(x), invs = lambda?1/(lambda + s):s>eps?1/s:0; cimg_forY(V,y) V(x,y)*=invs; } return V*U.transpose(); @@ -31616,15 +31616,15 @@ namespace cimg_library { cimg_instance, A._width,A._height,A._depth,A._spectrum,A._data); typedef _cimg_Ttfloat Ttfloat; - const Ttfloat epsilon = 1e-4f; + const Ttfloat eps = 1e-4f; CImg B = A.get_column(1), V(*this,false); for (int i = 1; i<(int)siz; ++i) { - const Ttfloat m = A(0,i)/(B[i - 1]?B[i - 1]:epsilon); + const Ttfloat m = A(0,i)/(B[i - 1]?B[i - 1]:eps); B[i] -= m*A(2,i - 1); V[i] -= m*V[i - 1]; } - (*this)[siz - 1] = (T)(V[siz - 1]/(B[siz - 1]?B[siz - 1]:epsilon)); - for (int i = (int)siz - 2; i>=0; --i) (*this)[i] = (T)((V[i] - A(2,i)*(*this)[i + 1])/(B[i]?B[i]:epsilon)); + (*this)[siz - 1] = (T)(V[siz - 1]/(B[siz - 1]?B[siz - 1]:eps)); + for (int i = (int)siz - 2; i>=0; --i) (*this)[i] = (T)((V[i] - A(2,i)*(*this)[i + 1])/(B[i]?B[i]:eps)); return *this; } @@ -31940,7 +31940,7 @@ namespace cimg_library { const CImg& SVD(CImg& U, CImg& S, CImg& V, const bool sorting=true, const unsigned int max_iteration=40, const float lambda=0) const { typedef _cimg_Ttfloat Ttfloat; - const Ttfloat epsilon = (Ttfloat)1e-25; + const Ttfloat eps = (Ttfloat)1e-25; if (is_empty()) { U.assign(); S.assign(); V.assign(); } else if (_depth!=1 || _spectrum!=1) @@ -32079,9 +32079,9 @@ namespace cimg_library { t x = S[l], y = S[nm]; g = rv1[nm]; h = rv1[k]; - f = ((y - z)*(y + z) + (g - h)*(g + h))/std::max(epsilon,(Ttfloat)2*h*y); + f = ((y - z)*(y + z) + (g - h)*(g + h))/std::max(eps,(Ttfloat)2*h*y); g = cimg::hypot(f,(Ttfloat)1); - f = ((x - z)*(x + z) + h*((y/(f + (f>=0?g:-g))) - h))/std::max(epsilon,(Ttfloat)x); + f = ((x - z)*(x + z) + h*((y/(f + (f>=0?g:-g))) - h))/std::max(eps,(Ttfloat)x); c = s = 1; for (int j = l; j<=nm; ++j) { const int i = j + 1; @@ -32090,8 +32090,8 @@ namespace cimg_library { g = c*g; t y1 = S[i], z1 = cimg::hypot(f,h); rv1[j] = z1; - c = f/std::max(epsilon,(Ttfloat)z1); - s = h/std::max(epsilon,(Ttfloat)z1); + c = f/std::max(eps,(Ttfloat)z1); + s = h/std::max(eps,(Ttfloat)z1); f = x*c + g*s; g = g*c - x*s; h = y1*s; @@ -32104,7 +32104,7 @@ namespace cimg_library { z1 = cimg::hypot(f,h); S[j] = z1; if (z1) { - z1 = 1/std::max(epsilon,(Ttfloat)z1); + z1 = 1/std::max(eps,(Ttfloat)z1); c = f*z1; s = h*z1; }