diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec70c75..9f0aaa06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Version 5.0.2: + * Updated the C wrappers for PGPLOT for the Numpy 2.0 C API + * Python v3.9 or newer is now required. + * Several minor bug fixes, including to `injectpsr.py`, thanks to @remsforian + ## Version 5.0.1: * Minor improvements over v5.0.0 * Some clarifications and improvements to the build process diff --git a/README.md b/README.md index f65b9d75..fc215a61 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ PRESTO is a large suite of pulsar search and analysis software developed primari **PRESTO has discovered well over 1000 pulsars, including ~400 recycled and/or binary pulsars!** +## Version 5.0.2: + * Updated the C wrappers for PGPLOT for the Numpy 2.0 C API (with thanks to Tom Marsh) + * Python v3.9 or newer is now required. + * Several minor bug fixes, including to `injectpsr.py`, thanks to @remsforian + ## Version 5.0.1: * Minor improvements over v5.0.0 * Some clarifications and improvements to the build process diff --git a/meson.build b/meson.build index d0964463..482d9fda 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('PRESTO', 'c', - version: '5.0.1', + version: '5.0.2', license: 'GPL-2.0', default_options: [ 'buildtype=release', diff --git a/python/meson.build b/python/meson.build index 71b0a639..06a3ea47 100644 --- a/python/meson.build +++ b/python/meson.build @@ -1,5 +1,5 @@ project('PRESTO_python', 'c', 'fortran', - version: '5.0.1', + version: '5.0.2', license: 'GPL-2.0', default_options: [ 'buildtype=release', @@ -41,17 +41,6 @@ incdir_numpy = run_command(py3, ).stdout().strip() inc_np = include_directories(incdir_numpy) - -# Don't use the deprecated NumPy C API. Define this to a fixed version instead of -# NPY_API_VERSION in order not to break compilation for released SciPy versions -# when NumPy introduces a new deprecation. Use in a meson.build file:: -# -# py3.extension_module('_name', -# 'source_fname', -# numpy_nodepr_api) -# -numpy_nodepr_api = '-DNPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION' - incdir_f2py = incdir_numpy / '..' / '..' / 'f2py' / 'src' inc_f2py = include_directories(incdir_f2py) fortranobject_c = incdir_f2py / 'fortranobject.c' diff --git a/python/ppgplot_src/_ppgplot.c b/python/ppgplot_src/_ppgplot.c index 9648befa..f13499fc 100644 --- a/python/ppgplot_src/_ppgplot.c +++ b/python/ppgplot_src/_ppgplot.c @@ -2,17 +2,16 @@ * FILE: * _ppgplot.c * DESCRIPTION: - * ppgplot: Python / Numeric Python interface to the PGPLOT graphical - * library. - * Tested with PGPLOT 5.2, Python 2.3.1 and Numeric 23.1, on - * Linux (v2.4.x). + * ppgplot: Python / Numeric Python interface to the PGPLOT graphical library. + * Tested with PGPLOT 5.2.2, Python 3.10+, and Numpy 1.2X/2.X on Linux * AUTHOR(S): - * Nick Patavalis (npat@efault.net) + * Nick Patavalis (npat@efault.net), Tom Marsh, Scott Ransom * NOTES: * - A few ppgplot functions have not been interfaced yet. * - The pythonic calling conventions of some functions are *not* * identical to the original PGPLOT ones. * - added pgpt1 15/04/2008 TRM + * - updates to docs and for Numpy 2.0 in June 2024 by SMR */ #include @@ -74,32 +73,51 @@ tofloatvector (PyObject *o, float **v, npy_intp *vsz) TRM, 12/02/09. This avoids an irritating deprecation warning from numpy. */ PyArrayObject* array = NULL; - array = (PyArrayObject*) PyArray_FromAny(o, PyArray_DescrFromType(NPY_FLOAT), 1, 1, NPY_ALIGNED | NPY_C_CONTIGUOUS | NPY_FORCECAST, NULL); - if(array == NULL) return NULL; - *vsz = PyArray_Size(array); - *v = (float*) PyArray_DATA(array); + array = (PyArrayObject*) PyArray_FromAny(o, PyArray_DescrFromType(NPY_FLOAT), 1, 1, + NPY_ARRAY_ALIGNED | NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_FORCECAST, NULL); + if (array == NULL) return NULL; + *vsz = PyArray_Size((PyArrayObject*) array); + *v = (float*) PyArray_DATA((PyArrayObject*) array); return (PyObject*)array; } /*************************************************************************/ +//static PyObject * +//tofloatmatX(PyObject *o, float **m, npy_intp *nr, npy_intp *nc) +//{ +// /* +// This is based on the tofloatvector() changes by TRM. +// */ +// PyArrayObject* array = NULL; +// array = (PyArrayObject*) PyArray_FromAny(o, PyArray_DescrFromType(NPY_FLOAT), 1, 1, +// NPY_ARRAY_ALIGNED | NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_FORCECAST, NULL); +// if(array == NULL) return NULL; +// *vsz = PyArray_Size(array); +// *v = (float*) PyArray_DATA(array); +// return (PyObject*)array; +//} + +/*************************************************************************/ + static PyObject * tofloatmat(PyObject *o, float **m, int *nr, int *nc) { + npy_intp newdims[2]; PyArrayObject *a1, *af1, *af2; int ownedaf1=0; char **tmpdat; /* Check if args are arrays. */ if (!PyArray_Check(o)) { - PyErr_SetString(PpgTYPEErr,"object is not an array"); - return(NULL); + PyErr_SetString(PpgTYPEErr,"object is not an array"); + return(NULL); } a1 = (PyArrayObject *)o; /* Check if args are matrices. */ if (a1->nd != 2) { - PyErr_SetString(PpgTYPEErr,"object is not a matrix"); - return(NULL); + PyErr_SetString(PpgTYPEErr,"object is not a matrix"); + return(NULL); } #ifdef DEBUG_TOARRAY @@ -107,29 +125,24 @@ tofloatmat(PyObject *o, float **m, int *nr, int *nc) #endif switch (a1->descr->type_num) { - case PyArray_FLOAT: - af1 = a1; - break; - case PyArray_CHAR: -#ifndef USE_NUMARRAY - case PyArray_UBYTE: -#endif -// case PyArray_SBYTE: - case PyArray_SHORT: - case PyArray_INT: -#ifndef USE_NUMARRAY - case PyArray_LONG: -#endif - case PyArray_DOUBLE: - if (!(af1 = (PyArrayObject *)PyArray_Cast(a1,PyArray_FLOAT))) { - PyErr_SetString(PpgTYPEErr,"cannot cast matrix to floats"); - return(NULL); - } - ownedaf1 = 1; - break; + case NPY_FLOAT: + af1 = a1; + break; + case NPY_CHAR: + case NPY_UBYTE: + case NPY_SHORT: + case NPY_INT: + case NPY_LONG: + case NPY_DOUBLE: + if (!(af1 = (PyArrayObject *)PyArray_Cast(a1,NPY_FLOAT))) { + PyErr_SetString(PpgTYPEErr,"cannot cast matrix to floats"); + return(NULL); + } + ownedaf1 = 1; + break; default: - PyErr_SetString(PpgTYPEErr,"cannot cast matrix to floats"); - return(NULL); + PyErr_SetString(PpgTYPEErr,"cannot cast matrix to floats"); + return(NULL); break; } @@ -139,11 +152,14 @@ tofloatmat(PyObject *o, float **m, int *nr, int *nc) af2 = af1; /* (void *) avoids irritating gcc warning about strict aliasing */ - if (PyArray_As2D((PyObject **)(void *)&af2, (char ***)&tmpdat, nr, nc, PyArray_FLOAT) == -1) { - af2 = NULL; - goto bailout; + if (PyArray_AsCArray((PyObject **)(void *)&af2, (char ***)&tmpdat, + newdims, 2, PyArray_DescrFromType(NPY_FLOAT)) == -1) { + af2 = NULL; + goto bailout; } - + *nr = (int ) newdims[0]; + *nc = (int ) newdims[1]; + /* WARNING: What follows is a little tricky and I dunno if I'm really allowed to do this. On the other hand it really conserves time and memory! So this assert statement will make sure that diff --git a/python/ppgplot_src/meson.build b/python/ppgplot_src/meson.build index 90978fe9..50d20a19 100644 --- a/python/ppgplot_src/meson.build +++ b/python/ppgplot_src/meson.build @@ -1,5 +1,3 @@ -# Note: will need to fix Numpy API deprecation soon -SMR -# c_args: [numpy_nodepr_api, '-Wno-unused-variable'], py3.extension_module('_ppgplot', '_ppgplot.c', include_directories: inc_np, dependencies : [py3_dep, libm, pgplot, cpgplot, x11, png], diff --git a/python/pyproject.toml b/python/pyproject.toml index a866bb79..fd844643 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,12 +1,12 @@ [build-system] build-backend = 'mesonpy' -requires = ['meson-python', 'numpy<2.0'] +requires = ['meson-python', 'numpy'] [project] name = 'presto' -version = '5.0.1' +version = '5.0.2' description = 'PulsaR Exploration and Search TOolkit' -requires-python = '>=3.8' +requires-python = '>=3.9' dependencies = ['numpy', 'scipy', 'astropy', 'matplotlib'] authors = [ {name = 'Scott Ransom', email = 'sransom@nrao.edu'},