Skip to content

util

try_conjugate(x: Any) -> Any

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
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def try_conjugate(x:Any) -> Any:
    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