Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtschump committed Feb 9, 2024
2 parents 660414c + b5482a3 commit faa5318
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions CImg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<double>::nan(); // nan

// Set value property :
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -31442,9 +31446,9 @@ namespace cimg_library {
CImg<Tfloat> _get_invert_svd(const float lambda) const {
CImg<Tfloat> 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();
Expand Down Expand Up @@ -31612,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<Ttfloat> 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;
}

Expand Down Expand Up @@ -31936,7 +31940,7 @@ namespace cimg_library {
const CImg<T>& SVD(CImg<t>& U, CImg<t>& S, CImg<t>& 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)
Expand Down Expand Up @@ -32075,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;
Expand All @@ -32086,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;
Expand All @@ -32100,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;
}
Expand Down

0 comments on commit faa5318

Please sign in to comment.