Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Useless dimshuffle("x","x") #1244

Open
ricardoV94 opened this issue Feb 24, 2025 · 0 comments
Open

Useless dimshuffle("x","x") #1244

ricardoV94 opened this issue Feb 24, 2025 · 0 comments

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 24, 2025

Description

import pytensor
import pytensor.tensor as pt

x = pt.tensor("x", shape=(None, None))
y = x.dimshuffle("x", "x")
pytensor.function([x], y).dprint()
# DeepCopyOp [id A] 1
#  └─ DimShuffle{order=[x,x]} [id B] 0
#     └─ x [id C]

Whenever a DimShuffle only has x and it has as many entries as the inputs, it's basically a specify_shape(x, (1,) * x.type.ndim). If the dimensions were known to be length1, the DimShuffle would be removed correctly

This is a low priority one since the DimShuffle is little more expensive than the specify_shape

@ricardoV94 ricardoV94 changed the title Useless squeeze/expand_dims dimshuffle Useless dimshuffle("x", "x") Feb 24, 2025
@ricardoV94 ricardoV94 changed the title Useless dimshuffle("x", "x") Useless dimshuffle("x","x") Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant