# tfp.util.DeferredTensor

Variable tracking object which applies function upon convert_to_tensor.

tfp.util.DeferredTensor(
pretransformed_input, transform_fn, dtype=None, shape=NONE_SPECIFIED, name=None
)


#### Example

import tensorflow.compat.v2 as tf
import tensorflow_probability as tfp
tfb = tfp.bijectors
tfd = tfp.distributions

# Note: it'd be better to use tfp.util.TransformedVariable;
#       this example is for illustration only.
trainable_normal = tfd.Normal(
loc=tf.Variable(0.),
scale=tfp.util.DeferredTensor(tf.Variable(0.), tf.math.exp))

trainable_normal.loc
# ==> <tf.Variable 'Variable:0' shape=() dtype=float32, numpy=0.0>

trainable_normal.scale
# ==> <DeferredTensor: dtype=float32, shape=[], fn=exp>

# Operators work with DeferredTensor.
trainable_normal.scale + 1.
# ==> 2.

with tf.GradientTape() as tape:
negloglik = -trainable_normal.log_prob(0.5)
g = tape.gradient(negloglik, trainable_normal.trainable_variables)
# ==> (-0.5, 0.75)


Which we could then fit as:

opt = tf.optimizers.Adam(learning_rate=0.05)
loss = tf.function(lambda: -trainable_normal.log_prob(0.5), autograph=True)
for _ in range(int(1e3)):
opt.minimize(loss, trainable_normal.trainable_variables)
trainable_normal.mean()
# ==> 0.5
trainable_normal.stddev()
# ==> (approximately) 0.0075


It is also possible to parameterize a DeferredTensor with a bijector, e.g.:

# Note: it'd be better to use tfp.util.TransformedVariable;
#       this example is for illustration only.
d = tfd.Normal(loc=0.,
scale=tfp.util.DeferredTensor(tf.Variable([0.54, 1.85]),
tfb.Softplus()))
d.stddev()
# ==> [1., 2.]
tf.convert_to_tensor(d.scale)
# ==> [1., 2.]


#### Args:

• pretransformed_input: object with shape, dtype properties (typically a tf.Variable) passed into transform_fn when this object is acted upon in a Tensor context, eg, tf.convert_to_tensor, +, tf.math.exp, etc.
• transform_fn: Python callable or tfp.bijectors.Bijector-like instance. When callable, should take pretransformed_input and return a Tensor (representing by this object).
• dtype: Equivalent to what would otherwise be transform_fn(pretransformed_input).dtype. Default value: None (i.e., getattr(transform_fn, 'dtype', None) or pretransformed_input.dtype).
• shape: Equivalent to what would otherwise be transform_fn(pretransformed_input).shape. Default value: 'None' (i.e., getattr(transform_fn, 'forward_event_shape', lambda x: x)( pretransformed_input.shape)).
• name: Python str representing this object's name; used only in graph mode. Default value: None (i.e., (getattr(transform_fn, 'name', None) or transform_fn.__name__ + '_' + pretransformed_input.name)).

#### Attributes:

• dtype: Represents the type of the elements in a Tensor.
• name: The string name of this object.
• name_scope: Returns a tf.name_scope instance for this class.
• pretransformed_input: Input to transform_fn.
• shape: Represents the shape of a Tensor.
• submodules: Sequence of all sub-modules.

Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).

a = tf.Module()
b = tf.Module()
c = tf.Module()
a.b = b
b.c = c
assert list(a.submodules) == [b, c]
assert list(b.submodules) == [c]
assert list(c.submodules) == []

• trainable_variables: Sequence of trainable variables owned by this module and its submodules.

• transform_fn: Function which characterizes the Tensorization of this object.

• variables: Sequence of variables owned by this module and its submodules.

#### Raises:

• TypeError: if transform_fn is not callable.
• TypeError: if pretransformed_input lacks dtype and/or shape properties (and dtype and/or shape arguments are unspecified).

## Methods

### __abs__

__abs__(
x, name=None
)


Computes the absolute value of a tensor.

Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.

Given a tensor x of complex numbers, this operation returns a tensor of type float32 or float64 that is the absolute value of each element in x. All elements in x must be complex numbers of the form $$a + bj$$. The absolute value is computed as $$\sqrt{a^2 + b^2}$$. For example:

x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]])
tf.abs(x)  # [5.25594902, 6.60492229]


#### Args:

• x: A Tensor or SparseTensor of type float16, float32, float64, int32, int64, complex64 or complex128.
• name: A name for the operation (optional).

#### Returns:

A Tensor or SparseTensor the same size, type, and sparsity as x with absolute values. Note, for complex64 or complex128 input, the returned Tensor will be of type float32 or float64, respectively.

If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.abs(x.values, ...), x.dense_shape)

### __add__

View source

__add__(
*args, **kwargs
)


Dispatches to add for strings and add_v2 for all other types.

### __and__

View source

__and__(
*args, **kwargs
)


Returns the truth value of x AND y element-wise.

NOTE: math.logical_and supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor of type bool.
• y: A Tensor of type bool.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __bool__

__bool__()


Dummy method to prevent a tensor from being used as a Python bool.

This overload raises a TypeError when the user inadvertently treats a Tensor as a boolean (most commonly in an if or while statement), in code that was not converted by AutoGraph. For example:

if tf.constant(True):  # Will raise.
# ...

if tf.constant(5) < tf.constant(7):  # Will raise.
# ...


#### Raises:

TypeError.

### __div__

View source

__div__(
*args, **kwargs
)


Divide two values using Python 2 semantics.

Used for Tensor.div.

#### Args:

• x: Tensor numerator of real numeric type.
• y: Tensor denominator of real numeric type.
• name: A name for the operation (optional).

#### Returns:

x / y returns the quotient of x and y.

### __floordiv__

View source

__floordiv__(
*args, **kwargs
)


Divides x / y elementwise, rounding toward the most negative integer.

The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division.

x and y must have the same type, and the result will have the same type as well.

#### Args:

• x: Tensor numerator of real numeric type.
• y: Tensor denominator of real numeric type.
• name: A name for the operation (optional).

#### Returns:

x / y rounded down.

#### Raises:

• TypeError: If the inputs are complex.

### __ge__

View source

__ge__(
*args, **kwargs
)


Returns the truth value of (x >= y) element-wise.

NOTE: math.greater_equal supports broadcasting. More about broadcasting here

#### Example:

x = tf.constant([5, 4, 6, 7])
y = tf.constant([5, 2, 5, 10])
tf.math.greater_equal(x, y) ==> [True, True, True, False]

x = tf.constant([5, 4, 6, 7])
y = tf.constant([5])
tf.math.greater_equal(x, y) ==> [True, False, True, True]


#### Args:

• x: A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __getitem__

View source

__getitem__(
*args, **kwargs
)


This operation extracts the specified region from the tensor. The notation is similar to NumPy with the restriction that currently only support basic indexing. That means that using a non-scalar tensor as input is not currently allowed.

#### Some useful examples:

# Strip leading and trailing 2 elements
foo = tf.constant([1,2,3,4,5,6])
print(foo[2:-2].eval())  # => [3,4]

# Skip every other row and reverse the order of the columns
foo = tf.constant([[1,2,3], [4,5,6], [7,8,9]])
print(foo[::2,::-1].eval())  # => [[3,2,1], [9,8,7]]

# Use scalar tensors as indices on both dimensions
print(foo[tf.constant(0), tf.constant(2)].eval())  # => 3

# Insert another dimension
foo = tf.constant([[1,2,3], [4,5,6], [7,8,9]])
print(foo[tf.newaxis, :, :].eval()) # => [[[1,2,3], [4,5,6], [7,8,9]]]
print(foo[:, tf.newaxis, :].eval()) # => [[[1,2,3]], [[4,5,6]], [[7,8,9]]]
print(foo[:, :, tf.newaxis].eval()) # => [[[1],[2],[3]], [[4],[5],[6]],
[[7],[8],[9]]]

