Repository: scipy/scipy
File: scipy/linalg/src/_linalg_inv.hh (C++)

Code before:
            temp_idx /= shape[i];
        }
        T* slice_ptr = (T *)(Am_data + (offset/sizeof(T)));
        copy_slice(scratch, slice_ptr, n, n, strides[ndim-2], strides[ndim-1]); // XXX: make it in one go
        swap_cf(scratch, data, n, n, n);

        // detect the structure if not given
        slice_structure = structure;
        if (slice_structure == St::NONE) {
            // Get the bandwidth of the slice
            bandwidth(data, n, n, &lower_band, &upper_band);

            if ((upper_band == 0) && (lower_band == 0)) {
                slice_structure = St::DIAGONAL;
            }
            else if(lower_band == 0) {
                slice_structure = St::UPPER_TRIANGULAR;
                uplo = 'U';
            } else if (upper_band == 0) {
                slice_structure = St::LOWER_TRIANGULAR;
                uplo = 'L';
            } else {
                // Check if symmetric/hermitian
                std::tie(is_symm, is_herm) = is_sym_or_herm(data, n);

                if(is_symm && type_traits<T>::is_complex) {
                    // complex symmetric matrix
                    slice_structure = St::SYM;
                }
                else if (is_symm || is_herm) {
                    // either real symmetric or complex hermitian; try Cholesky first,
                    // fall back to sym/her if it fails
                    slice_structure = St::POS_DEF;
                }
                else {
                    // give up auto-detection
                    slice_structure = St::GENERAL;
                }
            }
        }

        init_status(slice_status, idx, slice_structure);

        switch(slice_structure) {
            case St::DIAGONAL:
            {
                invert_slice_diagonal(intn, data, slice_status);

                if ((slice_status.lapack_info < 0) || (slice_status.is_singular )) {
                    vec_status.push_back(slice_status);
                    goto free_exit;

Review comment (suggestion):
This branch logic needs inverting here. The complex arrays with zero imaginary parts while being posdef will fall here. 

An example, I added a print statement in this branch 

```
In [12]: import numpy as np
    ...: import scipy.linalg as la
    ...: a = (np.eye(4) + np.ones(4)).astype(np.complex128)
    ...: print("eigs: ", la.eigvals(a))
    ...: print("cholesky success :\n", la.cholesky(a))
    ...: la.inv(a)
eigs:  [1.+0.j 5.+0.j 1.+0.j 1.+0.j]
cholesky success :
 [[1.41421356+0.j 0.70710678+0.j 0.70710678+0.j 0.70710678+0.j]
 [0.        +0.j 1.22474487+0.j 0.40824829+0.j 0.40824829+0.j]
 [0.        +0.j 0.        +0.j 1.15470054+0.j 0.28867513+0.j]
 [0.        +0.j 0.        +0.j 0.        +0.j 1.11803399+0.j]]
Branch taken: complex symmetric matrix
Out[12]: 
array([[ 0.8+0.j, -0.2+0.j, -0.2+0.j, -0.2+0.j],
       [-0.2-0.j,  0.8+0.j, -0.2+0.j, -0.2+0.j],
       [-0.2-0.j, -0.2-0.j,  0.8+0.j, -0.2+0.j],
       [-0.2-0.j, -0.2-0.j, -0.2-0.j,  0.8+0.j]])
```

and it is printed. The logic should check `((is_herm) && (type_traits<T>::is_complex))` and go to POS_DEF check then otherwise fall-through to SYM branch. 

This also applies to `solve`

Code after:
            temp_idx /= shape[i];
        }
        T* slice_ptr = (T *)(Am_data + (offset/sizeof(T)));
        copy_slice(scratch, slice_ptr, n, n, strides[ndim-2], strides[ndim-1]); // XXX: make it in one go
        swap_cf(scratch, data, n, n, n);

        // detect the structure if not given
        slice_structure = structure;
        if (slice_structure == St::NONE) {
            // Get the bandwidth of the slice
            bandwidth(data, n, n, &lower_band, &upper_band);

            if ((upper_band == 0) && (lower_band == 0)) {
                slice_structure = St::DIAGONAL;
            }
            else if(lower_band == 0) {
                slice_structure = St::UPPER_TRIANGULAR;
                uplo = 'U';
            } else if (upper_band == 0) {
                slice_structure = St::LOWER_TRIANGULAR;
                uplo = 'L';
            } else {
                // Check if symmetric/hermitian
                std::tie(is_symm, is_herm) = is_sym_or_herm(data, n);

                if constexpr (!type_traits<T>::is_complex) {
                    // Real: is_symm and is_herm are always equal
                    if (is_symm) {
                        // try Cholesky first, fall back to sytrf if it fails
                        slice_structure = St::POS_DEF;
                    }
                    else {
                        slice_structure = St::GENERAL;
                    }
                }
                else {
                    // Complex
                    if (!is_symm && !is_herm) {
                        slice_structure = St::GENERAL;
                    }
                    else if (is_herm) {
                        // Hermitian (may also be symmetric if entries are real)
                        // try Cholesky first, fall back to hetrf if it fails
                        slice_structure = St::POS_DEF;
                    }
                    else {
                        // is_symm && !is_herm: complex symmetric, not hermitian
                        slice_structure = St::SYM;
                    }
                }
            }