MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / constant_value

Function constant_value

tensorflow/python/framework/tensor_util.py:768–802  ·  view source on GitHub ↗

Returns the constant value of the given tensor, if efficiently calculable. This function attempts to partially evaluate the given tensor, and returns its value as a numpy ndarray if this succeeds. Compatibility(V1): If `constant_value(tensor)` returns a non-`None` result, it will no longer

(tensor, partial=False)

Source from the content-addressed store, hash-verified

766
767@tf_export("get_static_value")
768def constant_value(tensor, partial=False): # pylint: disable=invalid-name
769 """Returns the constant value of the given tensor, if efficiently calculable.
770
771 This function attempts to partially evaluate the given tensor, and
772 returns its value as a numpy ndarray if this succeeds.
773
774 Compatibility(V1): If `constant_value(tensor)` returns a non-`None` result, it
775 will no longer be possible to feed a different value for `tensor`. This allows
776 the result of this function to influence the graph that is constructed, and
777 permits static shape optimizations.
778
779 Args:
780 tensor: The Tensor to be evaluated.
781 partial: If True, the returned numpy array is allowed to have partially
782 evaluated values. Values that can't be evaluated will be None.
783
784 Returns:
785 A numpy ndarray containing the constant value of the given `tensor`,
786 or None if it cannot be calculated.
787
788 Raises:
789 TypeError: if tensor is not an ops.Tensor.
790 """
791 if isinstance(tensor, ops.EagerTensor):
792 return tensor.numpy()
793 if not is_tensor(tensor):
794 return tensor
795 if not isinstance(tensor, ops.Tensor):
796 return None
797 ret = _ConstantValue(tensor, partial)
798 if ret is not None:
799 # The caller may now depend on the constant value of `tensor`, so we
800 # conservatively prevent it from being fed.
801 tensor.graph.prevent_feeding(tensor)
802 return ret
803
804
805def constant_value_as_shape(tensor): # pylint: disable=invalid-name

Callers 2

_ConstantValueFunction · 0.70
constant_value_as_shapeFunction · 0.70

Calls 4

_ConstantValueFunction · 0.85
prevent_feedingMethod · 0.80
is_tensorFunction · 0.70
numpyMethod · 0.45

Tested by

no test coverage detected