Skip to content

pytensor.tensor.cartesian does not work on TensorVariables #7633

@AuguB

Description

@AuguB

Describe the issue:

pytensor.tensor.cartesian does not work on TensorVariables

Reproduceable code example:

a = pm.Normal("a", shape=(7,))
b = pm.Normal("b", shape=(2,7))

pm.math.cartesian(a, b).shape.eval()
# Throws an error
# I need [7,2,7]

pytensor.tensor.mul(a,b).shape()
# [2,7] <- not what I need

Error message:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/anaconda3/envs/dev_refactor_2/lib/python3.12/site-packages/pymc/math.py", line 214, in cartesian
    arrays_integer = [np.arange(len(x)) for x in arrays_2d]
                                ^^^^^^
TypeError: len() of unsized object

PyMC version information:

5.19.1 conda

Context for the issue:

I don't know if there is another way to do this, but I have two TensorVariables with possibly matching dimension lengths, and I need the cartesian product of them. I can't seem to find a way to let the matching dimensions be combined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions