from __future__ import annotations

import autograd.numpy as np

from ..expression import Expr, ExprLike
from ..constants import Curvature as C


class logdet(Expr):
    """Log-determinant of a matrix.

    logdet(A) = log(det(A)) for positive definite matrix A.
    Concave on the cone of positive definite matrices.
    """

    def __init__(self, left: ExprLike) -> None:
        super().__init__("logdet", left)

    def __call__(self, x: np.ndarray) -> np.ndarray:
        return np.log(np.linalg.det(x))

    @property
    def curvature(self) -> C:
        return C.UNKNOWN

    @property
    def shape(self) -> tuple[int, ...]:
        return (1,)