Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed dace::math::pow for Integer case #1748

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Unfixed ipow.
After some digging I found out that `ipow` is only called for positive integers that are known at compile time.
And I know now whym because the `half` vectors do not play nice.
  • Loading branch information
philip-paul-mueller committed Nov 13, 2024
commit 9773ee819b2da91528bb4eec1746d26eef753051
28 changes: 11 additions & 17 deletions dace/runtime/include/dace/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,27 +570,21 @@ namespace dace
for (IterationBound_t i = 0; i < stop; ++i)
result *= a;
return result;
};
}
#endif

template<
typename T,
typename U,
typename = std::enable_if_t<std::is_integral<U>::value>
>
DACE_HDFI T ipow(const T& a, const U b)
/* Implements the power where the exponent is known as code generation time.
*
* Furthermore, as in accordance with `CPPUnparse._BinOp` the function assumes
* that the exponent is a positive, i.e. $b > 0` integer.
*
* TODO: Find out whyt the function can not be `constexpr`.
*/
template<typename T>
DACE_HDFI T ipow(const T& a, const unsigned int b)
{
if(std::is_signed<U>::value) {
if(b < 0)
return 0;
}
if(b == 0) {
return T(1);
};
using IterationBound_t = std::make_unsigned_t<U>;
T result = a;
const IterationBound_t stop{b};
for (IterationBound_t i = 1; i < stop; ++i)
for (unsigned int i = 1; i < b; ++i)
result *= a;
return result;
}
Expand Down
Loading