Skip to content

Commit

Permalink
Automated rollback of change 138583261
Browse files Browse the repository at this point in the history
Change: 139651838
  • Loading branch information
Jonathan Hseu authored and tensorflower-gardener committed Nov 19, 2016
1 parent ed0dc84 commit 3866dd2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 43 deletions.
2 changes: 0 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ BUS_ANY was used.
* The C API type `TF_SessionWithGraph` has been renamed to `TF_Session`,
indicating its preferred use in language bindings for TensorFlow.
What was previously `TF_Session` has been renamed to `TF_DeprecatedSession`.
* Renamed Tensor to Output in the Python API. Tensor will be an alias for Output
until TensorFlow 2.0 is released.
* Renamed TF_Port to TF_Output in the C API.

# Release 0.11.0
Expand Down
8 changes: 4 additions & 4 deletions tensorflow/contrib/labeled_tensor/python/ops/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class LabeledTensor(object):
axes: lt.Axes containing axis names and coordinate labels.
"""

@tc.accepts(object, ops.Output,
@tc.accepts(object, ops.Tensor,
tc.Union(Axes, tc.Collection(tc.Union(string_types, AxisLike))))
def __init__(self, tensor, axes):
"""Construct a LabeledTenor.
Expand Down Expand Up @@ -489,15 +489,15 @@ def __hash__(self):
# typecheck type abbreviations:
# abbreviations for third-party types with very long reprs
tc.register_type_abbreviation(tensor_shape.Dimension, 'tensorflow.Dimension')
tc.register_type_abbreviation(ops.Output, 'tensorflow.Output')
tc.register_type_abbreviation(ops.Tensor, 'tensorflow.Tensor')
tc.register_type_abbreviation(dtypes.DType, 'tensorflow.DType')
# core LabeledTensor types
tc.register_type_abbreviation(Axis, 'labeled_tensor.Axis')
tc.register_type_abbreviation(Axes, 'labeled_tensor.Axes')
tc.register_type_abbreviation(LabeledTensor, 'labeled_tensor.LabeledTensor')


@tc.returns(ops.Output)
@tc.returns(ops.Tensor)
@tc.accepts(LabeledTensor)
def _convert_labeled_tensor_to_tensor(value, *args, **kwargs):
# call ops.convert_to_tensor to handle optional arguments appropriately
Expand All @@ -510,7 +510,7 @@ def _convert_labeled_tensor_to_tensor(value, *args, **kwargs):

# tc class for anything that can be coerced into a LabeledTensor
# pylint: disable=invalid-name
LabeledTensorLike = tc.Union(LabeledTensor, ops.Output, np.ndarray, Scalar)
LabeledTensorLike = tc.Union(LabeledTensor, ops.Tensor, np.ndarray, Scalar)
# pylint: enable=invalid-name


Expand Down
2 changes: 1 addition & 1 deletion tensorflow/contrib/labeled_tensor/python/ops/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


