3737
3838#include " IECore/Exception.h"
3939
40- #include " OpenEXR/ImathMath.h"
41-
4240#include < cassert>
4341
4442namespace IECore
@@ -70,13 +68,13 @@ struct DefaultLevenbergMarquardtTraits
7068};
7169
7270template <typename T>
73- T DefaultLevenbergMarquardtTraits<T>::g_machinePrecision( Imath::limits <T>::epsilon() );
71+ T DefaultLevenbergMarquardtTraits<T>::g_machinePrecision( std::numeric_limits <T>::epsilon() );
7472
7573template <typename T>
76- T DefaultLevenbergMarquardtTraits<T>::g_sqrtMin( Imath::Math<T>:: sqrt( Imath::limits <T>::smallest () ) );
74+ T DefaultLevenbergMarquardtTraits<T>::g_sqrtMin( std:: sqrt( std::numeric_limits <T>::min () ) );
7775
7876template <typename T>
79- T DefaultLevenbergMarquardtTraits<T>::g_sqrtMax( Imath::Math<T>:: sqrt( Imath::limits <T>::max() ) );
77+ T DefaultLevenbergMarquardtTraits<T>::g_sqrtMax( std:: sqrt( std::numeric_limits <T>::max() ) );
8078
8179template <typename T, typename ErrorFn, template <typename > class Traits >
8280LevenbergMarquardt<T, ErrorFn, Traits>::LevenbergMarquardt()
@@ -168,7 +166,7 @@ typename LevenbergMarquardt<T, ErrorFn, Traits>::Status LevenbergMarquardt<T, Er
168166
169167 T delta = 0 ;
170168 T xnorm = 0 ;
171- T eps = Imath::Math<T> ::sqrt ( std::max<T>( m_epsilon, Traits<T>::machinePrecision () ) );
169+ T eps = std ::sqrt ( std::max<T>( m_epsilon, Traits<T>::machinePrecision () ) );
172170
173171 if (( m_n <= 0 ) || ( m_m < m_n ) || ( m_ftol < 0 . )
174172 || ( m_xtol < 0 . ) || ( m_gtol < 0 . ) || ( m_stepBound <= 0 . ) )
@@ -186,7 +184,7 @@ typename LevenbergMarquardt<T, ErrorFn, Traits>::Status LevenbergMarquardt<T, Er
186184 for ( unsigned j = 0 ; j < m_n; j++ )
187185 {
188186 T temp = x[j];
189- step = eps * Imath::Math<T> ::fabs ( temp );
187+ step = eps * std ::fabs ( temp );
190188 if ( step == 0 . )
191189 {
192190 step = eps;
@@ -269,7 +267,7 @@ typename LevenbergMarquardt<T, ErrorFn, Traits>::Status LevenbergMarquardt<T, Er
269267 {
270268 sum += m_fjac[j * m_m + i] * m_qtf[i] / fnorm;
271269 }
272- gnorm = std::max<T>( gnorm, Imath::Math<T> ::fabs ( sum / wa2[m_ipvt[j]] ) );
270+ gnorm = std::max<T>( gnorm, std ::fabs ( sum / wa2[m_ipvt[j]] ) );
273271 }
274272 }
275273 }
@@ -333,7 +331,7 @@ typename LevenbergMarquardt<T, ErrorFn, Traits>::Status LevenbergMarquardt<T, Er
333331 }
334332 assert ( m_wa3.size () == m_n );
335333 temp1 = euclideanNorm ( m_wa3.begin (), m_wa3.end () ) / fnorm;
336- temp2 = Imath::Math<T> ::sqrt ( par ) * pnorm / fnorm;
334+ temp2 = std ::sqrt ( par ) * pnorm / fnorm;
337335 prered = sqr ( temp1 ) + 2 * sqr ( temp2 );
338336 dirder = -( sqr ( temp1 ) + sqr ( temp2 ) );
339337
@@ -384,7 +382,7 @@ typename LevenbergMarquardt<T, ErrorFn, Traits>::Status LevenbergMarquardt<T, Er
384382 }
385383
386384 // / tests for convergence
387- if ( Imath::Math<T> ::fabs ( actred ) <= m_ftol && prered <= m_ftol && 0.5 * ratio <= 1 )
385+ if ( std ::fabs ( actred ) <= m_ftol && prered <= m_ftol && 0.5 * ratio <= 1 )
388386 {
389387 return Success;
390388 }
@@ -399,7 +397,7 @@ typename LevenbergMarquardt<T, ErrorFn, Traits>::Status LevenbergMarquardt<T, Er
399397 {
400398 return CallLimit;
401399 }
402- if ( Imath::Math<T> ::fabs ( actred ) <= Traits<T>::machinePrecision () &&
400+ if ( std ::fabs ( actred ) <= Traits<T>::machinePrecision () &&
403401 prered <= Traits<T>::machinePrecision () && 0.5 * ratio <= 1 )
404402 {
405403 return FailedFTol;
@@ -503,7 +501,7 @@ void LevenbergMarquardt<T, ErrorFn, Traits>::qrFactorize()
503501 {
504502 temp = m_fjac[m_m * k + j] / rdiag[k];
505503 temp = std::max<T>( 0 ., 1 - temp * temp );
506- rdiag[k] *= Imath::Math<T> ::sqrt ( temp );
504+ rdiag[k] *= std ::sqrt ( temp );
507505 temp = rdiag[k] / m_wa3[k];
508506 if ( T ( 0.05 ) * sqr ( temp ) <= Traits<T>::machinePrecision () )
509507 {
@@ -607,7 +605,7 @@ T LevenbergMarquardt<T, ErrorFn, Traits>::computeLMParameter( std::vector<T> &x,
607605 paru = gnorm / delta;
608606 if ( paru == 0 . )
609607 {
610- paru = Imath::limits <T>::smallest () / std::min<T>( delta, 0.1 );
608+ paru = std::numeric_limits <T>::min () / std::min<T>( delta, 0.1 );
611609 }
612610
613611 par = std::max<T>( par, parl );
@@ -623,9 +621,9 @@ T LevenbergMarquardt<T, ErrorFn, Traits>::computeLMParameter( std::vector<T> &x,
623621 // / evaluate the function at the current value of par.
624622 if ( par == 0 . )
625623 {
626- par = std::max<T>( Imath::limits <T>::smallest (), 0.001 * paru );
624+ par = std::max<T>( std::numeric_limits <T>::min (), 0.001 * paru );
627625 }
628- temp = Imath::Math<T> ::sqrt ( par );
626+ temp = std ::sqrt ( par );
629627 for ( j = 0 ; j < m_n; j++ )
630628 {
631629 m_wa3[j] = temp * m_diag[j];
@@ -641,7 +639,7 @@ T LevenbergMarquardt<T, ErrorFn, Traits>::computeLMParameter( std::vector<T> &x,
641639
642640 // / if the function is small enough, accept the current value of par. Also test for the exceptional cases where parl
643641 // / is zero or the number of iterations has reached 10.
644- if ( Imath::Math<T> ::fabs ( fp ) <= 0.1 * delta || ( parl == 0 . && fp <= fp_old && fp_old < 0 . ) || iter == 10 )
642+ if ( std ::fabs ( fp ) <= 0.1 * delta || ( parl == 0 . && fp <= fp_old && fp_old < 0 . ) || iter == 10 )
645643 {
646644 break ;
647645 }
@@ -721,16 +719,16 @@ void LevenbergMarquardt<T, ErrorFn, Traits>::qrSolve( std::vector<T> &r, std::ve
721719 unsigned kk = k + m_m * k;
722720 T sinTheta, cosTheta;
723721
724- if ( Imath::Math<T>:: fabs ( r[kk] ) < Imath::Math<T> ::fabs ( sdiag[k] ) )
722+ if ( std:: fabs ( r[kk] ) < std ::fabs ( sdiag[k] ) )
725723 {
726724 T cotTheta = r[kk] / sdiag[k];
727- sinTheta = 0.5 / Imath::Math<T> ::sqrt ( 0.25 + 0.25 * sqr ( cotTheta ) );
725+ sinTheta = 0.5 / std ::sqrt ( 0.25 + 0.25 * sqr ( cotTheta ) );
728726 cosTheta = sinTheta * cotTheta;
729727 }
730728 else
731729 {
732730 T tanTheta = sdiag[k] / r[kk];
733- cosTheta = 0.5 / Imath::Math<T> ::sqrt ( 0.25 + 0.25 * sqr ( tanTheta ) );
731+ cosTheta = 0.5 / std ::sqrt ( 0.25 + 0.25 * sqr ( tanTheta ) );
734732 sinTheta = cosTheta * tanTheta;
735733 }
736734
@@ -802,7 +800,7 @@ T LevenbergMarquardt<T, ErrorFn, Traits>::euclideanNorm( typename std::vector<T>
802800 // / sum squares
803801 for ( typename std::vector<T>::const_iterator it = begin; it != end; ++it )
804802 {
805- T xabs = Imath::Math<T> ::fabs ( *it );
803+ T xabs = std ::fabs ( *it );
806804 if ( xabs > Traits<T>::sqrtMin () && xabs < agiant )
807805 {
808806 // / sum for intermediate components.
@@ -845,22 +843,22 @@ T LevenbergMarquardt<T, ErrorFn, Traits>::euclideanNorm( typename std::vector<T>
845843 // / calculation of norm.
846844 if ( s1 != 0 )
847845 {
848- return x1max * Imath::Math<T> ::sqrt ( s1 + ( s2 / x1max ) / x1max );
846+ return x1max * std ::sqrt ( s1 + ( s2 / x1max ) / x1max );
849847 }
850848
851849 if ( s2 != 0 )
852850 {
853851 if ( s2 >= x3max )
854852 {
855- return Imath::Math<T> ::sqrt ( s2 * ( 1 + ( x3max / s2 ) * ( x3max * s3 ) ) );
853+ return std ::sqrt ( s2 * ( 1 + ( x3max / s2 ) * ( x3max * s3 ) ) );
856854 }
857855 else
858856 {
859- return Imath::Math<T> ::sqrt ( x3max * (( s2 / x3max ) + ( x3max * s3 ) ) );
857+ return std ::sqrt ( x3max * (( s2 / x3max ) + ( x3max * s3 ) ) );
860858 }
861859 }
862860
863- return x3max * Imath::Math<T> ::sqrt ( s3 );
861+ return x3max * std ::sqrt ( s3 );
864862}
865863
866864} // namespace IECore
0 commit comments