allow to optionally disable optimised handling of pow()

This commit is contained in:
conrad
2025-07-14 14:02:19 +10:00
parent ac3fcabca8
commit 39b2a52bd0
8 changed files with 44 additions and 18 deletions
+6 -6
View File
@@ -2872,7 +2872,7 @@ Cube<eT>::Cube(const eOpCube<T1, eop_type>& X)
init_cold();
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -2902,7 +2902,7 @@ Cube<eT>::operator=(const eOpCube<T1, eop_type>& X)
init_warm(X.get_n_rows(), X.get_n_cols(), X.get_n_slices());
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -2932,7 +2932,7 @@ Cube<eT>::operator+=(const eOpCube<T1, eop_type>& X)
if(bad_alias) { const Cube<eT> tmp(X); return (*this).operator+=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -2962,7 +2962,7 @@ Cube<eT>::operator-=(const eOpCube<T1, eop_type>& X)
if(bad_alias) { const Cube<eT> tmp(X); return (*this).operator-=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -2992,7 +2992,7 @@ Cube<eT>::operator%=(const eOpCube<T1, eop_type>& X)
if(bad_alias) { const Cube<eT> tmp(X); return (*this).operator%=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -3022,7 +3022,7 @@ Cube<eT>::operator/=(const eOpCube<T1, eop_type>& X)
if(bad_alias) { const Cube<eT> tmp(X); return (*this).operator/=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
+6 -6
View File
@@ -5201,7 +5201,7 @@ Mat<eT>::Mat(const eOp<T1, eop_type>& X)
init_cold();
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -5231,7 +5231,7 @@ Mat<eT>::operator=(const eOp<T1, eop_type>& X)
init_warm(X.get_n_rows(), X.get_n_cols());
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -5260,7 +5260,7 @@ Mat<eT>::operator+=(const eOp<T1, eop_type>& X)
if(bad_alias) { const Mat<eT> tmp(X); return (*this).operator+=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -5289,7 +5289,7 @@ Mat<eT>::operator-=(const eOp<T1, eop_type>& X)
if(bad_alias) { const Mat<eT> tmp(X); return (*this).operator-=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -5335,7 +5335,7 @@ Mat<eT>::operator%=(const eOp<T1, eop_type>& X)
if(bad_alias) { const Mat<eT> tmp(X); return (*this).operator%=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
@@ -5364,7 +5364,7 @@ Mat<eT>::operator/=(const eOp<T1, eop_type>& X)
if(bad_alias) { const Mat<eT> tmp(X); return (*this).operator/=(tmp); }
if(is_same_type<eop_type, eop_pow>::value)
if(arma_config::optimise_powexpr && is_same_type<eop_type, eop_pow>::value)
{
constexpr bool eT_non_int = is_non_integral<eT>::value;
+7
View File
@@ -65,6 +65,13 @@ struct arma_config
#endif
#if defined(ARMA_OPTIMISE_POWEXPR)
static constexpr bool optimise_powexpr = true;
#else
static constexpr bool optimise_powexpr = false;
#endif
#if defined(ARMA_CHECK_CONFORMANCE)
static constexpr bool check_conform = true;
#else
+9
View File
@@ -172,6 +172,11 @@
//// of inv() and inv_sympd() within compound expressions
#endif
#if !defined(ARMA_OPTIMISE_POWEXPR)
#define ARMA_OPTIMISE_POWEXPR
//// Comment out the above line to disable optimised handling of pow()
#endif
#if !defined(ARMA_CHECK_CONFORMANCE)
#define ARMA_CHECK_CONFORMANCE
//// Comment out the above line to disable conformance checks for bounds and size.
@@ -346,6 +351,10 @@
#undef ARMA_OPTIMISE_INVEXPR
#endif
#if defined(ARMA_DONT_OPTIMISE_POWEXPR)
#undef ARMA_OPTIMISE_POWEXPR
#endif
#if defined(ARMA_DONT_CHECK_CONFORMANCE)
#if defined(ARMA_CHECK_CONFORMANCE) && (ARMA_WARN_LEVEL >= 2)
#pragma message ("WARNING: conformance checks disabled")
+9
View File
@@ -172,6 +172,11 @@
//// of inv() and inv_sympd() within compound expressions
#endif
#if !defined(ARMA_OPTIMISE_POWEXPR)
#define ARMA_OPTIMISE_POWEXPR
//// Comment out the above line to disable optimised handling of pow()
#endif
#if !defined(ARMA_CHECK_CONFORMANCE)
#define ARMA_CHECK_CONFORMANCE
//// Comment out the above line to disable conformance checks for bounds and size.
@@ -346,6 +351,10 @@
#undef ARMA_OPTIMISE_INVEXPR
#endif
#if defined(ARMA_DONT_OPTIMISE_POWEXPR)
#undef ARMA_OPTIMISE_POWEXPR
#endif
#if defined(ARMA_DONT_CHECK_CONFORMANCE)
#if defined(ARMA_CHECK_CONFORMANCE) && (ARMA_WARN_LEVEL >= 2)
#pragma message ("WARNING: conformance checks disabled")
+1
View File
@@ -1440,6 +1440,7 @@ inline void arma_debug_check(bool state, const char* msg) { arma_conform_check(
out << "\n@ arma_config::optimise_band = " << arma_config::optimise_band;
out << "\n@ arma_config::optimise_sym = " << arma_config::optimise_sym;
out << "\n@ arma_config::optimise_invexpr = " << arma_config::optimise_invexpr;
out << "\n@ arma_config::optimise_powexpr = " << arma_config::optimise_powexpr;
out << "\n@ arma_config::check_conform = " << arma_config::check_conform;
out << "\n@ arma_config::check_nonfinite = " << arma_config::check_nonfinite;
out << "\n@ arma_config::fast_math = " << arma_config::fast_math;
+4 -4
View File
@@ -407,14 +407,14 @@ accu(const eOp<T1,eop_pow>& expr)
typedef eOp<T1,eop_pow> expr_type;
if(expr.aux == eT(2))
if(arma_config::optimise_powexpr && (expr.aux == eT(2)))
{
typedef eOp<T1,eop_square> modified_expr_type;
return accu( reinterpret_cast< const modified_expr_type& >(expr) );
}
if((expr.aux == eT(0.5)) && is_non_integral<eT>::value)
if(arma_config::optimise_powexpr && (expr.aux == eT(0.5)) && is_non_integral<eT>::value)
{
typedef eOp<T1,eop_sqrt> modified_expr_type;
@@ -1048,14 +1048,14 @@ accu(const eOpCube<T1,eop_pow>& expr)
typedef eOpCube<T1,eop_pow> expr_type;
if(expr.aux == eT(2))
if(arma_config::optimise_powexpr && (expr.aux == eT(2)))
{
typedef eOpCube<T1,eop_square> modified_expr_type;
return accu( reinterpret_cast< const modified_expr_type& >(expr) );
}
if((expr.aux == eT(0.5)) && is_non_integral<eT>::value)
if(arma_config::optimise_powexpr && (expr.aux == eT(0.5)) && is_non_integral<eT>::value)
{
typedef eOpCube<T1,eop_sqrt> modified_expr_type;
+2 -2
View File
@@ -154,7 +154,7 @@ op_sum::apply(Mat<typename T1::elem_type>& out, const Op< eOp<T1,eop_pow>, op_su
typedef typename T1::elem_type eT;
if(in.m.aux == eT(2))
if(arma_config::optimise_powexpr && (in.m.aux == eT(2)))
{
typedef Op< eOp<T1,eop_square>, op_sum > modified_whole_expr_type;
@@ -163,7 +163,7 @@ op_sum::apply(Mat<typename T1::elem_type>& out, const Op< eOp<T1,eop_pow>, op_su
return;
}
if((in.m.aux == eT(0.5)) && is_non_integral<eT>::value)
if(arma_config::optimise_powexpr && (in.m.aux == eT(0.5)) && is_non_integral<eT>::value)
{
typedef Op< eOp<T1,eop_sqrt>, op_sum > modified_whole_expr_type;