C++ API `DenseBincount` violates assertion in shape inference step
I suspect [here](https://github.com/tensorflow/tensorflow/blob/41b93a8b310086f69aab6b6369d2af9d5178881d/tensorflow/core/ops/math_ops.cc#L1895-L1900), a shape function of `DenseBincount`:
```C++
      if (c->Rank(c->input(0)) == 1) {
        c->set_output(0, c->MakeShape({size_val}));
      } else if (c->Rank(c->input(0)) == 2) {
        c->set_output(0, c->MakeShape({c->Dim(c->input(0), 0), size_val}));
      }
      return absl::OkStatus();
```
Because it assumes 1 or 2 ranked input tensors only, 0-ranked input tensor makes output unset.
How about to add a guard so that it can make sure only 1 or 2 ranked input tensors reach there? Hi @Sehun0819 ,

Thanks for findings. Proposed a fix in above PR. Thanks! @Sehun0819,
The PR which was proposed for the API **raw_ops.DenseBincount** lacks validation of input to be a vector has been merged. Also the respective changes are also available in the respective files.

https://github.com/tensorflow/tensorflow/pull/63114/files

**if (data.dims() <= 1)**  in [bincount_op.cc](https://github.com/tensorflow/tensorflow/pull/63114/files#diff-539b05632aa822e749c0d2d78ce544e17fb6f1eb510d1b180098acf60c0c9b3e) and **if (c->Rank(c->input(0)) == 1 || c->Rank(c->input(0)) == 0)** in [math_ops.cc](https://github.com/tensorflow/tensorflow/pull/63114/files#diff-285d834bdca6b7da7f6f950b0fa28d677591e9f5273068148f4f9425282be5b9)

Thank you!
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.17

### Custom code

Yes

### OS platform and distribution

Linux Ubuntu 22.04 LTS

### Mobile device

_No response_

### Python version

3.11.7

### Bazel version

6.5.0

### GCC/compiler version

clang 16

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

C++ API `DenseBincount` violates assertion in shape inference step.
Error location is [here](https://github.com/tensorflow/tensorflow/blob/83f1804f3427ae888e62b26b5bcba8afc9e24ef7/tensorflow/core/framework/shape_inference.cc#L111-L115):
```C++
#ifndef NDEBUG
  for (int i = 0; i < num_outputs(); ++i) {
    DCHECK(output(i).IsSet()) << i << " for " << attrs_.SummarizeNode();
  }
#endif  // NDEBUG
```
Seems like output is not set properly in shape function of `DenseBincount`.
Note that in release build, same code terminates normally with another diagnosis.

### Standalone code to reproduce the issue

```C++
#include "tensorflow/cc/framework/scope.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/public/session.h"
#include "tensorflow/cc/ops/array_ops.h"
#include "tensorflow/cc/ops/standard_ops.h"

using namespace tensorflow;

int main() {
  SessionOptions options;
  std::unique_ptr<tensorflow::Session>
    session(tensorflow::NewSession(options));
  Scope scope = Scope::NewRootScope();

  Input input = 1;
  Input size = 1;
  Input weights = ops::RandomNormal(scope,{1,1,1,1},DT_FLOAT);
  auto target = ops::DenseBincount(scope.WithOpName("target"), input, size, weights);

  Status status;
  GraphDef graph_def;
  status = scope.ToGraphDef(&graph_def);
  if (!status.ok()) {
    LOG(WARNING) << "Could not build graph: " << status.message();
  }

  status = session->Create(graph_def);
  if (!status.ok()) {
    LOG(WARNING) << "Could not create session: " << status.message();
  }

  std::vector<Tensor> outputs;
  status = session->Run({}, {"target"}, {"target"}, &outputs);
  if (!status.ok()) {
    LOG(WARNING) << "Could not run session: " << status.message();
  }

  return 0;
}
```


### Relevant log output

Release build:
```shell
2024-02-27 20:40:33.778448: W tensorflow/core/framework/local_rendezvous.cc:404] Local rendezvous is aborting with status: INVALID_ARGUMENT: `weights` must be the same shape as `arr` or a length-0 `Tensor`, in which case it acts as all weights equal to 1. Received [1,1,1,1]
         [[{{node target}}]]
2024-02-27 20:40:33.781525: W tensorflow/core/kernels/reproduce/DenseBincount.cc:35] Could not run session: `weights` must be the same shape as `arr` or a length-0 `Tensor`, in which case it acts as all weights equal to 1. Received [1,1,1,1]
         [[{{node target}}]]
```

Debug build:
```shell
2024-02-27 20:29:28.448037: F tensorflow/core/framework/shape_inference.cc:113] Check failed: output(i).IsSet() 0 for {{node target}} = DenseBincount[T=DT_FLOAT, Tidx=DT_INT32, binary_output=false, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Const_1/Const, Const_1/Const, RandomNormal)
Aborted (core dumped)
```
