#include "Python.h" #include "arrayobject.h" #include "ufuncobject.h" #include "abstract.h" #ifdef macintosh #include "mymath.h" #else #include #endif #ifndef CHAR_BIT #define CHAR_BIT 8 #endif #ifndef LONG_BIT #define LONG_BIT (CHAR_BIT * sizeof(long)) #endif #ifndef INT_BIT #define INT_BIT (CHAR_BIT * sizeof(int)) #endif #ifndef SHORT_BIT #define SHORT_BIT (CHAR_BIT * sizeof(short)) #endif /* A whole slew of basic math functions are provided by Konrad Hinsen. */ #ifndef __STDC__ extern double fmod Py_PROTO((double, double)); extern double frexp Py_PROTO((double, int *)); extern double ldexp Py_PROTO((double, int)); extern double modf Py_PROTO((double, double *)); #endif #ifndef M_PI #define M_PI 3.14159265359 #endif #if defined(HAVE_HYPOT) #ifndef NeXT extern double hypot Py_PROTO((double, double)); #endif #else double hypot(double x, double y) { double yx; x = fabs(x); y = fabs(y); if (x < y) { double temp = x; x = y; y = temp; } if (x == 0.) return 0.; else { yx = y/x; return x*sqrt(1.+yx*yx); } } #endif #ifdef i860 /* Cray APP has bogus definition of HUGE_VAL in */ #undef HUGE_VAL #endif #ifdef HUGE_VAL #define CHECK(x) if (errno != 0) ; else if (-HUGE_VAL <= (x) && (x) <= HUGE_VAL) ; else errno = ERANGE #else #define CHECK(x) /* Don't know how to check */ #endif /* First, the C functions that do the real work */ /* constants */ static Py_complex c_1 = {1., 0.}; static Py_complex c_half = {0.5, 0.}; static Py_complex c_i = {0., 1.}; static Py_complex c_i2 = {0., 0.5}; static Py_complex c_mi = {0., -1.}; static Py_complex c_pi2 = {M_PI/2., 0.}; static Py_complex c_sqrt(Py_complex x) { Py_complex r; double s,d; if (x.real == 0. && x.imag == 0.) r = x; else { s = sqrt(0.5*(fabs(x.real) + hypot(x.real,x.imag))); d = 0.5*x.imag/s; if (x.real > 0.) { r.real = s; r.imag = d; } else if (x.imag >= 0.) { r.real = d; r.imag = s; } else { r.real = -d; r.imag = -s; } } return r; } static Py_complex c_log(Py_complex x) { Py_complex r; double l = hypot(x.real,x.imag); r.imag = atan2(x.imag, x.real); r.real = log(l); return r; } static Py_complex c_prodi(Py_complex x) { Py_complex r; r.real = -x.imag; r.imag = x.real; return r; } static Py_complex c_acos(Py_complex x) { return c_neg(c_prodi(c_log(c_sum(x,c_prod(c_i, c_sqrt(c_diff(c_1,c_prod(x,x)))))))); } static Py_complex c_acosh(Py_complex x) { return c_log(c_sum(x,c_prod(c_i, c_sqrt(c_diff(c_1,c_prod(x,x)))))); } static Py_complex c_asin(Py_complex x) { return c_neg(c_prodi(c_log(c_sum(c_prod(c_i,x), c_sqrt(c_diff(c_1,c_prod(x,x))))))); } static Py_complex c_asinh(Py_complex x) { return c_neg(c_log(c_diff(c_sqrt(c_sum(c_1,c_prod(x,x))),x))); } static Py_complex c_atan(Py_complex x) { return c_prod(c_i2,c_log(c_quot(c_sum(c_i,x),c_diff(c_i,x)))); } static Py_complex c_atanh(Py_complex x) { return c_prod(c_half,c_log(c_quot(c_sum(c_1,x),c_diff(c_1,x)))); } static Py_complex c_cos(Py_complex x) { Py_complex r; r.real = cos(x.real)*cosh(x.imag); r.imag = -sin(x.real)*sinh(x.imag); return r; } static Py_complex c_cosh(Py_complex x) { Py_complex r; r.real = cos(x.imag)*cosh(x.real); r.imag = sin(x.imag)*sinh(x.real); return r; } static Py_complex c_exp(Py_complex x) { Py_complex r; double l = exp(x.real); r.real = l*cos(x.imag); r.imag = l*sin(x.imag); return r; } static Py_complex c_log10(Py_complex x) { Py_complex r; double l = hypot(x.real,x.imag); r.imag = atan2(x.imag, x.real)/log(10.); r.real = log10(l); return r; } static Py_complex c_sin(Py_complex x) { Py_complex r; r.real = sin(x.real)*cosh(x.imag); r.imag = cos(x.real)*sinh(x.imag); return r; } static Py_complex c_sinh(Py_complex x) { Py_complex r; r.real = cos(x.imag)*sinh(x.real); r.imag = sin(x.imag)*cosh(x.real); return r; } static Py_complex c_tan(Py_complex x) { Py_complex r; double sr,cr,shi,chi; double rs,is,rc,ic; double d; sr = sin(x.real); cr = cos(x.real); shi = sinh(x.imag); chi = cosh(x.imag); rs = sr*chi; is = cr*shi; rc = cr*chi; ic = -sr*shi; d = rc*rc + ic*ic; r.real = (rs*rc+is*ic)/d; r.imag = (is*rc-rs*ic)/d; return r; } static Py_complex c_tanh(Py_complex x) { Py_complex r; double si,ci,shr,chr; double rs,is,rc,ic; double d; si = sin(x.imag); ci = cos(x.imag); shr = sinh(x.real); chr = cosh(x.real); rs = ci*shr; is = si*chr; rc = ci*chr; ic = si*shr; d = rc*rc + ic*ic; r.real = (rs*rc+is*ic)/d; r.imag = (is*rc-rs*ic)/d; return r; } static long powll(long x, long n, int nbits) /* Overflow check: overflow will occur if log2(abs(x)) * n > nbits. */ { long r = 1; long p = x; double logtwox; long mask = 1; if (n < 0) PyErr_SetString(PyExc_ValueError, "Integer to a negative power"); if (x != 0) { logtwox = log10 (fabs ( (double) x))/log10 ( (double) 2.0); if (logtwox * (double) n > (double) nbits) PyErr_SetString(PyExc_ArithmeticError, "Integer overflow in power."); } while (mask > 0 && n >= mask) { if (n & mask) r *= p; mask <<= 1; p *= p; } return r; } static void UBYTE_add(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i 255) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } *((unsigned char *)op)=(unsigned char) x; } } static void SBYTE_multiply(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; int x; for(i=0; i 127 || x < -128) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } *((signed char *)op)=(signed char) x; } } static void SHORT_multiply(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; short a, b, ah, bh, x, y; int s; for(i=0; i> (SHORT_BIT/2); bh = b >> (SHORT_BIT/2); /* Quick test for common case: two small positive shorts */ if (ah == 0 && bh == 0) { if ((x=a*b) < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } else { *((short *)op)=x; continue; } } /* Arrange that a >= b >= 0 */ if (a < 0) { a = -a; if (a < 0) { /* Largest negative */ if (b == 0 || b == 1) { *((short *)op)=a*b; continue; } else { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } } s = -s; ah = a >> (SHORT_BIT/2); } if (b < 0) { b = -b; if (b < 0) { /* Largest negative */ if (a == 0 || a == 1) { *((short *)op)=a*b; continue; } else { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } } s = -s; bh = b >> (SHORT_BIT/2); } /* 1) both ah and bh > 0 : then report overflow */ if (ah != 0 && bh != 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } /* 2) both ah and bh = 0 : then compute a*b and report overflow if it comes out negative */ if (ah == 0 && bh == 0) { if ((x=a*b) < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } else { *((short *)op)=s * x; continue; } } if (a < b) { /* Swap */ x = a; a = b; b = x; ah = bh; /* bh not used beyond this point */ } /* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if it's >= 2^31 compute al*bl and report overflow if it's negative add (ah*bl)<<32 to al*bl and report overflow if it's negative (NB b == bl in this case, and we make a = al) */ y = ah*b; if (y >= (1 << (SHORT_BIT/2 - 1))) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } a &= (1 << (SHORT_BIT/2)) - 1; x = a*b; if (x < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } x += y << (SHORT_BIT/2); if (x < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } *((short *)op)=s*x; } } static void INT_multiply(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; int a, b, ah, bh, x, y; int s; for(i=0; i> (INT_BIT/2); bh = b >> (INT_BIT/2); /* Quick test for common case: two small positive ints */ if (ah == 0 && bh == 0) { if ((x=a*b) < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } else { *((int *)op)=x; continue; } } /* Arrange that a >= b >= 0 */ if (a < 0) { a = -a; if (a < 0) { /* Largest negative */ if (b == 0 || b == 1) { *((int *)op)=a*b; continue; } else { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } } s = -s; ah = a >> (INT_BIT/2); } if (b < 0) { b = -b; if (b < 0) { /* Largest negative */ if (a == 0 || a == 1) { *((int *)op)=a*b; continue; } else { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } } s = -s; bh = b >> (INT_BIT/2); } /* 1) both ah and bh > 0 : then report overflow */ if (ah != 0 && bh != 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } /* 2) both ah and bh = 0 : then compute a*b and report overflow if it comes out negative */ if (ah == 0 && bh == 0) { if ((x=a*b) < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } else { *((int *)op)=s * x; continue; } } if (a < b) { /* Swap */ x = a; a = b; b = x; ah = bh; /* bh not used beyond this point */ } /* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if it's >= 2^31 compute al*bl and report overflow if it's negative add (ah*bl)<<32 to al*bl and report overflow if it's negative (NB b == bl in this case, and we make a = al) */ y = ah*b; if (y >= (1 << (INT_BIT/2 - 1))) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } a &= (1 << (INT_BIT/2)) - 1; x = a*b; if (x < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } x += y << (INT_BIT/2); if (x < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } *((int *)op)=s*x; } } static void LONG_multiply(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; long a, b, ah, bh, x, y; int s; for(i=0; i> (LONG_BIT/2); bh = b >> (LONG_BIT/2); /* Quick test for common case: two small positive ints */ if (ah == 0 && bh == 0) { if ((x=a*b) < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } else { *((long *)op)=x; continue; } } /* Arrange that a >= b >= 0 */ if (a < 0) { a = -a; if (a < 0) { /* Largest negative */ if (b == 0 || b == 1) { *((long *)op)=a*b; continue; } else { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } } s = -s; ah = a >> (LONG_BIT/2); } if (b < 0) { b = -b; if (b < 0) { /* Largest negative */ if (a == 0 || a == 1) { *((long *)op)=a*b; continue; } else { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } } s = -s; bh = b >> (LONG_BIT/2); } /* 1) both ah and bh > 0 : then report overflow */ if (ah != 0 && bh != 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } /* 2) both ah and bh = 0 : then compute a*b and report overflow if it comes out negative */ if (ah == 0 && bh == 0) { if ((x=a*b) < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } else { *((long *)op)=s * x; continue; } } if (a < b) { /* Swap */ x = a; a = b; b = x; ah = bh; /* bh not used beyond this point */ } /* 3) ah > 0 and bh = 0 : compute ah*bl and report overflow if it's >= 2^31 compute al*bl and report overflow if it's negative add (ah*bl)<<32 to al*bl and report overflow if it's negative (NB b == bl in this case, and we make a = al) */ y = ah*b; if (y >= (1L << (LONG_BIT/2 - 1))) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } a &= (1L << (LONG_BIT/2)) - 1; x = a*b; if (x < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } x += y << (LONG_BIT/2); if (x < 0) { PyErr_SetString (PyExc_ArithmeticError, "Integer overflow in multiply."); return; } *((long *)op)=s*x; } } static void FLOAT_multiply(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((unsigned char *)i2); } } static void SBYTE_greater(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((signed char *)i2); } } static void SHORT_greater(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((short *)i2); } } static void INT_greater(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((int *)i2); } } static void LONG_greater(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((long *)i2); } } static void FLOAT_greater(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((float *)i2); } } static void DOUBLE_greater(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((double *)i2); } } static void UBYTE_greater_equal(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i= *((unsigned char *)i2); } } static void SBYTE_greater_equal(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i= *((signed char *)i2); } } static void SHORT_greater_equal(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i= *((short *)i2); } } static void INT_greater_equal(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i= *((int *)i2); } } static void LONG_greater_equal(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i= *((long *)i2); } } static void FLOAT_greater_equal(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i= *((float *)i2); } } static void DOUBLE_greater_equal(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i= *((double *)i2); } } static void UBYTE_less(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((unsigned char *)i2) ? *((unsigned char *)i1) : *((unsigned char *)i2); } } static void SBYTE_maximum(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((signed char *)i2) ? *((signed char *)i1) : *((signed char *)i2); } } static void SHORT_maximum(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((short *)i2) ? *((short *)i1) : *((short *)i2); } } static void INT_maximum(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((int *)i2) ? *((int *)i1) : *((int *)i2); } } static void LONG_maximum(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((long *)i2) ? *((long *)i1) : *((long *)i2); } } static void FLOAT_maximum(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((float *)i2) ? *((float *)i1) : *((float *)i2); } } static void DOUBLE_maximum(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i *((double *)i2) ? *((double *)i1) : *((double *)i2); } } static void UBYTE_minimum(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i> *((unsigned char *)i2); } } static void SBYTE_right_shift(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i> *((signed char *)i2); } } static void SHORT_right_shift(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i> *((short *)i2); } } static void INT_right_shift(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i> *((int *)i2); } } static void LONG_right_shift(char **args, int *dimensions, int *steps, void *func) { int i, is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; char *i1=args[0], *i2=args[1], *op=args[2]; for(i=0; i> *((long *)i2); } } static PyUFuncGenericFunction add_functions[] = { UBYTE_add, SBYTE_add, SHORT_add, INT_add, LONG_add, FLOAT_add, DOUBLE_add, CFLOAT_add, CDOUBLE_add, NULL, }; static PyUFuncGenericFunction subtract_functions[] = { UBYTE_subtract, SBYTE_subtract, SHORT_subtract, INT_subtract, LONG_subtract, FLOAT_subtract, DOUBLE_subtract, CFLOAT_subtract, CDOUBLE_subtract, NULL, }; static PyUFuncGenericFunction multiply_functions[] = { UBYTE_multiply, SBYTE_multiply, SHORT_multiply, INT_multiply, LONG_multiply, FLOAT_multiply, DOUBLE_multiply, NULL, NULL, NULL, }; static PyUFuncGenericFunction divide_functions[] = { UBYTE_divide, SBYTE_divide, SHORT_divide, INT_divide, LONG_divide, FLOAT_divide, DOUBLE_divide, NULL, NULL, NULL, }; static PyUFuncGenericFunction divide_safe_functions[] = { UBYTE_divide_safe, SBYTE_divide_safe, SHORT_divide_safe, INT_divide_safe, LONG_divide_safe, FLOAT_divide_safe, DOUBLE_divide_safe, }; static PyUFuncGenericFunction conjugate_functions[] = { UBYTE_conjugate, SBYTE_conjugate, SHORT_conjugate, INT_conjugate, LONG_conjugate, FLOAT_conjugate, DOUBLE_conjugate, CFLOAT_conjugate, CDOUBLE_conjugate, NULL, }; static PyUFuncGenericFunction remainder_functions[] = { UBYTE_remainder, SBYTE_remainder, SHORT_remainder, INT_remainder, LONG_remainder, NULL, NULL, NULL, }; static PyUFuncGenericFunction power_functions[] = { UBYTE_power, SBYTE_power, SHORT_power, INT_power, LONG_power, NULL, NULL, NULL, NULL, NULL, }; static PyUFuncGenericFunction absolute_functions[] = { SBYTE_absolute, SHORT_absolute, INT_absolute, LONG_absolute, FLOAT_absolute, DOUBLE_absolute, CFLOAT_absolute, CDOUBLE_absolute, NULL, }; static PyUFuncGenericFunction negative_functions[] = { SBYTE_negative, SHORT_negative, INT_negative, LONG_negative, FLOAT_negative, DOUBLE_negative, CFLOAT_negative, CDOUBLE_negative, NULL, }; static PyUFuncGenericFunction greater_functions[] = { UBYTE_greater, SBYTE_greater, SHORT_greater, INT_greater, LONG_greater, FLOAT_greater, DOUBLE_greater, }; static PyUFuncGenericFunction greater_equal_functions[] = { UBYTE_greater_equal, SBYTE_greater_equal, SHORT_greater_equal, INT_greater_equal, LONG_greater_equal, FLOAT_greater_equal, DOUBLE_greater_equal, }; static PyUFuncGenericFunction less_functions[] = { UBYTE_less, SBYTE_less, SHORT_less, INT_less, LONG_less, FLOAT_less, DOUBLE_less, }; static PyUFuncGenericFunction less_equal_functions[] = { UBYTE_less_equal, SBYTE_less_equal, SHORT_less_equal, INT_less_equal, LONG_less_equal, FLOAT_less_equal, DOUBLE_less_equal, }; static PyUFuncGenericFunction equal_functions[] = { UBYTE_equal, SBYTE_equal, SHORT_equal, INT_equal, LONG_equal, FLOAT_equal, DOUBLE_equal, }; static PyUFuncGenericFunction not_equal_functions[] = { UBYTE_not_equal, SBYTE_not_equal, SHORT_not_equal, INT_not_equal, LONG_not_equal, FLOAT_not_equal, DOUBLE_not_equal, }; static PyUFuncGenericFunction logical_and_functions[] = { UBYTE_logical_and, SBYTE_logical_and, SHORT_logical_and, INT_logical_and, LONG_logical_and, FLOAT_logical_and, DOUBLE_logical_and, }; static PyUFuncGenericFunction logical_or_functions[] = { UBYTE_logical_or, SBYTE_logical_or, SHORT_logical_or, INT_logical_or, LONG_logical_or, FLOAT_logical_or, DOUBLE_logical_or, }; static PyUFuncGenericFunction logical_xor_functions[] = { UBYTE_logical_xor, SBYTE_logical_xor, SHORT_logical_xor, INT_logical_xor, LONG_logical_xor, FLOAT_logical_xor, DOUBLE_logical_xor, }; static PyUFuncGenericFunction logical_not_functions[] = { UBYTE_logical_not, SBYTE_logical_not, SHORT_logical_not, INT_logical_not, LONG_logical_not, FLOAT_logical_not, DOUBLE_logical_not, }; static PyUFuncGenericFunction maximum_functions[] = { UBYTE_maximum, SBYTE_maximum, SHORT_maximum, INT_maximum, LONG_maximum, FLOAT_maximum, DOUBLE_maximum, }; static PyUFuncGenericFunction minimum_functions[] = { UBYTE_minimum, SBYTE_minimum, SHORT_minimum, INT_minimum, LONG_minimum, FLOAT_minimum, DOUBLE_minimum, }; static PyUFuncGenericFunction bitwise_and_functions[] = { UBYTE_bitwise_and, SBYTE_bitwise_and, SHORT_bitwise_and, INT_bitwise_and, LONG_bitwise_and, NULL, }; static PyUFuncGenericFunction bitwise_or_functions[] = { UBYTE_bitwise_or, SBYTE_bitwise_or, SHORT_bitwise_or, INT_bitwise_or, LONG_bitwise_or, NULL, }; static PyUFuncGenericFunction bitwise_xor_functions[] = { UBYTE_bitwise_xor, SBYTE_bitwise_xor, SHORT_bitwise_xor, INT_bitwise_xor, LONG_bitwise_xor, NULL, }; static PyUFuncGenericFunction invert_functions[] = { UBYTE_invert, SBYTE_invert, SHORT_invert, INT_invert, LONG_invert, NULL, }; static PyUFuncGenericFunction left_shift_functions[] = { UBYTE_left_shift, SBYTE_left_shift, SHORT_left_shift, INT_left_shift, LONG_left_shift, NULL, }; static PyUFuncGenericFunction right_shift_functions[] = { UBYTE_right_shift, SBYTE_right_shift, SHORT_right_shift, INT_right_shift, LONG_right_shift, NULL, }; static PyUFuncGenericFunction arccos_functions[] = { NULL, NULL, NULL, NULL, NULL, }; static PyUFuncGenericFunction ceil_functions[] = { NULL, NULL, NULL, }; static PyUFuncGenericFunction arctan2_functions[] = { NULL, NULL, NULL, }; static void * add_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Add, }; static void * subtract_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Subtract, }; static void * multiply_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)c_prod, (void *)c_prod, (void *)PyNumber_Multiply, }; static void * divide_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)c_quot, (void *)c_quot, (void *)PyNumber_Divide, }; static void * divide_safe_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, }; static void * conjugate_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)"conjugate", }; static void * remainder_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)fmod, (void *)fmod, (void *)PyNumber_Remainder, }; static void * power_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)pow, (void *)pow, (void *)c_pow, (void *)c_pow, (void *)PyNumber_Power, }; static void * absolute_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Absolute, }; static void * negative_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Negative, }; static void * bitwise_and_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_And, }; static void * bitwise_or_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Or, }; static void * bitwise_xor_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Xor, }; static void * invert_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Invert, }; static void * left_shift_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Lshift, }; static void * right_shift_data[] = { (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL, (void *)PyNumber_Rshift, }; static void * arccos_data[] = { (void *)acos, (void *)acos, (void *)c_acos, (void *)c_acos, (void *)"arccos", }; static void * arcsin_data[] = { (void *)asin, (void *)asin, (void *)c_asin, (void *)c_asin, (void *)"arcsin", }; static void * arctan_data[] = { (void *)atan, (void *)atan, (void *)c_atan, (void *)c_atan, (void *)"arctan", }; static void * cos_data[] = { (void *)cos, (void *)cos, (void *)c_cos, (void *)c_cos, (void *)"cos", }; static void * cosh_data[] = { (void *)cosh, (void *)cosh, (void *)c_cosh, (void *)c_cosh, (void *)"cosh", }; static void * exp_data[] = { (void *)exp, (void *)exp, (void *)c_exp, (void *)c_exp, (void *)"exp", }; static void * log_data[] = { (void *)log, (void *)log, (void *)c_log, (void *)c_log, (void *)"log", }; static void * log10_data[] = { (void *)log10, (void *)log10, (void *)c_log10, (void *)c_log10, (void *)"log10", }; static void * sin_data[] = { (void *)sin, (void *)sin, (void *)c_sin, (void *)c_sin, (void *)"sin", }; static void * sinh_data[] = { (void *)sinh, (void *)sinh, (void *)c_sinh, (void *)c_sinh, (void *)"sinh", }; static void * sqrt_data[] = { (void *)sqrt, (void *)sqrt, (void *)c_sqrt, (void *)c_sqrt, (void *)"sqrt", }; static void * tan_data[] = { (void *)tan, (void *)tan, (void *)c_tan, (void *)c_tan, (void *)"tan", }; static void * tanh_data[] = { (void *)tanh, (void *)tanh, (void *)c_tanh, (void *)c_tanh, (void *)"tanh", }; static void * ceil_data[] = { (void *)ceil, (void *)ceil, (void *)"ceil", }; static void * fabs_data[] = { (void *)fabs, (void *)fabs, (void *)"fabs", }; static void * floor_data[] = { (void *)floor, (void *)floor, (void *)"floor", }; static void * arctan2_data[] = { (void *)atan2, (void *)atan2, (void *)"arctan2", }; static void * fmod_data[] = { (void *)fmod, (void *)fmod, (void *)"fmod", }; static void * hypot_data[] = { (void *)hypot, (void *)hypot, (void *)"hypot", }; static char add_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, }; static char divide_safe_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, }; static char conjugate_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, }; static char remainder_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, }; static char absolute_signatures[] = { PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_FLOAT, PyArray_CDOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, }; static char negative_signatures[] = { PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, }; static char greater_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_LONG, PyArray_SBYTE, PyArray_SBYTE, PyArray_LONG, PyArray_SHORT, PyArray_SHORT, PyArray_LONG, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_LONG, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_LONG, }; static char logical_not_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, }; static char bitwise_and_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_LONG, PyArray_OBJECT, PyArray_OBJECT, PyArray_OBJECT, }; static char invert_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_INT, PyArray_INT, PyArray_LONG, PyArray_LONG, PyArray_OBJECT, PyArray_OBJECT, }; static char arccos_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_OBJECT, PyArray_OBJECT, }; static char ceil_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, }; static char arctan2_signatures[] = { PyArray_FLOAT, PyArray_FLOAT, PyArray_FLOAT, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_OBJECT, PyArray_OBJECT, }; static void InitOperators(PyObject *dictionary) { PyObject *f; add_functions[9] = PyUFunc_OO_O; subtract_functions[9] = PyUFunc_OO_O; multiply_functions[7] = PyUFunc_FF_F_As_DD_D; multiply_functions[8] = PyUFunc_DD_D; multiply_functions[9] = PyUFunc_OO_O; divide_functions[7] = PyUFunc_FF_F_As_DD_D; divide_functions[8] = PyUFunc_DD_D; divide_functions[9] = PyUFunc_OO_O; conjugate_functions[9] = PyUFunc_O_O_method; remainder_functions[5] = PyUFunc_ff_f_As_dd_d; remainder_functions[6] = PyUFunc_dd_d; remainder_functions[7] = PyUFunc_OO_O; power_functions[5] = PyUFunc_ff_f_As_dd_d; power_functions[6] = PyUFunc_dd_d; power_functions[7] = PyUFunc_FF_F_As_DD_D; power_functions[8] = PyUFunc_DD_D; power_functions[9] = PyUFunc_OO_O; absolute_functions[8] = PyUFunc_O_O; negative_functions[8] = PyUFunc_O_O; bitwise_and_functions[5] = PyUFunc_OO_O; bitwise_or_functions[5] = PyUFunc_OO_O; bitwise_xor_functions[5] = PyUFunc_OO_O; invert_functions[5] = PyUFunc_O_O; left_shift_functions[5] = PyUFunc_OO_O; right_shift_functions[5] = PyUFunc_OO_O; arccos_functions[0] = PyUFunc_f_f_As_d_d; arccos_functions[1] = PyUFunc_d_d; arccos_functions[2] = PyUFunc_F_F_As_D_D; arccos_functions[3] = PyUFunc_D_D; arccos_functions[4] = PyUFunc_O_O_method; ceil_functions[0] = PyUFunc_f_f_As_d_d; ceil_functions[1] = PyUFunc_d_d; ceil_functions[2] = PyUFunc_O_O_method; arctan2_functions[0] = PyUFunc_ff_f_As_dd_d; arctan2_functions[1] = PyUFunc_dd_d; arctan2_functions[2] = PyUFunc_O_O_method; f = PyUFunc_FromFuncAndData(add_functions, add_data, add_signatures, 10, 2, 1, PyUFunc_Zero, "add", 1); PyDict_SetItemString(dictionary, "add", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(subtract_functions, subtract_data, add_signatures, 10, 2, 1, PyUFunc_Zero, "subtract", 1); PyDict_SetItemString(dictionary, "subtract", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(multiply_functions, multiply_data, add_signatures, 10, 2, 1, PyUFunc_One, "multiply", 1); PyDict_SetItemString(dictionary, "multiply", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(divide_functions, divide_data, add_signatures, 10, 2, 1, PyUFunc_One, "divide", 1); PyDict_SetItemString(dictionary, "divide", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(divide_safe_functions, divide_safe_data, divide_safe_signatures, 7, 2, 1, PyUFunc_One, "divide_safe", 1); PyDict_SetItemString(dictionary, "divide_safe", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(conjugate_functions, conjugate_data, conjugate_signatures, 10, 1, 1, PyUFunc_None, "conjugate", 1); PyDict_SetItemString(dictionary, "conjugate", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(remainder_functions, remainder_data, remainder_signatures, 8, 2, 1, PyUFunc_Zero, "remainder", 1); PyDict_SetItemString(dictionary, "remainder", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(power_functions, power_data, add_signatures, 10, 2, 1, PyUFunc_One, "power", 1); PyDict_SetItemString(dictionary, "power", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(absolute_functions, absolute_data, absolute_signatures, 9, 1, 1, PyUFunc_None, "absolute", 1); PyDict_SetItemString(dictionary, "absolute", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(negative_functions, negative_data, negative_signatures, 9, 1, 1, PyUFunc_None, "negative", 1); PyDict_SetItemString(dictionary, "negative", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(greater_functions, divide_safe_data, greater_signatures, 7, 2, 1, PyUFunc_None, "greater", 1); PyDict_SetItemString(dictionary, "greater", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(greater_equal_functions, divide_safe_data, greater_signatures, 7, 2, 1, PyUFunc_None, "greater_equal", 1); PyDict_SetItemString(dictionary, "greater_equal", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(less_functions, divide_safe_data, greater_signatures, 7, 2, 1, PyUFunc_None, "less", 1); PyDict_SetItemString(dictionary, "less", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(less_equal_functions, divide_safe_data, greater_signatures, 7, 2, 1, PyUFunc_None, "less_equal", 1); PyDict_SetItemString(dictionary, "less_equal", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(equal_functions, divide_safe_data, greater_signatures, 7, 2, 1, PyUFunc_One, "equal", 1); PyDict_SetItemString(dictionary, "equal", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(not_equal_functions, divide_safe_data, greater_signatures, 7, 2, 1, PyUFunc_None, "not_equal", 1); PyDict_SetItemString(dictionary, "not_equal", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(logical_and_functions, divide_safe_data, divide_safe_signatures, 7, 2, 1, PyUFunc_One, "logical_and", 1); PyDict_SetItemString(dictionary, "logical_and", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(logical_or_functions, divide_safe_data, divide_safe_signatures, 7, 2, 1, PyUFunc_Zero, "logical_or", 1); PyDict_SetItemString(dictionary, "logical_or", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(logical_xor_functions, divide_safe_data, divide_safe_signatures, 7, 2, 1, PyUFunc_None, "logical_xor", 1); PyDict_SetItemString(dictionary, "logical_xor", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(logical_not_functions, divide_safe_data, logical_not_signatures, 7, 1, 1, PyUFunc_None, "logical_not", 1); PyDict_SetItemString(dictionary, "logical_not", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(maximum_functions, divide_safe_data, divide_safe_signatures, 7, 2, 1, PyUFunc_None, "maximum", 1); PyDict_SetItemString(dictionary, "maximum", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(minimum_functions, divide_safe_data, divide_safe_signatures, 7, 2, 1, PyUFunc_None, "minimum", 1); PyDict_SetItemString(dictionary, "minimum", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(bitwise_and_functions, bitwise_and_data, bitwise_and_signatures, 6, 2, 1, PyUFunc_One, "bitwise_and", 1); PyDict_SetItemString(dictionary, "bitwise_and", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(bitwise_or_functions, bitwise_or_data, bitwise_and_signatures, 6, 2, 1, PyUFunc_Zero, "bitwise_or", 1); PyDict_SetItemString(dictionary, "bitwise_or", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(bitwise_xor_functions, bitwise_xor_data, bitwise_and_signatures, 6, 2, 1, PyUFunc_None, "bitwise_xor", 1); PyDict_SetItemString(dictionary, "bitwise_xor", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(invert_functions, invert_data, invert_signatures, 6, 1, 1, PyUFunc_None, "invert", 1); PyDict_SetItemString(dictionary, "invert", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(left_shift_functions, left_shift_data, bitwise_and_signatures, 6, 2, 1, PyUFunc_None, "left_shift", 1); PyDict_SetItemString(dictionary, "left_shift", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(right_shift_functions, right_shift_data, bitwise_and_signatures, 6, 2, 1, PyUFunc_None, "right_shift", 1); PyDict_SetItemString(dictionary, "right_shift", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, arccos_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "arccos", 1); PyDict_SetItemString(dictionary, "arccos", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, arcsin_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "arcsin", 1); PyDict_SetItemString(dictionary, "arcsin", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, arctan_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "arctan", 1); PyDict_SetItemString(dictionary, "arctan", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, cos_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "cos", 1); PyDict_SetItemString(dictionary, "cos", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, cosh_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "cosh", 1); PyDict_SetItemString(dictionary, "cosh", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, exp_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "exp", 1); PyDict_SetItemString(dictionary, "exp", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, log_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "log", 1); PyDict_SetItemString(dictionary, "log", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, log10_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "log10", 1); PyDict_SetItemString(dictionary, "log10", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, sin_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "sin", 1); PyDict_SetItemString(dictionary, "sin", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, sinh_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "sinh", 1); PyDict_SetItemString(dictionary, "sinh", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, sqrt_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "sqrt", 1); PyDict_SetItemString(dictionary, "sqrt", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, tan_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "tan", 1); PyDict_SetItemString(dictionary, "tan", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arccos_functions, tanh_data, arccos_signatures, 5, 1, 1, PyUFunc_None, "tanh", 1); PyDict_SetItemString(dictionary, "tanh", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(ceil_functions, ceil_data, ceil_signatures, 3, 1, 1, PyUFunc_None, "ceil", 1); PyDict_SetItemString(dictionary, "ceil", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(ceil_functions, fabs_data, ceil_signatures, 3, 1, 1, PyUFunc_None, "fabs", 1); PyDict_SetItemString(dictionary, "fabs", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(ceil_functions, floor_data, ceil_signatures, 3, 1, 1, PyUFunc_None, "floor", 1); PyDict_SetItemString(dictionary, "floor", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arctan2_functions, arctan2_data, arctan2_signatures, 3, 2, 1, PyUFunc_None, "arctan2", 1); PyDict_SetItemString(dictionary, "arctan2", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arctan2_functions, fmod_data, arctan2_signatures, 3, 2, 1, PyUFunc_None, "fmod", 1); PyDict_SetItemString(dictionary, "fmod", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(arctan2_functions, hypot_data, arctan2_signatures, 3, 2, 1, PyUFunc_None, "hypot", 1); PyDict_SetItemString(dictionary, "hypot", f); Py_DECREF(f); } /* Initialization function for the module (*must* be called initArray) */ static struct PyMethodDef methods[] = { {NULL, NULL, 0} /* sentinel */ }; void initumath() { PyObject *m, *d, *s; /* Create the module and add the functions */ m = Py_InitModule("umath", methods); /* Import the array and ufunc objects */ import_array(); import_ufunc(); /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); s = PyString_FromString("1.0"); PyDict_SetItemString(d, "__version__", s); Py_DECREF(s); /* Load the ufunc operators into the array module's namespace */ InitOperators(d); PyDict_SetItemString(d, "pi", s = PyFloat_FromDouble(atan(1.0) * 4.0)); Py_DECREF(s); PyDict_SetItemString(d, "e", s = PyFloat_FromDouble(exp(1.0))); Py_DECREF(s); /* Setup the array object's numerical structures */ PyArray_SetNumericOps(d); /* Check for errors */ if (PyErr_Occurred()) Py_FatalError("can't initialize module umath"); }