Skip to content

Commit

Permalink
Merge pull request #3547 from jkseppan/numpy-deprecation
Browse files Browse the repository at this point in the history
Conflicts:
	src/_path.cpp

Conflicted with bug fix for picking zero length path collection 5e2b03c
PR #3592
  • Loading branch information
tacaswell committed Oct 17, 2014
2 parents 7f71233 + b279c15 commit 0f4a68d
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 396 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -6,12 +6,14 @@ env:
- secure: E7OCdqhZ+PlwJcn+Hd6ns9TDJgEUXiUNEI0wu7xjxB2vBRRIKtZMbuaZjd+iKDqCKuVOJKu0ClBUYxmgmpLicTwi34CfTUYt6D4uhrU+8hBBOn1iiK51cl/aBvlUUrqaRLVhukNEBGZcyqAjXSA/Qsnp2iELEmAfOUa92ZYo1sk=
- BUILD_DOCS=false
- TEST_ARGS=--no-pep8
- NUMPY=numpy

language: python

matrix:
include:
- python: 2.6
env: NUMPY=numpy==1.6
- python: 2.7
- python: 3.3
- python: 3.4
Expand All @@ -21,7 +23,7 @@ matrix:
env: BUILD_DOCS=true

install:
- pip install -q --use-mirrors nose python-dateutil numpy pep8 pyparsing pillow
- pip install -q --use-mirrors nose python-dateutil $NUMPY pep8 pyparsing pillow
- sudo apt-get update && sudo apt-get -qq install inkscape libav-tools
# We use --no-install-recommends to avoid pulling in additional large latex docs that we don't need
- if [[ $BUILD_DOCS == true ]]; then sudo apt-get install -qq --no-install-recommends dvipng texlive-latex-base texlive-latex-extra texlive-fonts-recommended graphviz; fi
Expand Down
177 changes: 99 additions & 78 deletions lib/matplotlib/delaunay/_delaunay.cpp

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions lib/matplotlib/tri/_tri.cpp
Expand Up @@ -328,7 +328,7 @@ void Triangulation::calculate_edges()

