Note: Functions taking Tensor
arguments can also take anything accepted by
tf.convert_to_tensor
.
- Control Flow Operations
- Logical Operators
- Comparison Operators
- Debugging Operations
tf.is_finite(x, name=None)
tf.is_inf(x, name=None)
tf.is_nan(x, name=None)
tf.verify_tensor_all_finite(t, msg, name=None)
tf.check_numerics(tensor, message, name=None)
tf.add_check_numerics_ops()
tf.Assert(condition, data, summarize=None, name=None)
tf.Print(input_, data, message=None, first_n=None, summarize=None, name=None)
TensorFlow provides several operations and classes that you can use to control the execution of operations and add conditional dependencies to your graph.
Return a tensor with the same shape and contents as the input tensor or value.
input
: ATensor
.name
: A name for the operation (optional).
A Tensor
. Has the same type as input
.
Group tensors together.
This creates a tuple of tensors with the same values as the tensors
argument, except that the value of each tensor is only returned after the
values of all tensors have been computed.
control_inputs
contains additional ops that have to finish before this op
finishes, but whose outputs are not returned.
This can be used as a "join" mechanism for parallel computations: all the
argument tensors can be computed in parallel, but the values of any tensor
returned by tuple
are only available after all the parallel computations
are done.
See also group
and with_dependencies
.
tensors
: A list ofTensor
s orIndexedSlices
, some entries can beNone
.name
: (optional) A name to use as aname_scope
for the operation.control_inputs
: List of additional ops to finish before returning.
Same as tensors
.
ValueError
: Iftensors
does not contain anyTensor
orIndexedSlices
.
Create an op that groups multiple operations.
When this op finishes, all ops in input
have finished. This op has no
output.
See also tuple
and with_dependencies
.
*inputs
: One or more tensors to group.**kwargs
: Optional parameters to pass when constructing the NodeDef.name
: A name for this operation (optional).
An Operation that executes all its inputs.
ValueError
: If an unknown keyword argument is provided, or if there are no inputs.
Does nothing. Only useful as a placeholder for control edges.
name
: A name for the operation (optional).
The created Operation.
Increments 'ref' until it reaches 'limit'.
This operation outputs "ref" after the update is done. This makes it easier to chain operations that need to use the updated value.
ref
: A mutableTensor
. Must be one of the following types:int32
,int64
. Should be from a scalarVariable
node.limit
: Anint
. If incrementing ref would bring it above limit, instead generates an 'OutOfRange' error.name
: A name for the operation (optional).
A Tensor
. Has the same type as ref
.
A copy of the input before increment. If nothing else modifies the
input, the values produced will all be distinct.
TensorFlow provides several operations that you can use to add logical operators to your graph.
Returns the truth value of x AND y element-wise.
x
: ATensor
of typebool
.y
: ATensor
of typebool
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns the truth value of NOT x element-wise.
x
: ATensor
of typebool
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns the truth value of x OR y element-wise.
x
: ATensor
of typebool
.y
: ATensor
of typebool
.name
: A name for the operation (optional).
A Tensor
of type bool
.
x ^ y = (x | y) & ~(x & y).
TensorFlow provides several operations that you can use to add comparison operators to your graph.
Returns the truth value of (x == y) element-wise.
x
: ATensor
. Must be one of the following types:float32
,float64
,int32
,int64
,complex64
,quint8
,qint8
,qint32
.y
: ATensor
. Must have the same type asx
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns the truth value of (x != y) element-wise.
x
: ATensor
. Must be one of the following types:float32
,float64
,int32
,int64
,complex64
,quint8
,qint8
,qint32
.y
: ATensor
. Must have the same type asx
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns the truth value of (x < y) element-wise.
x
: ATensor
. Must be one of the following types:float32
,float64
,int32
,int64
.y
: ATensor
. Must have the same type asx
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns the truth value of (x <= y) element-wise.
x
: ATensor
. Must be one of the following types:float32
,float64
,int32
,int64
.y
: ATensor
. Must have the same type asx
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns the truth value of (x > y) element-wise.
x
: ATensor
. Must be one of the following types:float32
,float64
,int32
,int64
.y
: ATensor
. Must have the same type asx
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns the truth value of (x >= y) element-wise.
x
: ATensor
. Must be one of the following types:float32
,float64
,int32
,int64
.y
: ATensor
. Must have the same type asx
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Selects elements from t
or e
, depending on condition
.
The condition
, t
, and e
tensors must all have the same shape,
and the output will also have that shape. The condition
tensor acts
as an element-wise mask that chooses, based on the value at each
element, whether the corresponding element in the output should be
taken from t
(if true) or e
(if false). For example:
For example:
# 'condition' tensor is [[True, False]
# [True, False]]
# 't' is [[1, 1],
# [1, 1]]
# 'e' is [[2, 2],
# [2, 2]]
select(condition, t, e) ==> [[1, 2],
[1, 2]]
condition
: ATensor
of typebool
.t
: ATensor
with the same shape ascondition
.e
: ATensor
with the same type and shape ast
.name
: A name for the operation (optional).
A Tensor
with the same type and shape as t
and e
.
Returns locations of true values in a boolean tensor.
This operation returns the coordinates of true elements in input
. The
coordinates are returned in a 2-D tensor where the first dimension (rows)
represents the number of true elements, and the second dimension (columns)
represents the coordinates of the true elements. Keep in mind, the shape of
the output tensor can vary depending on how many true values there are in
input
. Indices are output in row-major order.
For example:
# 'input' tensor is [[True, False]
# [True, False]]
# 'input' has two true values, so output has two coordinates.
# 'input' has rank of 2, so coordinates have two indices.
where(input) ==> [[0, 0],
[1, 0]]
# `input` tensor is [[[True, False]
# [True, False]]
# [[False, True]
# [False, True]]
# [[False, False]
# [False, True]]]
# 'input' has 5 true values, so output has 5 coordinates.
# 'input' has rank of 3, so coordinates have three indices.
where(input) ==> [[0, 0, 0],
[0, 1, 0],
[1, 0, 1],
[1, 1, 1],
[2, 1, 1]]
input
: ATensor
of typebool
.name
: A name for the operation (optional).
A Tensor
of type int64
.
TensorFlow provides several operations that you can use to validate values and debug your graph.
Returns which elements of x are finite.
x
: ATensor
. Must be one of the following types:float32
,float64
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns which elements of x are Inf.
x
: ATensor
. Must be one of the following types:float32
,float64
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Returns which elements of x are NaN.
x
: ATensor
. Must be one of the following types:float32
,float64
.name
: A name for the operation (optional).
A Tensor
of type bool
.
Assert that the tensor does not contain any NaN's or Inf's.
t
: Tensor to check.msg
: Message to log on failure.name
: A name for this operation (optional).
Same tensor as t
.
Checks a tensor for NaN and Inf values.
When run, reports an InvalidArgument
error if tensor
has any values
that are not a number (NaN) or infinity (Inf). Otherwise, passes tensor
as-is.
tensor
: ATensor
. Must be one of the following types:float32
,float64
.message
: Astring
. Prefix of the error message.name
: A name for the operation (optional).
A Tensor
. Has the same type as tensor
.
Connect a check_numerics to every floating point tensor.
check_numerics
operations themselves are added for each float
or double
tensor in the graph. For all ops in the graph, the check_numerics
op for
all of its (float
or double
) inputs is guaranteed to run before the
check_numerics
op on any of its outputs.
A group
op depending on all check_numerics
ops added.
Asserts that the given condition is true.
If condition
evaluates to false, print the list of tensors in data
.
summarize
determines how many entries of the tensors to print.
condition
: The condition to evaluate.data
: The tensors to print out when condition is false.summarize
: Print this many entries of each tensor.name
: A name for this operation (optional).
Prints a list of tensors.
This is an identity op with the side effect of printing data
when
evaluating.
input_
: A tensor passed through this op.data
: A list of tensors to print out when op is evaluated.message
: A string, prefix of the error message.first_n
: Only logfirst_n
number of times. Negative numbers log always; this is the default.summarize
: Only print this many entries of each tensor.name
: A name for the operation (optional).
Same tensor as input_
.