summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorTim Hochberg <tim_hochberg@local>2006-02-23 16:08:03 +0000
committerTim Hochberg <tim_hochberg@local>2006-02-23 16:08:03 +0000
commitee7b258d90768a6ec1e7a697e3b7b5067eda00e4 (patch)
tree9a61946a45776951045eb565984c794cfa74b149 /numpy/core/src
parentede85cec1879d0d18a797749ccf7fc1853a2146e (diff)
downloadnumpy-ee7b258d90768a6ec1e7a697e3b7b5067eda00e4.tar.gz
Add optimizations for integral powers of complex numbers to nc_pow.
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umathmodule.c.src38
1 files changed, 30 insertions, 8 deletions
diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src
index 896371e65..11d7c0c7b 100644
--- a/numpy/core/src/umathmodule.c.src
+++ b/numpy/core/src/umathmodule.c.src
@@ -644,22 +644,44 @@ nc_expm1@c@(c@typ@ *x, c@typ@ *r)
static void
nc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
{
- @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;
+ intp n;
+ @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;
if (br == 0. && bi == 0.) {
r->real = 1.;
r->imag = 0.;
+ return;
}
- else if (ar == 0. && ai == 0.) {
+ if (ar == 0. && ai == 0.) {
r->real = 0.;
r->imag = 0.;
+ return;
}
- else {
- nc_log@c@(a, r);
- nc_prod@c@(r, b, r);
- nc_exp@c@(r, r);
- }
- return;
+ if (bi == 0 && (n=(intp)br) == br) {
+ if (n > -100 && n < 100) {
+ c@typ@ p, a;
+ intp mask = 1;
+ if (n < 0) n = -n;
+ a = nc_1@c@;
+ p.real = ar; p.imag = ai;
+ while (1) {
+ if (n & mask)
+ nc_prod@c@(&a,&p,&a);
+ mask <<= 1;
+ if (n < mask || mask <= 0) break;
+ nc_prod@c@(&p,&p,&p);
+ }
+ r->real = a.real; r->imag = a.imag;
+ if (bi < 0) nc_quot@c@(&nc_1@c@, r, r);
+ return;
+ }
+ }
+ /* complexobect.c uses an inline version of this formula
+ investigate whether this had better performance or accuracy */
+ nc_log@c@(a, r);
+ nc_prod@c@(r, b, r);
+ nc_exp@c@(r, r);
+ return;
}