斷言條件 x 和 y 在元素層麵是接近的。
用法
tf.compat.v1.assert_near(
x, y, rtol=None, atol=None, data=None, summarize=None, message=None, name=None
)參數
-
x浮點數或複數Tensor。 -
y浮點數或複數Tensor,與dtype相同,可廣播到x。 -
rtolTensor。dtype與x相同,並且可廣播到x。相對容差。默認為10 * eps。 -
atolTensor。dtype與x相同,並且可廣播到x。絕對的容忍度。默認為10 * eps。 -
data如果條件為 False,則打印出的張量。默認為錯誤消息和x,y的前幾個條目。 -
summarize打印每個張量的這麽多條目。 -
message默認消息的前綴字符串。 -
name此操作的名稱(可選)。默認為"assert_near"。
返回
-
如果
x和y不夠接近,則會引發InvalidArgumentError的操作。
將依賴項添加到操作的示例:
with tf.control_dependencies([tf.compat.v1.assert_near(x, y)]):
output = tf.reduce_sum(x)
如果對於每對(可能是廣播)元素 x[i] , y[i] ,我們有
tf.abs(x[i] - y[i]) <= atol + rtol * tf.abs(y[i]) 。
如果x 和y 都是空的,這很容易滿足。
默認的 atol 和 rtol 是 10 * eps ,其中 eps 是最小的可表示正數,例如 1 + eps != 1 。這是關於 1.2e-6 in 32bit , 2.22e-15 in 64bit 和 0.00977 in 16bit 。請參閱numpy.finfo。
numpy 兼容性
類似於 numpy.testing.assert_allclose ,除了容差取決於數據類型。這是因為 TensorFlow 經常與 32bit , 64bit 甚至 16bit 數據一起使用。
相關用法
- Python tf.compat.v1.assert_negative用法及代碼示例
- Python tf.compat.v1.assert_none_equal用法及代碼示例
- Python tf.compat.v1.assert_non_positive用法及代碼示例
- Python tf.compat.v1.assert_non_negative用法及代碼示例
- Python tf.compat.v1.assert_less_equal用法及代碼示例
- Python tf.compat.v1.assert_integer用法及代碼示例
- Python tf.compat.v1.assert_greater用法及代碼示例
- Python tf.compat.v1.assert_rank_at_least用法及代碼示例
- Python tf.compat.v1.assert_less用法及代碼示例
- Python tf.compat.v1.assert_rank_in用法及代碼示例
- Python tf.compat.v1.assert_greater_equal用法及代碼示例
- Python tf.compat.v1.assert_rank用法及代碼示例
- Python tf.compat.v1.assert_positive用法及代碼示例
- Python tf.compat.v1.assert_equal用法及代碼示例
- Python tf.compat.v1.assign_add用法及代碼示例
- Python tf.compat.v1.assign用法及代碼示例
- Python tf.compat.v1.assign_sub用法及代碼示例
- Python tf.compat.v1.autograph.to_graph用法及代碼示例
- Python tf.compat.v1.arg_max用法及代碼示例
- Python tf.compat.v1.arg_min用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.assert_near。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