// Convert to python _edges array.
npy_intp dims[2] = {static_cast<npy_intp>(edge_set.size()), 2};
_edges = (PyArrayObject*)PyArray_SimpleNew(2, dims, PyArray_INT);
_edges = (PyArrayObject*)PyArray_SimpleNew(2, dims, NPY_INT);
int* edges_ptr = (int*)PyArray_DATA(_edges);
for (EdgeSet::const_iterator it = edge_set.begin(); it != edge_set.end(); ++it) {
*edges_ptr++ = it->start;
Expand All @@ -343,7 +343,7 @@ void Triangulation::calculate_neighbors()

// Create _neighbors array with shape (ntri,3) and initialise all to -1.
npy_intp dims[2] = {_ntri,3};
_neighbors = (PyArrayObject*)PyArray_SimpleNew(2, dims, PyArray_INT);
_neighbors = (PyArrayObject*)PyArray_SimpleNew(2, dims, NPY_INT);
int* neighbors_ptr = (int*)PyArray_DATA(_neighbors);
std::fill(neighbors_ptr, neighbors_ptr + 3*_ntri, -1);

Expand Down Expand Up @@ -386,7 +386,7 @@ Py::Object Triangulation::calculate_plane_coefficients(const Py::Tuple &args)
args.verify_length(1);

PyArrayObject* z = (PyArrayObject*)PyArray_ContiguousFromObject(
args[0].ptr(), PyArray_DOUBLE, 1, 1);
args[0].ptr(), NPY_DOUBLE, 1, 1);
if (z == 0 || PyArray_DIM(z,0) != PyArray_DIM(_x,0)) {
Py_XDECREF(z);
throw Py::ValueError(
Expand All @@ -401,7 +401,7 @@ Py::Object Triangulation::calculate_plane_coefficients(const Py::Tuple &args)

npy_intp dims[2] = {_ntri, 3};
planes_array = (PyArrayObject*)PyArray_SimpleNew(2, dims,
PyArray_DOUBLE);
NPY_DOUBLE);
double* planes = (double*)PyArray_DATA(planes_array);
const int* tris = get_triangles_ptr();
const double* xs = (const double*)PyArray_DATA(_x);
Expand Down Expand Up @@ -624,7 +624,7 @@ Py::Object Triangulation::set_mask(const Py::Tuple &args)
if (args[0] != Py::None())
{
_mask = (PyArrayObject*)PyArray_ContiguousFromObject(
args[0].ptr(), PyArray_BOOL, 1, 1);
args[0].ptr(), NPY_BOOL, 1, 1);
if (_mask == 0 || PyArray_DIM(_mask,0) != PyArray_DIM(_triangles,0)) {
Py_XDECREF(_mask);
throw Py::ValueError(
Expand Down Expand Up @@ -712,7 +712,7 @@ Py::Object TriContourGenerator::contour_to_segs(const Contour& contour)
const ContourLine& line = contour[i];
npy_intp dims[2] = {static_cast<npy_intp>(line.size()),2};
PyArrayObject* py_line = (PyArrayObject*)PyArray_SimpleNew(
2, dims, PyArray_DOUBLE);
2, dims, NPY_DOUBLE);
double* p = (double*)PyArray_DATA(py_line);
for (ContourLine::const_iterator it = line.begin(); it != line.end(); ++it) {
*p++ = it->x;
Expand All @@ -736,13 +736,13 @@ Py::Object TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour
// Create segs array for point coordinates.
npy_intp segs_dims[2] = {n_points, 2};
PyArrayObject* segs = (PyArrayObject*)PyArray_SimpleNew(
2, segs_dims, PyArray_DOUBLE);
2, segs_dims, NPY_DOUBLE);
double* segs_ptr = (double*)PyArray_DATA(segs);

// Create kinds array for code types.
npy_intp kinds_dims[1] = {n_points};
PyArrayObject* kinds = (PyArrayObject*)PyArray_SimpleNew(
1, kinds_dims, PyArray_UBYTE);
1, kinds_dims, NPY_UBYTE);
unsigned char* kinds_ptr = (unsigned char*)PyArray_DATA(kinds);

for (line = contour.begin(); line != contour.end(); ++line) {
Expand Down Expand Up @@ -1367,9 +1367,9 @@ TrapezoidMapTriFinder::find_many(const Py::Tuple& args)

// Check input arguments.
PyArrayObject* x = (PyArrayObject*)PyArray_ContiguousFromObject(
args[0].ptr(), PyArray_DOUBLE, 0, 0);
args[0].ptr(), NPY_DOUBLE, 0, 0);
PyArrayObject* y = (PyArrayObject*)PyArray_ContiguousFromObject(
args[1].ptr(), PyArray_DOUBLE, 0, 0);
args[1].ptr(), NPY_DOUBLE, 0, 0);
bool ok = (x != 0 && y != 0 && PyArray_NDIM(x) == PyArray_NDIM(y));
int ndim = x == 0 ? 0 : PyArray_NDIM(x);
for (int i = 0; ok && i < ndim; ++i)
Expand All @@ -1383,7 +1383,7 @@ TrapezoidMapTriFinder::find_many(const Py::Tuple& args)

// Create integer array to return.
PyArrayObject* tri = (PyArrayObject*)PyArray_SimpleNew(
ndim, PyArray_DIMS(x), PyArray_INT);
ndim, PyArray_DIMS(x), NPY_INT);

// Fill returned array.
double* x_ptr = (double*)PyArray_DATA(x);
Expand Down Expand Up @@ -2234,9 +2234,9 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)

