tfp.experimental.distributions.marginal_fns.ps.identity
Stay organized with collections
Save and categorize content based on your preferences.
Return a Tensor with the same shape and contents as input.
tfp.experimental.distributions.marginal_fns.ps.identity(
input, name=None
)
The return value is not the same Tensor as the original, but contains the same
values. This operation is fast when used on the same device.
For example:
a = tf.constant([0.78])
a_identity = tf.identity(a)
a.numpy()
array([0.78], dtype=float32)
a_identity.numpy()
array([0.78], dtype=float32)
Calling tf.identity
on a variable will make a Tensor that represents the
value of that variable at the time it is called. This is equivalent to calling
<variable>.read_value()
.
a = tf.Variable(5)
a_identity = tf.identity(a)
a.assign_add(1)
<tf.Variable ... shape=() dtype=int32, numpy=6>
a.numpy()
6
a_identity.numpy()
5
This function can also be used to explicitly transfer tensors between devices.
For example, to transfer a tensor in GPU memory back to host memory, one can
use:
with tf.device("/gpu:0"):
x_on_gpu = tf.constant(1)
with tf.device("/cpu:0"):
x_on_cpu = tf.identity(x_on_gpu)
x_on_cpu.device
'/job:localhost/replica:0/task:0/device:CPU:0'
Args |
input
|
A Tensor , a Variable , a CompositeTensor or anything that can be
converted to a tensor using tf.convert_to_tensor .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor or CompositeTensor. Has the same type and contents as input .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-05-09 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2023-05-09 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-05-09 UTC."],[],[]]