Skip to content

slogdet cannot be built for a batched input on any backend #2393

Description

@guillaume-osmo

Description

pt.linalg.slogdet cannot be built at all for a batched input, on any backend — this is not backend-specific. slogdet_specialization rewrites Blockwise{Det} into a bare SLogDet, whose make_node asserts x.ndim == 2, so the rewrite fails and the graph then dies on the same assertion.

import numpy as np
import pytensor
import pytensor.tensor as pt

A = pt.tensor("A", shape=(4, 3, 3), dtype="float32")
Av = np.broadcast_to(np.eye(3, dtype="float32") * 2, (4, 3, 3)).copy()

print(pytensor.function([A], pt.linalg.det(A), mode="CVM")(Av))      # [8. 8. 8. 8.]
print(pytensor.function([A], pt.linalg.slogdet(A), mode="CVM")(Av))
# Rewrite failure due to: slogdet_specialization
#   node: Blockwise{Det, (m,m)->()}(A)
#   File "pytensor/tensor/linalg/summary.py", line 95, in make_node
#     assert x.ndim == 2
# AssertionError

Batched det works, so the asymmetry is just that slogdet_specialization does not wrap SLogDet in a Blockwise when the input it matched was itself batched.

Found while fixing #2385 — noting it separately since it is not an MLX issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions