Skip to content

util

try_conjugate(x)

Return the complex conjugate.

\[ x^* \qquad \mathbb{K}\to\mathbb{K} \]

Tries to call a method conjugate. If not found, simply returns the element as is.

Python implementation.

Source code in vector\_pyutil.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def try_conjugate(x):
    r"""Return the complex conjugate.

    $$
        x^* \qquad \mathbb{K}\to\mathbb{K}
    $$

    Tries to call a method `conjugate`.
    If not found, simply returns the element as is.

    Python implementation.
    """
    conj = getattr(x, 'conjugate', None)
    return conj() if callable(conj) else x