Skip to content

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

Open
Open
@ricardoV94

Description

@ricardoV94

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions