Skip to content

Reshape should take each shape dimension as a separate input #881

Open
@ricardoV94

Description

@ricardoV94

Description

Reshape has only two inputs, x, and a vector of the output shape. This is cumbersome because many times we want to analyze the individual dimensions to rewrite Reshape as expand_dims or get rid of useless Reshape. Also the Reshape Op needs to be parametrized with the output length, because historically we didn't have static shapes, and couldn't always guess how many entries the shape vector had.

Most times Reshape is used to concatenate dimensions, so we end up with stuff like [x.shape[0], ..., x.shape[n] * x.shape[m], ..., x.shape[-1]], wrapped in a MakeVector. This makes Resahpe rewrites harder because they have to handle the case where things are joined in a MakeVector or may have been constant folded into a single tensor.

# Since output_shape is a symbolic vector, we trust extract_constant
# to go through however it is formed to see if its i-th element is 1.
# We need only_process_constants=False for that.
dim = extract_constant(
output_shape[i], only_process_constants=False, elemwise=False
)

SpecifyShape already works with a variable number of inputs and we haven't any trouble with it.

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