Skip to content

Commit

Permalink
Unfixed ipow.
Browse files Browse the repository at this point in the history
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
1 parent 28efc8c commit 9773ee8
Showing 1 changed file with 11 additions and 17 deletions.
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

0 comments on commit 9773ee8

Please sign in to comment.