From 441f2840a6ec59f2acd1ad9c4c1fbee96121b246 Mon Sep 17 00:00:00 2001 From: Christopher Ariza Date: Thu, 11 Jul 2024 16:25:27 -0700 Subject: [PATCH 1/7] updated build numpy version --- requirements-build-3_11.txt | 2 +- requirements-build-3_12.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-build-3_11.txt b/requirements-build-3_11.txt index 34bd9a84..b2025344 100644 --- a/requirements-build-3_11.txt +++ b/requirements-build-3_11.txt @@ -1,2 +1,2 @@ -numpy==1.23.5 +numpy==2.0.0 diff --git a/requirements-build-3_12.txt b/requirements-build-3_12.txt index ced6559e..2ad4686d 100644 --- a/requirements-build-3_12.txt +++ b/requirements-build-3_12.txt @@ -1,2 +1,2 @@ -numpy==1.26.2 +numpy==2.0.0 setuptools==69.* From 4080fb837786e526a790510d2cfd9ec642cc1a86 Mon Sep 17 00:00:00 2001 From: Christopher Ariza Date: Thu, 11 Jul 2024 16:26:41 -0700 Subject: [PATCH 2/7] updated setup.py Extension definition --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 54b65297..15cf25b9 100644 --- a/setup.py +++ b/setup.py @@ -41,8 +41,8 @@ def get_ext_dir(*components: tp.Iterable[str]) -> tp.Sequence[str]: 'src/methods.c', 'src/tri_map.c', ], - include_dirs=get_ext_dir('numpy', 'core', 'include'), - library_dirs=get_ext_dir('numpy', 'core', 'lib'), + include_dirs=get_ext_dir('numpy', '_core', 'include'), + library_dirs=get_ext_dir('numpy', '_core', 'lib'), define_macros=[("AK_VERSION", AK_VERSION)], libraries=['npymath'], # not including mlib at this time ) From 2eae22275585ccbac3a573052fe2914afe331bf2 Mon Sep 17 00:00:00 2001 From: Christopher Ariza Date: Thu, 11 Jul 2024 16:57:13 -0700 Subject: [PATCH 3/7] first pass updates --- src/delimited_to_arrays.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/delimited_to_arrays.c b/src/delimited_to_arrays.c index 0a4aa60b..106bc98e 100644 --- a/src/delimited_to_arrays.c +++ b/src/delimited_to_arrays.c @@ -1364,7 +1364,7 @@ AK_CPL_to_array_float(AK_CodePointLine* cpl, PyArray_Descr* dtype, char tsep, ch // initialize error code to 0; only update on error. int error = 0; bool matched_elsize = true; - int elsize = dtype->elsize; + int elsize = PyDataType_ELSIZE(dtype); NPY_BEGIN_THREADS_DEF; NPY_BEGIN_THREADS; @@ -1442,7 +1442,7 @@ AK_CPL_to_array_int(AK_CodePointLine* cpl, PyArray_Descr* dtype, char tsep) // initialize error code to 0; only update on error. int error = 0; bool matched_elsize = true; - int elsize = dtype->elsize; + int elsize = PyDataType_ELSIZE(dtype); NPY_BEGIN_THREADS_DEF; NPY_BEGIN_THREADS; @@ -1515,7 +1515,7 @@ AK_CPL_to_array_uint(AK_CodePointLine* cpl, PyArray_Descr* dtype, char tsep) // initialize error code to 0; only update on error. int error = 0; bool matched_elsize = true; - int elsize = dtype->elsize; + int elsize = PyDataType_ELSIZE(dtype); NPY_BEGIN_THREADS_DEF; NPY_BEGIN_THREADS; @@ -1583,15 +1583,15 @@ AK_CPL_to_array_unicode(AK_CodePointLine* cpl, PyArray_Descr* dtype) bool capped_points; // mutate the passed dtype as it is new and will be stolen in array construction - if (dtype->elsize == 0) { + if (PyDataType_ELSIZE(dtype) == 0) { field_points = cpl->offset_max; - dtype->elsize = (int)(field_points * UCS4_SIZE); + // dtype->elsize = (int)(field_points * UCS4_SIZE); + PyDataType_SET_ELSIZE(dtype, (npy_intp)(field_points * UCS4_SIZE)); capped_points = false; } else { // assume that elsize is already given in units of 4 - // assert(dtype->elsize % UCS4_SIZE == 0); - field_points = dtype->elsize / UCS4_SIZE; + field_points = PyDataType_ELSIZE(dtype) / UCS4_SIZE; capped_points = true; } @@ -1649,13 +1649,14 @@ AK_CPL_to_array_bytes(AK_CodePointLine* cpl, PyArray_Descr* dtype) Py_ssize_t field_points; bool capped_points; - if (dtype->elsize == 0) { + if (PyDataType_ELSIZE(dtype) == 0) { field_points = cpl->offset_max; - dtype->elsize = (int)field_points; + // dtype->elsize = (int)field_points; + PyDataType_SET_ELSIZE(dtype, (npy_intp)field_points); capped_points = false; } else { - field_points = dtype->elsize; + field_points = PyDataType_ELSIZE(dtype); capped_points = true; } From 6e73e58ecca20f77b1db6ecb33059e637726862b Mon Sep 17 00:00:00 2001 From: Christopher Ariza Date: Thu, 11 Jul 2024 17:32:56 -0700 Subject: [PATCH 4/7] new handling for npy complex types --- src/delimited_to_arrays.c | 1 + src/methods.c | 7 ++++--- src/tri_map.c | 12 +++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/delimited_to_arrays.c b/src/delimited_to_arrays.c index 106bc98e..db0d5d62 100644 --- a/src/delimited_to_arrays.c +++ b/src/delimited_to_arrays.c @@ -1070,6 +1070,7 @@ AK_CPL_Free(AK_CodePointLine* cpl) PyMem_Free(cpl->offsets); if (cpl->type_parser) { PyMem_Free(cpl->type_parser); + // TODO: use AK_TP_Free } PyMem_Free(cpl); } diff --git a/src/methods.c b/src/methods.c index 061ccd50..e01897db 100644 --- a/src/methods.c +++ b/src/methods.c @@ -558,18 +558,19 @@ isna_element(PyObject *m, PyObject *args, PyObject *kwargs) Py_complex val = ((PyComplexObject*)element)->cval; return PyBool_FromLong(isnan(val.real) || isnan(val.imag)); } + // TODO: fix! if (PyArray_IsScalar(element, Complex64)) { npy_cfloat val = PyArrayScalar_VAL(element, Complex64); - return PyBool_FromLong(isnan(val.real) || isnan(val.imag)); + return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val))); } if (PyArray_IsScalar(element, Complex128)) { npy_cdouble val = PyArrayScalar_VAL(element, Complex128); - return PyBool_FromLong(isnan(val.real) || isnan(val.imag)); + return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val))); } # ifdef PyComplex256ArrType_Type if (PyArray_IsScalar(element, Complex256)) { npy_clongdouble val = PyArrayScalar_VAL(element, Complex256); - return PyBool_FromLong(isnan(val.real) || isnan(val.imag)); + return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val))); } # endif diff --git a/src/tri_map.c b/src/tri_map.c index 7f585f04..985a0fa3 100644 --- a/src/tri_map.c +++ b/src/tri_map.c @@ -14,7 +14,9 @@ static inline NPY_DATETIMEUNIT AK_dt_unit_from_array(PyArrayObject* a) { // This is based on get_datetime_metadata_from_dtype in the NumPy source, but that function is private. This does not check that the dtype is of the appropriate type. - PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyArray_DESCR(a)->c_metadata)->meta); + PyArray_Descr* dt = PyArray_DESCR(a); // borrowed ref + PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyDataType_C_METADATA(dt))->meta); + // PyArray_DatetimeMetaData* dma = &(((PyArray_DatetimeDTypeMetaData *)PyArray_DESCR(a)->c_metadata)->meta); return dma->base; } @@ -856,9 +858,9 @@ AK_TM_fill_object(TriMapObject* tm, #define AK_TM_TRANSFER_FLEXIBLE(c_type) do { \ Py_ssize_t one_count = from_src ? tm->src_one_count : tm->dst_one_count;\ TriMapOne* one_pairs = from_src ? tm->src_one : tm->dst_one; \ - npy_intp t_element_size = PyArray_DESCR(array_to)->elsize; \ + npy_intp t_element_size = PyArray_ITEMSIZE(array_to); \ npy_intp t_element_cp = t_element_size / sizeof(c_type); \ - npy_intp f_element_size = PyArray_DESCR(array_from)->elsize; \ + npy_intp f_element_size = PyArray_ITEMSIZE(array_from); \ c_type* array_to_data = (c_type*)PyArray_DATA(array_to); \ c_type* f; \ c_type* t; \ @@ -906,7 +908,7 @@ AK_TM_fill_unicode(TriMapObject* tm, Py_UCS4* array_to_data = (Py_UCS4*)PyArray_DATA(array_to); // code points per element - npy_intp cp = PyArray_DESCR(array_to)->elsize / UCS4_SIZE; + npy_intp cp = PyArray_ITEMSIZE(array_to) / UCS4_SIZE; bool decref_fill_value = false; if (PyBytes_Check(fill_value)) { @@ -948,7 +950,7 @@ AK_TM_fill_string(TriMapObject* tm, ? tm->final_src_fill : tm->final_dst_fill); char* array_to_data = (char*)PyArray_DATA(array_to); - npy_intp cp = PyArray_DESCR(array_to)->elsize; + npy_intp cp = PyArray_ITEMSIZE(array_to); if (!PyBytes_Check(fill_value)) { return -1; } From 7bc05f221689a393e92cc6be0bc5eab2624e9348 Mon Sep 17 00:00:00 2001 From: Christopher Ariza Date: Thu, 11 Jul 2024 17:40:52 -0700 Subject: [PATCH 5/7] updated type names for 2.0 --- performance/__main__.py | 6 +++--- src/methods.c | 1 - test/test_util.py | 12 ++++++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/performance/__main__.py b/performance/__main__.py index 774526f6..718ee57c 100644 --- a/performance/__main__.py +++ b/performance/__main__.py @@ -507,9 +507,9 @@ def __init__(self): self.values = [ np.longlong(-1), np.int_(-1), np.intc(-1), np.short(-1), np.byte(-1), np.ubyte(1), np.ushort(1), np.uintc(1), np.uint(1), np.ulonglong(1), - np.half(1.0), np.single(1.0), np.float_(1.0), np.longfloat(1.0), - np.csingle(1.0j), np.complex_(1.0j), np.clongfloat(1.0j), - np.bool_(0), np.str_('1'), np.unicode_('1'), np.void(1), + np.half(1.0), np.single(1.0), np.float64(1.0), np.longdouble(1.0), + np.csingle(1.0j), np.complex_(1.0j), np.clongdouble(1.0j), + np.bool_(0), np.str_('1'), np.str_('1'), np.void(1), np.object(), np.datetime64('NaT'), np.timedelta64('NaT'), np.nan, 12, 12.0, True, None, float('NaN'), object(), (1, 2, 3), NT(1, 2, 3), datetime.date(2020, 12, 31), datetime.timedelta(14), diff --git a/src/methods.c b/src/methods.c index e01897db..06dcfe20 100644 --- a/src/methods.c +++ b/src/methods.c @@ -558,7 +558,6 @@ isna_element(PyObject *m, PyObject *args, PyObject *kwargs) Py_complex val = ((PyComplexObject*)element)->cval; return PyBool_FromLong(isnan(val.real) || isnan(val.imag)); } - // TODO: fix! if (PyArray_IsScalar(element, Complex64)) { npy_cfloat val = PyArrayScalar_VAL(element, Complex64); return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val))); diff --git a/test/test_util.py b/test/test_util.py index 9e00f142..b300dbfd 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -527,11 +527,11 @@ def test_dtype_from_element_core_dtypes(self) -> None: np.ulonglong, np.half, np.single, - np.float_, - np.longfloat, + np.float64, + np.longdouble, np.csingle, - np.complex_, - np.clongfloat, + np.complex128, + np.clongdouble, np.bool_, ] for dtype in dtypes: @@ -540,12 +540,12 @@ def test_dtype_from_element_core_dtypes(self) -> None: def test_dtype_from_element_str_and_misc_dtypes(self) -> None: dtype_obj_pairs = [ (np.dtype(' Date: Thu, 11 Jul 2024 17:44:21 -0700 Subject: [PATCH 6/7] use AK_TP_Free --- src/delimited_to_arrays.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/delimited_to_arrays.c b/src/delimited_to_arrays.c index db0d5d62..941404d4 100644 --- a/src/delimited_to_arrays.c +++ b/src/delimited_to_arrays.c @@ -1069,8 +1069,7 @@ AK_CPL_Free(AK_CodePointLine* cpl) PyMem_Free(cpl->buffer); PyMem_Free(cpl->offsets); if (cpl->type_parser) { - PyMem_Free(cpl->type_parser); - // TODO: use AK_TP_Free + AK_TP_Free(cpl->type_parser); } PyMem_Free(cpl); } From ebf4c06d81cd444062178b82c5da1cd61ae5db04 Mon Sep 17 00:00:00 2001 From: Christopher Ariza Date: Thu, 11 Jul 2024 18:07:06 -0700 Subject: [PATCH 7/7] use better complex converters --- src/methods.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/methods.c b/src/methods.c index 06dcfe20..21bcbeb4 100644 --- a/src/methods.c +++ b/src/methods.c @@ -560,7 +560,7 @@ isna_element(PyObject *m, PyObject *args, PyObject *kwargs) } if (PyArray_IsScalar(element, Complex64)) { npy_cfloat val = PyArrayScalar_VAL(element, Complex64); - return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val))); + return PyBool_FromLong(isnan(npy_crealf(val)) || isnan(npy_cimagf(val))); } if (PyArray_IsScalar(element, Complex128)) { npy_cdouble val = PyArrayScalar_VAL(element, Complex128); @@ -569,7 +569,7 @@ isna_element(PyObject *m, PyObject *args, PyObject *kwargs) # ifdef PyComplex256ArrType_Type if (PyArray_IsScalar(element, Complex256)) { npy_clongdouble val = PyArrayScalar_VAL(element, Complex256); - return PyBool_FromLong(isnan(npy_creal(val)) || isnan(npy_cimag(val))); + return PyBool_FromLong(isnan(npy_creall(val)) || isnan(npy_cimagl(val))); } # endif