[Python-checkins] python/nondist/sandbox/twister test_twister.py,1.2,1.3 MersenneTwister.c,1.3,1.4 random.py,1.4,1.5

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Wed, 18 Dec 2002 12:36:04 -0800


Update of /cvsroot/python/python/nondist/sandbox/twister
In directory sc8-pr-cvs1:/tmp/cvs-serv17592

Modified Files:
	test_twister.py MersenneTwister.c random.py 
Log Message:
Eliminated jumpahead() method for MersenneTwister.  It should be
considered specific to generators that support direct computation
of state sequences.


Index: test_twister.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/test_twister.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_twister.py	18 Dec 2002 18:02:11 -0000	1.2
--- test_twister.py	18 Dec 2002 20:36:01 -0000	1.3
***************
*** 55,73 ****
              self.assertEqual(round(a-e, 14), 0)
  
-     def test_jumpahead(self):
-         ## For the MersenneTwister, there is no exact analog to jumpahead(n)
-         ## where n represents a discrete number of forward steps.  The use case
-         ## for jumpahead is to create a non-overlapping sequence.  Here, we test
-         ## that jumpahead(n) at least generates a different sequence from
-         ## the original and on successive calls.  
-         N = 500000
-         a = self.gen.random()
-         self.gen.jumpahead(N)
-         b = self.gen.random()
-         self.assertNotEqual(a, b)
-         self.gen.jumpahead(N)
-         c = self.gen.random()
-         self.assertNotEqual(b, c)
-         
  def test_main():
      suite = unittest.TestSuite()
--- 55,58 ----

Index: MersenneTwister.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/MersenneTwister.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MersenneTwister.c	18 Dec 2002 19:21:08 -0000	1.3
--- MersenneTwister.c	18 Dec 2002 20:36:01 -0000	1.4
***************
*** 310,334 ****
  }
  
- #define SLICESIZE 6
- 
- static PyObject *
- random_jumpahead(RandomObject *self, PyObject *spinvalue)
- {
- 	unsigned long init_key[SLICESIZE];
- 	unsigned long spin;
- 	int i;
- 
- 	spin = PyInt_AsLong(spinvalue);
- 	if (spin == -1 && PyErr_Occurred())
- 		return NULL;
- 
- 	for (i=0 ; i<SLICESIZE ; i++)
- 		init_key[i] = self->state[i];
- 	init_key[0] ^= spin;
- 	init_key[1] ^= spin + 0x123;
- 
- 	return init_by_array(self, init_key, SLICESIZE);
- }
- 
  static PyMethodDef random_methods[] = {
  	{"random",      (PyCFunction)random_random,  METH_NOARGS,
--- 310,313 ----
***************
*** 342,348 ****
  	{"setstate",      (PyCFunction)random_setstate,  METH_O,
  		PyDoc_STR("setstate(state) -> None.  Restores generator state.")},
- 	{"jumpahead",   (PyCFunction)random_jumpahead,  METH_O,
- 		PyDoc_STR("jumpahead(int) -> None.  Create a new state from\n\
- the existing state and the supplied integer.")},
  	{NULL,          NULL}           /* sentinel */
  };
--- 321,324 ----

Index: random.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/random.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** random.py	18 Dec 2002 19:00:00 -0000	1.4
--- random.py	18 Dec 2002 20:36:01 -0000	1.5
***************
*** 139,143 ****
              self._setstate = geninstance.setstate
              self._randbelow = geninstance._randbelow
-             self.jumpahead = geninstance.jumpahead
          self.gauss_next = None
          self.seed(*seeds)
--- 139,142 ----
***************
*** 172,175 ****
--- 171,175 ----
  
      def _randbelow(self, n, int=int):
+         """Internal helper method returns an integer in the range [0,n)."""
          return int(self.random() * n)
  
***************
*** 886,891 ****
  getstate = _inst.getstate
  setstate = _inst.setstate
- jumpahead = _inst.jumpahead
  try:
      whseed = _inst.whseed
  except AttributeError:
--- 886,891 ----
  getstate = _inst.getstate
  setstate = _inst.setstate
  try:
+     jumpahead = _inst.jumpahead
      whseed = _inst.whseed
  except AttributeError: