Repository: tensorflow
Issue: Support smaller indices in Sparse Matrix
Labels: stat:awaiting tensorflower,type:feature,comp:ops

### Issue type

Feature Request

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

Yes

### Source

source

### TensorFlow version

2.13

### Custom code

Yes

### OS platform and distribution

-

### Mobile device

-

### Python version

-

### Bazel version

-

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Sparse tensors have only int64 index https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor
We have some sparse matrices which do not have that big indices, but we have rather lots of numbers, but still it's sparse enough s using dense matrix would be wasteful.
Having support for int32 and int16 for index would lead to lots of memory savings, effectively having 2-4x smaller memory footprint of the sparse matrix.

### Standalone code to reproduce the issue

```shell
>>> import tensorflow as tf
>>> tf.sparse.SparseTensor(indices=[[0, 0], [1, 2]], values=[1, 2], dense_shape=[3, 4])
<tensorflow.python.framework.sparse_tensor.SparseTensor object at 0x000002064DEBFFA0>
>>> tf.sparse.SparseTensor(indices=tf.constant([[0, 0], [1, 2]], dtype=tf.int64), values=[1, 2], dense_shape=[3, 4]).indices 
<tf.Tensor: shape=(2, 2), dtype=int64, numpy=
array([[0, 0],
       [1, 2]], dtype=int64)>
>>> tf.sparse.SparseTensor(indices=tf.constant([[0, 0], [1, 2]], dtype=tf.int32), values=[1, 2], dense_shape=[3, 4]).indices 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\tools\miniconda3\envs\wanna-hmic-cc\lib\site-packages\tensorflow\python\framework\sparse_tensor.py", line 125, in __init__
    indices = ops.convert_to_tensor(
  File "C:\tools\miniconda3\envs\wanna-hmic-cc\lib\site-packages\tensorflow\python\profiler\trace.py", line 183, in wrapped
    return func(*args, **kwargs)
  File "C:\tools\miniconda3\envs\wanna-hmic-cc\lib\site-packages\tensorflow\python\framework\ops.py", line 1662, in convert_to_tensor
    raise ValueError(
ValueError: Tensor conversion requested dtype int64 for Tensor with dtype int32: <tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[0, 0],
       [1, 2]])>
>>> tf.sparse.SparseTensor(indices=tf.constant([[0, 0], [1, 2]], dtype=tf.int16), values=[1, 2], dense_shape=[3, 4]).indices
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\tools\miniconda3\envs\wanna-hmic-cc\lib\site-packages\tensorflow\python\framework\sparse_tensor.py", line 125, in __init__
    indices = ops.convert_to_tensor(
  File "C:\tools\miniconda3\envs\wanna-hmic-cc\lib\site-packages\tensorflow\python\profiler\trace.py", line 183, in wrapped
    return func(*args, **kwargs)
  File "C:\tools\miniconda3\envs\wanna-hmic-cc\lib\site-packages\tensorflow\python\framework\ops.py", line 1662, in convert_to_tensor
    raise ValueError(
ValueError: Tensor conversion requested dtype int64 for Tensor with dtype int16: <tf.Tensor: shape=(2, 2), dtype=int16, numpy=
array([[0, 0],
       [1, 2]], dtype=int16)>
```


### Relevant log output

_No response_