# Ellipses (3 equivalent operations)
foo = tf.constant([[1,2,3], [4,5,6], [7,8,9]])
print(foo[tf.newaxis, :, :].eval())  # => [[[1,2,3], [4,5,6], [7,8,9]]]
print(foo[tf.newaxis, ...].eval())  # => [[[1,2,3], [4,5,6], [7,8,9]]]
print(foo[tf.newaxis].eval())  # => [[[1,2,3], [4,5,6], [7,8,9]]]

foo = tf.constant([[1,2,3], [4,5,6], [7,8,9]])
print(foo[foo > 2].eval())  # => [3, 4, 5, 6, 7, 8, 9]


#### Notes:

• tf.newaxis is None as in NumPy.
• An implicit ellipsis is placed at the end of the slice_spec
• NumPy advanced indexing is currently not supported.

#### Args:

• tensor: An ops.Tensor object.
• slice_spec: The arguments to Tensor.getitem.
• var: In the case of variable slice assignment, the Variable object to slice (i.e. tensor is the read-only view of this variable).

#### Returns:

The appropriate slice of "tensor", based on "slice_spec".

#### Raises:

• ValueError: If a slice range is negative size.
• TypeError: If the slice indices aren't int, slice, ellipsis, tf.newaxis or scalar int32/int64 tensors.

### __gt__

View source

__gt__(
*args, **kwargs
)


Returns the truth value of (x > y) element-wise.

NOTE: math.greater supports broadcasting. More about broadcasting here

#### Example:

x = tf.constant([5, 4, 6])
y = tf.constant([5, 2, 5])
tf.math.greater(x, y) ==> [False, True, True]

x = tf.constant([5, 4, 6])
y = tf.constant([5])
tf.math.greater(x, y) ==> [False, False, True]


#### Args:

• x: A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __invert__

View source

__invert__(
*args, **kwargs
)


Returns the truth value of NOT x element-wise.

#### Args:

• x: A Tensor of type bool.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __iter__

View source

__iter__(
*args, **kwargs
)


### __le__

View source

__le__(
*args, **kwargs
)


Returns the truth value of (x <= y) element-wise.

NOTE: math.less_equal supports broadcasting. More about broadcasting here

#### Example:

x = tf.constant([5, 4, 6])
y = tf.constant([5])
tf.math.less_equal(x, y) ==> [True, True, False]

x = tf.constant([5, 4, 6])
y = tf.constant([5, 6, 6])
tf.math.less_equal(x, y) ==> [True, True, True]


#### Args:

• x: A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __lt__

View source

__lt__(
*args, **kwargs
)


Returns the truth value of (x < y) element-wise.

NOTE: math.less supports broadcasting. More about broadcasting here

#### Example:

x = tf.constant([5, 4, 6])
y = tf.constant([5])
tf.math.less(x, y) ==> [False, True, False]

x = tf.constant([5, 4, 6])
y = tf.constant([5, 6, 7])
tf.math.less(x, y) ==> [False, True, True]


#### Args:

• x: A Tensor. Must be one of the following types: float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __matmul__

View source

__matmul__(
*args, **kwargs
)


Multiplies matrix a by matrix b, producing a * b.

The inputs must, following any transpositions, be tensors of rank >= 2 where the inner 2 dimensions specify valid matrix multiplication dimensions, and any further outer dimensions specify matching batch size.

Both matrices must be of the same type. The supported types are: float16, float32, float64, int32, complex64, complex128.

Either matrix can be transposed or adjointed (conjugated and transposed) on the fly by setting one of the corresponding flag to True. These are False by default.

If one or both of the matrices contain a lot of zeros, a more efficient multiplication algorithm can be used by setting the corresponding a_is_sparse or b_is_sparse flag to True. These are False by default. This optimization is only available for plain matrices (rank-2 tensors) with datatypes bfloat16 or float32.

A simple 2-D tensor matrix multiplication:

a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) a # 2-D tensor b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2]) b # 2-D tensor c = tf.matmul(a, b) c # a * b

A batch matrix multiplication with batch shape [2]

