Revision: 6683
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6683&view=rev
Author:   jdh2358
Date:     2008-12-19 19:31:23 +0000 (Fri, 19 Dec 2008)

Log Message:
-----------
fixed a min/max bug when initial values all nan

Modified Paths:
--------------
    trunk/py4science/examples/pyrex/trailstats/c_ringbuf.pxi
    trunk/py4science/examples/pyrex/trailstats/movavg_fast.py
    trunk/py4science/examples/pyrex/trailstats/ringbuf.h
    trunk/py4science/examples/pyrex/trailstats/ringbuf.pyx
    trunk/py4science/examples/pyrex/trailstats/ringbufnan.c
    trunk/py4science/examples/pyrex/trailstats/setup.py

Modified: trunk/py4science/examples/pyrex/trailstats/c_ringbuf.pxi
===================================================================
--- trunk/py4science/examples/pyrex/trailstats/c_ringbuf.pxi    2008-12-19 
12:40:09 UTC (rev 6682)
+++ trunk/py4science/examples/pyrex/trailstats/c_ringbuf.pxi    2008-12-19 
19:31:23 UTC (rev 6683)
@@ -18,6 +18,7 @@
    double ringbuf_min(ringbuf_t *rb_ptr)
    double ringbuf_max(ringbuf_t *rb_ptr)
    double ringbuf_median(ringbuf_t *rb_ptr)
+   double ringbuf_ptile(ringbuf_t *rb_ptr, double x)
    int    ringbuf_N_good(ringbuf_t *rb_ptr)
    int    ringbuf_N_added(ringbuf_t *rb_ptr)
    int    ringbuf_N_filled(ringbuf_t *rb_ptr)
@@ -28,8 +29,12 @@
                                             double *dstd,
                                             double *dmin,
                                             double *dmax,
-                                            double *dmed, int *ng)
+                                           double *dmed, 
+                                            double *dptile5, 
+                                            double *dptile95,  
+                                            int *ng)
    void c_runstats2(int nrb, int nd, int step, int ofs,
                  double *data, double *dmean, double *dstd,
-                 double *dmin, double *dmax, double *dmed, int *ng)
+                 double *dmin, double *dmax, double *dmed, double *dptile5, 
+                                            double *dptile95, int *ng)
 

Modified: trunk/py4science/examples/pyrex/trailstats/movavg_fast.py
===================================================================
--- trunk/py4science/examples/pyrex/trailstats/movavg_fast.py   2008-12-19 
12:40:09 UTC (rev 6682)
+++ trunk/py4science/examples/pyrex/trailstats/movavg_fast.py   2008-12-19 
19:31:23 UTC (rev 6683)
@@ -5,10 +5,10 @@
 import ringbuf
 
 x = numpy.random.rand(10000)
-dmean, dstd, dmin, dmax, dmedian, ng = ringbuf.runstats(x, 30)
+dmean, dstd, dmin, dmax, dmedian, ptile5, ptile95, ng = ringbuf.runstats(x, 30)
 
 r = numpy.rec.fromarrays([dmean, dstd, dmin, dmax, dmedian, ng],
-                         names='dmean,dstd,dmin,dmax,dmedian,ngood')
+                         
names='dmean,dstd,dmin,dmax,dmedian,ptile5,ptile95,ngood')
 
 
 

Modified: trunk/py4science/examples/pyrex/trailstats/ringbuf.h
===================================================================
--- trunk/py4science/examples/pyrex/trailstats/ringbuf.h        2008-12-19 
12:40:09 UTC (rev 6682)
+++ trunk/py4science/examples/pyrex/trailstats/ringbuf.h        2008-12-19 
19:31:23 UTC (rev 6683)
@@ -25,6 +25,7 @@
 double ringbuf_min(ringbuf_t *rb_ptr);
 double ringbuf_max(ringbuf_t *rb_ptr);
 double ringbuf_median(ringbuf_t *rb_ptr);
+double ringbuf_ptile(ringbuf_t *rb_ptr, double val);
 int ringbuf_N_added(ringbuf_t *rb_ptr);
 int ringbuf_N_filled(ringbuf_t *rb_ptr);
 int ringbuf_N_good(ringbuf_t *rb_ptr);
