Technically, any function with a signature like the ones in numpy.random.RandomState
Technically, any function with a signature like the ones in
will do. This function must accept the shape (sometimes called size) of the output as
numpy.random.RandomState will do. This function must accept
the last positional argument.
the shape (sometimes called size) of the output as the last
positional argument.
:type fn: string or function reference. A string will be interpreted as the name of a
:type fn: string or function reference. A string will
member function of numpy.random.RandomState.
be interpreted as the name of a member function of
numpy.random.RandomState.
:param outtype: the theano Type of the output
:param outtype: the theano Type of the output
...
@@ -96,8 +99,6 @@ class RandomFunction(gof.Op):
...
@@ -96,8 +99,6 @@ class RandomFunction(gof.Op):
self.fn=getattr(numpy.random.RandomState,fn)
self.fn=getattr(numpy.random.RandomState,fn)
else:
else:
self.fn=fn
self.fn=fn
#backport
#self.fn = getattr(numpy.random.RandomState, fn) if isinstance(fn, str) else fn
self.outtype=outtype
self.outtype=outtype
self.inplace=inplace
self.inplace=inplace
ifself.inplace:
ifself.inplace:
...
@@ -162,9 +163,10 @@ class RandomFunction(gof.Op):
...
@@ -162,9 +163,10 @@ class RandomFunction(gof.Op):
asserttype(r)==numpy.random.RandomState
asserttype(r)==numpy.random.RandomState
r_orig=r
r_orig=r
# If shape == [], that means numpy will compute the correct shape,
# If shape == [], that means no shape is enforced, and numpy is
# numpy uses shape "None" to represent that. Else, numpy expects a tuple.
# trusted to draw the appropriate number of samples, numpy uses
# TODO: compute the appropriate shape?
# shape "None" to represent that. Else, numpy expects a tuple.
# TODO: compute the appropriate shape, and pass it to numpy.
iflen(shape)==0:
iflen(shape)==0:
shape=None
shape=None
else:
else:
...
@@ -200,7 +202,6 @@ class RandomFunction(gof.Op):
...
@@ -200,7 +202,6 @@ class RandomFunction(gof.Op):
raiseValueError('Shape mismatch: "out" should have shape starting with %s (plus %i extra dimensions), but the value produced by "perform" has shape %s'\
raiseValueError('Shape mismatch: "out" should have shape starting with %s (plus %i extra dimensions), but the value produced by "perform" has shape %s'\