diff options
author | Travis Oliphant <oliphant@enthought.com> | 2002-04-03 20:25:53 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2002-04-03 20:25:53 +0000 |
commit | db8bb3424741a0486653e63d8cee49212c1cc65c (patch) | |
tree | 6725121d7b4ebfb1774c68e1ff91d75c43830200 | |
parent | 694e465f0c311bf87ec5ca565fe67622a0d4496b (diff) | |
download | numpy-db8bb3424741a0486653e63d8cee49212c1cc65c.tar.gz |
Moved isnan and friends from cephes to special. Made comparison functions return UBYTES. Added Complex comparison functions which work on real parts.
-rw-r--r-- | scipy_base/__init__.py | 11 | ||||
-rw-r--r-- | scipy_base/convenience.py | 520 | ||||
-rw-r--r-- | scipy_base/fastumathmodule.c | 496 | ||||
-rw-r--r-- | scipy_base/function_base.py | 3 | ||||
-rw-r--r-- | scipy_base/isnan.c | 241 | ||||
-rw-r--r-- | scipy_base/matrix_base.py | 2 | ||||
-rw-r--r-- | scipy_base/mconf_lite_BE.h | 119 | ||||
-rw-r--r-- | scipy_base/mconf_lite_LE.h | 119 | ||||
-rwxr-xr-x | scipy_base/setup_scipy_base.py | 15 | ||||
-rw-r--r-- | scipy_base/tests/test_type_check.py | 22 | ||||
-rwxr-xr-x | scipy_base/transform_base.py | 73 | ||||
-rw-r--r-- | scipy_base/type_check.py | 80 | ||||
-rw-r--r-- | weave/accelerate_tools.py | 20 | ||||
-rw-r--r-- | weave/ast_tools.py | 2 | ||||
-rwxr-xr-x | weave/misc.py | 2 |
15 files changed, 1548 insertions, 177 deletions
diff --git a/scipy_base/__init__.py b/scipy_base/__init__.py index 8a26aba03..d4987c677 100644 --- a/scipy_base/__init__.py +++ b/scipy_base/__init__.py @@ -12,13 +12,17 @@ from index_tricks import * from function_base import * from shape_base import * from matrix_base import * +from transform_base import * from polynomial import * from scimath import * # needs fastumath -Inf = inf = Numeric.array(1e308)**10 -NaN = nan = Numeric.array(0.0) / Numeric.array(0.0) +Inf = inf = fastumath.PINF +try: + NaN = nan = fastumath.NAN +except AttributeError: + NAN = nan = array(0.0)/array(0.0) #---- testing ----# @@ -33,9 +37,8 @@ def test_suite(level=1): import scipy_base.testing import scipy_base this_mod = scipy_base - # ieee_754 gets tested in the type_check module. # testing is the module that actually does all the testing... - ignore = ['ieee_754','testing'] + ignore = ['testing'] return scipy_base.testing.harvest_test_suites(this_mod,ignore = ignore, level=level) diff --git a/scipy_base/convenience.py b/scipy_base/convenience.py new file mode 100644 index 000000000..bcba1a9b0 --- /dev/null +++ b/scipy_base/convenience.py @@ -0,0 +1,520 @@ +"""Contains basic routines of common interest. Always imported first. + Basically MLab minus the LinearAlgebra-dependent functions. + + But max is changed to amax (array max) + and min is changed to amin (array min) + so that the builtin max and min are still available. +""" + + +__all__ = ['logspace','linspace','round','any','all','fix','mod','fftshift', + 'ifftshift','fftfreq','cont_ft','toeplitz','hankel','real','imag', + 'iscomplex','isreal','iscomplexobj','isrealobj','isposinf', + 'isneginf','nan_to_num','eye','tri','diag','fliplr','flipud', + 'rot90','tril','triu','amax','amin','ptp','cumsum','prod','cumprod', + 'diff','squeeze','angle','unwrap','real_if_close', + 'sort_complex'] + +import Numeric + +def logspace(start,stop,num=50,endpoint=1): + """Evenly spaced samples on a logarithmic scale. + + Return num evenly spaced samples from 10**start to 10**stop. If + endpoint=1 then last sample is 10**stop. + """ + if endpoint: + step = (stop-start)/float((num-1)) + y = Numeric.arange(0,num) * step + start + else: + step = (stop-start)/float(num) + y = Numeric.arange(0,num) * step + start + return Numeric.power(10.0,y) + +def linspace(start,stop,num=50,endpoint=1,retstep=0): + """Evenly spaced samples. + + Return num evenly spaced samples from start to stop. If endpoint=1 then + last sample is stop. If retstep is 1 then return the step value used. + """ + if endpoint: + step = (stop-start)/float((num-1)) + y = Numeric.arange(0,num) * step + start + else: + step = (stop-start)/float(num) + y = Numeric.arange(0,num) * step + start + if retstep: + return y, step + else: + return y + +#def round(arr): +# return Numeric.floor(arr+0.5) +round = Numeric.around +any = Numeric.sometrue +all = Numeric.alltrue + +def fix(x): + """Round x to nearest integer towards zero. + """ + x = Numeric.asarray(x) + y = Numeric.floor(x) + return Numeric.where(x<0,y+1,y) + +def mod(x,y): + """x - y*floor(x/y) + + For numeric arrays, x % y has the same sign as x while + mod(x,y) has the same sign as y. + """ + return x - y*Numeric.floor(x*1.0/y) + +def fftshift(x,axes=None): + """Shift the result of an FFT operation. + + Return a shifted version of x (useful for obtaining centered spectra). + This function swaps "half-spaces" for all axes listed (defaults to all) + """ + ndim = len(x.shape) + if axes == None: + axes = range(ndim) + y = x + for k in axes: + N = x.shape[k] + p2 = int(Numeric.ceil(N/2.0)) + mylist = Numeric.concatenate((Numeric.arange(p2,N),Numeric.arange(p2))) + y = Numeric.take(y,mylist,k) + return y + +def ifftshift(x,axes=None): + """Reverse the effect of fftshift. + """ + ndim = len(x.shape) + if axes == None: + axes = range(ndim) + y = x + for k in axes: + N = x.shape[k] + p2 = int(Numeric.floor(N/2.0)) + mylist = Numeric.concatenate((Numeric.arange(p2,N),Numeric.arange(p2))) + y = Numeric.take(y,mylist,k) + return y + +def fftfreq(N,sample=1.0): + """FFT sample frequencies + + Return the frequency bins in cycles/unit (with zero at the start) given a + window length N and a sample spacing. + """ + N = int(N) + sample = float(sample) + return Numeric.concatenate((Numeric.arange(0,(N-1)/2+1,1,'d'),Numeric.arange(-(N-1)/2,0,1,'d')))/N/sample + +def cont_ft(gn,fr,delta=1.0,n=None): + """Compute the (scaled) DFT of gn at frequencies fr. + + If the gn are alias-free samples of a continuous time function then the + correct value for the spacing, delta, will give the properly scaled, + continuous Fourier spectrum. + + The DFT is obtained when delta=1.0 + """ + if n is None: + n = Numeric.arange(len(gn)) + dT = delta + trans_kernel = Numeric.exp(-2j*Numeric.pi*fr[:,Numeric.NewAxis]*dT*n) + return dT*Numeric.dot(trans_kernel,gn) + +def toeplitz(c,r=None): + """Construct a toeplitz matrix (i.e. a matrix with constant diagonals). + + Description: + + toeplitz(c,r) is a non-symmetric Toeplitz matrix with c as its first + column and r as its first row. + + toeplitz(c) is a symmetric (Hermitian) Toeplitz matrix (r=c). + + See also: hankel + """ + if isscalar(c) or isscalar(r): + return c + if r is None: + r = c + r[0] = Numeric.conjugate(r[0]) + c = Numeric.conjugate(c) + r,c = map(Numeric.asarray,(r,c)) + r,c = map(Numeric.ravel,(r,c)) + rN,cN = map(len,(r,c)) + if r[0] != c[0]: + print "Warning: column and row values don't agree; column value used." + vals = r_[r[rN-1:0:-1], c] + cols = grid[0:cN] + rows = grid[rN:0:-1] + indx = cols[:,Numeric.NewAxis]*Numeric.ones((1,rN)) + \ + rows[Numeric.NewAxis,:]*Numeric.ones((cN,1)) - 1 + return Numeric.take(vals, indx) + + +def hankel(c,r=None): + """Construct a hankel matrix (i.e. matrix with constant anti-diagonals). + + Description: + + hankel(c,r) is a Hankel matrix whose first column is c and whose + last row is r. + + hankel(c) is a square Hankel matrix whose first column is C. + Elements below the first anti-diagonal are zero. + + See also: toeplitz + """ + if isscalar(c) or isscalar(r): + return c + if r is None: + r = Numeric.zeros(len(c)) + elif r[0] != c[-1]: + print "Warning: column and row values don't agree; column value used." + r,c = map(Numeric.asarray,(r,c)) + r,c = map(Numeric.ravel,(r,c)) + rN,cN = map(len,(r,c)) + vals = r_[c, r[1:rN]] + cols = grid[1:cN+1] + rows = grid[0:rN] + indx = cols[:,Numeric.NewAxis]*Numeric.ones((1,rN)) + \ + rows[Numeric.NewAxis,:]*Numeric.ones((cN,1)) - 1 + return Numeric.take(vals, indx) + + +def real(val): + aval = asarray(val) + if aval.typecode() in ['F', 'D']: + return aval.real + else: + return aval + +def imag(val): + aval = asarray(val) + if aval.typecode() in ['F', 'D']: + return aval.imag + else: + return array(0,aval.typecode())*aval + +def iscomplex(x): + return imag(x) != Numeric.zeros(asarray(x).shape) + +def isreal(x): + return imag(x) == Numeric.zeros(asarray(x).shape) + +def iscomplexobj(x): + return asarray(x).typecode() in ['F', 'D'] + +def isrealobj(x): + return not asarray(x).typecode() in ['F', 'D'] + +def isposinf(val): + # complex not handled currently (and potentially ambiguous) + return Numeric.logical_and(isinf(val),val > 0) + +def isneginf(val): + # complex not handled currently (and potentially ambiguous) + return Numeric.logical_and(isinf(val),val < 0) + +def nan_to_num(x): + # mapping: + # NaN -> 0 + # Inf -> scipy.limits.double_max + # -Inf -> scipy.limits.double_min + # complex not handled currently + import limits + try: + t = x.typecode() + except AttributeError: + t = type(x) + if t in [ComplexType,'F','D']: + y = nan_to_num(x.real) + 1j * nan_to_num(x.imag) + else: + x = Numeric.asarray(x) + are_inf = isposinf(x) + are_neg_inf = isneginf(x) + are_nan = isnan(x) + choose_array = are_neg_inf + are_nan * 2 + are_inf * 3 + y = Numeric.choose(choose_array, + (x,scipy.limits.double_min, 0., scipy.limits.double_max)) + return y + +# These are from Numeric +from Numeric import * +import Numeric +import Matrix +from utility import isscalar +from fastumath import * + + +# Elementary matrices + +# zeros is from matrixmodule in C +# ones is from Numeric.py + + +def eye(N, M=None, k=0, typecode=None): + """eye(N, M=N, k=0, typecode=None) returns a N-by-M matrix where the + k-th diagonal is all ones, and everything else is zeros. + """ + if M is None: M = N + if type(M) == type('d'): + typecode = M + M = N + m = equal(subtract.outer(arange(N), arange(M)),-k) + if typecode is None: + return m + else: + return m.astype(typecode) + +def tri(N, M=None, k=0, typecode=None): + """tri(N, M=N, k=0, typecode=None) returns a N-by-M matrix where all + the diagonals starting from lower left corner up to the k-th are all ones. + """ + if M is None: M = N + if type(M) == type('d'): + typecode = M + M = N + m = greater_equal(subtract.outer(arange(N), arange(M)),-k) + if typecode is None: + return m + else: + return m.astype(typecode) + +# matrix manipulation + +def diag(v, k=0): + """diag(v,k=0) returns the k-th diagonal if v is a matrix or + returns a matrix with v as the k-th diagonal if v is a vector. + """ + v = asarray(v) + s = v.shape + if len(s)==1: + n = s[0]+abs(k) + if k > 0: + v = concatenate((zeros(k, v.typecode()),v)) + elif k < 0: + v = concatenate((v,zeros(-k, v.typecode()))) + return eye(n, k=k)*v + elif len(s)==2: + v = add.reduce(eye(s[0], s[1], k=k)*v) + if k > 0: return v[k:] + elif k < 0: return v[:k] + else: return v + else: + raise ValueError, "Input must be 1- or 2-D." + +def fliplr(m): + """fliplr(m) returns a 2-D matrix m with the rows preserved and + columns flipped in the left/right direction. Only works with 2-D + arrays. + """ + m = asarray(m) + if len(m.shape) != 2: + raise ValueError, "Input must be 2-D." + return m[:, ::-1] + +def flipud(m): + """flipud(m) returns a 2-D matrix with the columns preserved and + rows flipped in the up/down direction. Only works with 2-D arrays. + """ + m = asarray(m) + if len(m.shape) != 2: + raise ValueError, "Input must be 2-D." + return m[::-1] + +# reshape(x, m, n) is not used, instead use reshape(x, (m, n)) + +def rot90(m, k=1): + """rot90(m,k=1) returns the matrix found by rotating m by k*90 degrees + in the counterclockwise direction. + """ + m = asarray(m) + if len(m.shape) != 2: + raise ValueError, "Input must be 2-D." + k = k % 4 + if k == 0: return m + elif k == 1: return transpose(fliplr(m)) + elif k == 2: return fliplr(flipud(m)) + else: return fliplr(transpose(m)) # k==3 + +def tril(m, k=0): + """tril(m,k=0) returns the elements on and below the k-th diagonal of + m. k=0 is the main diagonal, k > 0 is above and k < 0 is below the main + diagonal. + """ + svsp = m.spacesaver() + m = asarray(m,savespace=1) + out = tri(m.shape[0], m.shape[1], k=k, typecode=m.typecode())*m + out.savespace(svsp) + return out + +def triu(m, k=0): + """triu(m,k=0) returns the elements on and above the k-th diagonal of + m. k=0 is the main diagonal, k > 0 is above and k < 0 is below the main + diagonal. + """ + svsp = m.spacesaver() + m = asarray(m,savespace=1) + out = (1-tri(m.shape[0], m.shape[1], k-1, m.typecode()))*m + out.savespace(svsp) + return out + +# Data analysis + +# Basic operations +def amax(m,axis=-1): + """Returns the maximum of m along dimension axis. + """ + if axis is None: + m = ravel(m) + axis = 0 + else: + m = asarray(m) + return maximum.reduce(m,axis) + +def amin(m,axis=-1): + """Returns the minimum of m along dimension axis. + """ + if axis is None: + m = ravel(m) + axis = 0 + else: + m = asarray(m) + return minimum.reduce(m,axis) + +# Actually from Basis, but it fits in so naturally here... + +def ptp(m,axis=-1): + """Returns the maximum - minimum along the the given dimension + """ + if axis is None: + m = ravel(m) + axis = 0 + else: + m = asarray(m) + return amax(m,axis)-amin(m,axis) + +def cumsum(m,axis=-1): + """Returns the cumulative sum of the elements along the given axis + """ + if axis is None: + m = ravel(m) + axis = 0 + else: + m = asarray(m) + return add.accumulate(m,axis) + +def prod(m,axis=-1): + """Returns the product of the elements along the given axis + """ + if axis is None: + m = ravel(m) + axis = 0 + else: + m = asarray(m) + return multiply.reduce(m,axis) + +def cumprod(m,axis=-1): + """Returns the cumulative product of the elments along the given axis + """ + if axis is None: + m = ravel(m) + axis = 0 + else: + m = asarray(m) + return multiply.accumulate(m,axis) + +def diff(x, n=1,axis=-1): + """Calculates the nth order, discrete difference along given axis. + """ + x = asarray(x) + nd = len(x.shape) + slice1 = [slice(None)]*nd + slice2 = [slice(None)]*nd + slice1[axis] = slice(1,None) + slice2[axis] = slice(None,-1) + if n > 1: + return diff(x[slice1]-x[slice2], n-1, axis=axis) + else: + return x[slice1]-x[slice2] + +def squeeze(a): + "Returns a with any ones from the shape of a removed" + a = asarray(a) + b = asarray(a.shape) + return reshape (a, tuple (compress (not_equal (b, 1), b))) + +def angle(z,deg=0): + """Return the angle of complex argument z.""" + if deg: + fact = 180/pi + else: + fact = 1.0 + z = asarray(z) + if z.typecode() in ['D','F']: + zimag = z.imag + zreal = z.real + else: + zimag = 0 + zreal = z + return arctan2(zimag,zreal) * fact + +import copy +def unwrap(p,discont=pi,axis=-1): + """unwrap(p,discont=pi,axis=-1) + + unwraps radian phase p by changing absolute jumps greater than discont to + their 2*pi complement along the given axis. + """ + p = asarray(p) + nd = len(p.shape) + dd = diff(p,axis=axis) + slice1 = [slice(None,None)]*nd # full slices + slice1[axis] = slice(1,None) + ddmod = mod(dd+pi,2*pi)-pi + putmask(ddmod,(ddmod==-pi) & (dd > 0),pi) + ph_correct = ddmod - dd; + putmask(ph_correct,abs(dd)<discont,0) + up = array(p,copy=1,typecode='d') + up[slice1] = p[slice1] + cumsum(ph_correct,axis) + return up + + + +def real_if_close(a,tol=1e-13): + a = Numeric.asarray(a) + if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol): + a = a.real + return a + +def sort_complex(a): + """ Doesn't currently work for integer arrays -- only float or complex. + """ + a = asarray(a,typecode=a.typecode().upper()) + def complex_cmp(x,y): + res = cmp(x.real,y.real) + if res == 0: + res = cmp(x.imag,y.imag) + return res + l = a.tolist() + l.sort(complex_cmp) + return array(l) + + + + +def test(level=10): + from scipy_base.testing import module_test + module_test(__name__,__file__,level=level) + +def test_suite(level=1): + from scipy_base.testing import module_test_suite + return module_test_suite(__name__,__file__,level=level) + + + diff --git a/scipy_base/fastumathmodule.c b/scipy_base/fastumathmodule.c index 48b71909c..f5870e9ef 100644 --- a/scipy_base/fastumathmodule.c +++ b/scipy_base/fastumathmodule.c @@ -4,13 +4,13 @@ #include "Numeric/ufuncobject.h" #include "abstract.h" #include <math.h> +#include "mconf_lite.h" /* Fast umath module whose functions do not check for range and domain errors. - Replacement for umath + Replacement for umath + additions for isnan, isfinite, and isinf */ - #ifndef CHAR_BIT #define CHAR_BIT 8 #endif @@ -37,9 +37,122 @@ extern double modf (double, double *); #endif #ifndef M_PI -#define M_PI 3.14159265359 +#define M_PI 3.1415926535897931 #endif + +#define ABS(x) ((x) < 0 ? -(x) : (x)) + +/* isnan and isinf and isfinite functions */ +static void FLOAT_isnan(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) ABS(isnan((double)(*((float *)i1)))); + } +} + +static void DOUBLE_isnan(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) ABS(isnan((double)(*((double *)i1)))); + } +} + +static void CFLOAT_isnan(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) isnan((double)((float *)i1)[0]) || isnan((double)((float *)i1)[1]); + } +} + +static void CDOUBLE_isnan(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) isnan((double)((double *)i1)[0]) || isnan((double)((double *)i1)[1]); + } +} + + +static void FLOAT_isinf(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) !(isfinite((double)(*((float *)i1))) || isnan((double)(*((float *)i1)))); + } +} + +static void DOUBLE_isinf(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op)= (unsigned char) !(isfinite((double)(*((double *)i1))) || isnan((double)(*((double *)i1)))); + } +} + +static void CFLOAT_isinf(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op)= (unsigned char) !((isfinite((double)(((float *)i1)[0])) && isfinite((double)(((float *)i1)[1]))) || isnan((double)(((float *)i1)[0])) || isnan((double)(((float *)i1)[1]))); + } +} + +static void CDOUBLE_isinf(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op)= (unsigned char) !((isfinite((double)(((double *)i1)[0])) && isfinite((double)(((double *)i1)[1]))) || isnan((double)(((double *)i1)[0])) || isnan((double)(((double *)i1)[1]))); + } +} + + +static void FLOAT_isfinite(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) isfinite((double)(*((float *)i1))); + } +} + +static void DOUBLE_isfinite(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) isfinite((double)(*((double *)i1))); + } +} + +static void CFLOAT_isfinite(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) isfinite((double)((float *)i1)[0]) && isfinite((double)((float *)i1)[1]); + } +} + +static void CDOUBLE_isfinite(char **args, int *dimensions, int *steps, void *func) { + int i, is1=steps[0], os=steps[1], n=dimensions[0]; + char *i1=args[0], *op=args[1]; + for (i=0; i < n; i++, i1+=is1, op+=os) { + *((unsigned char *)op) = (unsigned char) isfinite((double)((double *)i1)[0]) && isfinite((double)((double *)i1)[1]); + } +} + +static PyUFuncGenericFunction isnan_functions[] = {FLOAT_isnan, DOUBLE_isnan, CFLOAT_isnan, CDOUBLE_isnan, NULL}; +static PyUFuncGenericFunction isinf_functions[] = {FLOAT_isinf, DOUBLE_isinf, CFLOAT_isinf, CDOUBLE_isinf, NULL}; +static PyUFuncGenericFunction isfinite_functions[] = {FLOAT_isfinite, DOUBLE_isfinite, CFLOAT_isfinite, CDOUBLE_isfinite, NULL}; + +static char isinf_signatures[] = { PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_UBYTE, }; + +static void * isnan_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL}; +static void * isinf_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL}; +static void * isfinite_data[] = {(void *)NULL, (void *)NULL, (void *)NULL, (void *)NULL}; + + #if !defined(HAVE_INVERSE_HYPERBOLIC) static double acosh(double x) { @@ -348,6 +461,7 @@ static long powll(long x, long n, int nbits) 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]; @@ -1058,343 +1172,404 @@ 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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((signed char *)i1) > *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) > *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((short *)i1) > *((short *)i2); + *((unsigned char *)op)=*((short *)i1) > *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((int *)i1) > *((int *)i2); + *((unsigned char *)op)=*((int *)i1) > *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) > *((long *)i2); + *((unsigned char *)op)=*((long *)i1) > *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((float *)i1) > *((float *)i2); + *((unsigned char *)op)=*((float *)i1) > *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((double *)i1) > *((double *)i2); + *((unsigned char *)op)=*((double *)i1) > *((double *)i2); + } +} + +/* complex numbers are compared by there real parts. */ +static void CFLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)= ((float *)i1)[0] > ((float *)i2)[0]; + } +} +static void CDOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)= ((double *)i1)[0] > ((double *)i2)[0]; } } + 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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((unsigned char *)i1) >= *((unsigned char *)i2); + *((unsigned char *)op)=*((unsigned char *)i1) >= *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((signed char *)i1) >= *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) >= *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((short *)i1) >= *((short *)i2); + *((unsigned char *)op)=*((short *)i1) >= *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((int *)i1) >= *((int *)i2); + *((unsigned char *)op)=*((int *)i1) >= *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) >= *((long *)i2); + *((unsigned char *)op)=*((long *)i1) >= *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((float *)i1) >= *((float *)i2); + *((unsigned char *)op)=*((float *)i1) >= *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((double *)i1) >= *((double *)i2); + *((unsigned char *)op)=*((double *)i1) >= *((double *)i2); } } +static void CFLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=*((float *)i1) >= *((float *)i2); + } +} +static void CDOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=*((double *)i1) >= *((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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((unsigned char *)i1) < *((unsigned char *)i2); + *((unsigned char *)op)=*((unsigned char *)i1) < *((unsigned char *)i2); } } static void SBYTE_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((signed char *)i1) < *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) < *((signed char *)i2); } } static void SHORT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((short *)i1) < *((short *)i2); + *((unsigned char *)op)=*((short *)i1) < *((short *)i2); } } static void INT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((int *)i1) < *((int *)i2); + *((unsigned char *)op)=*((int *)i1) < *((int *)i2); } } static void LONG_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) < *((long *)i2); + *((unsigned char *)op)=*((long *)i1) < *((long *)i2); } } static void FLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((float *)i1) < *((float *)i2); + *((unsigned char *)op)=*((float *)i1) < *((float *)i2); } } static void DOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((double *)i1) < *((double *)i2); + *((unsigned char *)op)=*((double *)i1) < *((double *)i2); + } +} +static void CFLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=*((float *)i1) < *((float *)i2); + } +} +static void CDOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=*((double *)i1) < *((double *)i2); } } + static void UBYTE_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((unsigned char *)i1) <= *((unsigned char *)i2); + *((unsigned char *)op)=*((unsigned char *)i1) <= *((unsigned char *)i2); } } static void SBYTE_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((signed char *)i1) <= *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) <= *((signed char *)i2); } } static void SHORT_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((short *)i1) <= *((short *)i2); + *((unsigned char *)op)=*((short *)i1) <= *((short *)i2); } } static void INT_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((int *)i1) <= *((int *)i2); + *((unsigned char *)op)=*((int *)i1) <= *((int *)i2); } } static void LONG_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) <= *((long *)i2); + *((unsigned char *)op)=*((long *)i1) <= *((long *)i2); } } static void FLOAT_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((float *)i1) <= *((float *)i2); + *((unsigned char *)op)=*((float *)i1) <= *((float *)i2); } } static void DOUBLE_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((double *)i1) <= *((double *)i2); + *((unsigned char *)op)=*((double *)i1) <= *((double *)i2); + } +} +static void CFLOAT_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=*((float *)i1) <= *((float *)i2); + } +} +static void CDOUBLE_less_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=*((double *)i1) <= *((double *)i2); } } static void CHAR_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((char *)i1) == *((char *)i2); + *((unsigned char *)op)=*((char *)i1) == *((char *)i2); } } static void UBYTE_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((unsigned char *)i1) == *((unsigned char *)i2); + *((unsigned char *)op)=*((unsigned char *)i1) == *((unsigned char *)i2); } } static void SBYTE_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((signed char *)i1) == *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) == *((signed char *)i2); } } static void SHORT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((short *)i1) == *((short *)i2); + *((unsigned char *)op)=*((short *)i1) == *((short *)i2); } } static void INT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((int *)i1) == *((int *)i2); + *((unsigned char *)op)=*((int *)i1) == *((int *)i2); } } static void LONG_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) == *((long *)i2); + *((unsigned char *)op)=*((long *)i1) == *((long *)i2); } } static void FLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((float *)i1) == *((float *)i2); + *((unsigned char *)op)=*((float *)i1) == *((float *)i2); } } static void DOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((double *)i1) == *((double *)i2); + *((unsigned char *)op)=*((double *)i1) == *((double *)i2); } } static void CFLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=(((float *)i1)[0] == ((float *)i2)[0]) && (((float *)i1)[1] == ((float *)i2)[1]); + *((unsigned char *)op)=(((float *)i1)[0] == ((float *)i2)[0]) && (((float *)i1)[1] == ((float *)i2)[1]); } } static void CDOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=(((double *)i1)[0] == ((double *)i2)[0]) && (((double *)i1)[1] == ((double *)i2)[1]); + *((unsigned char *)op)=(((double *)i1)[0] == ((double *)i2)[0]) && (((double *)i1)[1] == ((double *)i2)[1]); } } static void OBJECT_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=(PyObject_Compare(*((PyObject **)i1),*((PyObject **)i2)) == 0); + *((unsigned char *)op)=(PyObject_Compare(*((PyObject **)i1),*((PyObject **)i2)) == 0); } } static void CHAR_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((char *)i1) != *((char *)i2); + *((unsigned char *)op)=*((char *)i1) != *((char *)i2); } } static void UBYTE_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((unsigned char *)i1) != *((unsigned char *)i2); + *((unsigned char *)op)=*((unsigned char *)i1) != *((unsigned char *)i2); } } static void SBYTE_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((signed char *)i1) != *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) != *((signed char *)i2); } } static void SHORT_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((short *)i1) != *((short *)i2); + *((unsigned char *)op)=*((short *)i1) != *((short *)i2); } } static void INT_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((int *)i1) != *((int *)i2); + *((unsigned char *)op)=*((int *)i1) != *((int *)i2); } } static void LONG_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) != *((long *)i2); + *((unsigned char *)op)=*((long *)i1) != *((long *)i2); } } static void FLOAT_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((float *)i1) != *((float *)i2); + *((unsigned char *)op)=*((float *)i1) != *((float *)i2); } } static void DOUBLE_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((double *)i1) != *((double *)i2); + *((unsigned char *)op)=*((double *)i1) != *((double *)i2); } } static void CFLOAT_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=(((float *)i1)[0] != ((float *)i2)[0]) || (((float *)i1)[1] != ((float *)i2)[1]); + *((unsigned char *)op)=(((float *)i1)[0] != ((float *)i2)[0]) || (((float *)i1)[1] != ((float *)i2)[1]); } } static void CDOUBLE_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=(((double *)i1)[0] != ((double *)i2)[0]) || (((double *)i1)[1] != ((double *)i2)[1]); + *((unsigned char *)op)=(((double *)i1)[0] != ((double *)i2)[0]) || (((double *)i1)[1] != ((double *)i2)[1]); } } static void OBJECT_not_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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=(PyObject_Compare(*((PyObject **)i1),*((PyObject **)i2)) != 0); + *((unsigned char *)op)=(PyObject_Compare(*((PyObject **)i1),*((PyObject **)i2)) != 0); } } static void UBYTE_logical_and(char **args, int *dimensions, int *steps, void *func) { @@ -1408,42 +1583,56 @@ static void SBYTE_logical_and(char **args, int *dimensions, int *steps, void *fu 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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((signed char *)op)=*((signed char *)i1) && *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) && *((signed char *)i2); } } static void SHORT_logical_and(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((short *)op)=*((short *)i1) && *((short *)i2); + *((unsigned char *)op)=*((short *)i1) && *((short *)i2); } } static void INT_logical_and(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((int *)op)=*((int *)i1) && *((int *)i2); + *((unsigned char *)op)=*((int *)i1) && *((int *)i2); } } static void LONG_logical_and(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) && *((long *)i2); + *((unsigned char *)op)=*((long *)i1) && *((long *)i2); } } static void FLOAT_logical_and(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((float *)op)=(float)(*((float *)i1) && *((float *)i2)); + *((unsigned char *)op)=(*((float *)i1) && *((float *)i2)); } } static void DOUBLE_logical_and(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((double *)op)=(double)(*((double *)i1) && *((double *)i2)); + *((unsigned char *)op)=(*((double *)i1) && *((double *)i2)); + } +} +static void CFLOAT_logical_and(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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=*((float *)i1) && *((float *)i2); + } +} +static void CDOUBLE_logical_and(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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=(*((double *)i1) && *((double *)i2)); } } static void UBYTE_logical_or(char **args, int *dimensions, int *steps, void *func) { @@ -1457,42 +1646,56 @@ static void SBYTE_logical_or(char **args, int *dimensions, int *steps, void *fun 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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((signed char *)op)=*((signed char *)i1) || *((signed char *)i2); + *((unsigned char *)op)=*((signed char *)i1) || *((signed char *)i2); } } static void SHORT_logical_or(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((short *)op)=*((short *)i1) || *((short *)i2); + *((unsigned char *)op)=*((short *)i1) || *((short *)i2); } } static void INT_logical_or(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((int *)op)=*((int *)i1) || *((int *)i2); + *((unsigned char *)op)=*((int *)i1) || *((int *)i2); } } static void LONG_logical_or(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=*((long *)i1) || *((long *)i2); + *((unsigned char *)op)=*((long *)i1) || *((long *)i2); } } static void FLOAT_logical_or(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((float *)op)=(float)(*((float *)i1) || *((float *)i2)); + *((unsigned char *)op)=(*((float *)i1) || *((float *)i2)); } } static void DOUBLE_logical_or(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((double *)op)=*((double *)i1) || *((double *)i2); + *((unsigned char *)op)=(*((double *)i1) || *((double *)i2)); + } +} +static void CFLOAT_logical_or(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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=(*((float *)i1) || *((float *)i2)); + } +} +static void CDOUBLE_logical_or(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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char *)op)=(*((double *)i1) || *((double *)i2)); } } static void UBYTE_logical_xor(char **args, int *dimensions, int *steps, void *func) { @@ -1506,58 +1709,76 @@ static void SBYTE_logical_xor(char **args, int *dimensions, int *steps, void *fu 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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((signed char *)op)=(*((signed char *)i1) || *((signed char *)i2)) && !(*((signed char *)i1) && *((signed char *)i2)); + *((unsigned char *)op)=(*((signed char *)i1) || *((signed char *)i2)) && !(*((signed char *)i1) && *((signed char *)i2)); } } static void SHORT_logical_xor(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((short *)op)=(*((short *)i1) || *((short *)i2)) && !(*((short *)i1) && *((short *)i2)); + *((unsigned char*)op)=(*((short *)i1) || *((short *)i2)) && !(*((short *)i1) && *((short *)i2)); } } static void INT_logical_xor(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((int *)op)=(*((int *)i1) || *((int *)i2)) && !(*((int *)i1) && *((int *)i2)); + *((unsigned char*)op)=(*((int *)i1) || *((int *)i2)) && !(*((int *)i1) && *((int *)i2)); } } static void LONG_logical_xor(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((long *)op)=(*((long *)i1) || *((long *)i2)) && !(*((long *)i1) && *((long *)i2)); + *((unsigned char*)op)=(*((long *)i1) || *((long *)i2)) && !(*((long *)i1) && *((long *)i2)); } } static void FLOAT_logical_xor(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((float *)op)=(float)((*((float *)i1) || *((float *)i2)) && !(*((float *)i1) && *((float *)i2))); + *((unsigned char*)op)=((*((float *)i1) || *((float *)i2)) && !(*((float *)i1) && *((float *)i2))); } } static void DOUBLE_logical_xor(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<n; i++, i1+=is1, i2+=is2, op+=os) { - *((double *)op)=(*((double *)i1) || *((double *)i2)) && !(*((double *)i1) && *((double *)i2)); + *((unsigned char*)op)=(*((double *)i1) || *((double *)i2)) && !(*((double *)i1) && *((double *)i2)); + } +} +static void CFLOAT_logical_xor(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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char*)op)=((*((float *)i1) || *((float *)i2)) && !(*((float *)i1) && *((float *)i2))); + } +} +static void CDOUBLE_logical_xor(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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((unsigned char*)op)=(*((double *)i1) || *((double *)i2)) && !(*((double *)i1) && *((double *)i2)); } } static void UBYTE_logical_not(char **args, int *dimensions, int *steps, void *func) {int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((unsigned char *)i1);}} static void SBYTE_logical_not(char **args, int *dimensions, int *steps, void *func) -{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((signed char *)op)=!*((signed char *)i1);}} +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((signed char *)i1);}} static void SHORT_logical_not(char **args, int *dimensions, int *steps, void *func) -{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((short *)op)=!*((short *)i1);}} +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((short *)i1);}} static void INT_logical_not(char **args, int *dimensions, int *steps, void *func) -{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((int *)op)=!*((int *)i1);}} +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((int *)i1);}} static void LONG_logical_not(char **args, int *dimensions, int *steps, void *func) -{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((long *)op)=!*((long *)i1);}} +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((long *)i1);}} static void FLOAT_logical_not(char **args, int *dimensions, int *steps, void *func) -{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((float *)op)=(float)(!*((float *)i1));}} +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char*)op)=(!*((float *)i1));}} static void DOUBLE_logical_not(char **args, int *dimensions, int *steps, void *func) -{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((double *)op)=!*((double *)i1);}} +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((double *)i1);}} +static void CFLOAT_logical_not(char **args, int *dimensions, int *steps, void *func) +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char*)op)=(!*((float *)i1));}} +static void CDOUBLE_logical_not(char **args, int *dimensions, int *steps, void *func) +{int i; char *i1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, i1+=steps[0], op+=steps[1]) {*((unsigned char *)op)=!*((double *)i1);}} static void UBYTE_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]; @@ -1607,6 +1828,22 @@ static void DOUBLE_maximum(char **args, int *dimensions, int *steps, void *func) *((double *)op)=*((double *)i1) > *((double *)i2) ? *((double *)i1) : *((double *)i2); } } +static void CFLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((float *)op)=*((float *)i1) > *((float *)i2) ? *((float *)i1) : *((float *)i2); + ((float *)op)[1]=*((float *)i1) > *((float *)i2) ? ((float *)i1)[1] : ((float *)i2)[1]; + } +} +static void CDOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((double *)op)=*((double *)i1) > *((double *)i2) ? *((double *)i1) : *((double *)i2); + ((double *)op)[1]=*((double *)i1) > *((double *)i2) ? ((double *)i1)[1] : ((double *)i2)[1]; + } +} 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]; @@ -1656,6 +1893,22 @@ static void DOUBLE_minimum(char **args, int *dimensions, int *steps, void *func) *((double *)op)=*((double *)i1) < *((double *)i2) ? *((double *)i1) : *((double *)i2); } } +static void CFLOAT_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((float *)op)=*((float *)i1) < *((float *)i2) ? *((float *)i1) : *((float *)i2); + ((float *)op)[1]=*((float *)i1) < *((float *)i2) ? ((float *)i1)[1] : ((float *)i2)[1]; + } +} +static void CDOUBLE_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<n; i++, i1+=is1, i2+=is2, op+=os) { + *((double *)op)=*((double *)i1) < *((double *)i2) ? *((double *)i1) : *((double *)i2); + ((double *)op)[1]=*((double *)i1) < *((double *)i2) ? ((double *)i1)[1] : ((double *)i2)[1]; + } +} static void UBYTE_bitwise_and(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]; @@ -1852,18 +2105,18 @@ static PyUFuncGenericFunction remainder_functions[] = { UBYTE_remainder, SBYTE_ 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 greater_functions[] = { UBYTE_greater, SBYTE_greater, SHORT_greater, INT_greater, LONG_greater, FLOAT_greater, DOUBLE_greater, CFLOAT_greater, CDOUBLE_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, CFLOAT_greater_equal, CDOUBLE_greater_equal, }; +static PyUFuncGenericFunction less_functions[] = { UBYTE_less, SBYTE_less, SHORT_less, INT_less, LONG_less, FLOAT_less, DOUBLE_less, CFLOAT_less, CDOUBLE_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, CFLOAT_less_equal, CDOUBLE_less_equal, }; static PyUFuncGenericFunction equal_functions[] = { CHAR_equal, UBYTE_equal, SBYTE_equal, SHORT_equal, INT_equal, LONG_equal, FLOAT_equal, DOUBLE_equal, CFLOAT_equal, CDOUBLE_equal, OBJECT_equal}; static PyUFuncGenericFunction not_equal_functions[] = { CHAR_not_equal, UBYTE_not_equal, SBYTE_not_equal, SHORT_not_equal, INT_not_equal, LONG_not_equal, FLOAT_not_equal, DOUBLE_not_equal, CFLOAT_not_equal, CDOUBLE_not_equal, OBJECT_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 logical_and_functions[] = { UBYTE_logical_and, SBYTE_logical_and, SHORT_logical_and, INT_logical_and, LONG_logical_and, FLOAT_logical_and, DOUBLE_logical_and, CFLOAT_logical_and, CDOUBLE_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, CFLOAT_logical_or, CDOUBLE_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, CFLOAT_logical_xor, CDOUBLE_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, CFLOAT_logical_xor, CDOUBLE_logical_xor, }; +static PyUFuncGenericFunction maximum_functions[] = { UBYTE_maximum, SBYTE_maximum, SHORT_maximum, INT_maximum, LONG_maximum, FLOAT_maximum, DOUBLE_maximum, CFLOAT_maximum, CDOUBLE_maximum,}; +static PyUFuncGenericFunction minimum_functions[] = { UBYTE_minimum, SBYTE_minimum, SHORT_minimum, INT_minimum, LONG_minimum, FLOAT_minimum, DOUBLE_minimum, CFLOAT_minimum, CDOUBLE_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, }; @@ -1918,9 +2171,10 @@ static char conjugate_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_S 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 equal_signatures[] = { PyArray_CHAR, PyArray_CHAR, PyArray_LONG, 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, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_LONG, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_LONG, PyArray_OBJECT, PyArray_OBJECT, PyArray_LONG}; -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 equal_signatures[] = { PyArray_CHAR, PyArray_CHAR, PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_UBYTE, PyArray_INT, PyArray_INT, PyArray_UBYTE, PyArray_LONG, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_UBYTE, PyArray_OBJECT, PyArray_OBJECT, PyArray_UBYTE}; +static char greater_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_SHORT, PyArray_UBYTE, PyArray_INT, PyArray_INT, PyArray_UBYTE, PyArray_LONG, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_CDOUBLE, PyArray_UBYTE }; +static char logical_not_signatures[] = { PyArray_UBYTE, PyArray_UBYTE, PyArray_SBYTE, PyArray_UBYTE, PyArray_SHORT, PyArray_UBYTE, PyArray_INT, PyArray_UBYTE, PyArray_LONG, PyArray_UBYTE, PyArray_FLOAT, PyArray_UBYTE, PyArray_DOUBLE, PyArray_UBYTE, PyArray_CFLOAT, PyArray_UBYTE, PyArray_CDOUBLE, PyArray_UBYTE, }; +static char maximum_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, }; 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, }; @@ -1999,6 +2253,25 @@ static void InitOperators(PyObject *dictionary) { arctan2_functions[1] = PyUFunc_dd_d; arctan2_functions[2] = PyUFunc_O_O_method; + + f = PyUFunc_FromFuncAndData(isinf_functions, isinf_data, isinf_signatures, + 4, 1, 1, PyUFunc_None, "isinf", + "isinf(x) returns non-zero if x is infinity.", 0); + PyDict_SetItemString(dictionary, "isinf", f); + Py_DECREF(f); + + f = PyUFunc_FromFuncAndData(isfinite_functions, isfinite_data, isinf_signatures, + 4, 1, 1, PyUFunc_None, "isfinite", + "isfinite(x) returns non-zero if x is not infinity or not a number.", 0); + PyDict_SetItemString(dictionary, "isfinite", f); + Py_DECREF(f); + + f = PyUFunc_FromFuncAndData(isnan_functions, isnan_data, isinf_signatures, + 4, 1, 1, PyUFunc_None, "isnan", + "isnan(x) returns non-zero if x is not a number.", 0); + PyDict_SetItemString(dictionary, "isnan", f); + Py_DECREF(f); + f = PyUFunc_FromFuncAndData(add_functions, add_data, add_signatures, 10, 2, 1, PyUFunc_Zero, "add", "Add the arguments elementwise.", 0); @@ -2050,22 +2323,22 @@ static void InitOperators(PyObject *dictionary) { PyDict_SetItemString(dictionary, "negative", f); Py_DECREF(f); f = PyUFunc_FromFuncAndData(greater_functions, divide_safe_data, greater_signatures, - 7, 2, 1, PyUFunc_None, "greater", + 9, 2, 1, PyUFunc_None, "greater", "greater(x,y) is array of 1's where x > y, 0 otherwise.",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", + 9, 2, 1, PyUFunc_None, "greater_equal", "greater_equal(x,y) is array of 1's where x >=y, 0 otherwise.", 0); 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", + 9, 2, 1, PyUFunc_None, "less", "less(x,y) is array of 1's where x < y, 0 otherwise.", 0); 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", + 9, 2, 1, PyUFunc_None, "less_equal", "less_equal(x,y) is array of 1's where x <= y, 0 otherwise.", 0); PyDict_SetItemString(dictionary, "less_equal", f); Py_DECREF(f); @@ -2079,33 +2352,33 @@ static void InitOperators(PyObject *dictionary) { "not_equal(x,y) is array of 0's where x == y, 1 otherwise.", 0); 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", + f = PyUFunc_FromFuncAndData(logical_and_functions, divide_safe_data, greater_signatures, + 9, 2, 1, PyUFunc_One, "logical_and", "logical_and(x,y) returns array of 1's where x and y both true.", 0); 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", + f = PyUFunc_FromFuncAndData(logical_or_functions, divide_safe_data, greater_signatures, + 9, 2, 1, PyUFunc_Zero, "logical_or", "logical_or(x,y) returns array of 1's where x or y or both are true.", 0); 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", + f = PyUFunc_FromFuncAndData(logical_xor_functions, divide_safe_data, greater_signatures, + 9, 2, 1, PyUFunc_None, "logical_xor", "logical_xor(x,y) returns array of 1's where exactly one of x or y is true.", 0); 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", + 9, 1, 1, PyUFunc_None, "logical_not", "logical_not(x) returns array of 1's where x is false, 0 otherwise.", 0); 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", + f = PyUFunc_FromFuncAndData(maximum_functions, divide_safe_data, maximum_signatures, + 9, 2, 1, PyUFunc_None, "maximum", "maximum(x,y) returns maximum of x and y taken elementwise.", 0); 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", + f = PyUFunc_FromFuncAndData(minimum_functions, divide_safe_data, maximum_signatures, + 9, 2, 1, PyUFunc_None, "minimum", "minimum(x,y) returns minimum of x and y taken elementwise.", 0); PyDict_SetItemString(dictionary, "minimum", f); Py_DECREF(f); @@ -2272,7 +2545,7 @@ DL_EXPORT(void) initfastumath() { /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); - s = PyString_FromString("1.0"); + s = PyString_FromString("2.0"); PyDict_SetItemString(d, "__version__", s); Py_DECREF(s); @@ -2283,7 +2556,18 @@ DL_EXPORT(void) initfastumath() { Py_DECREF(s); PyDict_SetItemString(d, "e", s = PyFloat_FromDouble(exp(1.0))); Py_DECREF(s); - + PyDict_SetItemString(d, "PINF", s = PyFloat_FromDouble(1.0/0.0)); + Py_DECREF(s); + PyDict_SetItemString(d, "NINF", s = PyFloat_FromDouble(-1.0/0.0)); + Py_DECREF(s); + PyDict_SetItemString(d, "PZERO", s = PyFloat_FromDouble(0.0)); + Py_DECREF(s); + PyDict_SetItemString(d, "NZERO", s = PyFloat_FromDouble(-0.0)); + Py_DECREF(s); +#if defined(NAN) + PyDict_SetItemString(d, "NAN", s = PyFloat_FromDouble(NAN)); + Py_DECREF(s); +#endif /* Temporarily set "invert" to "conjugate" in the dictionary so the call to SetNumericOps will make ~ do complex conjugation */ diff --git a/scipy_base/function_base.py b/scipy_base/function_base.py index 7f6480731..ba8a99c85 100644 --- a/scipy_base/function_base.py +++ b/scipy_base/function_base.py @@ -1,6 +1,7 @@ import types import Numeric from Numeric import * +from fastumath import * __all__ = ['round','any','all','logspace','linspace','fix','mod', 'select','trim_zeros','amax','amin','ptp','cumsum', @@ -262,4 +263,4 @@ def test_suite(level=1): return module_test_suite(__name__,__file__,level=level) if __name__ == '__main__': - test()
\ No newline at end of file + test() diff --git a/scipy_base/isnan.c b/scipy_base/isnan.c new file mode 100644 index 000000000..c5719d283 --- /dev/null +++ b/scipy_base/isnan.c @@ -0,0 +1,241 @@ +/* isnan() + * signbit() + * isfinite() + * + * Floating point numeric utilities + * + * + * + * SYNOPSIS: + * + * double ceil(), floor(), frexp(), ldexp(); --- gone + * int signbit(), isnan(), isfinite(); + * double x, y; + * int expnt, n; + * + * y = floor(x); -gone + * y = ceil(x); -gone + * y = frexp( x, &expnt ); -gone + * y = ldexp( x, n ); -gone + * n = signbit(x); + * n = isnan(x); + * n = isfinite(x); + * + * + * + * DESCRIPTION: + * + * All four routines return a double precision floating point + * result. + * + * floor() returns the largest integer less than or equal to x. + * It truncates toward minus infinity. + * + * ceil() returns the smallest integer greater than or equal + * to x. It truncates toward plus infinity. + * + * frexp() extracts the exponent from x. It returns an integer + * power of two to expnt and the significand between 0.5 and 1 + * to y. Thus x = y * 2**expn. + * + * ldexp() multiplies x by 2**n. + * + * signbit(x) returns 1 if the sign bit of x is 1, else 0. + * + * These functions are part of the standard C run time library + * for many but not all C compilers. The ones supplied are + * written in C for either DEC or IEEE arithmetic. They should + * be used only if your compiler library does not already have + * them. + * + * The IEEE versions assume that denormal numbers are implemented + * in the arithmetic. Some modifications will be required if + * the arithmetic has abrupt rather than gradual underflow. + */ + + +/* +Cephes Math Library Release 2.3: March, 1995 +Copyright 1984, 1995 by Stephen L. Moshier +*/ + + +#include "mconf_lite.h" + +#ifdef UNK +#undef UNK +#if BIGENDIAN +#define MIEEE 1 +#else +#define IBMPC 1 +#endif +#endif + + +/* Return 1 if the sign bit of x is 1, else 0. */ + +#if !defined(signbit) +int signbit(x) +double x; +{ +union + { + double d; + short s[4]; + int i[2]; + } u; + +u.d = x; + +if( sizeof(int) == 4 ) + { +#ifdef IBMPC + return( u.i[1] < 0 ); +#endif +#ifdef DEC + return( u.s[3] < 0 ); +#endif +#ifdef MIEEE + return( u.i[0] < 0 ); +#endif + } +else + { +#ifdef IBMPC + return( u.s[3] < 0 ); +#endif +#ifdef DEC + return( u.s[3] < 0 ); +#endif +#ifdef MIEEE + return( u.s[0] < 0 ); +#endif + } +} +#endif + +/* Return 1 if x is a number that is Not a Number, else return 0. */ + +#if !defined(isnan) +int isnan(x) +double x; +{ +#ifdef NANS +union + { + double d; + unsigned short s[4]; + unsigned int i[2]; + } u; + +u.d = x; + +if( sizeof(int) == 4 ) + { +#ifdef IBMPC + if( ((u.i[1] & 0x7ff00000) == 0x7ff00000) + && (((u.i[1] & 0x000fffff) != 0) || (u.i[0] != 0))) + return 1; +#endif +#ifdef DEC + if( (u.s[1] & 0x7fff) == 0) + { + if( (u.s[2] | u.s[1] | u.s[0]) != 0 ) + return(1); + } +#endif +#ifdef MIEEE + if( ((u.i[0] & 0x7ff00000) == 0x7ff00000) + && (((u.i[0] & 0x000fffff) != 0) || (u.i[1] != 0))) + return 1; +#endif + return(0); + } +else + { /* size int not 4 */ +#ifdef IBMPC + if( (u.s[3] & 0x7ff0) == 0x7ff0) + { + if( ((u.s[3] & 0x000f) | u.s[2] | u.s[1] | u.s[0]) != 0 ) + return(1); + } +#endif +#ifdef DEC + if( (u.s[3] & 0x7fff) == 0) + { + if( (u.s[2] | u.s[1] | u.s[0]) != 0 ) + return(1); + } +#endif +#ifdef MIEEE + if( (u.s[0] & 0x7ff0) == 0x7ff0) + { + if( ((u.s[0] & 0x000f) | u.s[1] | u.s[2] | u.s[3]) != 0 ) + return(1); + } +#endif + return(0); + } /* size int not 4 */ + +#else +/* No NANS. */ +return(0); +#endif +} +#endif + + +/* Return 1 if x is not infinite and is not a NaN. */ + +#if !defined(isfinite) +int isfinite(x) +double x; +{ +#ifdef INFINITIES +union + { + double d; + unsigned short s[4]; + unsigned int i[2]; + } u; + +u.d = x; + +if( sizeof(int) == 4 ) + { +#ifdef IBMPC + if( (u.i[1] & 0x7ff00000) != 0x7ff00000) + return 1; +#endif +#ifdef DEC + if( (u.s[3] & 0x7fff) != 0) + return 1; +#endif +#ifdef MIEEE + if( (u.i[0] & 0x7ff00000) != 0x7ff00000) + return 1; +#endif + return(0); + } +else + { +#ifdef IBMPC + if( (u.s[3] & 0x7ff0) != 0x7ff0) + return 1; +#endif +#ifdef DEC + if( (u.s[3] & 0x7fff) != 0) + return 1; +#endif +#ifdef MIEEE + if( (u.s[0] & 0x7ff0) != 0x7ff0) + return 1; +#endif + return(0); + } +#else +/* No INFINITY. */ +return(1); +#endif +} +#endif diff --git a/scipy_base/matrix_base.py b/scipy_base/matrix_base.py index caef98540..1e321f518 100644 --- a/scipy_base/matrix_base.py +++ b/scipy_base/matrix_base.py @@ -10,7 +10,7 @@ from Numeric import * from fastumath import * from type_check import isscalar from index_tricks import mgrid,r_,c_ -# Elementary Matrices +# Elementary matrices # zeros is from matrixmodule in C # ones is from Numeric.py diff --git a/scipy_base/mconf_lite_BE.h b/scipy_base/mconf_lite_BE.h new file mode 100644 index 000000000..b2129e07c --- /dev/null +++ b/scipy_base/mconf_lite_BE.h @@ -0,0 +1,119 @@ +/* mconf_lite.h + * + * Common include file for math routines + * + * + * + * SYNOPSIS: + * + * #include "mconf_lite.h" + * + * + * + * DESCRIPTION: + * + * The file also includes a conditional assembly definition + * for the type of computer arithmetic (IEEE, DEC, Motorola + * IEEE, or UNKnown). + * + * For Digital Equipment PDP-11 and VAX computers, certain + * IBM systems, and others that use numbers with a 56-bit + * significand, the symbol DEC should be defined. In this + * mode, most floating point constants are given as arrays + * of octal integers to eliminate decimal to binary conversion + * errors that might be introduced by the compiler. + * + * For little-endian computers, such as IBM PC, that follow the + * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE + * Std 754-1985), the symbol IBMPC should be defined. These + * numbers have 53-bit significands. In this mode, constants + * are provided as arrays of hexadecimal 16 bit integers. + * + * Big-endian IEEE format is denoted MIEEE. On some RISC + * systems such as Sun SPARC, double precision constants + * must be stored on 8-byte address boundaries. Since integer + * arrays may be aligned differently, the MIEEE configuration + * may fail on such machines. + * + * To accommodate other types of computer arithmetic, all + * constants are also provided in a normal decimal radix + * which one can hope are correctly converted to a suitable + * format by the available C language compiler. To invoke + * this mode, define the symbol UNK. + * + * An important difference among these modes is a predefined + * set of machine arithmetic constants for each. The numbers + * MACHEP (the machine roundoff error), MAXNUM (largest number + * represented), and several other parameters are preset by + * the configuration symbol. Check the file const.c to + * ensure that these values are correct for your computer. + * + * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL + * may fail on many systems. Verify that they are supposed + * to work on your computer. + */ + +/* +Cephes Math Library Release 2.3: June, 1995 +Copyright 1984, 1987, 1989, 1995 by Stephen L. Moshier + +Modified to handle just the parts necessary for isnan to work. +*/ + + +/* Type of computer arithmetic */ + +/* PDP-11, Pro350, VAX: + */ +/* #define DEC 1 */ + +/* Not sure about these pdp defines */ +#if defined(vax) || defined(__vax__) || defined(decvax) || \ + defined(__decvax__) || defined(pro350) || defined(pdp11) +#define DEC 1 + +#elif defined(ns32000) || defined(sun386) || \ + defined(i386) || defined(MIPSEL) || defined(_MIPSEL) || \ + defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha) || \ + defined(sequent) || defined(i386) || \ + defined(__ns32000__) || defined(__sun386__) || defined(__i386__) +#define IBMPC 1 /* Intel IEEE, low order words come first */ +#define BIGENDIAN 0 + +#elif defined(sel) || defined(pyr) || defined(mc68000) || defined (m68k) || \ + defined(is68k) || defined(tahoe) || defined(ibm032) || \ + defined(ibm370) || defined(MIPSEB) || defined(_MIPSEB) || \ + defined(__convex__) || defined(DGUX) || defined(hppa) || \ + defined(apollo) || defined(_CRAY) || defined(__hppa) || \ + defined(__hp9000) || defined(__hp9000s300) || \ + defined(__hp9000s700) || defined(__AIX) || defined(_AIX) \ + defined(__pyr__) || defined(__mc68000__) || defined(__sparc) ||\ + defined(_IBMR2) || defined (BIT_ZERO_ON_LEFT) +#define MIEEE 1 /* Motorola IEEE, high order words come first */ +#define BIGENDIAN 1 + +#else +#define UNK 1 /* Machine not known +#define BIGENDIAN 1 /* This is a BE file */ +#endif + + +/* Define to ask for infinity support, else undefine. */ +#define INFINITIES 1 + +/* Define to ask for support of numbers that are Not-a-Number, + else undefine. This may automatically define INFINITIES in some files. */ +#define NANS 1 + +/* Define to distinguish between -0.0 and +0.0. */ +#define MINUSZERO 1 + +#if !defined(signbit) +int signbit(double); +#endif +#if !defined(isnan) +int isnan(double); +#endif +#if !defined(isfinite) +int isfinite(double); +#endif diff --git a/scipy_base/mconf_lite_LE.h b/scipy_base/mconf_lite_LE.h new file mode 100644 index 000000000..f5d1aec84 --- /dev/null +++ b/scipy_base/mconf_lite_LE.h @@ -0,0 +1,119 @@ +/* mconf_lite.h + * + * Common include file for math routines + * + * + * + * SYNOPSIS: + * + * #include "mconf_lite.h" + * + * + * + * DESCRIPTION: + * + * The file also includes a conditional assembly definition + * for the type of computer arithmetic (IEEE, DEC, Motorola + * IEEE, or UNKnown). + * + * For Digital Equipment PDP-11 and VAX computers, certain + * IBM systems, and others that use numbers with a 56-bit + * significand, the symbol DEC should be defined. In this + * mode, most floating point constants are given as arrays + * of octal integers to eliminate decimal to binary conversion + * errors that might be introduced by the compiler. + * + * For little-endian computers, such as IBM PC, that follow the + * IEEE Standard for Binary Floating Point Arithmetic (ANSI/IEEE + * Std 754-1985), the symbol IBMPC should be defined. These + * numbers have 53-bit significands. In this mode, constants + * are provided as arrays of hexadecimal 16 bit integers. + * + * Big-endian IEEE format is denoted MIEEE. On some RISC + * systems such as Sun SPARC, double precision constants + * must be stored on 8-byte address boundaries. Since integer + * arrays may be aligned differently, the MIEEE configuration + * may fail on such machines. + * + * To accommodate other types of computer arithmetic, all + * constants are also provided in a normal decimal radix + * which one can hope are correctly converted to a suitable + * format by the available C language compiler. To invoke + * this mode, define the symbol UNK. + * + * An important difference among these modes is a predefined + * set of machine arithmetic constants for each. The numbers + * MACHEP (the machine roundoff error), MAXNUM (largest number + * represented), and several other parameters are preset by + * the configuration symbol. Check the file const.c to + * ensure that these values are correct for your computer. + * + * Configurations NANS, INFINITIES, MINUSZERO, and DENORMAL + * may fail on many systems. Verify that they are supposed + * to work on your computer. + */ + +/* +Cephes Math Library Release 2.3: June, 1995 +Copyright 1984, 1987, 1989, 1995 by Stephen L. Moshier + +Modified to handle just the parts necessary for isnan to work. +*/ + + +/* Type of computer arithmetic */ + +/* PDP-11, Pro350, VAX: + */ +/* #define DEC 1 */ + +/* Not sure about these pdp defines */ +#if defined(vax) || defined(__vax__) || defined(decvax) || \ + defined(__decvax__) || defined(pro350) || defined(pdp11) +#define DEC 1 + +#elif defined(ns32000) || defined(sun386) || \ + defined(i386) || defined(MIPSEL) || defined(_MIPSEL) || \ + defined(BIT_ZERO_ON_RIGHT) || defined(__alpha__) || defined(__alpha) || \ + defined(sequent) || defined(i386) || \ + defined(__ns32000__) || defined(__sun386__) || defined(__i386__) +#define IBMPC 1 /* Intel IEEE, low order words come first */ +#define BIGENDIAN 0 + +#elif defined(sel) || defined(pyr) || defined(mc68000) || defined (m68k) || \ + defined(is68k) || defined(tahoe) || defined(ibm032) || \ + defined(ibm370) || defined(MIPSEB) || defined(_MIPSEB) || \ + defined(__convex__) || defined(DGUX) || defined(hppa) || \ + defined(apollo) || defined(_CRAY) || defined(__hppa) || \ + defined(__hp9000) || defined(__hp9000s300) || \ + defined(__hp9000s700) || defined(__AIX) || defined(_AIX) \ + defined(__pyr__) || defined(__mc68000__) || defined(__sparc) ||\ + defined(_IBMR2) || defined (BIT_ZERO_ON_LEFT) +#define MIEEE 1 /* Motorola IEEE, high order words come first */ +#define BIGENDIAN 1 + +#else +#define UNK 1 /* Machine not known +#define BIGENDIAN 0 /* This is a LE file */ +#endif + + +/* Define to ask for infinity support, else undefine. */ +#define INFINITIES 1 + +/* Define to ask for support of numbers that are Not-a-Number, + else undefine. This may automatically define INFINITIES in some files. */ +#define NANS 1 + +/* Define to distinguish between -0.0 and +0.0. */ +#define MINUSZERO 1 + +#if !defined(signbit) +int signbit(double); +#endif +#if !defined(isnan) +int isnan(double); +#endif +#if !defined(isfinite) +int isfinite(double); +#endif diff --git a/scipy_base/setup_scipy_base.py b/scipy_base/setup_scipy_base.py index 0e51d1bea..575668096 100755 --- a/scipy_base/setup_scipy_base.py +++ b/scipy_base/setup_scipy_base.py @@ -1,9 +1,10 @@ #!/usr/bin/env python -import os +import os, sys from glob import glob from scipy_distutils.core import Extension from scipy_distutils.misc_util import get_path, default_config_dict,dot_join +import shutil def configuration(parent_package=''): parent_path = parent_package @@ -20,11 +21,19 @@ def configuration(parent_package=''): config['package_dir']['scipy_base.tests'] = test_path # fastumath module - sources = ['fastumathmodule.c'] + sources = ['fastumathmodule.c','isnan.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension('scipy_base.fastumath',sources,libraries=[]) config['ext_modules'].append(ext) - + + # Test to see if big or little-endian machine and get correct default + # mconf.h module. + if sys.byteorder == "little": + print "### Little Endian detected ####" + shutil.copy2(os.path.join(local_path,'mconf_lite_LE.h'),os.path.join(local_path,'mconf_lite.h')) + else: + print "### Big Endian detected ####" + shutil.copy2(os.path.join(local_path,'mconf_lite_BE.h'),os.path.join(local_path,'mconf_lite.h')) return config diff --git a/scipy_base/tests/test_type_check.py b/scipy_base/tests/test_type_check.py index ec6fe2d5c..05432784d 100644 --- a/scipy_base/tests/test_type_check.py +++ b/scipy_base/tests/test_type_check.py @@ -57,19 +57,19 @@ class test_isreal(unittest.TestCase): res = isreal(z) assert_array_equal(res,[0,1,1]) -class test_array_iscomplex(unittest.TestCase): +class test_iscomplexobj(unittest.TestCase): def check_basic(self): z = array([-1,0,1]) - assert(not array_iscomplex(z)) + assert(not iscomplexobj(z)) z = array([-1j,0,-1]) - assert(array_iscomplex(z)) + assert(iscomplexobj(z)) -class test_array_isreal(unittest.TestCase): +class test_isrealobj(unittest.TestCase): def check_basic(self): z = array([-1,0,1]) - assert(array_isreal(z)) + assert(isrealobj(z)) z = array([-1j,0,-1]) - assert(not array_isreal(z)) + assert(not isrealobj(z)) class test_isnan(unittest.TestCase): def check_goodvalues(self): @@ -178,12 +178,12 @@ class test_real_if_close(unittest.TestCase): def check_basic(self): a = rand(10) b = real_if_close(a+1e-15j) - assert(array_isreal(b)) + assert(isrealobj(b)) assert_array_equal(a,b) b = real_if_close(a+1e-7j) - assert(array_iscomplex(b)) + assert(iscomplexobj(b)) b = real_if_close(a+1e-7j,tol=1e-6) - assert(array_isreal(b)) + assert(isrealobj(b)) #----------------------------------------------------------------------------- @@ -195,8 +195,8 @@ def test_suite(level=1): suites.append( unittest.makeSuite(test_real_if_close,'check_') ) suites.append( unittest.makeSuite(test_real,'check_') ) suites.append( unittest.makeSuite(test_imag,'check_') ) - suites.append( unittest.makeSuite(test_array_iscomplex,'check_') ) - suites.append( unittest.makeSuite(test_array_isreal,'check_') ) + suites.append( unittest.makeSuite(test_iscomplexobj,'check_') ) + suites.append( unittest.makeSuite(test_isrealobj,'check_') ) suites.append( unittest.makeSuite(test_iscomplex,'check_') ) suites.append( unittest.makeSuite(test_isreal,'check_') ) suites.append( unittest.makeSuite(test_isnan,'check_') ) diff --git a/scipy_base/transform_base.py b/scipy_base/transform_base.py new file mode 100755 index 000000000..647708313 --- /dev/null +++ b/scipy_base/transform_base.py @@ -0,0 +1,73 @@ +import Numeric +__all__ = ['fftshift','ifftshift','fftfreq','cont_ft'] + +def fftshift(x,axes=None): + """ Shift the result of an FFT operation. + + Return a shifted version of x (useful for obtaining centered spectra). + This function swaps "half-spaces" for all axes listed (defaults to all) + """ + ndim = len(x.shape) + if axes == None: + axes = range(ndim) + y = x + for k in axes: + N = x.shape[k] + p2 = int(Numeric.ceil(N/2.0)) + mylist = Numeric.concatenate((Numeric.arange(p2,N),Numeric.arange(p2))) + y = Numeric.take(y,mylist,k) + return y + +def ifftshift(x,axes=None): + """ Reverse the effect of fftshift. + """ + ndim = len(x.shape) + if axes == None: + axes = range(ndim) + y = x + for k in axes: + N = x.shape[k] + p2 = int(Numeric.floor(N/2.0)) + mylist = Numeric.concatenate((Numeric.arange(p2,N),Numeric.arange(p2))) + y = Numeric.take(y,mylist,k) + return y + +def fftfreq(N,sample=1.0): + """ FFT sample frequencies + + Return the frequency bins in cycles/unit (with zero at the start) given a + window length N and a sample spacing. + """ + N = int(N) + sample = float(sample) + return Numeric.concatenate((Numeric.arange(0,(N-1)/2+1,1,'d'),Numeric.arange(-(N-1)/2,0,1,'d')))/N/sample + +def cont_ft(gn,fr,delta=1.0,n=None): + """ Compute the (scaled) DFT of gn at frequencies fr. + + If the gn are alias-free samples of a continuous time function then the + correct value for the spacing, delta, will give the properly scaled, + continuous Fourier spectrum. + + The DFT is obtained when delta=1.0 + """ + if n is None: + n = Numeric.arange(len(gn)) + dT = delta + trans_kernel = Numeric.exp(-2j*Numeric.pi*fr[:,Numeric.NewAxis]*dT*n) + return dT*Numeric.dot(trans_kernel,gn) + +#----------------------------------------------------------------------------- +# Test Routines +#----------------------------------------------------------------------------- + +def test(level=10): + from scipy_base.testing import module_test + module_test(__name__,__file__,level=level) + +def test_suite(level=1): + from scipy_base.testing import module_test_suite + return module_test_suite(__name__,__file__,level=level) + +if __name__ == '__main__': + test() diff --git a/scipy_base/type_check.py b/scipy_base/type_check.py index b4d2e44bc..c9c0ecb91 100644 --- a/scipy_base/type_check.py +++ b/scipy_base/type_check.py @@ -5,18 +5,19 @@ from fastumath import * import limits -# For now, we'll use Tim Peter's IEEE module for NaN, Inf, -Inf comparison -# stuff. Perhaps move to cephes in the future?? -from ieee_754 import PINF,MINF,NAN - -__all__ = ['ScalarType','array_iscomplex','array_isreal','imag','iscomplex', +__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex', 'isscalar','isneginf','isposinf','isnan','isinf','isfinite', 'isreal','isscalar','nan_to_num','real','real_if_close', - 'typename'] + 'typename','cast'] ScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType] -toChar = lambda x: Numeric.array(x, Numeric.Character) +try: + Char = Numeric.Character +except AttributeError: + Char = 'c' + +toChar = lambda x: Numeric.array(x, Char) toInt8 = lambda x: Numeric.array(x, Numeric.Int8)# or use variable names such as Byte toInt16 = lambda x: Numeric.array(x, Numeric.Int16) toInt32 = lambda x: Numeric.array(x, Numeric.Int32) @@ -66,29 +67,29 @@ def iscomplex(x): def isreal(x): return imag(x) == Numeric.zeros(asarray(x).shape) -def array_iscomplex(x): +def iscomplexobj(x): return asarray(x).typecode() in ['F', 'D'] -def array_isreal(x): +def isrealobj(x): return not asarray(x).typecode() in ['F', 'D'] #----------------------------------------------------------------------------- -def isnan(val): - # fast, but apparently not portable (according to notes by Tim Peters) - #return val != val - # very slow -- should really use cephes methods or *something* different - import ieee_754 - vals = ravel(val) - if array_iscomplex(vals): - r = array(map(ieee_754.isnan,real(vals))) - i = array(map(ieee_754.isnan,imag(vals))) - results = Numeric.logical_or(r,i) - else: - results = array(map(ieee_754.isnan,vals)) - if isscalar(val): - results = results[0] - return results +##def isnan(val): +## # fast, but apparently not portable (according to notes by Tim Peters) +## #return val != val +## # very slow -- should really use cephes methods or *something* different +## import ieee_754 +## vals = ravel(val) +## if array_iscomplex(vals): +## r = array(map(ieee_754.isnan,real(vals))) +## i = array(map(ieee_754.isnan,imag(vals))) +## results = Numeric.logical_or(r,i) +## else: +## results = array(map(ieee_754.isnan,vals)) +## if isscalar(val): +## results = results[0] +## return results def isposinf(val): # complex not handled currently (and potentially ambiguous) @@ -98,22 +99,23 @@ def isposinf(val): def isneginf(val): # complex not handled currently (and potentially ambiguous) #return Numeric.logical_and(isinf(val),val < 0) - return val == MINF + return val == NINF -def isinf(val): - return Numeric.logical_or(isposinf(val),isneginf(val)) - -def isfinite(val): - vals = asarray(val) - if array_iscomplex(vals): - r = isfinite(real(vals)) - i = isfinite(imag(vals)) - results = Numeric.logical_and(r,i) - else: - fin = Numeric.logical_not(isinf(val)) - an = Numeric.logical_not(isnan(val)) - results = Numeric.logical_and(fin,an) - return results +##def isinf(val): +## return Numeric.logical_or(isposinf(val),isneginf(val)) + +##def isfinite(val): +## vals = asarray(val) +## if iscomplexobj(vals): +## r = isfinite(real(vals)) +## i = isfinite(imag(vals)) +## results = Numeric.logical_and(r,i) +## else: +## fin = Numeric.logical_not(isinf(val)) +## an = Numeric.logical_not(isnan(val)) +## results = Numeric.logical_and(fin,an) +## return results + def nan_to_num(x): # mapping: # NaN -> 0 diff --git a/weave/accelerate_tools.py b/weave/accelerate_tools.py index 6a0e63cc6..ae5767c5d 100644 --- a/weave/accelerate_tools.py +++ b/weave/accelerate_tools.py @@ -94,7 +94,7 @@ class Vector(Type_Descriptor): def setitem(self,A,v,t): return self.getitem(A,v,t) -class Matrix(Vector): +class matrix(Vector): dims = 2 class IntegerVector(Vector): @@ -102,7 +102,7 @@ class IntegerVector(Vector): cxxbase = 'int' pybase = Integer -class IntegerMatrix(Matrix): +class Integermatrix(matrix): typecode = 'PyArray_INT' cxxbase = 'int' pybase = Integer @@ -112,7 +112,7 @@ class LongVector(Vector): cxxbase = 'long' pybase = Integer -class LongMatrix(Matrix): +class Longmatrix(matrix): typecode = 'PyArray_LONG' cxxbase = 'long' pybase = Integer @@ -122,7 +122,7 @@ class DoubleVector(Vector): cxxbase = 'double' pybase = Double -class DoubleMatrix(Matrix): +class Doublematrix(matrix): typecode = 'PyArray_DOUBLE' cxxbase = 'double' pybase = Double @@ -145,11 +145,11 @@ class XRange(Type_Descriptor): # Singletonize the type names # ----------------------------------------------- IntegerVector = IntegerVector() -IntegerMatrix = IntegerMatrix() +Integermatrix = Integermatrix() LongVector = LongVector() -LongMatrix = LongMatrix() +Longmatrix = Longmatrix() DoubleVector = DoubleVector() -DoubleMatrix = DoubleMatrix() +Doublematrix = Doublematrix() XRange = XRange() typedefs = { @@ -157,11 +157,11 @@ typedefs = { FloatType: Double, StringType: String, (Numeric.ArrayType,1,'i'): IntegerVector, - (Numeric.ArrayType,2,'i'): IntegerMatrix, + (Numeric.ArrayType,2,'i'): Integermatrix, (Numeric.ArrayType,1,'l'): LongVector, - (Numeric.ArrayType,2,'l'): LongMatrix, + (Numeric.ArrayType,2,'l'): Longmatrix, (Numeric.ArrayType,1,'d'): DoubleVector, - (Numeric.ArrayType,2,'d'): DoubleMatrix, + (Numeric.ArrayType,2,'d'): Doublematrix, XRangeType : XRange, } diff --git a/weave/ast_tools.py b/weave/ast_tools.py index 48b87cd90..4d69bb7a5 100644 --- a/weave/ast_tools.py +++ b/weave/ast_tools.py @@ -146,7 +146,7 @@ def harvest_variables(ast_list): return variables def match(pattern, data, vars=None): - """Match `data' to `pattern', with variable extraction. + """match `data' to `pattern', with variable extraction. pattern Pattern to match against, possibly containing variables. diff --git a/weave/misc.py b/weave/misc.py index bd621b9de..b83ea4d8b 100755 --- a/weave/misc.py +++ b/weave/misc.py @@ -146,7 +146,7 @@ def harvest_variables(ast_list): return variables def match(pattern, data, vars=None): - """Match `data' to `pattern', with variable extraction. + """match `data' to `pattern', with variable extraction. pattern Pattern to match against, possibly containing variables. |