a = tf.constant(np.arange(1, 13, dtype=np.int32), shape=[2, 2, 3]) a # 3-D tensor b = tf.constant(np.arange(13, 25, dtype=np.int32), shape=[2, 3, 2]) b # 3-D tensor c = tf.matmul(a, b) c # a * b

Since python >= 3.5 the @ operator is supported (see PEP 465). In TensorFlow, it simply calls the tf.matmul() function, so the following lines are equivalent:

d = a @ b @ [[10], [11]] d = tf.matmul(tf.matmul(a, b), [[10], [11]])

#### Args:

• a: tf.Tensor of type float16, float32, float64, int32, complex64, complex128 and rank > 1.
• b: tf.Tensor with same type and rank as a.
• transpose_a: If True, a is transposed before multiplication.
• transpose_b: If True, b is transposed before multiplication.
• adjoint_a: If True, a is conjugated and transposed before multiplication.
• adjoint_b: If True, b is conjugated and transposed before multiplication.
• a_is_sparse: If True, a is treated as a sparse matrix.
• b_is_sparse: If True, b is treated as a sparse matrix.
• name: Name for the operation (optional).

#### Returns:

A tf.Tensor of the same type as a and b where each inner-most matrix is the product of the corresponding matrices in a and b, e.g. if all transpose or adjoint attributes are False:

output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.

• Note: This is matrix product, not element-wise product.

#### Raises:

• ValueError: If transpose_a and adjoint_a, or transpose_b and adjoint_b are both set to True.

### __mod__

View source

__mod__(
*args, **kwargs
)


Returns element-wise remainder of division. When x < 0 xor y < 0 is

true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.

NOTE: math.floormod supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor. Must be one of the following types: int32, int64, bfloat16, half, float32, float64.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor. Has the same type as x.

### __mul__

View source

__mul__(
*args, **kwargs
)


Dispatches cwise mul for "DenseDense" and "DenseSparse".

### __neg__

View source

__neg__(
*args, **kwargs
)


Computes numerical negative value element-wise.

I.e., $$y = -x$$.

#### Args:

• x: A Tensor. Must be one of the following types: bfloat16, half, float32, float64, int32, int64, complex64, complex128.
• name: A name for the operation (optional).

#### Returns:

A Tensor. Has the same type as x.

If x is a SparseTensor, returns SparseTensor(x.indices, tf.math.negative(x.values, ...), x.dense_shape)

### __nonzero__

__nonzero__()


Dummy method to prevent a tensor from being used as a Python bool.

This is the Python 2.x counterpart to __bool__() above.

#### Raises:

TypeError.

### __or__

View source

__or__(
*args, **kwargs
)


Returns the truth value of x OR y element-wise.

NOTE: math.logical_or supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor of type bool.
• y: A Tensor of type bool.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __pow__

View source

__pow__(
*args, **kwargs
)


Computes the power of one value to another.

Given a tensor x and a tensor y, this operation computes $$x^y$$ for corresponding elements in x and y. For example:

x = tf.constant([[2, 2], [3, 3]])
y = tf.constant([[8, 16], [2, 3]])
tf.pow(x, y)  # [[256, 65536], [9, 27]]


#### Args:

• x: A Tensor of type float16, float32, float64, int32, int64, complex64, or complex128.
• y: A Tensor of type float16, float32, float64, int32, int64, complex64, or complex128.
• name: A name for the operation (optional).

#### Returns:

A Tensor.

### __radd__

View source

__radd__(
*args, **kwargs
)


Dispatches to add for strings and add_v2 for all other types.

### __rand__

View source

__rand__(
*args, **kwargs
)


Returns the truth value of x AND y element-wise.

NOTE: math.logical_and supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor of type bool.
• y: A Tensor of type bool.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __rdiv__

View source

__rdiv__(
*args, **kwargs
)


Divide two values using Python 2 semantics.

Used for Tensor.div.

#### Args:

• x: Tensor numerator of real numeric type.
• y: Tensor denominator of real numeric type.
• name: A name for the operation (optional).

#### Returns:

x / y returns the quotient of x and y.

### __rfloordiv__

View source

