question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Q] What is the excact output ConstantOfShape with empty input shape

See original GitHub issue

The definition of ConstantOfShape contains a notable special case:

input: 1D tensor. The shape of the expected output tensor. If empty tensor is given, the output would be a scalar

However the test case for this is missing. I also couldn’t find any other notion how a “scalar” tensor is defined.
So what are the dimensions of the output tensor in this case? To put it in code: Is the following supposed to pass:

graph = self._make_graph([],
        [make_node("Constant", [], ['shape'],
                   value=make_tensor('shape', TensorProto.INT64, (0,), [])), # Empty tensor?
         make_node("ConstantOfShape", ['shape'], ['y'], value=make_tensor('value', TensorProto.INT32, (1, ), (2, )))],
        [])
self._assert_inferred(graph,
        [make_tensor_value_info('shape', TensorProto.INT64, (0,)),
make_tensor_value_info('y', TensorProto.INT32, [])]) # scalar tensor
# Runtime output would be the scalar value "2" in a tensor of an empty shape(?)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Flamefirecommented, Jul 12, 2019

While I agree with the definition of @yuslepukhin (see my example test code) this is nowhere documented. So as documentation about “scalar tensor” and a test case for this special case is missing I wouldn’t close this until that is done.

0reactions
stale[bot]commented, Mar 29, 2022

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tensorflow scatter_nd with empty tensors? - Stack Overflow
I thought about using a conditional on the shape of the input, but tf.cond executes both pathways. How can I handle this situation...
Read more >
Understanding Tensorflow's tensors shape: static and dynamic
The shape is the number of elements in each dimension, e.g.: a scalar has a rank 0 and an empty shape () ,...
Read more >
tf.constant | TensorFlow v2.11.0
Creates a constant tensor from a tensor-like object. ... tf.constant( value, dtype=None, shape=None, name='Const' ) ...
Read more >
How to Reshape Input Data for Long Short-Term Memory ...
In this tutorial, you will discover how to define the input layer to LSTM models ... Once reshaped, we can print the new...
Read more >
Chapter 14: SOLUTIONS TO TEXT PROBLEMS:
Marginal revenue and marginal cost are graphed in Figure 3. The curves cross at a ... The market price rises to P2, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found