summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2012-02-03 15:49:03 -0700
committerCharles Harris <charlesr.harris@gmail.com>2012-02-04 17:54:37 -0700
commit93c2a70282b2b7382334bf0a7fa769bb0bcbce28 (patch)
treef7188c517903ea9ee774f3d8e5b40edebb6dcb29 /numpy/core/src
parent91eed7a8e32ad42943472e9eef24955bee2a0976 (diff)
downloadnumpy-93c2a70282b2b7382334bf0a7fa769bb0bcbce28.tar.gz
UPD: Use prefixed macros in numpy/core/src/umath/funcs.inc.src.
Also make the templated stuff a bit simpler.
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umath/funcs.inc.src136
-rw-r--r--numpy/core/src/umath/umathmodule.c.src442
2 files changed, 69 insertions, 509 deletions
diff --git a/numpy/core/src/umath/funcs.inc.src b/numpy/core/src/umath/funcs.inc.src
index 5278a848a..0b9398cd2 100644
--- a/numpy/core/src/umath/funcs.inc.src
+++ b/numpy/core/src/umath/funcs.inc.src
@@ -6,6 +6,7 @@
* object functions.
*/
+#define NPY_NO_DEPRECATED_API
#include "numpy/npy_3kcompat.h"
@@ -202,7 +203,8 @@ npy_ObjectLogicalNot(PyObject *i1)
/**begin repeat
*
- * #typ = float, double, longdouble#
+ * #ctype = npy_cfloat, npy_cdouble, npy_clongdouble#
+ * #ftype = npy_float, npy_double, npy_longdouble#
* #c = f, ,l#
* #C = F, ,L#
* #precision = 1,2,4#
@@ -221,18 +223,18 @@ npy_ObjectLogicalNot(PyObject *i1)
} while(0)
/* constants */
-static c@typ@ nc_1@c@ = {1., 0.};
-static c@typ@ nc_half@c@ = {0.5, 0.};
-static c@typ@ nc_i@c@ = {0., 1.};
-static c@typ@ nc_i2@c@ = {0., 0.5};
+static @ctype@ nc_1@c@ = {1., 0.};
+static @ctype@ nc_half@c@ = {0.5, 0.};
+static @ctype@ nc_i@c@ = {0., 1.};
+static @ctype@ nc_i2@c@ = {0., 0.5};
/*
- * static c@typ@ nc_mi@c@ = {0.0@c@, -1.0@c@};
- * static c@typ@ nc_pi2@c@ = {NPY_PI_2@c@., 0.0@c@};
+ * static @ctype@ nc_mi@c@ = {0.0@c@, -1.0@c@};
+ * static @ctype@ nc_pi2@c@ = {NPY_PI_2@c@., 0.0@c@};
*/
static void
-nc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
+nc_sum@c@(@ctype@ *a, @ctype@ *b, @ctype@ *r)
{
r->real = a->real + b->real;
r->imag = a->imag + b->imag;
@@ -240,7 +242,7 @@ nc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
}
static void
-nc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
+nc_diff@c@(@ctype@ *a, @ctype@ *b, @ctype@ *r)
{
r->real = a->real - b->real;
r->imag = a->imag - b->imag;
@@ -248,7 +250,7 @@ nc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
}
static void
-nc_neg@c@(c@typ@ *a, c@typ@ *r)
+nc_neg@c@(@ctype@ *a, @ctype@ *r)
{
r->real = -a->real;
r->imag = -a->imag;
@@ -256,66 +258,66 @@ nc_neg@c@(c@typ@ *a, c@typ@ *r)
}
static void
-nc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
+nc_prod@c@(@ctype@ *a, @ctype@ *b, @ctype@ *r)
{
- @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;
+ @ftype@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;
r->real = ar*br - ai*bi;
r->imag = ar*bi + ai*br;
return;
}
static void
-nc_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
+nc_quot@c@(@ctype@ *a, @ctype@ *b, @ctype@ *r)
{
- @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;
- @typ@ d = br*br + bi*bi;
+ @ftype@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;
+ @ftype@ d = br*br + bi*bi;
r->real = (ar*br + ai*bi)/d;
r->imag = (ai*br - ar*bi)/d;
return;
}
static void
-nc_sqrt@c@(c@typ@ *x, c@typ@ *r)
+nc_sqrt@c@(@ctype@ *x, @ctype@ *r)
{
*r = npy_csqrt@c@(*x);
return;
}
static void
-nc_rint@c@(c@typ@ *x, c@typ@ *r)
+nc_rint@c@(@ctype@ *x, @ctype@ *r)
{
r->real = npy_rint@c@(x->real);
r->imag = npy_rint@c@(x->imag);
}
static void
-nc_log@c@(c@typ@ *x, c@typ@ *r)
+nc_log@c@(@ctype@ *x, @ctype@ *r)
{
*r = npy_clog@c@(*x);
return;
}
static void
-nc_log1p@c@(c@typ@ *x, c@typ@ *r)
+nc_log1p@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ l = npy_hypot@c@(x->real + 1,x->imag);
+ @ftype@ l = npy_hypot@c@(x->real + 1,x->imag);
r->imag = npy_atan2@c@(x->imag, x->real + 1);
r->real = npy_log@c@(l);
return;
}
static void
-nc_exp@c@(c@typ@ *x, c@typ@ *r)
+nc_exp@c@(@ctype@ *x, @ctype@ *r)
{
*r = npy_cexp@c@(*x);
return;
}
static void
-nc_exp2@c@(c@typ@ *x, c@typ@ *r)
+nc_exp2@c@(@ctype@ *x, @ctype@ *r)
{
- c@typ@ a;
+ @ctype@ a;
a.real = x->real*NPY_LOGE2@c@;
a.imag = x->imag*NPY_LOGE2@c@;
nc_exp@c@(&a, r);
@@ -323,22 +325,22 @@ nc_exp2@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_expm1@c@(c@typ@ *x, c@typ@ *r)
+nc_expm1@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ a = npy_exp@c@(x->real);
+ @ftype@ a = npy_exp@c@(x->real);
r->real = a*npy_cos@c@(x->imag) - 1.0@c@;
r->imag = a*npy_sin@c@(x->imag);
return;
}
static void
-nc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
+nc_pow@c@(@ctype@ *a, @ctype@ *b, @ctype@ *r)
{
npy_intp n;
- @typ@ ar = npy_creal@c@(*a);
- @typ@ br = npy_creal@c@(*b);
- @typ@ ai = npy_cimag@c@(*a);
- @typ@ bi = npy_cimag@c@(*b);
+ @ftype@ ar = npy_creal@c@(*a);
+ @ftype@ br = npy_creal@c@(*b);
+ @ftype@ ai = npy_cimag@c@(*a);
+ @ftype@ bi = npy_cimag@c@(*b);
if (br == 0. && bi == 0.) {
*r = npy_cpack@c@(1., 0.);
@@ -381,7 +383,7 @@ nc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
return;
}
else if (n > -100 && n < 100) {
- c@typ@ p, aa;
+ @ctype@ p, aa;
npy_intp mask = 1;
if (n < 0) n = -n;
aa = nc_1@c@;
@@ -405,9 +407,9 @@ nc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)
static void
-nc_prodi@c@(c@typ@ *x, c@typ@ *r)
+nc_prodi@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ xr = x->real;
+ @ftype@ xr = x->real;
r->real = -x->imag;
r->imag = xr;
return;
@@ -415,7 +417,7 @@ nc_prodi@c@(c@typ@ *x, c@typ@ *r)
static void
-nc_acos@c@(c@typ@ *x, c@typ@ *r)
+nc_acos@c@(@ctype@ *x, @ctype@ *r)
{
/*
* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,
@@ -433,13 +435,13 @@ nc_acos@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_acosh@c@(c@typ@ *x, c@typ@ *r)
+nc_acosh@c@(@ctype@ *x, @ctype@ *r)
{
/*
* return nc_log(nc_sum(x,
* nc_prod(nc_sqrt(nc_sum(x,nc_1)), nc_sqrt(nc_diff(x,nc_1)))));
*/
- c@typ@ t;
+ @ctype@ t;
nc_sum@c@(x, &nc_1@c@, &t);
nc_sqrt@c@(&t, &t);
@@ -452,14 +454,14 @@ nc_acosh@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_asin@c@(c@typ@ *x, c@typ@ *r)
+nc_asin@c@(@ctype@ *x, @ctype@ *r)
{
/*
* return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),
* nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));
*/
if (fabs(x->real) > 1e-3 || fabs(x->imag) > 1e-3) {
- c@typ@ a, *pa=&a;
+ @ctype@ a, *pa=&a;
nc_prod@c@(x, x, r);
nc_diff@c@(&nc_1@c@, r, r);
nc_sqrt@c@(r, r);
@@ -476,7 +478,7 @@ nc_asin@c@(c@typ@ *x, c@typ@ *r)
*
* |x| < 1e-3 => |rel. error| < 1e-18 (f), 1e-24, 1e-36 (l)
*/
- c@typ@ x2;
+ @ctype@ x2;
nc_prod@c@(x, x, &x2);
*r = nc_1@c@;
@@ -496,7 +498,7 @@ nc_asin@c@(c@typ@ *x, c@typ@ *r)
static void
-nc_asinh@c@(c@typ@ *x, c@typ@ *r)
+nc_asinh@c@(@ctype@ *x, @ctype@ *r)
{
/*
* return nc_log(nc_sum(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x));
@@ -515,7 +517,7 @@ nc_asinh@c@(c@typ@ *x, c@typ@ *r)
*
* |x| < 1e-3 => |rel. error| < 1e-18 (f), 1e-24, 1e-36 (l)
*/
- c@typ@ x2;
+ @ctype@ x2;
nc_prod@c@(x, x, &x2);
*r = nc_1@c@;
@@ -534,13 +536,13 @@ nc_asinh@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_atan@c@(c@typ@ *x, c@typ@ *r)
+nc_atan@c@(@ctype@ *x, @ctype@ *r)
{
/*
* return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));
*/
if (fabs(x->real) > 1e-3 || fabs(x->imag) > 1e-3) {
- c@typ@ a, *pa=&a;
+ @ctype@ a, *pa=&a;
nc_diff@c@(&nc_i@c@, x, pa);
nc_sum@c@(&nc_i@c@, x, r);
nc_quot@c@(r, pa, r);
@@ -554,7 +556,7 @@ nc_atan@c@(c@typ@ *x, c@typ@ *r)
*
* |x| < 1e-3 => |rel. error| < 1e-18 (f), 1e-24, 1e-36 (l)
*/
- c@typ@ x2;
+ @ctype@ x2;
nc_prod@c@(x, x, &x2);
*r = nc_1@c@;
@@ -573,13 +575,13 @@ nc_atan@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_atanh@c@(c@typ@ *x, c@typ@ *r)
+nc_atanh@c@(@ctype@ *x, @ctype@ *r)
{
/*
* return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));
*/
if (fabs(x->real) > 1e-3 || fabs(x->imag) > 1e-3) {
- c@typ@ a, *pa=&a;
+ @ctype@ a, *pa=&a;
nc_diff@c@(&nc_1@c@, x, r);
nc_sum@c@(&nc_1@c@, x, pa);
nc_quot@c@(pa, r, r);
@@ -593,7 +595,7 @@ nc_atanh@c@(c@typ@ *x, c@typ@ *r)
*
* |x| < 1e-3 => |rel. error| < 1e-18 (f), 1e-24, 1e-36 (l)
*/
- c@typ@ x2;
+ @ctype@ x2;
nc_prod@c@(x, x, &x2);
*r = nc_1@c@;
@@ -612,25 +614,25 @@ nc_atanh@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_cos@c@(c@typ@ *x, c@typ@ *r)
+nc_cos@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ xr=x->real, xi=x->imag;
+ @ftype@ xr=x->real, xi=x->imag;
r->real = npy_cos@c@(xr)*npy_cosh@c@(xi);
r->imag = -npy_sin@c@(xr)*npy_sinh@c@(xi);
return;
}
static void
-nc_cosh@c@(c@typ@ *x, c@typ@ *r)
+nc_cosh@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ xr=x->real, xi=x->imag;
+ @ftype@ xr=x->real, xi=x->imag;
r->real = npy_cos@c@(xi)*npy_cosh@c@(xr);
r->imag = npy_sin@c@(xi)*npy_sinh@c@(xr);
return;
}
static void
-nc_log10@c@(c@typ@ *x, c@typ@ *r)
+nc_log10@c@(@ctype@ *x, @ctype@ *r)
{
nc_log@c@(x, r);
r->real *= NPY_LOG10E@c@;
@@ -639,7 +641,7 @@ nc_log10@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_log2@c@(c@typ@ *x, c@typ@ *r)
+nc_log2@c@(@ctype@ *x, @ctype@ *r)
{
nc_log@c@(x, r);
r->real *= NPY_LOG2E@c@;
@@ -648,30 +650,30 @@ nc_log2@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_sin@c@(c@typ@ *x, c@typ@ *r)
+nc_sin@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ xr=x->real, xi=x->imag;
+ @ftype@ xr=x->real, xi=x->imag;
r->real = npy_sin@c@(xr)*npy_cosh@c@(xi);
r->imag = npy_cos@c@(xr)*npy_sinh@c@(xi);
return;
}
static void
-nc_sinh@c@(c@typ@ *x, c@typ@ *r)
+nc_sinh@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ xr=x->real, xi=x->imag;
+ @ftype@ xr=x->real, xi=x->imag;
r->real = npy_cos@c@(xi)*npy_sinh@c@(xr);
r->imag = npy_sin@c@(xi)*npy_cosh@c@(xr);
return;
}
static void
-nc_tan@c@(c@typ@ *x, c@typ@ *r)
+nc_tan@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ sr,cr,shi,chi;
- @typ@ rs,is,rc,ic;
- @typ@ d;
- @typ@ xr=x->real, xi=x->imag;
+ @ftype@ sr,cr,shi,chi;
+ @ftype@ rs,is,rc,ic;
+ @ftype@ d;
+ @ftype@ xr=x->real, xi=x->imag;
sr = npy_sin@c@(xr);
cr = npy_cos@c@(xr);
shi = npy_sinh@c@(xi);
@@ -687,12 +689,12 @@ nc_tan@c@(c@typ@ *x, c@typ@ *r)
}
static void
-nc_tanh@c@(c@typ@ *x, c@typ@ *r)
+nc_tanh@c@(@ctype@ *x, @ctype@ *r)
{
- @typ@ si,ci,shr,chr;
- @typ@ rs,is,rc,ic;
- @typ@ d;
- @typ@ xr=x->real, xi=x->imag;
+ @ftype@ si,ci,shr,chr;
+ @ftype@ rs,is,rc,ic;
+ @ftype@ d;
+ @ftype@ xr=x->real, xi=x->imag;
si = npy_sin@c@(xi);
ci = npy_cos@c@(xi);
shr = npy_sinh@c@(xr);
diff --git a/numpy/core/src/umath/umathmodule.c.src b/numpy/core/src/umath/umathmodule.c.src
deleted file mode 100644
index a6a9b7b2b..000000000
--- a/numpy/core/src/umath/umathmodule.c.src
+++ /dev/null
@@ -1,442 +0,0 @@
-/* -*- c -*- */
-
-/*
- * vim:syntax=c
- */
-
-/*
- *****************************************************************************
- ** INCLUDES **
- *****************************************************************************
- */
-
-/*
- * _UMATHMODULE IS needed in __ufunc_api.h, included from numpy/ufuncobject.h.
- * This is a mess and it would be nice to fix it. It has nothing to do with
- * __ufunc_api.c
- */
-#define _UMATHMODULE
-#define NPY_NO_DEPRECATED_API
-
-#include "Python.h"
-
-#include "npy_config.h"
-#ifdef ENABLE_SEPARATE_COMPILATION
-#define PY_ARRAY_UNIQUE_SYMBOL _npy_umathmodule_ARRAY_API
-#endif
-
-#include "numpy/ndarrayobject.h"
-#include "numpy/ufuncobject.h"
-#include "abstract.h"
-
-#include "numpy/npy_math.h"
-
-/*
- *****************************************************************************
- ** INCLUDE GENERATED CODE **
- *****************************************************************************
- */
-#include "funcs.inc"
-#include "loops.h"
-#include "ufunc_object.h"
-#include "ufunc_type_resolution.h"
-#include "__umath_generated.c"
-#include "__ufunc_api.c"
-
-static PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om};
-
-static int
-object_ufunc_type_resolver(PyUFuncObject *ufunc,
- NPY_CASTING casting,
- PyArrayObject **operands,
- PyObject *type_tup,
- PyArray_Descr **out_dtypes)
-{
- int i, nop = ufunc->nin + ufunc->nout;
- PyArray_Descr *obj_dtype;
-
- obj_dtype = PyArray_DescrFromType(NPY_OBJECT);
- if (obj_dtype == NULL) {
- return -1;
- }
-
- for (i = 0; i < nop; ++i) {
- Py_INCREF(obj_dtype);
- out_dtypes[i] = obj_dtype;
- }
-
- return 0;
-}
-
-static int
-object_ufunc_loop_selector(PyUFuncObject *ufunc,
- PyArray_Descr **NPY_UNUSED(dtypes),
- PyUFuncGenericFunction *out_innerloop,
- void **out_innerloopdata,
- int *out_needs_api)
-{
- *out_innerloop = ufunc->functions[0];
- *out_innerloopdata = ufunc->data[0];
- *out_needs_api = 1;
-
- return 0;
-}
-
-static PyObject *
-ufunc_frompyfunc(PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *NPY_UNUSED(kwds)) {
- /* Keywords are ignored for now */
-
- PyObject *function, *pyname = NULL;
- int nin, nout, i;
- PyUFunc_PyFuncData *fdata;
- PyUFuncObject *self;
- char *fname, *str;
- Py_ssize_t fname_len = -1;
- int offset[2];
-
- if (!PyArg_ParseTuple(args, "Oii", &function, &nin, &nout)) {
- return NULL;
- }
- if (!PyCallable_Check(function)) {
- PyErr_SetString(PyExc_TypeError, "function must be callable");
- return NULL;
- }
- self = PyArray_malloc(sizeof(PyUFuncObject));
- if (self == NULL) {
- return NULL;
- }
- PyObject_Init((PyObject *)self, &PyUFunc_Type);
-
- self->userloops = NULL;
- self->nin = nin;
- self->nout = nout;
- self->nargs = nin + nout;
- self->identity = PyUFunc_None;
- self->functions = pyfunc_functions;
- self->ntypes = 1;
- self->check_return = 0;
-
- /* generalized ufunc */
- self->core_enabled = 0;
- self->core_num_dim_ix = 0;
- self->core_num_dims = NULL;
- self->core_dim_ixs = NULL;
- self->core_offsets = NULL;
- self->core_signature = NULL;
-
- self->type_resolver = &object_ufunc_type_resolver;
- self->legacy_inner_loop_selector = &object_ufunc_loop_selector;
-
- pyname = PyObject_GetAttrString(function, "__name__");
- if (pyname) {
- (void) PyString_AsStringAndSize(pyname, &fname, &fname_len);
- }
- if (PyErr_Occurred()) {
- fname = "?";
- fname_len = 1;
- PyErr_Clear();
- }
-
- /*
- * self->ptr holds a pointer for enough memory for
- * self->data[0] (fdata)
- * self->data
- * self->name
- * self->types
- *
- * To be safest, all of these need their memory aligned on void * pointers
- * Therefore, we may need to allocate extra space.
- */
- offset[0] = sizeof(PyUFunc_PyFuncData);
- i = (sizeof(PyUFunc_PyFuncData) % sizeof(void *));
- if (i) {
- offset[0] += (sizeof(void *) - i);
- }
- offset[1] = self->nargs;
- i = (self->nargs % sizeof(void *));
- if (i) {
- offset[1] += (sizeof(void *)-i);
- }
- self->ptr = PyArray_malloc(offset[0] + offset[1] + sizeof(void *) +
- (fname_len + 14));
- if (self->ptr == NULL) {
- Py_XDECREF(pyname);
- return PyErr_NoMemory();
- }
- Py_INCREF(function);
- self->obj = function;
- fdata = (PyUFunc_PyFuncData *)(self->ptr);
- fdata->nin = nin;
- fdata->nout = nout;
- fdata->callable = function;
-
- self->data = (void **)(((char *)self->ptr) + offset[0]);
- self->data[0] = (void *)fdata;
- self->types = (char *)self->data + sizeof(void *);
- for (i = 0; i < self->nargs; i++) {
- self->types[i] = NPY_OBJECT;
- }
- str = self->types + offset[1];
- memcpy(str, fname, fname_len);
- memcpy(str+fname_len, " (vectorized)", 14);
- self->name = str;
-
- Py_XDECREF(pyname);
-
- /* Do a better job someday */
- self->doc = "dynamic ufunc based on a python function";
-
- return (PyObject *)self;
-}
-
-/*
- *****************************************************************************
- ** SETUP UFUNCS **
- *****************************************************************************
- */
-
-/* Less automated additions to the ufuncs */
-
-static PyUFuncGenericFunction frexp_functions[] = {
-#ifdef HAVE_FREXPF
- HALF_frexp,
- FLOAT_frexp,
-#endif
- DOUBLE_frexp
-#ifdef HAVE_FREXPL
- ,LONGDOUBLE_frexp
-#endif
-};
-
-static void * blank3_data[] = { (void *)NULL, (void *)NULL, (void *)NULL};
-static void * blank6_data[] = { (void *)NULL, (void *)NULL, (void *)NULL,
- (void *)NULL, (void *)NULL, (void *)NULL};
-static char frexp_signatures[] = {
-#ifdef HAVE_FREXPF
- NPY_HALF, NPY_HALF, NPY_INT,
- NPY_FLOAT, NPY_FLOAT, NPY_INT,
-#endif
- NPY_DOUBLE, NPY_DOUBLE, NPY_INT
-#ifdef HAVE_FREXPL
- ,NPY_LONGDOUBLE, NPY_LONGDOUBLE, NPY_INT
-#endif
-};
-
-#if NPY_SIZEOF_LONG == NPY_SIZEOF_INT
-#define LDEXP_LONG(typ) typ##_ldexp
-#else
-#define LDEXP_LONG(typ) typ##_ldexp_long
-#endif
-
-static PyUFuncGenericFunction ldexp_functions[] = {
-#ifdef HAVE_LDEXPF
- HALF_ldexp,
- FLOAT_ldexp,
- LDEXP_LONG(HALF),
- LDEXP_LONG(FLOAT),
-#endif
- DOUBLE_ldexp,
- LDEXP_LONG(DOUBLE)
-#ifdef HAVE_LDEXPL
- ,
- LONGDOUBLE_ldexp,
- LDEXP_LONG(LONGDOUBLE)
-#endif
-};
-
-static char ldexp_signatures[] = {
-#ifdef HAVE_LDEXPF
- NPY_HALF, NPY_INT, NPY_HALF,
- NPY_FLOAT, NPY_INT, NPY_FLOAT,
- NPY_HALF, NPY_LONG, NPY_HALF,
- NPY_FLOAT, NPY_LONG, NPY_FLOAT,
-#endif
- NPY_DOUBLE, NPY_INT, NPY_DOUBLE,
- NPY_DOUBLE, NPY_LONG, NPY_DOUBLE
-#ifdef HAVE_LDEXPL
- ,NPY_LONGDOUBLE, NPY_INT, NPY_LONGDOUBLE
- ,NPY_LONGDOUBLE, NPY_LONG, NPY_LONGDOUBLE
-#endif
-};
-
-static void
-InitOtherOperators(PyObject *dictionary) {
- PyObject *f;
- int num;
-
- num = sizeof(frexp_functions) / sizeof(frexp_functions[0]);
- f = PyUFunc_FromFuncAndData(frexp_functions, blank3_data,
- frexp_signatures, num,
- 1, 2, PyUFunc_None, "frexp",
- "Split the number, x, into a normalized"\
- " fraction (y1) and exponent (y2)",0);
- PyDict_SetItemString(dictionary, "frexp", f);
- Py_DECREF(f);
-
- num = sizeof(ldexp_functions) / sizeof(ldexp_functions[0]);
- f = PyUFunc_FromFuncAndData(ldexp_functions, blank6_data, ldexp_signatures, num,
- 2, 1, PyUFunc_None, "ldexp",
- "Compute y = x1 * 2**x2.",0);
- PyDict_SetItemString(dictionary, "ldexp", f);
- Py_DECREF(f);
-
-#if defined(NPY_PY3K)
- f = PyDict_GetItemString(dictionary, "true_divide");
- PyDict_SetItemString(dictionary, "divide", f);
-#endif
- return;
-}
-
-/* Setup the umath module */
-/* Remove for time being, it is declared in __ufunc_api.h */
-/*static PyTypeObject PyUFunc_Type;*/
-
-static struct PyMethodDef methods[] = {
- {"frompyfunc",
- (PyCFunction) ufunc_frompyfunc,
- METH_VARARGS | METH_KEYWORDS, NULL},
- {"seterrobj",
- (PyCFunction) ufunc_seterr,
- METH_VARARGS, NULL},
- {"geterrobj",
- (PyCFunction) ufunc_geterr,
- METH_VARARGS, NULL},
- {NULL, NULL, 0, NULL} /* sentinel */
-};
-
-
-#if defined(NPY_PY3K)
-static struct PyModuleDef moduledef = {
- PyModuleDef_HEAD_INIT,
- "umath",
- NULL,
- -1,
- methods,
- NULL,
- NULL,
- NULL,
- NULL
-};
-#endif
-
-#include <stdio.h>
-
-#if defined(NPY_PY3K)
-#define RETVAL m
-PyObject *PyInit_umath(void)
-#else
-#define RETVAL
-PyMODINIT_FUNC initumath(void)
-#endif
-{
- PyObject *m, *d, *s, *s2, *c_api;
- int UFUNC_FLOATING_POINT_SUPPORT = 1;
-
-#ifdef NO_UFUNC_FLOATING_POINT_SUPPORT
- UFUNC_FLOATING_POINT_SUPPORT = 0;
-#endif
- /* Create the module and add the functions */
-#if defined(NPY_PY3K)
- m = PyModule_Create(&moduledef);
-#else
- m = Py_InitModule("umath", methods);
-#endif
- if (!m) {
- return RETVAL;
- }
-
- /* Import the array */
- if (_import_array() < 0) {
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_ImportError,
- "umath failed: Could not import array core.");
- }
- return RETVAL;
- }
-
- /* Initialize the types */
- if (PyType_Ready(&PyUFunc_Type) < 0)
- return RETVAL;
-
- /* Add some symbolic constants to the module */
- d = PyModule_GetDict(m);
-
- c_api = NpyCapsule_FromVoidPtr((void *)PyUFunc_API, NULL);
- if (PyErr_Occurred()) {
- goto err;
- }
- PyDict_SetItemString(d, "_UFUNC_API", c_api);
- Py_DECREF(c_api);
- if (PyErr_Occurred()) {
- goto err;
- }
-
- s = PyString_FromString("0.4.0");
- PyDict_SetItemString(d, "__version__", s);
- Py_DECREF(s);
-
- /* Load the ufunc operators into the array module's namespace */
- InitOperators(d);
-
- InitOtherOperators(d);
-
- PyDict_SetItemString(d, "pi", s = PyFloat_FromDouble(NPY_PI));
- Py_DECREF(s);
- PyDict_SetItemString(d, "e", s = PyFloat_FromDouble(exp(1.0)));
- Py_DECREF(s);
-
-#define ADDCONST(str) PyModule_AddIntConstant(m, #str, UFUNC_##str)
-#define ADDSCONST(str) PyModule_AddStringConstant(m, "UFUNC_" #str, UFUNC_##str)
-
- ADDCONST(ERR_IGNORE);
- ADDCONST(ERR_WARN);
- ADDCONST(ERR_CALL);
- ADDCONST(ERR_RAISE);
- ADDCONST(ERR_PRINT);
- ADDCONST(ERR_LOG);
- ADDCONST(ERR_DEFAULT);
- ADDCONST(ERR_DEFAULT2);
-
- ADDCONST(SHIFT_DIVIDEBYZERO);
- ADDCONST(SHIFT_OVERFLOW);
- ADDCONST(SHIFT_UNDERFLOW);
- ADDCONST(SHIFT_INVALID);
-
- ADDCONST(FPE_DIVIDEBYZERO);
- ADDCONST(FPE_OVERFLOW);
- ADDCONST(FPE_UNDERFLOW);
- ADDCONST(FPE_INVALID);
-
- ADDCONST(FLOATING_POINT_SUPPORT);
-
- ADDSCONST(PYVALS_NAME);
-
-#undef ADDCONST
-#undef ADDSCONST
- PyModule_AddIntConstant(m, "UFUNC_BUFSIZE_DEFAULT", (long)NPY_BUFSIZE);
-
- PyModule_AddObject(m, "PINF", PyFloat_FromDouble(NPY_INFINITY));
- PyModule_AddObject(m, "NINF", PyFloat_FromDouble(-NPY_INFINITY));
- PyModule_AddObject(m, "PZERO", PyFloat_FromDouble(NPY_PZERO));
- PyModule_AddObject(m, "NZERO", PyFloat_FromDouble(NPY_NZERO));
- PyModule_AddObject(m, "NAN", PyFloat_FromDouble(NPY_NAN));
-
- s = PyDict_GetItemString(d, "conjugate");
- s2 = PyDict_GetItemString(d, "remainder");
- /* Setup the array object's numerical structures with appropriate
- ufuncs in d*/
- PyArray_SetNumericOps(d);
-
- PyDict_SetItemString(d, "conj", s);
- PyDict_SetItemString(d, "mod", s2);
-
- return RETVAL;
-
- err:
- /* Check for errors */
- if (!PyErr_Occurred()) {
- PyErr_SetString(PyExc_RuntimeError,
- "cannot load umath module.");
- }
- return RETVAL;
-}