__rfloordiv__(
*args, **kwargs
)


Divides x / y elementwise, rounding toward the most negative integer.

The same as tf.compat.v1.div(x,y) for integers, but uses tf.floor(tf.compat.v1.div(x,y)) for floating point arguments so that the result is always an integer (though possibly an integer represented as floating point). This op is generated by x // y floor division in Python 3 and in Python 2.7 with from __future__ import division.

x and y must have the same type, and the result will have the same type as well.

#### Args:

• x: Tensor numerator of real numeric type.
• y: Tensor denominator of real numeric type.
• name: A name for the operation (optional).

#### Returns:

x / y rounded down.

#### Raises:

• TypeError: If the inputs are complex.

### __rmatmul__

View source

__rmatmul__(
*args, **kwargs
)


Multiplies matrix a by matrix b, producing a * b.

The inputs must, following any transpositions, be tensors of rank >= 2 where the inner 2 dimensions specify valid matrix multiplication dimensions, and any further outer dimensions specify matching batch size.

Both matrices must be of the same type. The supported types are: float16, float32, float64, int32, complex64, complex128.

Either matrix can be transposed or adjointed (conjugated and transposed) on the fly by setting one of the corresponding flag to True. These are False by default.

If one or both of the matrices contain a lot of zeros, a more efficient multiplication algorithm can be used by setting the corresponding a_is_sparse or b_is_sparse flag to True. These are False by default. This optimization is only available for plain matrices (rank-2 tensors) with datatypes bfloat16 or float32.

A simple 2-D tensor matrix multiplication:

a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) a # 2-D tensor b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2]) b # 2-D tensor c = tf.matmul(a, b) c # a * b

A batch matrix multiplication with batch shape [2]

a = tf.constant(np.arange(1, 13, dtype=np.int32), shape=[2, 2, 3]) a # 3-D tensor b = tf.constant(np.arange(13, 25, dtype=np.int32), shape=[2, 3, 2]) b # 3-D tensor c = tf.matmul(a, b) c # a * b

Since python >= 3.5 the @ operator is supported (see PEP 465). In TensorFlow, it simply calls the tf.matmul() function, so the following lines are equivalent:

d = a @ b @ [[10], [11]] d = tf.matmul(tf.matmul(a, b), [[10], [11]])

#### Args:

• a: tf.Tensor of type float16, float32, float64, int32, complex64, complex128 and rank > 1.
• b: tf.Tensor with same type and rank as a.
• transpose_a: If True, a is transposed before multiplication.
• transpose_b: If True, b is transposed before multiplication.
• adjoint_a: If True, a is conjugated and transposed before multiplication.
• adjoint_b: If True, b is conjugated and transposed before multiplication.
• a_is_sparse: If True, a is treated as a sparse matrix.
• b_is_sparse: If True, b is treated as a sparse matrix.
• name: Name for the operation (optional).

#### Returns:

A tf.Tensor of the same type as a and b where each inner-most matrix is the product of the corresponding matrices in a and b, e.g. if all transpose or adjoint attributes are False:

output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j.

• Note: This is matrix product, not element-wise product.

#### Raises:

• ValueError: If transpose_a and adjoint_a, or transpose_b and adjoint_b are both set to True.

### __rmod__

View source

__rmod__(
*args, **kwargs
)


Returns element-wise remainder of division. When x < 0 xor y < 0 is

true, this follows Python semantics in that the result here is consistent with a flooring divide. E.g. floor(x / y) * y + mod(x, y) = x.

NOTE: math.floormod supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor. Must be one of the following types: int32, int64, bfloat16, half, float32, float64.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor. Has the same type as x.

### __rmul__

View source

__rmul__(
*args, **kwargs
)


Dispatches cwise mul for "DenseDense" and "DenseSparse".

### __ror__

View source

__ror__(
*args, **kwargs
)


Returns the truth value of x OR y element-wise.

NOTE: math.logical_or supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor of type bool.
• y: A Tensor of type bool.
• name: A name for the operation (optional).

#### Returns:

A Tensor of type bool.

### __rpow__

