`tf.linalg.cholesky` Produces Inconsistent Results with Complex and Float Tensors
Hi,

It seems the issue might be related to the requirements for Cholesky decomposition. For the decomposition to be valid, especially with complex matrices, each input matrix needs to be Hermitian (a matrix that is equal to its own conjugate transpose) and positive definite (all its eigenvalues are positive).

Here are some references for more details:

https://en.wikipedia.org/wiki/Cholesky_decomposition
https://www.tensorflow.org/api_docs/python/tf/linalg/cholesky

Also, here's a code snippet to check if your matrices meet these requirements:

```python
import tensorflow as tf
import numpy as np

params = [
    tf.complex(tf.random.uniform([1, 26, 2, 2], dtype=tf.float32), tf.random.uniform([1, 26, 2, 2], dtype=tf.float32)),
]

class Model1(tf.keras.Model):
    def __init__(self):
        super().__init__()
        self.p0 = tf.Variable(params[0]) # [1, 26, 2, 2] complex64

    @tf.function
    def __call__(self, v7_0):
        # Check if each matrix in the batch is Hermitian
        is_hermitian = tf.reduce_all(tf.math.equal(self.p0, tf.linalg.adjoint(self.p0)), axis=[-2, -1])

        # Calculate the eigenvalues for each matrix in the batch
        eigenvalues = tf.linalg.eigvalsh(self.p0)

        # Check for positive definiteness by ensuring the real parts of the eigenvalues are positive for each matrix
        is_positive_definite = tf.reduce_all(tf.math.real(eigenvalues) > 0, axis=-1)

        # Check if all matrices in the batch are Hermitian and positive definite
        valid_for_cholesky = tf.logical_and(is_hermitian, is_positive_definite)

        if tf.reduce_all(valid_for_cholesky):
            cho = tf.linalg.cholesky(self.p0)
            return cho 
        else:
            print("is_hermitian: ", is_hermitian.numpy())
            print("is_positive_definite: ", is_positive_definite.numpy())
            raise ValueError("Not all matrices are Hermitian positive definite.")

inputs = [
    tf.complex(tf.random.uniform([1, 26, 1, 2], dtype=tf.float32), tf.random.uniform([1, 26, 1, 2], dtype=tf.float32)),
]

model1 = Model1()

with tf.device('cpu'):
    tf.config.run_functions_eagerly(True)
    out1 = model1(*inputs)
    out2 = model1(*inputs)
    print(f'=========eager_output(version:{tf.__version__})================')
    try:
        for i in range(len(out1)):
            np.testing.assert_allclose(out1[i].numpy(), out2[i].numpy(), rtol=0.01, err_msg=f'at checking {i}th')
        print("Eager does not trigger assertion")
    except AssertionError as e:
        print("Eager triggers assertion")
        print(e)
``` Thanks for your response. I've revisited the [TensorFlow documentation on Cholesky](https://www.tensorflow.org/api_docs/python/tf/linalg/cholesky) and carefully checked the requirements:

