Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1760 from scottpurdy/remove-unused-stdrandom
Browse files Browse the repository at this point in the history
Removes StdRandom class that was defined in math.i but never used.
  • Loading branch information
scottpurdy committed Jan 17, 2015
2 parents ef487eb + 0363b0b commit 2bddf7d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
16 changes: 0 additions & 16 deletions nupic/bindings/math.i
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,3 @@ inline PyObject* shuffle(PyObject* obj)
}

} // End extend nupic::Random.

%pythoncode %{
import random
class StdRandom(random.Random):
"""An adapter for nupic::Random that allows use of inherited samplers
from the Python standard library 'random' module."""
def __init__(self, *args, **keywords):
self.rgen = Random(*args, **keywords)
def random(self): return self.rgen.getReal64()
def setstate(self, state): self.rgen.setState(state)
def getstate(self): return self.rgen.getState()
def jumpahead(self, n): self.rgen.jumpAhead(n)
def seed(self, seed=None):
if seed is None: self.rgen.setSeed(0)
else: self.rgen.setSeed(seed)
%}
23 changes: 1 addition & 22 deletions tests/unit/nupic/math/nupic_random_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import numpy

from nupic.bindings.math import Random, StdRandom
from nupic.bindings.math import Random



Expand Down Expand Up @@ -66,27 +66,6 @@ def testNupicRandomPickling(self):
"NuPIC random gave the same result twice?!?")


def testStdRandomStateFunctions(self):
"""Test the NuPIC StdRandom to make sure getstate / setstate works."""
sr = StdRandom(43)

srState = sr.getstate()
r1 = sr.random()
r2 = sr.random()
sr.setstate(srState)

self.assertEqual(sr.random(), r1)
self.assertEqual(sr.random(), r2)

srState = sr.getstate()
r1 = sr.random()
r2 = sr.random()
sr.setstate(srState)

self.assertEqual(sr.random(), r1)
self.assertEqual(sr.random(), r2)


def testSample(self):
r = Random(42)
population = numpy.array([1, 2, 3, 4], dtype="uint32")
Expand Down

0 comments on commit 2bddf7d

Please sign in to comment.