diff options
author | Travis Oliphant <oliphant@enthought.com> | 2009-08-27 19:28:44 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2009-08-27 19:28:44 +0000 |
commit | 2f7ce43c4c7e2453d0b21ee43cdae54dbbef60bd (patch) | |
tree | 941454c8883da7cf2cb89cd4dff03eef0c8357ec /numpy | |
parent | aff438e441b05a5f20287bb1b283f120be802ed9 (diff) | |
download | numpy-2f7ce43c4c7e2453d0b21ee43cdae54dbbef60bd.tar.gz |
Code compiles at least -- no merge with trunk yet.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/code_generators/numpy_api_order.txt | 5 | ||||
-rw-r--r-- | numpy/core/include/numpy/ndarrayobject.h | 1 | ||||
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 67 | ||||
-rw-r--r-- | numpy/core/src/multiarray/descriptor.c | 10 | ||||
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 8 | ||||
-rw-r--r-- | numpy/core/src/multiarray/parse_datetime.c | 124 | ||||
-rw-r--r-- | numpy/core/src/multiarray/scalartypes.c.src | 2 |
7 files changed, 128 insertions, 89 deletions
diff --git a/numpy/core/code_generators/numpy_api_order.txt b/numpy/core/code_generators/numpy_api_order.txt index e111f0fd3..6b7272459 100644 --- a/numpy/core/code_generators/numpy_api_order.txt +++ b/numpy/core/code_generators/numpy_api_order.txt @@ -174,3 +174,8 @@ PyArray_MultiIterFromObjects PyArray_GetEndianness PyArray_GetNDArrayCFeatureVersion PyArray_Acorrelate +PyArray_SetDatetimeParseFunction +PyArray_DatetimeToDatetimeStruct +PyArray_TimedeltaToTimedeltaStruct +PyArray_DatetimeStructToDatetime +PyArray_TimedeltaStructToTimedelta
\ No newline at end of file diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h index 69774053b..740f664cb 100644 --- a/numpy/core/include/numpy/ndarrayobject.h +++ b/numpy/core/include/numpy/ndarrayobject.h @@ -194,6 +194,7 @@ typedef enum { NPY_FR_B, NPY_FR_D, NPY_FR_h, + NPY_FR_m, NPY_FR_s, NPY_FR_ms, NPY_FR_us, diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index db5668ef6..b64d2585c 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -77,7 +77,7 @@ MyPyLong_AsUnsigned@Type@ (PyObject *obj) -static char * _SEQUENCE_MESSAGE = "error setting an array element with a sequence" +static char * _SEQUENCE_MESSAGE = "error setting an array element with a sequence"; /****************** getitem and setitem **********************/ @@ -159,7 +159,7 @@ static int */ static PyObject * -PyDateTime_FromNormalized(npy_datetime val, NPY_DATETIME_UNIT base) +PyDateTime_FromNormalized(npy_datetime val, NPY_DATETIMEUNIT base) { npy_datetimestruct ydate; @@ -167,7 +167,7 @@ PyDateTime_FromNormalized(npy_datetime val, NPY_DATETIME_UNIT base) PyDateTime_IMPORT; /* We just truncate the unused variables and don't wory about overflow */ - PyArray_DateTimeToDatetimeStruct(val, base, &ydate); + PyArray_DatetimeToDatetimeStruct(val, base, &ydate); /* FIXME?: We discard ydate.ns, ydate.ps, ydate.fs, and ydate.as */ return PyDateTime_FromDateAndTime(ydate.year, ydate.month, ydate.day, @@ -180,22 +180,22 @@ PyDateTime_FromNormalized(npy_datetime val, NPY_DATETIME_UNIT base) */ static PyObject * -PyTimeDelta_FromNormalized(npy_timedelta val, NPY_DATETIME_UNIT base) +PyTimeDelta_FromNormalized(npy_timedelta val, NPY_DATETIMEUNIT base) { npy_timedeltastruct td; PyDateTime_IMPORT; - PyArray_TimedeltatoTimedeltaStruct(val, base, &td); + PyArray_TimedeltaToTimedeltaStruct(val, base, &td); /* We discard td.ps and td.as */ - return PyDelta_FromDSU(td.day, td.sec, td.ms); + return PyDelta_FromDSU(td.day, td.sec, td.us); } static PyObject * -PyDatetime_FromInt64(datetime val, PyArray_Descr *descr) +PyDateTime_FromInt64(datetime val, PyArray_Descr *descr) { PyArray_DatetimeMetaData *meta; meta = PyDataType_GetDatetimeMetaData(descr); @@ -207,11 +207,11 @@ PyDatetime_FromInt64(datetime val, PyArray_Descr *descr) events = meta->events; div = val / events; rem = val % events; - PyTuple_SET_ITEM(obj, PyInt_FromLong(rem), 1); + PyTuple_SET_ITEM(obj, 1, PyInt_FromLong(rem)); meta->events = 1; /* This resets meta->events for recursive call */ - PyTuple_SET_ITEM(obj, PyDatetime_FromInt64(div, descr), 0); + PyTuple_SET_ITEM(obj, 0, PyDateTime_FromInt64(div, descr)); meta->events = events; - if PyErr_Ocurred() { + if (PyErr_Occurred()) { Py_DECREF(obj); return NULL; } @@ -228,12 +228,12 @@ PyDatetime_FromInt64(datetime val, PyArray_Descr *descr) /* Normalization and then conversion to Datetime */ /* FIXME? : Check for Overflow... */ - return PyDatetime_FromNormalized(val*meta->num, meta->base); + return PyDateTime_FromNormalized(val*meta->num, meta->base); } static PyObject * -PyTimedelta_FromInt64(timedelta val, PyArray_Descr *descr) +PyTimeDelta_FromInt64(timedelta val, PyArray_Descr *descr) { PyArray_DatetimeMetaData *meta; meta = PyDataType_GetDatetimeMetaData(descr); @@ -245,11 +245,11 @@ PyTimedelta_FromInt64(timedelta val, PyArray_Descr *descr) events = meta->events; div = val / events; rem = val % events; - PyTuple_SET_ITEM(obj, PyInt_FromLong(rem), 1); + PyTuple_SET_ITEM(obj, 1, PyInt_FromLong(rem)); meta->events = 1; /* This resets meta->events for recursive call */ - PyTuple_SET_ITEM(obj, PyTimedelta_FromInt64(div, descr), 0); + PyTuple_SET_ITEM(obj, 0, PyTimeDelta_FromInt64(div, descr)); meta->events = events; - if PyErr_Ocurred() { + if (PyErr_Occurred()) { Py_DECREF(obj); return NULL; } @@ -263,7 +263,7 @@ PyTimedelta_FromInt64(timedelta val, PyArray_Descr *descr) static npy_datetime -PyDateTime_AsNormalized(PyObject *obj, NPY_DATETIME_UNIT base) +PyDateTime_AsNormalized(PyObject *obj, NPY_DATETIMEUNIT base) { npy_datetimestruct ydate; @@ -280,10 +280,10 @@ PyDateTime_AsNormalized(PyObject *obj, NPY_DATETIME_UNIT base) ydate.day = PyDateTime_GET_DAY(obj); if (PyDateTime_Check(obj)) { - ydate.hour = PyDateTime_GET_HOUR(obj); - ydate.min = PyDateTime_GET_MINUTE(obj); - ydate.sec = PyDateTime_GET_SECOND(obj); - ydate.us = PyDateTime_GET_MICROSECOND(obj); + ydate.hour = PyDateTime_DATE_GET_HOUR(obj); + ydate.min = PyDateTime_DATE_GET_MINUTE(obj); + ydate.sec = PyDateTime_DATE_GET_SECOND(obj); + ydate.us = PyDateTime_DATE_GET_MICROSECOND(obj); } else { ydate.hour = 0; @@ -296,11 +296,11 @@ PyDateTime_AsNormalized(PyObject *obj, NPY_DATETIME_UNIT base) ydate.as = 0; /* We just truncate the unused variables and don't wory about overflow */ - return PyArray_DateTimeStructToDatetime(&ydate, base); + return PyArray_DatetimeStructToDatetime(base, &ydate); } static npy_timedelta -PyTimeDelta_AsNormalized(Pyobject *obj, NPY_DATETIME_UNIT base) +PyTimeDelta_AsNormalized(PyObject *obj, NPY_DATETIMEUNIT base) { npy_timedeltastruct td; @@ -330,7 +330,7 @@ PyTimeDelta_AsNormalized(Pyobject *obj, NPY_DATETIME_UNIT base) */ static npy_datetime -PyDatetime_AsInt64(PyObject *obj, PyArray_Descr *descr) +PyDateTime_AsInt64(PyObject *obj, PyArray_Descr *descr) { PyArray_DatetimeMetaData *meta; npy_datetime res; @@ -343,24 +343,25 @@ PyDatetime_AsInt64(PyObject *obj, PyArray_Descr *descr) PyErr_SetString(PyExc_ValueError, "need a 2-tuple on setting if events > 1"); return -1; } - tmp = PyDatetime_AsInt64(PyTuple_GET_ITEM(obj, 0), descr); + tmp = PyDateTime_AsInt64(PyTuple_GET_ITEM(obj, 0), descr); if (PyErr_Occurred()) return -1; /* FIXME: Check for overflow */ tmp *= meta->events; - tmp += MyPyLong_AsLongLong(PyTuple_GETITEM(obj, 1)); + tmp += MyPyLong_AsLongLong(PyTuple_GET_ITEM(obj, 1)); if (PyErr_Occurred()) return -1; return tmp; } - res = PyDatetime_AsNormalized(obj, meta->base); + res = PyDateTime_AsNormalized(obj, meta->base); return res / meta->num; } static timedelta -PyTimedelta_AsInt64(PyObject *obj, PyArray_Descr *descr) +PyTimeDelta_AsInt64(PyObject *obj, PyArray_Descr *descr) { PyArray_DatetimeMetaData *meta; + npy_timedelta res; meta = PyDataType_GetDatetimeMetaData(descr); if (meta->events > 1) { @@ -369,16 +370,16 @@ PyTimedelta_AsInt64(PyObject *obj, PyArray_Descr *descr) PyErr_SetString(PyExc_ValueError, "need a 2-tuple on setting if events > 1"); return -1; } - tmp = PyTimedelta_AsInt64(PyTuple_GET_ITEM(obj, 0), descr); + tmp = PyTimeDelta_AsInt64(PyTuple_GET_ITEM(obj, 0), descr); if (PyErr_Occurred()) return -1; /* FIXME: Check for overflow */ tmp *= meta->events; - tmp += MyPyLong_AsLongLong(PyTuple_GETITEM(obj, 1)); + tmp += MyPyLong_AsLongLong(PyTuple_GET_ITEM(obj, 1)); if (PyErr_Occurred()) return -1; return tmp; } - res = PyTimedelta_AsNormalized(obj, meta->base); + res = PyTimeDelta_AsNormalized(obj, meta->base); return res / meta->num; } @@ -430,11 +431,11 @@ TIMEDELTA_getitem(char *ip, PyArrayObject *ap) { if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { t1 = *((timedelta *)ip); - return PyTimedelta_FromInt64((timedelta)t1, ap->descr); + return PyTimeDelta_FromInt64((timedelta)t1, ap->descr); } else { ap->descr->f->copyswap(&t1, ip, !PyArray_ISNOTSWAPPED(ap), ap); - return PyTimedelta_FromInt64((timedelta)t1, ap->descr); + return PyTimeDelta_FromInt64((timedelta)t1, ap->descr); } } @@ -474,7 +475,7 @@ TIMEDELTA_setitem(PyObject *op, char *ov, PyArrayObject *ap) { temp = ((PyTimedeltaScalarObject *)op)->obval; } else { - temp = PyTimedelta_AsInt64(op, ap->descr); + temp = PyTimeDelta_AsInt64(op, ap->descr); } if (PyErr_Occurred()) { if (PySequence_Check(op)) { diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c index 03e93ec24..2bec10455 100644 --- a/numpy/core/src/multiarray/descriptor.c +++ b/numpy/core/src/multiarray/descriptor.c @@ -535,7 +535,7 @@ _convert_divisor_to_multiple(PyArray_DatetimeMetaData *meta) ind = ((int)meta->base - (int)NPY_FR_Y)*2; totry = _multiples_table[ind]; - baseunits = (NPY_DATETIMEUNIT *)_multiples_table[ind+1]; + baseunit = (NPY_DATETIMEUNIT *)_multiples_table[ind+1]; num = 3; if (meta->base == NPY_FR_W) num = 4; @@ -544,7 +544,7 @@ _convert_divisor_to_multiple(PyArray_DatetimeMetaData *meta) if (meta->base >= NPY_FR_s) { ind = (int)NPY_FR_s - (int)NPY_FR_Y; totry = _multiples_table[ind]; - baseunit = _multiples_table[ind+1]; + baseunit = (NPY_DATETIMEUNIT *)_multiples_table[ind+1]; baseunit[0] = meta->base - 1; baseunit[1] = meta->base - 2; if (meta->base == NPY_DATETIME_NUMUNITS-1) num = 1; @@ -558,7 +558,7 @@ _convert_divisor_to_multiple(PyArray_DatetimeMetaData *meta) if (i==num) { PyErr_SetString(PyExc_ValueError, "Divisor is not a multiple of a lower-unit"); } - meta->unit = (NPY_DATETIMEUNIT) baseunits[i]; + meta->base = (NPY_DATETIMEUNIT) baseunit[i]; meta->den = 1; meta->num = q; } @@ -1399,7 +1399,7 @@ _append_to_datetime_typestr(PyArray_Descr *self, PyObject *ret) { PyObject *tmp; PyObject *res; - int num, events; + int num, den, events; char *basestr; PyArray_DatetimeMetaData *dt_data; @@ -1849,7 +1849,7 @@ _get_pickleabletype_from_metadata(PyObject *metadata) PyTuple_SET_ITEM(newtup, 0, newdict); cobj = PyDict_GetItemString(metadata, NPY_METADATA_DTSTR); - dt_tuple = _get_datetime_tuple_from_descr(cobj); + dt_tuple = _get_datetime_tuple_from_cobj(cobj); PyTuple_SET_ITEM(newtup, 1, dt_tuple); diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 1a1fdb150..5f8055438 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1965,14 +1965,14 @@ array_set_datetimeparse_function(PyObject *NPY_UNUSED(dummy), PyObject *args, Py PyObject *_numpy_internal; if(!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, - &op, &repr)) { + &op)) { return NULL; } /* reset the array_repr function to built-in */ if (op == Py_None) { _numpy_internal = PyImport_ImportModule("numpy.core._internal"); if (_numpy_internal == NULL) return NULL; - op = PyObject_GetAttrSring(_numpy_internal, "datetime_from_string"); + op = PyObject_GetAttrString(_numpy_internal, "datetime_from_string"); } else { /* Must balance reference count increment in both branches */ if (!PyCallable_Check(op)) { @@ -2397,10 +2397,12 @@ static struct PyMethodDef array_module_methods[] = { {"set_numeric_ops", (PyCFunction)array_set_ops_function, METH_VARARGS|METH_KEYWORDS, NULL}, + {"set_datetimeparse_function", + (PyCFunction)array_set_datetimeparse_function, + METH_VARARGS|METH_KEYWORDS, NULL}, {"set_typeDict", (PyCFunction)array_set_typeDict, METH_VARARGS, NULL}, - {"array", (PyCFunction)_array_fromobject, METH_VARARGS|METH_KEYWORDS, NULL}, diff --git a/numpy/core/src/multiarray/parse_datetime.c b/numpy/core/src/multiarray/parse_datetime.c index 6705790b9..76ef9dcb3 100644 --- a/numpy/core/src/multiarray/parse_datetime.c +++ b/numpy/core/src/multiarray/parse_datetime.c @@ -59,13 +59,13 @@ static int day_of_week(npy_longlong absdate) { /* Add in four for the Thursday on Jan 1, 1970 (epoch offset)*/ - absdate += 4 + absdate += 4; if (absdate >= 0) { return absdate % 7; } else { - return 6 + (absdate + 1) % 7 + return 6 + (absdate + 1) % 7; } } @@ -157,7 +157,8 @@ days_to_ymdstruct(npy_datetime dlong) int month = 1, day = 1; int *monthoffset; - dlong += 1 + dlong += 1; + /* Approximate year */ year = 1970 + dlong / 365.2425; @@ -238,7 +239,7 @@ seconds_to_hmsstruct(npy_longlong dlong) * Create a datetime value from a filled datetime struct and resolution unit. */ NPY_NO_EXPORT npy_datetime -PyArray_DatetimeStructToDatetime(NPY_DATETIME_UNIT fr, npy_datetimestruct *d) +PyArray_DatetimeStructToDatetime(NPY_DATETIMEUNIT fr, npy_datetimestruct *d) { npy_datetime ret; npy_longlong days; /* The absolute number of days since Jan 1, 1970 */ @@ -249,7 +250,7 @@ PyArray_DatetimeStructToDatetime(NPY_DATETIME_UNIT fr, npy_datetimestruct *d) ret = d->year - 1970; } else if (fr == NPY_FR_M) { - ret = (d->year - 1970) * 12 + s.month - 1; + ret = (d->year - 1970) * 12 + d->month - 1; } else if (fr == NPY_FR_W) { /* This is just 7-days for now. */ if (days >= 0) @@ -259,6 +260,7 @@ PyArray_DatetimeStructToDatetime(NPY_DATETIME_UNIT fr, npy_datetimestruct *d) } else if (fr == NPY_FR_B) { npy_longlong x; + int dotw = day_of_week(days); if (dotw > 4) ret = 0; /* Invalid business day */ else { if (days >= 0) { /* offset to adjust first week */ @@ -287,41 +289,52 @@ PyArray_DatetimeStructToDatetime(NPY_DATETIME_UNIT fr, npy_datetimestruct *d) + (d->us / 1000); } else if (fr == NPY_FR_us) { - npy_int64 num = 86400 * 1000 * 1000; - ret = days * num + secs_from_hms(d->hour, d->minute, d->second) * 1000000 + npy_int64 num = 86400 * 1000; + num *= 1000; + ret = days * num + secs_from_hms(d->hour, d->min, d->sec) * 1000000 + d->us; } else if (fr == NPY_FR_ns) { - npy_int64 num = 86400 * 1000 * 1000 * 1000; - ret = days * num + secs_from_hms(d->hour, d->minute, d->second) * 1000000000 + npy_int64 num = 86400 * 1000; + num *= 1000 * 1000; + ret = days * num + secs_from_hms(d->hour, d->min, d->sec) * 1000000000 + d->us * 1000 + (d->ps / 1000); } else if (fr == NPY_FR_ps) { - npy_int64 num2 = 1000 * 1000 * 1000 * 1000; - npy_int64 num1 = 86400 * num2; - ret = days * num1 + secs_from_hms(d->hour, d->minute, d->second) * num2; + npy_int64 num2 = 1000 * 1000; + npy_int64 num1; + + num2 *= 1000 * 1000; + num1 = 86400 * num2; + ret = days * num1 + secs_from_hms(d->hour, d->min, d->sec) * num2 + d->us * 1000000 + d->ps; } else if (fr == NPY_FR_fs) { /* only 2.6 hours */ - npy_int64 num2 = 1000000 * 1000000 * 1000; + npy_int64 num2 = 1000000; + num2 *= 1000000; + num2 *= 1000; + /* get number of seconds as a postive or negative number */ if (days >= 0) { - ret = secs_from_hms(d->hour, d->minute, d->second); + ret = secs_from_hms(d->hour, d->min, d->sec); } else { - ret = ((d->hour - 24)*3600 + d->minute*60 + d->second); + ret = ((d->hour - 24)*3600 + d->min*60 + d->sec); } ret = ret * num2 + d->us * 1000000000 + d->ps * 1000 + (d->as / 1000); } else if (fr == NPY_FR_as) { /* only 9.2 secs */ - npy_int64 num1 = 1000000 * 1000000; - npy_int64 num2 = num1 * 1000000; + npy_int64 num1, num2; + + num1 = 1000000; + num1 *= 1000000; + num2 = num1 * 1000000; if (days >= 0) { - ret = d->second; + ret = d->sec; } else { - ret = d->second - 60; + ret = d->sec - 60; } ret = ret * num2 + d->us * num1 + d->ps * 1000000 + d->as; } @@ -342,7 +355,7 @@ PyArray_DatetimeStructToDatetime(NPY_DATETIME_UNIT fr, npy_datetimestruct *d) * Create a timdelta value from a filled timedelta struct and resolution unit. */ NPY_NO_EXPORT npy_datetime -PyArray_TimedeltaStructToTimedelta(NPY_DATETIME_UNIT fr, npy_timedeltastruct *d) +PyArray_TimedeltaStructToTimedelta(NPY_DATETIMEUNIT fr, npy_timedeltastruct *d) { npy_datetime ret; @@ -384,25 +397,35 @@ PyArray_TimedeltaStructToTimedelta(NPY_DATETIME_UNIT fr, npy_timedeltastruct *d) ret = d->day * 86400000 + d->sec * 1000 + d->us / 1000; } else if (fr == NPY_FR_us) { - npy_int64 num = 86400 * 1000 * 1000; - ret = d->day * num + d->sec * 1000000 + d->us + npy_int64 num = 86400000; + num *= 1000; + ret = d->day * num + d->sec * 1000000 + d->us; } else if (fr == NPY_FR_ns) { - npy_int64 num = 86400 * 1000 * 1000 * 1000; + npy_int64 num = 86400000; + num *= 1000000; ret = d->day * num + d->sec * 1000000000 + d->us * 1000 + (d->ps / 1000); } else if (fr == NPY_FR_ps) { - npy_int64 num2 = 1000 * 1000 * 1000 * 1000; - npy_int64 num1 = 86400 * num2; + npy_int64 num2, num1; + + num2 = 1000000; + num2 *= 1000000; + num1 = 86400 * num2; + ret = d->day * num1 + d->sec * num2 + d->us * 1000000 + d->ps; } else if (fr == NPY_FR_fs) { /* only 2.6 hours */ - npy_int64 num2 = 1000000 * 1000000 * 1000; + npy_int64 num2 = 1000000000; + num2 *= 1000000; ret = d->sec * num2 + d->us * 1000000000 + d->ps * 1000 + (d->as / 1000); } else if (fr == NPY_FR_as) { /* only 9.2 secs */ - npy_int64 num1 = 1000000 * 1000000; - npy_int64 num2 = num1 * 1000000; + npy_int64 num1, num2; + + num1 = 1000000; + num1 *= 1000000; + num2 = num1 * 1000000; ret = d->sec * num2 + d->us * num1 + d->ps * 1000000 + d->as; } else { /* Shouldn't get here */ @@ -419,7 +442,7 @@ PyArray_TimedeltaStructToTimedelta(NPY_DATETIME_UNIT fr, npy_timedeltastruct *d) * Fill the datetime struct from the value and resolution unit. */ NPY_NO_EXPORT void -PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, +PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIMEUNIT fr, npy_datetimestruct *result) { int year = 1970, month = 1, day = 1, @@ -531,7 +554,7 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, else if (fr == NPY_FR_ms) { if (val >= 0) { ymd = days_to_ymdstruct(val / 86400000); - tmp = val % 86400000 + tmp = val % 86400000; } else { ymd = days_to_ymdstruct((val - 86399999) / 86400000); @@ -548,7 +571,8 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, } else if (fr == NPY_FR_us) { npy_int64 num1, num2; - num1 = 86400 * 1000 * 1000; + num1 = 86400000; + num1 *= 1000; num2 = num1 - 1; if (val >= 0) { ymd = days_to_ymdstruct(val / num1); @@ -569,9 +593,11 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, } else if (fr == NPY_FR_ns) { npy_int64 num1, num2, num3; - num1 = 86400 * 1000 * 1000 * 1000; + num1 = 86400000; + num1 *= 1000000000; num2 = num1 - 1; - num3 = 1000000 * 1000000; + num3 = 1000000; + num3 *= 1000000; if (val >= 0) { ymd = days_to_ymdstruct(val / num1); tmp = val % num1; @@ -593,7 +619,8 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, } else if (fr == NPY_FR_ps) { npy_int64 num1, num2, num3; - num3 = 1000000000 * 1000; + num3 = 1000000000; + num3 *= 1000; num1 = 86400 * num3; num2 = num1 - 1; @@ -618,13 +645,14 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, } else if (fr == NPY_FR_fs) { /* entire range is only += 2.6 hours */ npy_int64 num1, num2; - num1 = 1000000000 * 1000; + num1 = 1000000000; + num1 *= 1000; num2 = num1 * 1000; if (val >= 0) { sec = val / num2; - fs = val % num2; - hms = seconds_to_hms(sec); + tmp = val % num2; + hms = seconds_to_hmsstruct(sec); hour = hms.hour; min = hms.min; sec = hms.sec; @@ -659,7 +687,7 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, num3 = num2 * 1000000; if (val >= 0) { hour = 0; - minute = 0; + min = 0; sec = val / num3; tmp = val % num3; } @@ -668,7 +696,7 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, day = 31; month = 12; hour = 23; - minute = 59; + min = 59; sec = 60 + (val - (num3-1)) / num3; tmp = (num3-1) + (val+1) % num3; } @@ -691,7 +719,7 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, result->ps = ps; result->as = as; - return result; + return; } /* FIXME: Overflow is not handled at all */ @@ -702,7 +730,7 @@ PyArray_DatetimeToDatetimeStruct(npy_datetime val, NPY_DATETIME_UNIT fr, * Fill the timedelta struct from the timedelta value and resolution unit. */ NPY_NO_EXPORT void -PyArray_TimedeltaToTimedeltaStruct(npy_timdelta val, NPY_DATETIME_UNIT fr, +PyArray_TimedeltaToTimedeltaStruct(npy_timedelta val, NPY_DATETIMEUNIT fr, npy_timedeltastruct *result) { npy_longlong day=0; @@ -753,7 +781,8 @@ PyArray_TimedeltaToTimedeltaStruct(npy_timdelta val, NPY_DATETIME_UNIT fr, } else if (fr == NPY_FR_us) { npy_int64 num1; - num1 = 86400 * 1000 * 1000; + num1 = 86400000; + num1 *= 1000; day = val / num1; us = val % num1; sec = us / 1000000; @@ -761,7 +790,8 @@ PyArray_TimedeltaToTimedeltaStruct(npy_timdelta val, NPY_DATETIME_UNIT fr, } else if (fr == NPY_FR_ns) { npy_int64 num1; - num1 = 86400 * 1000 * 1000 * 1000; + num1 = 86400000; + num1 *= 1000000; day = val / num1; val = val % num1; sec = val / 1000000000; @@ -770,8 +800,9 @@ PyArray_TimedeltaToTimedeltaStruct(npy_timdelta val, NPY_DATETIME_UNIT fr, ps = (val % 1000) * 1000; } else if (fr == NPY_FR_ps) { - npy_int64 num1, num2 - num2 = 1000000000 * 1000; + npy_int64 num1, num2; + num2 = 1000000000; + num2 *= 1000; num1 = 86400 * num2; day = val / num1; @@ -781,7 +812,6 @@ PyArray_TimedeltaToTimedeltaStruct(npy_timdelta val, NPY_DATETIME_UNIT fr, us = ps / 1000000; ps = ps % 1000000; } - } else if (fr == NPY_FR_fs) { /* entire range is only += 9.2 hours */ npy_int64 num1, num2; num1 = 1000000000; @@ -826,7 +856,7 @@ PyArray_TimedeltaToTimedeltaStruct(npy_timdelta val, NPY_DATETIME_UNIT fr, result->ps = ps; result->as = as; } + return; - return result; } diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index 71e34fad4..861cf0c99 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -2332,7 +2332,7 @@ static long } return x; } -#else if SIZEOF_LONGLONG==SIZEOF_DATETIME +#elif SIZEOF_LONGLONG==SIZEOF_DATETIME static long @lname@_arrtype_hash(PyObject *obj) { |