[Numpy-svn] r4494 - in trunk/numpy/random: mtrand tests

numpy-svn@scip... numpy-svn@scip...
Fri Nov 23 09:21:21 CST 2007


Author: stefan
Date: 2007-11-23 09:20:41 -0600 (Fri, 23 Nov 2007)
New Revision: 4494

Modified:
   trunk/numpy/random/mtrand/mtrand.c
   trunk/numpy/random/mtrand/mtrand.pyx
   trunk/numpy/random/tests/test_random.py
Log:
Fix randint for negative interval.


Modified: trunk/numpy/random/mtrand/mtrand.c
===================================================================
--- trunk/numpy/random/mtrand/mtrand.c	2007-11-23 14:53:33 UTC (rev 4493)
+++ trunk/numpy/random/mtrand/mtrand.c	2007-11-23 15:20:41 UTC (rev 4494)
@@ -1,4 +1,4 @@
-/* Generated by Pyrex 0.9.5.1a on Wed Aug 29 00:25:24 2007 */
+/* Generated by Pyrex 0.9.5.1a on Fri Nov 23 17:16:35 2007 */
 
 #include "Python.h"
 #include "structmember.h"
@@ -2438,7 +2438,7 @@
   if (__pyx_1) {
 
     /* "/home/stefan/work/scipy/numpy.patch/numpy/random/mtrand/mtrand.pyx":603 */
-    __pyx_3 = PyLong_FromUnsignedLong((rk_interval(__pyx_v_diff,((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state) + __pyx_v_lo)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; goto __pyx_L1;}
+    __pyx_3 = PyInt_FromLong((((long )rk_interval(__pyx_v_diff,((struct __pyx_obj_6mtrand_RandomState *)__pyx_v_self)->internal_state)) + __pyx_v_lo)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 603; goto __pyx_L1;}
     __pyx_r = __pyx_3;
     __pyx_3 = 0;
     goto __pyx_L0;

Modified: trunk/numpy/random/mtrand/mtrand.pyx
===================================================================
--- trunk/numpy/random/mtrand/mtrand.pyx	2007-11-23 14:53:33 UTC (rev 4493)
+++ trunk/numpy/random/mtrand/mtrand.pyx	2007-11-23 15:20:41 UTC (rev 4494)
@@ -598,9 +598,9 @@
         diff = hi - lo - 1
         if diff < 0:
             raise ValueError("low >= high")
-    
+
         if size is None:
-            return rk_interval(diff, self.internal_state) + lo
+            return <long>rk_interval(diff, self.internal_state) + lo
         else:
             array = <ndarray>_sp.empty(size, int)
             length = PyArray_SIZE(array)

Modified: trunk/numpy/random/tests/test_random.py
===================================================================
--- trunk/numpy/random/tests/test_random.py	2007-11-23 14:53:33 UTC (rev 4493)
+++ trunk/numpy/random/tests/test_random.py	2007-11-23 15:20:41 UTC (rev 4494)
@@ -9,5 +9,11 @@
     def test_zero_probability(self):
         random.multinomial(100, [0.2, 0.8, 0.0, 0.0, 0.0])
 
+    def test_int_negative_interval(self):
+        assert -5 <= random.randint(-5,-1) < -1
+        x = random.randint(-5,-1,5)
+        assert N.all(-5 <= x)
+        assert N.all(x < -1)
+
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list