Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/atoms/elementwise_full_dom/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <math.h>
#include <stdlib.h>

/* out[i] = c * x[i]^e. The exponents that arise from x^2 and x^(-1) and their
derivatives avoid pow, which is slow. */
/* out[i] = c * x[i]^e. The exponents that arise from x^2, x^(-1) and sqrt(x)
and their derivatives avoid pow, which is slow. */
static void scaled_pow(double *out, const double *x, int n, double c, double e)
{
if (e == 0.0)
Expand All @@ -49,6 +49,18 @@ static void scaled_pow(double *out, const double *x, int n, double c, double e)
{
for (int i = 0; i < n; i++) out[i] = c / (x[i] * x[i] * x[i]);
}
else if (e == 0.5)
{
for (int i = 0; i < n; i++) out[i] = c * sqrt(x[i]);
}
else if (e == -0.5)
{
for (int i = 0; i < n; i++) out[i] = c / sqrt(x[i]);
}
else if (e == -1.5)
{
for (int i = 0; i < n; i++) out[i] = c / (x[i] * sqrt(x[i]));
}
else
{
for (int i = 0; i < n; i++) out[i] = c * pow(x[i], e);
Expand Down
Loading