From 74a9cf8dce9d88a5d9e9aea3eaf64824eed052c7 Mon Sep 17 00:00:00 2001 From: dance858 Date: Mon, 30 Nov 2026 14:34:52 -0800 Subject: [PATCH] sqrts in pow --- src/atoms/elementwise_full_dom/power.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/atoms/elementwise_full_dom/power.c b/src/atoms/elementwise_full_dom/power.c index a69ba2e..c1ec925 100644 --- a/src/atoms/elementwise_full_dom/power.c +++ b/src/atoms/elementwise_full_dom/power.c @@ -21,8 +21,8 @@ #include #include -/* 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) @@ -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);