Type Optional
Namespace tensorflow.data.experimental
Parent PythonObjectContainer
Interfaces CompositeTensor, IOptional
Wraps a value that may/may not be present at runtime. An `Optional` can represent the result of an operation that may fail as a
value, rather than raising an exception and halting execution. For example,
tf.data.experimental.get_next_as_optional
returns an `Optional` that either
contains the next value from a `tf.compat.v1.data.Iterator` if one exists, or
a "none" value that indicates the end of the sequence has been reached. `Optional` can only be used by values that are convertible to `Tensor` or
`CompositeTensor`.
Methods
- from_value
- from_value
- from_value
- from_value
- from_value
- from_value
- get_value
- get_value_dyn
- has_value
- has_value_dyn
- none_from_structure
- none_from_structure_dyn
Properties
Public instance methods
object get_value(string name)
Returns the value wrapped by this optional. If this optional does not have a value (i.e. `self.has_value()` evaluates
to `False`), this operation will raise
tf.errors.InvalidArgumentError
at runtime.
Parameters
-
string
name - (Optional.) A name for the created operation.
Returns
-
object
- The wrapped value.
object get_value_dyn(object name)
Returns the value wrapped by this optional. If this optional does not have a value (i.e. `self.has_value()` evaluates
to `False`), this operation will raise
tf.errors.InvalidArgumentError
at runtime.
Parameters
-
object
name - (Optional.) A name for the created operation.
Returns
-
object
- The wrapped value.
Tensor has_value(string name)
object has_value_dyn(object name)
Public static methods
object from_value(double value)
Returns an `Optional` that wraps the given value.
Parameters
-
double
value - A value to wrap. The value must be convertible to `Tensor` or `CompositeTensor`.
Returns
-
object
- An `Optional` that wraps `value`.
object from_value(IDictionary<string, ValueTuple<object, object>> value)
Returns an `Optional` that wraps the given value.
Parameters
-
IDictionary<string, ValueTuple<object, object>>
value - A value to wrap. The value must be convertible to `Tensor` or `CompositeTensor`.
Returns
-
object
- An `Optional` that wraps `value`.
object from_value(IEnumerable<double> value)
Returns an `Optional` that wraps the given value.
Parameters
-
IEnumerable<double>
value - A value to wrap. The value must be convertible to `Tensor` or `CompositeTensor`.
Returns
-
object
- An `Optional` that wraps `value`.
object from_value(ValueTuple<object, object> value)
Returns an `Optional` that wraps the given value.
Parameters
-
ValueTuple<object, object>
value - A value to wrap. The value must be convertible to `Tensor` or `CompositeTensor`.
Returns
-
object
- An `Optional` that wraps `value`.
object from_value(Optional value)
Returns an `Optional` that wraps the given value.
Parameters
-
Optional
value - A value to wrap. The value must be convertible to `Tensor` or `CompositeTensor`.
Returns
-
object
- An `Optional` that wraps `value`.
object from_value(IGraphNodeBase value)
Returns an `Optional` that wraps the given value.
Parameters
-
IGraphNodeBase
value - A value to wrap. The value must be convertible to `Tensor` or `CompositeTensor`.
Returns
-
object
- An `Optional` that wraps `value`.
_OptionalImpl none_from_structure(TensorSpec value_structure)
Returns an `Optional` that has no value. NOTE: This method takes an argument that defines the structure of the value
that would be contained in the returned `Optional` if it had a value.
Parameters
-
TensorSpec
value_structure - A `Structure` object representing the structure of the components of this optional.
Returns
-
_OptionalImpl
- An `Optional` that has no value.
object none_from_structure_dyn(object value_structure)
Returns an `Optional` that has no value. NOTE: This method takes an argument that defines the structure of the value
that would be contained in the returned `Optional` if it had a value.
Parameters
-
object
value_structure - A `Structure` object representing the structure of the components of this optional.
Returns
-
object
- An `Optional` that has no value.
Public properties
object PythonObject get;
object value_structure get;
The structure of the components of this optional.
object value_structure_dyn get;
The structure of the components of this optional.