Revision: 6765
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6765&view=rev
Author: jdh2358
Date: 2009-01-08 19:17:15 +0000 (Thu, 08 Jan 2009)
Log Message:
-----------
fixed pointer arithmetic in nnbf
Modified Paths:
--------------
trunk/py4science/examples/pyrex/nnbf/nnbf.pyx
trunk/py4science/examples/pyrex/nnbf/nnbf_v2.pyx
trunk/py4science/examples/pyrex/nnbf/test_nnbf.py
Modified: trunk/py4science/examples/pyrex/nnbf/nnbf.pyx
===================================================================
--- trunk/py4science/examples/pyrex/nnbf/nnbf.pyx 2009-01-08 03:23:42 UTC
(rev 6764)
+++ trunk/py4science/examples/pyrex/nnbf/nnbf.pyx 2009-01-08 19:17:15 UTC
(rev 6765)
@@ -27,22 +27,23 @@
cdef class NNBF:
cdef readonly object data
- #cdef double* raw_data
+ cdef double* raw_data
cdef readonly int n, numrows, numpoints
def __init__(self, n):
"""
create a buffer to hold n dimensional points
"""
- #cdef np.ndarray[double, ndim=2] inner_data
+ cdef np.ndarray[double, ndim=2] inner_data
self.n = n
self.numrows = 100
# XXX how to create mepty as contiguous w/o copy?
- self.data = np.empty((self.numrows, self.n), dtype=np.float)
- #inner_data = self.data
- #self.raw_data = <double*>inner_data.data
+ data = np.empty((self.numrows, self.n), dtype=np.float)
+ self.data = np.ascontiguousarray(data, dtype=np.float)
+ inner_data = self.data
+ self.raw_data = <double*>inner_data.data
self.numpoints = 0
@@ -50,7 +51,7 @@
"""
add a point to the buffer, grow if necessary
"""
- #cdef np.ndarray[double, ndim=2] inner_data
+ cdef np.ndarray[double, ndim=2] inner_data
cdef np.ndarray[double, ndim=1] pp
pp = np.asarray(point).astype(np.float)
@@ -63,7 +64,9 @@
self.numrows *= 2
newdata = np.empty((self.numrows, self.n), np.float)
newdata[:self.numpoints] = self.data
- self.data = newdata
+ self.data = np.ascontiguousarray(newdata, dtype=np.float)
+ inner_data = self.data
+ self.raw_data = <double*>inner_data.data
#self.raw_data = <double*>inner_data.data
def get_data(NNBF self):
@@ -96,15 +99,16 @@
# don't do a python lookup inside the loop
n = self.n
-
+
for i in range(self.numpoints):
# XXX : is there a more efficient way to access the row
# data? Can/should we be using raw_data here?
#row = self.data[i]
neighbor = is_neighbor(
n,
- #<double*>row.data,
- dataptr + i,
+ #(<double*>self.data.data)+i*n,
+ self.raw_data + i*n,
+ #dataptr + i*n,
<double*>pp.data,
d2max)
Modified: trunk/py4science/examples/pyrex/nnbf/nnbf_v2.pyx
===================================================================
--- trunk/py4science/examples/pyrex/nnbf/nnbf_v2.pyx 2009-01-08 03:23:42 UTC
(rev 6764)
+++ trunk/py4science/examples/pyrex/nnbf/nnbf_v2.pyx 2009-01-08 19:17:15 UTC
(rev 6765)
@@ -27,22 +27,23 @@
cdef class NNBF:
cdef readonly object data
- #cdef double* raw_data
+ cdef double* raw_data
cdef readonly int n, numrows, numpoints
def __init__(self, n):
"""
create a buffer to hold n dimensional points
"""
- #cdef np.ndarray[double, ndim=2] inner_data
+ cdef np.ndarray[double, ndim=2] inner_data
self.n = n
self.numrows = 100
# XXX how to create mepty as contiguous w/o copy?
- self.data = np.empty((self.numrows, self.n), dtype=np.float)
- #inner_data = self.data
- #self.raw_data = <double*>inner_data.data
+ data = np.empty((self.numrows, self.n), dtype=np.float)
+ self.data = np.ascontiguousarray(data, dtype=np.float)
+ inner_data = self.data
+ self.raw_data = <double*>inner_data.data
self.numpoints = 0
@@ -50,7 +51,7 @@
"""
add a point to the buffer, grow if necessary
"""
- #cdef np.ndarray[double, ndim=2] inner_data
+ cdef np.ndarray[double, ndim=2] inner_data
cdef np.ndarray[double, ndim=1] pp
pp = np.asarray(point).astype(np.float)
@@ -63,7 +64,9 @@
self.numrows *= 2
newdata = np.empty((self.numrows, self.n), np.float)
newdata[:self.numpoints] = self.data
- self.data = newdata
+ self.data = np.ascontiguousarray(newdata, dtype=np.float)
+ inner_data = self.data
+ self.raw_data = <double*>inner_data.data
#self.raw_data = <double*>inner_data.data
def get_data(NNBF self):
@@ -96,15 +99,16 @@
# don't do a python lookup inside the loop
n = self.n
-
+
for i in range(self.numpoints):
# XXX : is there a more efficient way to access the row
# data? Can/should we be using raw_data here?
#row = self.data[i]
neighbor = is_neighbor(
n,
- #<double*>row.data,
- dataptr + i,
+ #(<double*>self.data.data)+i*n,
+ self.raw_data + i*n,
+ #dataptr + i*n,
<double*>pp.data,
d2max)
Modified: trunk/py4science/examples/pyrex/nnbf/test_nnbf.py
===================================================================
--- trunk/py4science/examples/pyrex/nnbf/test_nnbf.py 2009-01-08 03:23:42 UTC
(rev 6764)
+++ trunk/py4science/examples/pyrex/nnbf/test_nnbf.py 2009-01-08 19:17:15 UTC
(rev 6765)
@@ -44,7 +44,6 @@
-
if 1:
#def test_performance():
NUMDIM = 6
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins