diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-10-12 09:50:38 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-10-12 09:50:38 +0000 |
commit | 33e2d21b6e75d11572dbadb7a8a0038cd02206eb (patch) | |
tree | 53667f81c187a409b4536e58e4ae5660f84a4c8f /scipy/base/src | |
parent | e3ba6c65315e036990a8c28fd8dd5a072c7dc635 (diff) | |
download | numpy-33e2d21b6e75d11572dbadb7a8a0038cd02206eb.tar.gz |
Fixed remainder to behaved like Python.
Diffstat (limited to 'scipy/base/src')
-rw-r--r-- | scipy/base/src/arrayobject.c | 6 | ||||
-rw-r--r-- | scipy/base/src/multiarraymodule.c | 1 | ||||
-rw-r--r-- | scipy/base/src/scalartypes.inc.src | 25 | ||||
-rw-r--r-- | scipy/base/src/umathmodule.c.src | 48 |
4 files changed, 60 insertions, 20 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c index cf8b002b0..305bf46bf 100644 --- a/scipy/base/src/arrayobject.c +++ b/scipy/base/src/arrayobject.c @@ -2341,7 +2341,7 @@ array_divmod(PyArrayObject *op1, PyObject *op2) { PyObject *divp, *modp, *result; - divp = array_divide(op1, op2); + divp = array_floor_divide(op1, op2); if (divp == NULL) return NULL; modp = array_remainder(op1, op2); if (modp == NULL) { @@ -3556,8 +3556,8 @@ array_flags_get(PyArrayObject *self) module = PyImport_ImportModule("scipy.base._internal"); if (module == NULL) return NULL; } - return PyObject_CallMethod(module, "flagsobj", "Oi", - self, self->flags); + return PyObject_CallMethod(module, "flagsobj", "Oii", + self, self->flags, 0); } /* diff --git a/scipy/base/src/multiarraymodule.c b/scipy/base/src/multiarraymodule.c index 5c060a1fb..eb85c10fe 100644 --- a/scipy/base/src/multiarraymodule.c +++ b/scipy/base/src/multiarraymodule.c @@ -3727,7 +3727,6 @@ array_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds) return retobj; } - static struct PyMethodDef array_module_methods[] = { {"set_string_function", (PyCFunction)array_set_string_function, METH_VARARGS|METH_KEYWORDS, doc_set_string_function}, diff --git a/scipy/base/src/scalartypes.inc.src b/scipy/base/src/scalartypes.inc.src index 7825fab21..34041ea99 100644 --- a/scipy/base/src/scalartypes.inc.src +++ b/scipy/base/src/scalartypes.inc.src @@ -513,20 +513,17 @@ gentype_ndim_get(PyObject *self) static PyObject * gentype_flags_get(PyObject *self) { - PyObject *dict; - dict = PyDict_New(); - -#define ADDFLAG(flag, val) PyDict_SetItemString(dict, #flag, Py_##val); - - ADDFLAG(CONTIGUOUS, True); - ADDFLAG(OWN_DATA, True); - ADDFLAG(FORTRAN, True); - ADDFLAG(ALIGNED, True); - ADDFLAG(NOTSWAPPED, True); - ADDFLAG(WRITEABLE, False); - ADDFLAG(UPDATEIFCOPY, False); - return dict; -#undef ADDFLAG + static int flags=CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED | \ + NOTSWAPPED; + static PyObject *module=NULL; + + if (module==NULL) { + module = PyImport_ImportModule("scipy.base._internal"); + if (module == NULL) return NULL; + } + return PyObject_CallMethod(module, "flagsobj", "Oii", + self, flags, 1); + } static PyObject * diff --git a/scipy/base/src/umathmodule.c.src b/scipy/base/src/umathmodule.c.src index 67742fa7e..758b45be8 100644 --- a/scipy/base/src/umathmodule.c.src +++ b/scipy/base/src/umathmodule.c.src @@ -1266,11 +1266,53 @@ static void /**begin repeat +#TYPE=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG# +#typ=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong# +*/ +static void +@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func) +{ + register intp i; + intp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; + char *i1=args[0], *i2=args[1], *op=args[2]; + double x, y, res; + for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) { + x = *((@typ@ *)i1); + y = *((@typ@ *)i2); + res = x - floor(x/y)*y; + *((@typ@ *)op)= (@typ@)(res); + } +} +/**end repeat**/ + +/**begin repeat +#TYPE=FLOAT,DOUBLE,LONGDOUBLE# +#typ=float,double,longdouble# +#c=f,,l# +*/ +static void +@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func) +{ + register intp i; + intp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0]; + char *i1=args[0], *i2=args[1], *op=args[2]; + @typ@ x, y, res; + for(i=0; i<n; i++, i1+=is1, i2+=is2, op+=os) { + x = *((@typ@ *)i1); + y = *((@typ@ *)i2); + res = x - floor@c@(x/y)*y; + *((@typ@ *)op)= res; + } +} +/**end repeat**/ + + +/**begin repeat #TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG)*6# #typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong)*6# #OP= %*10, &*10, |*10, ^*10, <<*10, >>*10# -#kind=remainder*10, bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10# +#kind=fmod*10, bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10# */ static void @@ -1581,7 +1623,7 @@ static struct PyMethodDef methods[] = { }; DL_EXPORT(void) initumath(void) { - PyObject *m, *d, *s, *c_api; + PyObject *m, *d, *s, *s2, *c_api; double pinf, pzero, mynan; /* Create the module and add the functions */ @@ -1662,11 +1704,13 @@ DL_EXPORT(void) initumath(void) { PyModule_AddObject(m, "NAN", PyFloat_FromDouble(mynan)); s = PyDict_GetItemString(d, "conjugate"); + s2 = PyDict_GetItemString(d, "remainder"); /* Setup the array object's numerical structures with appropriate ufuncs in d*/ PyArray_SetNumericOps(d); PyDict_SetItemString(d, "conj", s); + PyDict_SetItemString(d, "mod", s2); err: /* Check for errors */ |