The input must be a tensor with dimensions [..., M, M], where the last two dimensions are square matrices.
The tensor should be symmetric and positive definite. The function only uses the lower-triangular part of the tensor, ignoring the upper-triangular part.
The output is a tensor of the same shape, containing the Cholesky decompositions for all submatrices [..., :, :].
Considering these requirements, I updated my code to ensure it meets both criteria: forming square matrices and being symmetric and positive definite. Despite this, I'm still encountering an error. This leads me to think the issue might not be with my implementation but could potentially be an issue within TensorFlow's handling of the Cholesky operation. Here's the code I updated, which I believe adheres to the documented requirements:
```python
import tensorflow as tf
import numpy as np

def generate_symmetric_positive_complex_tensor(shape):
    # Ensure the innermost shape is square
    assert shape[-1] == shape[-2], "Shape must be square to create a symmetric matrix"

    # Create a symmetric matrix for the real part and positive definite
    real_part = tf.random.uniform(shape, minval=0, maxval=1)
    real_symmetric = (real_part + tf.transpose(real_part, perm=[0,1,3,2])) / 2

    # Create a symmetric matrix for the imaginary part and positive definite
    imaginary_part = tf.random.uniform(shape, minval=0, maxval=1)
    imaginary_symmetric = (imaginary_part + tf.transpose(imaginary_part, perm=[0,1,3,2])) / 2

    # Combine into a complex tensor
    complex_tensor = tf.complex(real_symmetric, imaginary_symmetric)

    return complex_tensor

params = [
    generate_symmetric_positive_complex_tensor([1, 26, 2, 2]),
    # tf.complex(tf.random.uniform([1, 26, 2, 2], minval=0, maxval=1, dtype=tf.float32), tf.random.uniform([1, 26, 2, 2],minval=0, maxval=1, dtype=tf.float32)),
]

class Model1(tf.keras.Model):
    def __init__(self):
        super().__init__()
        self.p0 = tf.constant(params[0]) # [1, 26, 2, 2] complex64

    @tf.function
    def __call__(self):

        cho = tf.linalg.cholesky(self.p0)
        return cho
   
model1 = Model1()

tf.config.run_functions_eagerly(True)
out1 = model1()
out2 = model1()
print(f'=========eager_output(version:{tf.__version__})================')
try:
    for i in range(len(out1)):
        np.testing.assert_allclose(out1[i].numpy(), out2[i].numpy(), rtol=0.01, err_msg=f'at checking {i}th')
    print("Eager does not trigger assertion")
except AssertionError as e:
    print("Eager triggers assertion")
    print(e)
``` @SuryanarayanaY  I was able to replicate this issue on colab, please find the gist [here](https://colab.research.google.com/gist/sushreebarsa/4d9cfa90d00c6437c787cc80d43abe11/62451.ipynb#scrollTo=P1R23a332b52) for reference.
Thank you!
### Issue type

Bug

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

Yes

### Source

source

### TensorFlow version

2.15.0-dev20231005

### Custom code

Yes

### OS platform and distribution

Ubuntu

### Mobile device

_No response_

### Python version

3.9

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I'm encountering a situation where a `tf.linalig.cholesky` produces different outputs for the same input in eager execution mode, which should theoretically yield consistent results.


### Standalone code to reproduce the issue

```python
import tensorflow as tf
import numpy as np

params = [
tf.complex(tf.random.uniform([1, 26, 2, 2], dtype=tf.float32), tf.random.uniform([1, 26, 2, 2], dtype=tf.float32)),
]
class Model1(tf.keras.Model):
    def __init__(self):
        super().__init__()
        self.p0 = tf.Variable(params[0]) # [1, 26, 2, 2] complex64

    @tf.function
    def __call__(self, v7_0):

        cho = tf.linalg.cholesky(self.p0)

        return cho 

inputs = [
tf.complex(tf.random.uniform([1, 26, 1, 2], dtype=tf.float32), tf.random.uniform([1, 26, 1, 2], dtype=tf.float32)),
]

model1 = Model1()
with tf.device('cpu'):
    tf.config.run_functions_eagerly(True)
    out1 = model1(*inputs)
    out2 = model1(*inputs)
    print(f'=========eager_output(version:{tf.__version__})================')
    try :
        for i in range(len(out1)):
            np.testing.assert_allclose(out1[i].numpy(), out2[i].numpy(), rtol=0.01, err_msg=f'at checking {i}th')
        print("Eager does not trigger assertion")
    except AssertionError as e:
        print("Eeager triggers assertion")
        print(e)
```


### Relevant log output

```shell
2023-11-21 23:04:32.635629: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2023-11-21 23:04:32.635665: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2023-11-21 23:04:32.637083: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2023-11-21 23:04:32.645338: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-11-21 23:04:33.736439: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
2023-11-21 23:04:35.768320: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1924] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 4170 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 2070, pci bus id: 0000:02:00.0, compute capability: 7.5
2023-11-21 23:04:35.769152: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1924] Created device /job:localhost/replica:0/task:0/device:GPU:1 with 6678 MB memory:  -> device: 1, name: NVIDIA GeForce RTX 2070, pci bus id: 0000:04:00.0, compute capability: 7.5
2023-11-21 23:04:35.769846: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1924] Created device /job:localhost/replica:0/task:0/device:GPU:2 with 6674 MB memory:  -> device: 2, name: NVIDIA GeForce RTX 2070, pci bus id: 0000:83:00.0, compute capability: 7.5
2023-11-21 23:04:35.770891: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1924] Created device /job:localhost/replica:0/task:0/device:GPU:3 with 6260 MB memory:  -> device: 3, name: NVIDIA GeForce RTX 2070, pci bus id: 0000:84:00.0, compute capability: 7.5
2023-11-21 23:04:35.928481: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928511: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928518: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928524: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928530: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928541: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928553: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928561: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928567: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928573: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928578: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928584: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928590: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928595: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928601: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928606: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928613: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928623: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928633: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928640: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928645: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928651: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928656: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928881: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928896: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928902: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928907: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928913: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928918: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928923: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928929: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928934: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928940: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928945: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928951: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928956: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928962: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928967: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928973: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928978: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928983: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928988: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.928994: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.929000: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.929011: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
2023-11-21 23:04:35.929022: W tensorflow/core/kernels/linalg/cholesky_op.cc:56] Cholesky decomposition was not successful. Eigen::LLT failed with error code 1. Filling lower-triangular output with NaNs.
=========eager_output(version:2.15.0-dev20231005)================
Eeager triggers assertion

Not equal to tolerance rtol=0.01, atol=0
at checking 0th
x and y nan location mismatch:
 x: array([[[0.      +0.j      , 0.      +0.j      ],
        [0.      +0.j      , 0.      +0.j      ]],
...
 y: array([[[0.000000e+00+0.j      , 1.401298e-45     +nanj],
        [0.000000e+00+0.j      , 0.000000e+00+0.j      ]],
...
```