@@ -32,10 +33,10 @@
 double ringbuf_sd(ringbuf_t *rb_ptr);
 
 void c_runstats(int nrb, int nd, double *data, double *dmean, double *dstd,
-                double *dmin, double *dmax, double *dmed, int *ng);
+                double *dmin, double *dmax, double *dmed, double *dptile5, 
double *dptile95, int *ng);
 void c_runstats2(int nrb, int nd, int step, int ofs,
                  double *data, double *dmean, double *dstd,
-                 double *dmin, double *dmax, double *dmed, int *ng);
+                 double *dmin, double *dmax, double *dmed, double *dptile5, 
double *dptile95, int *ng);
 
 
 

Modified: trunk/py4science/examples/pyrex/trailstats/ringbuf.pyx
===================================================================
--- trunk/py4science/examples/pyrex/trailstats/ringbuf.pyx      2008-12-19 
12:40:09 UTC (rev 6682)
+++ trunk/py4science/examples/pyrex/trailstats/ringbuf.pyx      2008-12-19 
19:31:23 UTC (rev 6683)
@@ -14,7 +14,7 @@
 cdef class Ringbuf:
    cdef ringbuf_t *rb_ptr
 
-   def __new__(self, N):
+   def __cinit__(self, N):
       self.rb_ptr = new_ringbuf(N)
 
    def __dealloc__(self):
@@ -55,6 +55,9 @@
    def median(self):
       return ringbuf_median(self.rb_ptr)
 
+   def ptile(self, x):
+      return ringbuf_ptile(self.rb_ptr, x)
+
    def N_added(self):
       return ringbuf_N_added(self.rb_ptr)
 
@@ -73,7 +76,7 @@
 
    cdef object records
 
-   def __new__(self, N):
+   def __cinit__(self, N):
       self.rb_ptr = new_ringbuf(N)
       self.records = []
 
@@ -122,6 +125,9 @@
    def median(self):
       return ringbuf_median(self.rb_ptr)
 
+   def ptile(self, x):
+      return ringbuf_ptile(self.rb_ptr, x)
+
    def N_added(self):
       return ringbuf_N_added(self.rb_ptr)
 
@@ -160,6 +166,8 @@
     cdef c_numpy.ndarray c_dmin
     cdef c_numpy.ndarray c_dmax
     cdef c_numpy.ndarray c_dmedian
+    cdef c_numpy.ndarray c_dptile5
+    cdef c_numpy.ndarray c_dptile95
     cdef c_numpy.ndarray c_ng
 
     # make sure that the input array is a 1D numpy array of floats.
@@ -181,6 +189,8 @@
     dmin = numpy.empty_like(data)
     dmax = numpy.empty_like(data)
     dmedian = numpy.empty_like(data)
+    dptile5 = numpy.empty_like(data)
+    dptile95 = numpy.empty_like(data)
     ng = numpy.empty(data.shape, dtype=numpy.int_)
 
     # now we have to assign the c_data structures and friends to their
@@ -191,6 +201,8 @@
     c_dmin = dmin
     c_dmax = dmax
     c_dmedian = dmedian
+    c_dptile5 = dptile5
+    c_dptile95 = dptile95
     c_ng = ng
 
     # now we call the function and pass in the c data pointers to the
@@ -202,7 +214,9 @@
                         <double *>c_dmin.data,
                         <double *>c_dmax.data,
                         <double *>c_dmedian.data,
+                        <double *>c_dptile5.data,
+                        <double *>c_dptile95.data,
                         <int *>c_ng.data)
 
     # all done, return the arrays
-    return dmean, dstd, dmin, dmax, dmedian, ng
+    return dmean, dstd, dmin, dmax, dmedian, dptile5, dptile95, ng

Modified: trunk/py4science/examples/pyrex/trailstats/ringbufnan.c
===================================================================
--- trunk/py4science/examples/pyrex/trailstats/ringbufnan.c     2008-12-19 
12:40:09 UTC (rev 6682)
+++ trunk/py4science/examples/pyrex/trailstats/ringbufnan.c     2008-12-19 
19:31:23 UTC (rev 6683)
@@ -121,7 +121,7 @@
    d_old = rb_ptr->data[rb_ptr->i_oldest];
    rb_ptr->data[i_new] = d;
    good_new = !isnan(d);
