Returns the shape of a tensor. Args: input: A `Tensor` or `SparseTensor`. name: A name for the operation (optional). optimize: if true, encode the shape as a constant when possible. out_type: (Optional) The specified output type of the operation (`int32` or `int64`). Default
(input, name=None, optimize=True, out_type=dtypes.int32)
| 448 | |
| 449 | |
| 450 | def shape_internal(input, name=None, optimize=True, out_type=dtypes.int32): |
| 451 | # pylint: disable=redefined-builtin |
| 452 | """Returns the shape of a tensor. |
| 453 | |
| 454 | Args: |
| 455 | input: A `Tensor` or `SparseTensor`. |
| 456 | name: A name for the operation (optional). |
| 457 | optimize: if true, encode the shape as a constant when possible. |
| 458 | out_type: (Optional) The specified output type of the operation (`int32` or |
| 459 | `int64`). Defaults to tf.int32. |
| 460 | |
| 461 | Returns: |
| 462 | A `Tensor` of type `out_type`. |
| 463 | |
| 464 | """ |
| 465 | with ops.name_scope(name, "Shape", [input]) as name: |
| 466 | if isinstance( |
| 467 | input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)): |
| 468 | return gen_math_ops.cast(input.dense_shape, out_type) |
| 469 | else: |
| 470 | if not context.executing_eagerly(): |
| 471 | input_tensor = ops.convert_to_tensor(input) |
| 472 | input_shape = input_tensor.get_shape() |
| 473 | if optimize and input_shape.is_fully_defined(): |
| 474 | return constant(input_shape.as_list(), out_type, name=name) |
| 475 | return gen_array_ops.shape(input, name=name, out_type=out_type) |
| 476 | |
| 477 | |
| 478 | @tf_export("shape_n") |
no test coverage detected