Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cecd8a

Browse files
committed
Attempted to fix, once and for all, the problems of using "isnan" by
defining our own "MPL_isnan64" macro in C (modified from a similar solution in numarray). Also, checking in the unit test that demonstrates why we need isnan. -- ADS svn path=/trunk/matplotlib/; revision=1922
1 parent d1fcba3 commit 1cecd8a

3 files changed

Lines changed: 68 additions & 4 deletions

File tree

src/MPL_isnan.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// These definitions modified from numarray's Include/numarray/nummacro.h
2+
3+
#if defined(SIZEOF_VOID_P)
4+
#if SIZEOF_VOID_P == 8
5+
#define MPL_LP64 1
6+
#else
7+
#define MPL_LP64 0
8+
#endif
9+
#else
10+
#define MPL_LP64 0
11+
#endif
12+
13+
#if MPL_LP64
14+
typedef long int MPL_Int64;
15+
#else /* 32-bit platforms */
16+
#if defined(_MSC_VER)
17+
typedef __int64 MPL_Int64;
18+
#else
19+
typedef long long MPL_Int64;
20+
#endif
21+
#endif
22+
23+
#if !defined(MPL_isnan64)
24+
#define MPL_U64(u) (* (MPL_Int64 *) &(u) )
25+
26+
#if !defined(_MSC_VER)
27+
#define MPL_isnan64(u) \
28+
( (( MPL_U64(u) & 0x7ff0000000000000LL) == 0x7ff0000000000000LL) && ((MPL_U64(u) & 0x000fffffffffffffLL) != 0)) ? 1:0
29+
#else
30+
#define MPL_isnan64(u) \
31+
( (( MPL_U64(u) & 0x7ff0000000000000i64) == 0x7ff0000000000000i64) && ((MPL_U64(u) & 0x000fffffffffffffi64) != 0)) ? 1:0
32+
#endif
33+
#endif /* MPL_isnan64 */

src/_transforms.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <functional>
22
#include "_transforms.h"
33
#include "mplutils.h"
4+
#include "MPL_isnan.h"
45

56
#ifdef NUMARRAY
67
# include "numarray/arrayobject.h"
@@ -444,7 +445,6 @@ Bbox::update(const Py::Tuple &args) {
444445
Py::Object
445446
Bbox::update_numerix(const Py::Tuple &args) {
446447
//update the box from the numerix arrays x and y
447-
using std::isnan;
448448
_VERBOSE("Bbox::update_numerix");
449449

450450
args.verify_length(3);
@@ -491,15 +491,15 @@ Bbox::update_numerix(const Py::Tuple &args) {
491491
thisy = *(double *)(y->data + i*y->strides[0]);
492492

493493
if (!xok) {
494-
if (!isnan(thisx)) {
494+
if (!MPL_isnan64(thisx)) {
495495
minx=thisx;
496496
maxx=thisx;
497497
xok=1;
498498
}
499499
}
500500

501501
if (!yok) {
502-
if (!isnan(thisy)) {
502+
if (!MPL_isnan64(thisy)) {
503503
miny=thisy;
504504
maxy=thisx;
505505
yok=1;

unit/transforms_unit.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#from __future__ import division
22

3-
from matplotlib.numerix import array, asarray, alltrue
3+
from matplotlib.numerix import array, asarray, alltrue, arange
44
from matplotlib.numerix.mlab import rand
55
from matplotlib.transforms import Point, Bbox, Value, Affine
66
from matplotlib.transforms import multiply_affines
@@ -271,4 +271,35 @@ def rand_transform():
271271
polar = FuncXY(POLAR)
272272
assert( closeto_seq( polar.map(math.pi,1), (-1,0)) )
273273
assert( closeto_seq( polar.inverse(1,1), ( (math.pi/4), math.sqrt(2))) )
274+
275+
276+
277+
# This unit test requires "nan", which numarray.ieeespecial
278+
# exports. (But we can keep using the numerix module.)
279+
try:
280+
from numarray.ieeespecial import nan
281+
have_nan = True
282+
except ImportError:
283+
have_nan = False
284+
285+
if have_nan:
286+
y1=array([ 2,nan,1,2,3,4])
287+
y2=array([nan,nan,1,2,3,4])
288+
289+
x1=arange(len(y1))
290+
x2=arange(len(y2))
291+
292+
bbox1 = Bbox(Point(Value(0),Value(0)),
293+
Point(Value(1),Value(1)))
294+
295+
bbox2 = Bbox(Point(Value(0),Value(0)),
296+
Point(Value(1),Value(1)))
297+
298+
bbox1.update_numerix(x1,y1,1)
299+
bbox2.update_numerix(x2,y2,1)
300+
301+
assert( closeto_seq( bbox1.get_bounds(), bbox2.get_bounds() ) )
302+
else:
303+
print 'nan could not be imported from numarray.ieeespecial, test skipped'
304+
274305
print 'all tests passed'

0 commit comments

Comments
 (0)