Skip to content

Allow maths in shape constraints. #5

@jesnie

Description

@jesnie

Feature request

Allow maths in shape constraints.

Motivation

For example:

@check_shapes(
    "left: [left_rows, left_columns]",
    "right: [right_rows, right_columns]",
    "return: [left_rows * right_rows, left_columns + right_columns]",
)
def cartesian_product(left, right):
    ....

Proposal

The ability to do maths in shape constraints.

This is hard, because we need to be able to learn/infer the values of the variables (left_rows, left_columns, etc...), and in general we cannot work backwards solve arbitrary equations. We could solve this in a couple of ways:

  1. Require the user to declare their shapes in order, so that when a shape variable is used in maths, its value is already known.
  2. Check shapes lazily, and only evaluate a shape when all the required information is available.

I don't like (1), because I don't like have to impose an ordering on constraints, and because optional arguments can make it hard to predict when a variable value will actually be available. I like (2) better, but it does have the disadvantage that sometimes a shape variable value may never be known, and no check actually performed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions