pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

Try to make pytensor compatible with the Python array API standard

Open ricardoV94 opened this issue 10 months ago • 1 comments

Description

https://data-apis.org/array-api/latest/index.html

The standard considers lazy graph libraries so we should be fine. The only large difference I saw was that the .shape attribute should return a tuple of integers or None, whereas our variable.shape attribute returns a symbolic vector variable.

https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.shape.html#shape

That would be equivalent to our variable.type.shape (static shape).

However they mention it is okay to return a custom type as long as it behaves like a tuple. Our shape does because you can iter/index/tuplify it just fine, so it may be fine?

It seems dangerous to change the behavior of .shape. Opened an issue: https://github.com/data-apis/array-api/issues/891

ricardoV94 avatar Feb 04 '25 09:02 ricardoV94

Also I suspect the verification suite is not compatible with lazy backends right now, but it's worth checking and opening an issue with them if not: https://data-apis.org/array-api/latest/verification_test_suite.html

It shouldn't be too hard to monkey-patch it for testing as we can build graphs or constants just fine, and dispatch asarray to be x.eval()

ricardoV94 avatar Feb 04 '25 10:02 ricardoV94