提交 fe11af02 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Minor changes in documentation formatting, comment debug prints.

上级 c5204d53
...@@ -106,32 +106,36 @@ class RandomFunction(gof.Op): ...@@ -106,32 +106,36 @@ class RandomFunction(gof.Op):
def make_node(self, r, shape, *args): def make_node(self, r, shape, *args):
""" """
:param r: a numpy.RandomState instance, or a Variable of Type RandomStateType that will :param r: a numpy.RandomState instance, or a Variable of Type
contain a RandomState instance. RandomStateType that will contain a RandomState instance.
:param shape: an lvector with a shape defining how many samples to draw. :param shape: an lvector with a shape defining how many samples
In the case of scalar distributions, it is the shape of the tensor output by this Op. to draw. In the case of scalar distributions, it is the shape
In that case, at runtime, the value associated with this lvector must have a length of the tensor output by this Op. In that case, at runtime, the
equal to the number of dimensions promised by `self.outtype`. value associated with this lvector must have a length equal to
In general, the number of output dimenstions is equal to the number of dimensions promised by `self.outtype`.
len(self.outtype)+self.ndim_added. In a more general case, the number of output dimensions,
len(self.outtype), is equal to len(shape)+self.ndim_added.
:param args: the values associated with these variables will be passed to the RandomState The special case where len(shape) == 0 means that the smallest
function during perform as extra "*args"-style arguments. These should be castable to shape compatible with the argument's shape will be used.
variables of Type TensorType.
:param args: the values associated with these variables will
be passed to the RandomState function during perform as extra
"*args"-style arguments. These should be castable to variables
of Type TensorType.
:rtype: Apply :rtype: Apply
:return: Apply with two outputs. The first output is a gof.generic Variable from which :return: Apply with two outputs. The first output is a
to draw further random numbers. The second output is the outtype() instance holding gof.generic Variable from which to draw further random numbers.
the random draw. The second output is the outtype() instance holding the random
draw.
""" """
if shape == () or shape == []: if shape == () or shape == []:
shape = tensor.lvector() shape = tensor.lvector()
else: else:
shape = tensor.as_tensor_variable(shape, ndim=1) shape = tensor.as_tensor_variable(shape, ndim=1)
#print 'SHAPE TYPE', shape.type, tensor.lvector
assert shape.type.ndim == 1 assert shape.type.ndim == 1
assert (shape.type.dtype == 'int64') or (shape.type.dtype == 'int32') assert (shape.type.dtype == 'int64') or (shape.type.dtype == 'int32')
if not isinstance(r.type, RandomStateType): if not isinstance(r.type, RandomStateType):
...@@ -211,7 +215,7 @@ def _infer_ndim(ndim, shape, *args): ...@@ -211,7 +215,7 @@ def _infer_ndim(ndim, shape, *args):
# The shape will be computed at runtime, but we need to know ndim # The shape will be computed at runtime, but we need to know ndim
v_shape = tensor.constant([], dtype='int64') v_shape = tensor.constant([], dtype='int64')
if ndim is None: if ndim is None:
ndim = args_dim ndim = args_ndim
else: else:
v_shape = tensor.as_tensor_variable(shape) v_shape = tensor.as_tensor_variable(shape)
...@@ -316,7 +320,7 @@ def permutation_helper(random_state, n, shape): ...@@ -316,7 +320,7 @@ def permutation_helper(random_state, n, shape):
for i in numpy.ndindex(*shape): for i in numpy.ndindex(*shape):
out[i] = random_state.permutation(n) out[i] = random_state.permutation(n)
print 'RETURNING', out.shape #print 'RETURNING', out.shape
return out return out
def permutation(random_state, size=None, n=1, ndim=None): def permutation(random_state, size=None, n=1, ndim=None):
...@@ -333,7 +337,7 @@ def permutation(random_state, size=None, n=1, ndim=None): ...@@ -333,7 +337,7 @@ def permutation(random_state, size=None, n=1, ndim=None):
Note that the output will then be of dimension ndim+1. Note that the output will then be of dimension ndim+1.
""" """
ndim, size = _infer_ndim(ndim, size) ndim, size = _infer_ndim(ndim, size)
print "NDIM", ndim, size #print "NDIM", ndim, size
op = RandomFunction(permutation_helper, op = RandomFunction(permutation_helper,
tensor.TensorType(dtype='int64', broadcastable=(False,)*(ndim+1)), tensor.TensorType(dtype='int64', broadcastable=(False,)*(ndim+1)),
ndim_added=1) ndim_added=1)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论