View source

__rpow__(
*args, **kwargs
)


Computes the power of one value to another.

Given a tensor x and a tensor y, this operation computes $$x^y$$ for corresponding elements in x and y. For example:

x = tf.constant([[2, 2], [3, 3]])
y = tf.constant([[8, 16], [2, 3]])
tf.pow(x, y)  # [[256, 65536], [9, 27]]


#### Args:

• x: A Tensor of type float16, float32, float64, int32, int64, complex64, or complex128.
• y: A Tensor of type float16, float32, float64, int32, int64, complex64, or complex128.
• name: A name for the operation (optional).

#### Returns:

A Tensor.

### __rsub__

View source

__rsub__(
*args, **kwargs
)


Returns x - y element-wise.

NOTE: Subtract supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor. Must be one of the following types: bfloat16, half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor. Has the same type as x.

### __rtruediv__

View source

__rtruediv__(
*args, **kwargs
)


### __rxor__

View source

__rxor__(
*args, **kwargs
)


Logical XOR function.

x ^ y = (x | y) & ~(x & y)

Inputs are tensor and if the tensors contains more than one element, an element-wise logical XOR is computed.

#### Usage:

x = tf.constant([False, False, True, True], dtype = tf.bool)
y = tf.constant([False, True, False, True], dtype = tf.bool)
z = tf.logical_xor(x, y, name="LogicalXor")
#  here z = [False  True  True False]


#### Args:

• x: A Tensor type bool.
• y: A Tensor of type bool.

#### Returns:

A Tensor of type bool with the same size as that of x or y.

### __sub__

View source

__sub__(
*args, **kwargs
)


Returns x - y element-wise.

NOTE: Subtract supports broadcasting. More about broadcasting here

#### Args:

• x: A Tensor. Must be one of the following types: bfloat16, half, float32, float64, uint8, int8, uint16, int16, int32, int64, complex64, complex128.
• y: A Tensor. Must have the same type as x.
• name: A name for the operation (optional).

#### Returns:

A Tensor. Has the same type as x.

### __truediv__

View source

__truediv__(
*args, **kwargs
)


### __xor__

View source

__xor__(
*args, **kwargs
)


Logical XOR function.

x ^ y = (x | y) & ~(x & y)

Inputs are tensor and if the tensors contains more than one element, an element-wise logical XOR is computed.

#### Usage:

x = tf.constant([False, False, True, True], dtype = tf.bool)
y = tf.constant([False, True, False, True], dtype = tf.bool)
z = tf.logical_xor(x, y, name="LogicalXor")
#  here z = [False  True  True False]


#### Args:

• x: A Tensor type bool.
• y: A Tensor of type bool.

#### Returns:

A Tensor of type bool with the same size as that of x or y.

### get_shape

View source

get_shape()


Legacy means of getting Tensor shape, for compat with 2.0.0 LinOp.

### set_shape

View source

set_shape(
shape
)


Updates the shape of this pretransformed_input.

This method can be called multiple times, and will merge the given shape with the current shape of this object. It can be used to provide additional information about the shape of this object that cannot be inferred from the graph alone.

#### Args:

• shape: A TensorShape representing the shape of this pretransformed_input, a TensorShapeProto, a list, a tuple, or None.

#### Raises:

• ValueError: If shape is not compatible with the current shape of this pretransformed_input.

### with_name_scope

@classmethod
with_name_scope(
cls, method
)


Decorator to automatically enter the module name scope.

class MyModule(tf.Module):
@tf.Module.with_name_scope
def __call__(self, x):
if not hasattr(self, 'w'):
self.w = tf.Variable(tf.random.normal([x.shape[1], 64]))
return tf.matmul(x, self.w)


Using the above module would produce tf.Variables and tf.Tensors whose names included the module name:

mod = MyModule()
mod(tf.ones([8, 32]))
# ==> <tf.Tensor: ...>
mod.w
# ==> <tf.Variable ...'my_module/w:0'>


#### Args:

• method: The method to wrap.

#### Returns:

The original method wrapped such that it enters the module's name scope.