-#if 0
+#if 1
    printf("new value: %lf  good_new: %d\n", d, good_new);
    printf("i_next: %d i_oldest: %d N_filled: %d N_good: %d\n",
             rb_ptr->i_next, rb_ptr->i_oldest,
@@ -183,7 +183,7 @@
    {
       resum_ringbuf(rb_ptr);
    }
-#if 0
+#if 1
    printf("i_next: %d i_oldest: %d N_filled: %d N_good: %d\n",
             rb_ptr->i_next, rb_ptr->i_oldest,
             rb_ptr->N_filled, rb_ptr->N_good);
@@ -221,13 +221,21 @@
 
 double ringbuf_min(ringbuf_t *rb_ptr)
 {
+  if (rb_ptr->N_good==0)
+    return NaN;
    return rb_ptr->data[rb_ptr->i_sorted[0]];
 }
 
 double ringbuf_max(ringbuf_t *rb_ptr)
 {
-   int i_end;
+
+  int i_end;
+
+  if (rb_ptr->N_good==0)
+    return NaN;
+
    i_end = rb_ptr->N_good - 1;
+
    return rb_ptr->data[rb_ptr->i_sorted[i_end]];
 }
 
@@ -248,6 +256,16 @@
    }
 }
 
+double ringbuf_ptile(ringbuf_t *rb_ptr, double ptile)
+{
+   int i, N;
+
+   N = rb_ptr->N_good;
+   if (N == 0) return NaN;
+   i = (int)(ptile*N);
+   return rb_ptr->data[rb_ptr->i_sorted[i]];
+}
+
 int ringbuf_N_good(ringbuf_t *rb_ptr)
 {
    return rb_ptr->N_good;
@@ -272,6 +290,7 @@
 {
    int N;
 
+
    N = rb_ptr->N_good;
    if (N > 0)
    {
@@ -286,6 +305,7 @@
 double ringbuf_sd(ringbuf_t *rb_ptr)
 {
    double m, s;
+
    int N;
 
    N = rb_ptr->N_good;
@@ -304,7 +324,7 @@
 }
 
 void c_runstats(int nrb, int nd, double *data, double *dmean, double *dstd,
-                double *dmin, double *dmax, double *dmed, int *ng)
+                double *dmin, double *dmax, double *dmed, double *dptile5, 
double *dptile95, int *ng)
 {
     int i, j;
     ringbuf_t *rb_ptr;
@@ -319,6 +339,8 @@
         dmin[j] = ringbuf_min(rb_ptr);
         dmax[j] = ringbuf_max(rb_ptr);
         dmed[j] = ringbuf_median(rb_ptr);
+        dptile5[j] = ringbuf_ptile(rb_ptr, 0.05);
+        dptile95[j] = ringbuf_ptile(rb_ptr, 0.95);
         ng[j] = rb_ptr->N_good;
     }
     delete_ringbuf(rb_ptr);
@@ -327,7 +349,8 @@
 
 void c_runstats2(int nrb, int nd, int step, int ofs,
                  double *data, double *dmean, double *dstd,
-                 double *dmin, double *dmax, double *dmed, int *ng)
+                 double *dmin, double *dmax, double *dmed, double
+*dptile5, double *dptile95, int *ng)
 {
     int i, j;
     int npad = (nrb - 1) / 2;
@@ -339,6 +362,8 @@
     dmin += ofs;
     dmax += ofs;
     dmed += ofs;
+    dptile5 += ofs;
+    dptile95 += ofs;
     ng += ofs;
 
     rb_ptr = new_ringbuf(nrb);
@@ -355,6 +380,8 @@
         dmin[j*step] = ringbuf_min(rb_ptr);
         dmax[j*step] = ringbuf_max(rb_ptr);
         dmed[j*step] = ringbuf_median(rb_ptr);
+        dptile5[j*step] = ringbuf_ptile(rb_ptr, 0.05);
+        dptile95[j*step] = ringbuf_ptile(rb_ptr, 0.95);
         ng[j*step] = rb_ptr->N_good;
     }
     delete_ringbuf(rb_ptr);

Modified: trunk/py4science/examples/pyrex/trailstats/setup.py
===================================================================
--- trunk/py4science/examples/pyrex/trailstats/setup.py 2008-12-19 12:40:09 UTC 
(rev 6682)
+++ trunk/py4science/examples/pyrex/trailstats/setup.py 2008-12-19 19:31:23 UTC 
(rev 6683)
@@ -4,11 +4,8 @@
 
 # Make this usable by people who don't have pyrex installed (I've committed
 # the generated C sources to SVN).
-try:
-    from Pyrex.Distutils import build_ext
-    has_pyrex = True
-except ImportError:
-    has_pyrex = False
+from Cython.Distutils import build_ext
+has_pyrex = True
 
 import numpy
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to