提交 ead9e37d authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Split apart broadcast_shape so that it can work with many arguments

If we use Python varargs, we're limited in the number of arrays/shapes that can be processed/given. Now, there's a `broadcast_shape_iter` that takes a collection of arrays/shapes and doesn't face this restriction.
上级 61506810
...@@ -1462,14 +1462,33 @@ def broadcast_shape(*arrays, **kwargs): ...@@ -1462,14 +1462,33 @@ def broadcast_shape(*arrays, **kwargs):
Parameters Parameters
---------- ----------
*arrays: Tuple[TensorVariable] or Tuple[Tuple[Variable]] *arrays: `TensorVariable`s
A tuple of tensors, or a tuple of shapes (as tuples), The tensor variables, or their shapes (as tuples),
for which the broadcast shape is computed. for which the broadcast shape is computed.
arrays_are_shapes: bool (Optional) arrays_are_shapes: bool (Optional)
Indicates whether or not the `arrays` contains shape tuples. Indicates whether or not the `arrays` contains shape tuples.
If you use this approach, make sure that the broadcastable dimensions If you use this approach, make sure that the broadcastable dimensions
are (scalar) constants with the value `1` or `1` exactly. are (scalar) constants with the value `1` or `1` exactly.
"""
return broadcast_shape_iter(arrays, **kwargs)
def broadcast_shape_iter(arrays, **kwargs):
"""Compute the shape resulting from broadcasting arrays.
Parameters
----------
arrays: Iterable[TensorVariable] or Iterable[Tuple[Variable]]
An iterable of tensors, or a tuple of shapes (as tuples),
for which the broadcast shape is computed.
XXX: Do not call this with a generator/iterator; this function will not
make copies!
arrays_are_shapes: bool (Optional)
Indicates whether or not the `arrays` contains shape tuples.
If you use this approach, make sure that the broadcastable dimensions
are (scalar) constants with the value `1` or `1` exactly.
""" """
one = theano.scalar.ScalarConstant(theano.scalar.int64, 1) one = theano.scalar.ScalarConstant(theano.scalar.int64, 1)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论