Skip to content

Commit d8c1d0d

Browse files
committed
Remove usage of old Numpy API
1 parent d862c47 commit d8c1d0d

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

lib/matplotlib/delaunay/_delaunay.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "VoronoiDiagramGenerator.h"
77
#include "delaunay_utils.h"
88
#include "natneighbors.h"
9-
#include "numpy/noprefix.h"
9+
#include "numpy/ndarrayobject.h"
1010

1111
// support numpy 1.6 - this macro got renamed and deprecated at once in 1.7
1212
#ifndef NPY_ARRAY_IN_ARRAY
@@ -123,7 +123,7 @@ static PyObject* getMesh(int npoints, double *x, double *y)
123123
int tri0, tri1, reg0, reg1;
124124
double tri0x, tri0y, tri1x, tri1y;
125125
int length, numtri, i, j;
126-
intp dim[MAX_DIMS];
126+
npy_intp dim[NPY_MAXDIMS];
127127
int *edge_db_ptr, *tri_edges_ptr, *tri_nbrs_ptr;
128128
double *vertices_ptr;
129129
VoronoiDiagramGenerator vdg;
@@ -221,7 +221,7 @@ static PyObject* getMesh(int npoints, double *x, double *y)
221221
static PyObject *linear_planes(int ntriangles, double *x, double *y, double *z,
222222
int *nodes)
223223
{
224-
intp dims[2];
224+
npy_intp dims[2];
225225
PyObject *planes;
226226
int i;
227227
double *planes_ptr;
@@ -286,7 +286,7 @@ static PyObject *linear_interpolate_grid(double x0, double x1, int xsteps,
286286
int rowtri, coltri, tri;
287287
PyObject *z;
288288
double *z_ptr;
289-
intp dims[2];
289+
npy_intp dims[2];
290290

291291
dims[0] = ysteps;
292292
dims[1] = xsteps;
@@ -596,7 +596,7 @@ static PyObject *nn_interpolate_method(PyObject *self, PyObject *args)
596596
double x0, x1, y0, y1, defvalue;
597597
int xsteps, ysteps;
598598
int npoints, ntriangles;
599-
intp dims[2];
599+
npy_intp dims[2];
600600

601601
if (!PyArg_ParseTuple(args, "ddiddidOOOOOO", &x0, &x1, &xsteps,
602602
&y0, &y1, &ysteps, &defvalue, &pyx, &pyy, &pyz, &pycenters, &pynodes,

src/_png.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
249249
png_uint_32 height = 0;
250250
int bit_depth;
251251

252+
// TODO: Remove direct calls to Numpy API here
253+
252254
if (PyBytes_Check(filein) || PyUnicode_Check(filein)) {
253255
if ((py_file = mpl_PyFile_OpenFile(filein, (char *)"rb")) == NULL) {
254256
goto exit;
@@ -381,18 +383,15 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
381383
for (png_uint_32 y = 0; y < height; y++) {
382384
png_byte *row = row_pointers[y];
383385
for (png_uint_32 x = 0; x < width; x++) {
384-
size_t offset = y * A->strides[0] + x * A->strides[1];
385386
if (bit_depth == 16) {
386387
png_uint_16 *ptr = &reinterpret_cast<png_uint_16 *>(row)[x * dimensions[2]];
387388
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++) {
388-
*(float *)(A->data + offset + p *A->strides[2]) =
389-
(float)(ptr[p]) / max_value;
389+
*(float *)PyArray_GETPTR3(A, y, x, p) = (float)(ptr[p]) / max_value;
390390
}
391391
} else {
392392
png_byte *ptr = &(row[x * dimensions[2]]);
393393
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++) {
394-
*(float *)(A->data + offset + p *A->strides[2]) =
395-
(float)(ptr[p]) / max_value;
394+
*(float *)PyArray_GETPTR3(A, y, x, p) = (float)(ptr[p]) / max_value;
396395
}
397396
}
398397
}
@@ -414,28 +413,27 @@ static PyObject *_read_png(PyObject *filein, bool float_result)
414413
for (png_uint_32 y = 0; y < height; y++) {
415414
png_byte *row = row_pointers[y];
416415
for (png_uint_32 x = 0; x < width; x++) {
417-
size_t offset = y * A->strides[0] + x * A->strides[1];
418416
if (bit_depth == 16) {
419417
png_uint_16 *ptr = &reinterpret_cast<png_uint_16 *>(row)[x * dimensions[2]];
420418

421419
if (bit_depth == 16) {
422420
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++) {
423-
*(png_uint_16 *)(A->data + offset + p *A->strides[2]) = ptr[p];
421+
*(png_uint_16 *)PyArray_GETPTR3(A, y, x, p) = ptr[p];
424422
}
425423
} else {
426424
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++) {
427-
*(png_byte *)(A->data + offset + p *A->strides[2]) = ptr[p] >> 8;
425+
*(png_byte *)PyArray_GETPTR3(A, y, x, p) = ptr[p] >> 8;
428426
}
429427
}
430428
} else {
431429
png_byte *ptr = &(row[x * dimensions[2]]);
432430
if (bit_depth == 16) {
433431
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++) {
434-
*(png_uint_16 *)(A->data + offset + p *A->strides[2]) = ptr[p];
432+
*(png_uint_16 *)PyArray_GETPTR3(A, y, x, p) = ptr[p];
435433
}
436434
} else {
437435
for (png_uint_32 p = 0; p < (png_uint_32)dimensions[2]; p++) {
438-
*(png_byte *)(A->data + offset + p *A->strides[2]) = ptr[p];
436+
*(png_byte *)PyArray_GETPTR3(A, y, x, p) = ptr[p];
439437
}
440438
}
441439
}

src/ft2font_wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const char *PyFT2Image_as_array__doc__ =
139139
static PyObject *PyFT2Image_as_array(PyFT2Image *self, PyObject *args, PyObject *kwds)
140140
{
141141
npy_intp dims[] = {(npy_intp)self->x->get_height(), (npy_intp)self->x->get_width() };
142-
return PyArray_SimpleNewFromData(2, dims, PyArray_UBYTE, self->x->get_buffer());
142+
return PyArray_SimpleNewFromData(2, dims, NPY_UBYTE, self->x->get_buffer());
143143
}
144144

145145
static PyObject *PyFT2Image_get_width(PyFT2Image *self, PyObject *args, PyObject *kwds)

src/py_adaptors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class PathIterator
104104
m_simplify_threshold = simplify_threshold;
105105

106106
Py_XDECREF(m_vertices);
107-
m_vertices = (PyArrayObject *)PyArray_FromObject(vertices, PyArray_DOUBLE, 2, 2);
107+
m_vertices = (PyArrayObject *)PyArray_FromObject(vertices, NPY_DOUBLE, 2, 2);
108108

109109
if (!m_vertices || PyArray_DIM(m_vertices, 1) != 2) {
110110
PyErr_SetString(PyExc_ValueError, "Invalid vertices array");
@@ -115,7 +115,7 @@ class PathIterator
115115
m_codes = NULL;
116116

117117
if (codes != NULL && codes != Py_None) {
118-
m_codes = (PyArrayObject *)PyArray_FromObject(codes, PyArray_UINT8, 1, 1);
118+
m_codes = (PyArrayObject *)PyArray_FromObject(codes, NPY_UINT8, 1, 1);
119119

120120
if (!m_codes || PyArray_DIM(m_codes, 0) != PyArray_DIM(m_vertices, 0)) {
121121
PyErr_SetString(PyExc_ValueError, "Invalid codes array");

0 commit comments

Comments
 (0)