MCPcopy
hub / github.com/google/tf-quant-finance / get_shape

Function get_shape

tf_quant_finance/utils/shape_utils.py:30–60  ·  view source on GitHub ↗

Returns static shape of `x` if it is fully defined, or dynamic, otherwise. ####Example ```python import tensorflow as tf import tf_quant_finance as tff x = tf.zeros([5, 2]) prefer_static_shape(x) # Expected: [5, 2] Args: x: A tensor of any shape and `dtype` name: Python st

(
    x: tf.Tensor,
    name: Optional[str] = None)

Source from the content-addressed store, hash-verified

28
29
30def get_shape(
31 x: tf.Tensor,
32 name: Optional[str] = None) -> Union[tf.TensorShape, types.IntTensor]:
33 """Returns static shape of `x` if it is fully defined, or dynamic, otherwise.
34
35 ####Example
36 ```python
37 import tensorflow as tf
38 import tf_quant_finance as tff
39
40 x = tf.zeros([5, 2])
41 prefer_static_shape(x)
42 # Expected: [5, 2]
43
44 Args:
45 x: A tensor of any shape and `dtype`
46 name: Python string. The name to give to the ops created by this function.
47 Default value: `None` which maps to the default name
48 `get_shape`.
49
50 Returns:
51 A shape of `x` which a list, if the shape is fully defined, or a `Tensor`
52 for dynamically shaped `x`.
53 """
54 name = 'get_shape' if name is None else name
55 with tf.name_scope(name):
56 x = tf.convert_to_tensor(x)
57 is_fully_defined = x.shape.is_fully_defined()
58 if is_fully_defined:
59 return x.shape
60 return tf.shape(x)
61
62
63def common_shape(

Callers 1

Calls 1

shapeMethod · 0.45

Tested by

no test coverage detected