Returns value if value_or_tensor_or_var has a constant value. Args: value_or_tensor_or_var: A value, a `Tensor` or a `Variable`. dtype: Optional `tf.dtype`, if set it would check it has the right dtype. Returns: The constant value or None if it not constant. Raises: Va
(value_or_tensor_or_var, dtype=None)
| 140 | |
| 141 | |
| 142 | def constant_value(value_or_tensor_or_var, dtype=None): |
| 143 | """Returns value if value_or_tensor_or_var has a constant value. |
| 144 | |
| 145 | Args: |
| 146 | value_or_tensor_or_var: A value, a `Tensor` or a `Variable`. |
| 147 | dtype: Optional `tf.dtype`, if set it would check it has the right |
| 148 | dtype. |
| 149 | |
| 150 | Returns: |
| 151 | The constant value or None if it not constant. |
| 152 | |
| 153 | Raises: |
| 154 | ValueError: if value_or_tensor_or_var is None or the tensor_variable has the |
| 155 | wrong dtype. |
| 156 | """ |
| 157 | if value_or_tensor_or_var is None: |
| 158 | raise ValueError('value_or_tensor_or_var cannot be None') |
| 159 | value = value_or_tensor_or_var |
| 160 | if isinstance(value_or_tensor_or_var, (ops.Tensor, variables.Variable)): |
| 161 | if dtype and value_or_tensor_or_var.dtype != dtype: |
| 162 | raise ValueError('It has the wrong type %s instead of %s' % ( |
| 163 | value_or_tensor_or_var.dtype, dtype)) |
| 164 | if isinstance(value_or_tensor_or_var, variables.Variable): |
| 165 | value = None |
| 166 | else: |
| 167 | value = tensor_util.constant_value(value_or_tensor_or_var) |
| 168 | return value |
| 169 | |
| 170 | |
| 171 | def static_cond(pred, fn1, fn2): |
no outgoing calls
no test coverage detected