// x and y.
PyArrayObject* x = (PyArrayObject*)PyArray_ContiguousFromObject(
args[0].ptr(), PyArray_DOUBLE, 1, 1);
args[0].ptr(), NPY_DOUBLE, 1, 1);
PyArrayObject* y = (PyArrayObject*)PyArray_ContiguousFromObject(
args[1].ptr(), PyArray_DOUBLE, 1, 1);
args[1].ptr(), NPY_DOUBLE, 1, 1);
if (x == 0 || y == 0 || PyArray_DIM(x,0) != PyArray_DIM(y,0)) {
Py_XDECREF(x);
Py_XDECREF(y);
Expand All @@ -2245,7 +2245,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)

// triangles.
PyArrayObject* triangles = (PyArrayObject*)PyArray_ContiguousFromObject(
args[2].ptr(), PyArray_INT, 2, 2);
args[2].ptr(), NPY_INT, 2, 2);
if (triangles == 0 || PyArray_DIM(triangles,1) != 3) {
Py_XDECREF(x);
Py_XDECREF(y);
Expand All @@ -2258,7 +2258,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
if (args[3].ptr() != 0 && args[3] != Py::None())
{
mask = (PyArrayObject*)PyArray_ContiguousFromObject(
args[3].ptr(), PyArray_BOOL, 1, 1);
args[3].ptr(), NPY_BOOL, 1, 1);
if (mask == 0 || PyArray_DIM(mask,0) != PyArray_DIM(triangles,0)) {
Py_XDECREF(x);
Py_XDECREF(y);
Expand All @@ -2274,7 +2274,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
if (args[4].ptr() != 0 && args[4] != Py::None())
{
edges = (PyArrayObject*)PyArray_ContiguousFromObject(
args[4].ptr(), PyArray_INT, 2, 2);
args[4].ptr(), NPY_INT, 2, 2);
if (edges == 0 || PyArray_DIM(edges,1) != 2) {
Py_XDECREF(x);
Py_XDECREF(y);
Expand All @@ -2290,7 +2290,7 @@ Py::Object TriModule::new_triangulation(const Py::Tuple &args)
if (args[5].ptr() != 0 && args[5] != Py::None())
{
neighbors = (PyArrayObject*)PyArray_ContiguousFromObject(
args[5].ptr(), PyArray_INT, 2, 2);
args[5].ptr(), NPY_INT, 2, 2);
if (neighbors == 0 ||
PyArray_DIM(neighbors,0) != PyArray_DIM(triangles,0) ||
PyArray_DIM(neighbors,1) != PyArray_DIM(triangles,1)) {
Expand Down Expand Up @@ -2318,7 +2318,7 @@ Py::Object TriModule::new_tricontourgenerator(const Py::Tuple &args)
throw Py::ValueError("Expecting a C++ Triangulation object");

PyArrayObject* z = (PyArrayObject*)PyArray_ContiguousFromObject(
args[1].ptr(), PyArray_DOUBLE, 1, 1);
args[1].ptr(), NPY_DOUBLE, 1, 1);
if (z == 0 ||
PyArray_DIM(z,0) != ((Triangulation*)tri.ptr())->get_npoints()) {
Py_XDECREF(z);
Expand Down
3 changes: 3 additions & 0 deletions setupext.py
Expand Up @@ -830,6 +830,9 @@ def add_flags(self, ext):
ext.define_macros.append(('PY_ARRAY_UNIQUE_SYMBOL', array_api_name))
ext.add_hook('include_dirs', self.include_dirs_hook)

ext.define_macros.append(('NPY_NO_DEPRECATED_API',
'NPY_1_7_API_VERSION'))

def get_setup_requires(self):
return ['numpy>=1.6']

Expand Down
36 changes: 18 additions & 18 deletions src/_backend_agg.cpp
Expand Up @@ -947,16 +947,16 @@ RendererAgg::draw_text_image(const Py::Tuple& args)
if (PyArray_Check(image_obj.ptr()))
{
PyObject* image_array = PyArray_FromObject(
image_obj.ptr(), PyArray_UBYTE, 2, 2);
image_obj.ptr(), NPY_UBYTE, 2, 2);
if (!image_array)
{
throw Py::ValueError(
"First argument to draw_text_image must be a FT2Font.Image object or a Nx2 uint8 numpy array.");
}
image_obj = Py::Object(image_array, true);
buffer = (unsigned char *)PyArray_DATA(image_array);
width = PyArray_DIM(image_array, 1);
height = PyArray_DIM(image_array, 0);
buffer = (unsigned char *)PyArray_DATA((PyArrayObject*)image_array);
width = PyArray_DIM((PyArrayObject*)image_array, 1);
height = PyArray_DIM((PyArrayObject*)image_array, 0);
}
else
{
Expand Down Expand Up @@ -1500,7 +1500,7 @@ RendererAgg::_draw_path_collection_generic
typedef agg::conv_curve<clipped_t> curve_t;

PyArrayObject* offsets = (PyArrayObject*)PyArray_FromObject
(offsets_obj.ptr(), PyArray_DOUBLE, 0, 2);
(offsets_obj.ptr(), NPY_DOUBLE, 0, 2);
if (!offsets ||
(PyArray_NDIM(offsets) == 2 && PyArray_DIM(offsets, 1) != 2) ||
(PyArray_NDIM(offsets) == 1 && PyArray_DIM(offsets, 0) != 0))
Expand All @@ -1511,7 +1511,7 @@ RendererAgg::_draw_path_collection_generic
Py::Object offsets_arr_obj((PyObject*)offsets, true);

PyArrayObject* facecolors = (PyArrayObject*)PyArray_FromObject
(facecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
(facecolors_obj.ptr(), NPY_DOUBLE, 1, 2);
if (!facecolors ||
(PyArray_NDIM(facecolors) == 1 && PyArray_DIM(facecolors, 0) != 0) ||
(PyArray_NDIM(facecolors) == 2 && PyArray_DIM(facecolors, 1) != 4))
Expand All @@ -1522,7 +1522,7 @@ RendererAgg::_draw_path_collection_generic
Py::Object facecolors_arr_obj((PyObject*)facecolors, true);

PyArrayObject* edgecolors = (PyArrayObject*)PyArray_FromObject
(edgecolors_obj.ptr(), PyArray_DOUBLE, 1, 2);
(edgecolors_obj.ptr(), NPY_DOUBLE, 1, 2);
if (!edgecolors ||
(PyArray_NDIM(edgecolors) == 1 && PyArray_DIM(edgecolors, 0) != 0) ||
(PyArray_NDIM(edgecolors) == 2 && PyArray_DIM(edgecolors, 1) != 4))
Expand All @@ -1533,7 +1533,7 @@ RendererAgg::_draw_path_collection_generic
Py::Object edgecolors_arr_obj((PyObject*)edgecolors, true);

PyArrayObject* transforms_arr = (PyArrayObject*)PyArray_FromObject
(transforms_obj.ptr(), PyArray_DOUBLE, 1, 3);
(transforms_obj.ptr(), NPY_DOUBLE, 1, 3);
if (!transforms_arr ||
(PyArray_NDIM(transforms_arr) == 1 && PyArray_DIM(transforms_arr, 0) != 0) ||
(PyArray_NDIM(transforms_arr) == 2) ||
Expand All @@ -1546,11 +1546,11 @@ RendererAgg::_draw_path_collection_generic
}

size_t Npaths = path_generator.num_paths();
size_t Noffsets = offsets->dimensions[0];
size_t Noffsets = PyArray_DIM(offsets, 0);
size_t N = std::max(Npaths, Noffsets);
size_t Ntransforms = transforms_arr->dimensions[0];
size_t Nfacecolors = facecolors->dimensions[0];
size_t Nedgecolors = edgecolors->dimensions[0];
size_t Ntransforms = PyArray_DIM(transforms_arr, 0);
size_t Nfacecolors = PyArray_DIM(facecolors, 0);
size_t Nedgecolors = PyArray_DIM(edgecolors, 0);
size_t Nlinewidths = linewidths.length();
size_t Nlinestyles = std::min(linestyles_obj.length(), N);
size_t Naa = antialiaseds.length();
Expand Down Expand Up @@ -1867,7 +1867,7 @@ class QuadMeshGenerator
{
PyArrayObject* coordinates_array = \
(PyArrayObject*)PyArray_ContiguousFromObject(
coordinates, PyArray_DOUBLE, 3, 3);
coordinates, NPY_DOUBLE, 3, 3);

if (!coordinates_array)
{
Expand Down Expand Up @@ -1931,7 +1931,7 @@ RendererAgg::draw_quad_mesh(const Py::Tuple& args)
else
{
npy_intp dims[] = { 0, 0 };
edgecolors_obj = PyArray_SimpleNew(1, dims, PyArray_DOUBLE);
edgecolors_obj = PyArray_SimpleNew(1, dims, NPY_DOUBLE);
}
}

Expand Down Expand Up @@ -2040,7 +2040,7 @@ RendererAgg::draw_gouraud_triangle(const Py::Tuple& args)
bool has_clippath = render_clippath(gc.clippath, gc.clippath_trans);

PyArrayObject* points = (PyArrayObject*)PyArray_ContiguousFromAny
(points_obj.ptr(), PyArray_DOUBLE, 2, 2);
(points_obj.ptr(), NPY_DOUBLE, 2, 2);
if (!points ||
PyArray_DIM(points, 0) != 3 || PyArray_DIM(points, 1) != 2)
{
Expand All @@ -2050,7 +2050,7 @@ RendererAgg::draw_gouraud_triangle(const Py::Tuple& args)
points_obj = Py::Object((PyObject*)points, true);

PyArrayObject* colors = (PyArrayObject*)PyArray_ContiguousFromAny
(colors_obj.ptr(), PyArray_DOUBLE, 2, 2);
(colors_obj.ptr(), NPY_DOUBLE, 2, 2);
if (!colors ||
PyArray_DIM(colors, 0) != 3 || PyArray_DIM(colors, 1) != 4)
{
Expand Down Expand Up @@ -2089,7 +2089,7 @@ RendererAgg::draw_gouraud_triangles(const Py::Tuple& args)
bool has_clippath = render_clippath(gc.clippath, gc.clippath_trans);

PyArrayObject* points = (PyArrayObject*)PyArray_FromObject
(points_obj.ptr(), PyArray_DOUBLE, 3, 3);
(points_obj.ptr(), NPY_DOUBLE, 3, 3);
if (!points ||
PyArray_DIM(points, 1) != 3 || PyArray_DIM(points, 2) != 2)
{
Expand All @@ -2099,7 +2099,7 @@ RendererAgg::draw_gouraud_triangles(const Py::Tuple& args)
points_obj = Py::Object((PyObject*)points, true);

PyArrayObject* colors = (PyArrayObject*)PyArray_FromObject
(colors_obj.ptr(), PyArray_DOUBLE, 3, 3);
(colors_obj.ptr(), NPY_DOUBLE, 3, 3);
if (!colors ||
PyArray_DIM(colors, 1) != 3 || PyArray_DIM(colors, 2) != 4)
{
Expand Down
2 changes: 1 addition & 1 deletion src/_backend_gdk.c
Expand Up @@ -35,7 +35,7 @@ pixbuf_get_pixels_array(PyObject *self, PyObject *args)
if (gdk_pixbuf_get_has_alpha(gdk_pixbuf))
dims[2] = 4;

array = (PyArrayObject *)PyArray_SimpleNewFromData(3, dims, PyArray_UBYTE,
array = (PyArrayObject *)PyArray_SimpleNewFromData(3, dims, NPY_UBYTE,
(char *)gdk_pixbuf_get_pixels(gdk_pixbuf));
if (array == NULL)
return NULL;
Expand Down

0 comments on commit 0f4a68d

Please sign in to comment.