@tc.returns(core.LabeledTensor)
@tc.accepts(core.LabeledTensor, ops.Output, core.Axis,
@tc.accepts(core.LabeledTensor, ops.Tensor, core.Axis,
tc.Optional(string_types))
def _gather_1d_on_axis(labeled_tensor, indexer, axis, name=None):
with ops.name_scope(name, 'lt_take', [labeled_tensor]) as scope:
Expand Down
2 changes: 0 additions & 2 deletions tensorflow/python/framework/framework_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@@Graph
@@Operation
@@Output
@@Tensor
## Tensor types
Expand Down Expand Up @@ -74,7 +73,6 @@
from tensorflow.python.framework.ops import Graph
from tensorflow.python.framework.ops import Operation
from tensorflow.python.framework.ops import Tensor
from tensorflow.python.framework.ops import Output
from tensorflow.python.framework.ops import IndexedSlices

from tensorflow.python.framework.sparse_tensor import SparseTensor
Expand Down
51 changes: 24 additions & 27 deletions tensorflow/python/framework/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,28 +193,28 @@ class _TensorLike(object):
pass


class Output(_TensorLike):
class Tensor(_TensorLike):
"""Represents one of the outputs of an `Operation`.
An `Output` is a symbolic handle to one of the outputs of an
A `Tensor` is a symbolic handle to one of the outputs of an
`Operation`. It does not hold the values of that operation's output,
but instead provides a means of computing those values in a
TensorFlow [`Session`](../../api_docs/python/client.md#Session).
This class has two primary purposes:
1. An `Output` can be passed as an input to another `Operation`.
1. A `Tensor` can be passed as an input to another `Operation`.
This builds a dataflow connection between operations, which
enables TensorFlow to execute an entire `Graph` that represents a
large, multi-step computation.
2. After the graph has been launched in a session, the value of the
`Output` can be computed by passing it to
`Tensor` can be computed by passing it to
[`Session.run()`](../../api_docs/python/client.md#Session.run).
`t.eval()` is a shortcut for calling
`tf.get_default_session().run(t)`.
In the following example, `c`, `d`, and `e` are symbolic `Output`
In the following example, `c`, `d`, and `e` are symbolic `Tensor`
objects, whereas `result` is a numpy array that stores a concrete
value:
Expand Down Expand Up @@ -282,7 +282,7 @@ class Output(_TensorLike):
}

def __init__(self, op, value_index, dtype):
"""Creates a new `Output`.
"""Creates a new `Tensor`.
Args:
op: An `Operation`. `Operation` that computes this tensor.
Expand All @@ -299,7 +299,7 @@ def __init__(self, op, value_index, dtype):
self._value_index = value_index
self._dtype = dtypes.as_dtype(dtype)
self._shape = tensor_shape.unknown_shape()
# List of operations that use this Output as input. We maintain this list
# List of operations that use this Tensor as input. We maintain this list
# to easily navigate a computation graph.
self._consumers = []

Expand Down Expand Up @@ -376,7 +376,7 @@ def get_shape(self):
In some cases, the inferred shape may have unknown dimensions. If
the caller has additional information about the values of these
dimensions, `Output.set_shape()` can be used to augment the
dimensions, `Tensor.set_shape()` can be used to augment the
inferred shape.
Returns:
Expand Down Expand Up @@ -448,10 +448,10 @@ def _as_node_def_input(self):
"""Return a value to use for the NodeDef "input" attribute.
The returned string can be used in a NodeDef "input" attribute
to indicate that the NodeDef uses this Output as input.
to indicate that the NodeDef uses this Tensor as input.
Raises:
ValueError: if this Output's Operation does not have a name.
ValueError: if this Tensor's Operation does not have a name.
Returns:
a string.
Expand All @@ -464,15 +464,15 @@ def _as_node_def_input(self):
return "%s:%d" % (self._op.name, self._value_index)

def __str__(self):
return "Output(\"%s\"%s%s%s)" % (
return "Tensor(\"%s\"%s%s%s)" % (
self.name,
(", shape=%s" % self.get_shape())
if self.get_shape().ndims is not None else "",
(", dtype=%s" % self._dtype.name) if self._dtype else "",
(", device=%s" % self.device) if self.device else "")

def __repr__(self):
return "<tf.Output '%s' shape=%s dtype=%s>" % (
return "<tf.Tensor '%s' shape=%s dtype=%s>" % (
self.name, self.get_shape(), self._dtype.name)

def __hash__(self):
Expand All @@ -483,37 +483,37 @@ def __eq__(self, other):
# Necessary to support Python's collection membership operators
return id(self) == id(other)

# NOTE(mrry): This enables the Output's overloaded "right" binary
# NOTE(mrry): This enables the Tensor's overloaded "right" binary
# operators to run when the left operand is an ndarray, because it
# accords the Output class higher priority than an ndarray, or a
# accords the Tensor class higher priority than an ndarray, or a
# numpy matrix.
# TODO(mrry): Convert this to using numpy's __numpy_ufunc__
# mechanism, which allows more control over how Outputs interact
# mechanism, which allows more control over how Tensors interact
# with ndarrays.
__array_priority__ = 100

@staticmethod
def _override_operator(operator, func):
_override_helper(Output, operator, func)
_override_helper(Tensor, operator, func)

def __iter__(self):
"""Dummy method to prevent iteration. Do not call.
NOTE(mrry): If we register __getitem__ as an overloaded operator,
Python will valiantly attempt to iterate over the Output from 0 to
Python will valiantly attempt to iterate over the Tensor from 0 to
infinity. Declaring this method prevents this unintended
behavior.
Raises:
TypeError: when invoked.
"""
raise TypeError("'Output' object is not iterable.")
raise TypeError("'Tensor' object is not iterable.")

def __bool__(self):
"""Dummy method to prevent a tensor from being used as a Python `bool`.
This overload raises a `TypeError` when the user inadvertently
treats an `Output` as a boolean (e.g. in an `if` statement). For
treats a `Tensor` as a boolean (e.g. in an `if` statement). For
example:
```python
Expand All @@ -525,12 +525,12 @@ def __bool__(self):
```
This disallows ambiguities between testing the Python value vs testing the
dynamic condition of the `Output`.
dynamic condition of the `Tensor`.
Raises:
`TypeError`.
"""
raise TypeError("Using a `tf.Output` as a Python `bool` is not allowed. "
raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "
"Use `if t is not None:` instead of `if t:` to test if a "
"tensor is defined, and use TensorFlow ops such as "
"tf.cond to execute subgraphs conditioned on the value of "
Expand All @@ -544,7 +544,7 @@ def __nonzero__(self):
Raises:
`TypeError`.
"""
raise TypeError("Using a `tf.Output` as a Python `bool` is not allowed. "
raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. "
"Use `if t is not None:` instead of `if t:` to test if a "
"tensor is defined, and use TensorFlow ops such as "
"tf.cond to execute subgraphs conditioned on the value of "
Expand All @@ -557,12 +557,12 @@ def eval(self, feed_dict=None, session=None):
produce the inputs needed for the operation that produces this
tensor.
*N.B.* Before invoking `Output.eval()`, its graph must have been
*N.B.* Before invoking `Tensor.eval()`, its graph must have been
launched in a session, and either a default session must be
available, or `session` must be specified explicitly.
Args:
feed_dict: A dictionary that maps `Output` objects to feed values.
feed_dict: A dictionary that maps `Tensor` objects to feed values.
See [`Session.run()`](../../api_docs/python/client.md#Session.run) for a
description of the valid feed values.
session: (Optional.) The `Session` to be used to evaluate this tensor. If
Expand All @@ -575,9 +575,6 @@ def eval(self, feed_dict=None, session=None):
return _eval_using_default_session(self, feed_dict, self.graph, session)


Tensor = Output


def _TensorTensorConversionFunction(t, dtype=None, name=None, as_ref=False):
_ = name, as_ref
if dtype and not dtype.is_compatible_with(t.dtype):
Expand Down
12 changes: 6 additions & 6 deletions tensorflow/python/kernel_tests/constant_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,16 +596,16 @@ def testBadShape(self):

def testTensorStr(self):
a = tf.placeholder(tf.float32, name="a")
self.assertEqual("<tf.Output 'a:0' shape=<unknown> dtype=float32>", repr(a))
self.assertEqual("<tf.Tensor 'a:0' shape=<unknown> dtype=float32>", repr(a))

b = tf.placeholder(tf.int32, shape=(32, 40), name="b")
self.assertEqual(
"<tf.Output 'b:0' shape=(32, 40) dtype=int32>",
"<tf.Tensor 'b:0' shape=(32, 40) dtype=int32>",
repr(b))

c = tf.placeholder(tf.qint32, shape=(32, None, 2), name="c")
self.assertEqual(
"<tf.Output 'c:0' shape=(32, ?, 2) dtype=qint32>",
"<tf.Tensor 'c:0' shape=(32, ?, 2) dtype=qint32>",
repr(c))


Expand Down Expand Up @@ -695,13 +695,13 @@ def testBadShape(self):

def testTensorStr(self):
a = array_ops.placeholder_v2(tf.float32, shape=None, name="a")
self.assertEqual("<tf.Output 'a:0' shape=<unknown> dtype=float32>", repr(a))
self.assertEqual("<tf.Tensor 'a:0' shape=<unknown> dtype=float32>", repr(a))

b = array_ops.placeholder_v2(tf.int32, shape=(32, 40), name="b")
self.assertEqual("<tf.Output 'b:0' shape=(32, 40) dtype=int32>", repr(b))
self.assertEqual("<tf.Tensor 'b:0' shape=(32, 40) dtype=int32>", repr(b))

c = array_ops.placeholder_v2(tf.qint32, shape=(32, None, 2), name="c")
self.assertEqual("<tf.Output 'c:0' shape=(32, ?, 2) dtype=qint32>", repr(c))
self.assertEqual("<tf.Tensor 'c:0' shape=(32, ?, 2) dtype=qint32>", repr(c))


class PlaceholderWithDefaultTest(tf.test.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/python/kernel_tests/slice_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def testNotIterable(self):
c = tf.constant(5.0)
with self.assertRaisesWithPredicateMatch(
TypeError,
lambda e: "'Output' object is not iterable" in str(e)):
lambda e: "'Tensor' object is not iterable" in str(e)):
for _ in c:
pass

Expand Down

0 comments on commit 3866dd2

Please sign in to comment.