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

Provide static output shape for constant arange #1302

Merged
merged 6 commits into from
Mar 24, 2025

Conversation

Abhinav-Khot
Copy link
Contributor

@Abhinav-Khot Abhinav-Khot commented Mar 18, 2025

Description

Modified arange such that in scenarios where we are able to infer the shape from the arguments i.e the arguments are constant, type.shape is updated accordingly.

For example :

import pytensor
import pytensor.tensor as pt

print(pt.arange(1,10,1).type.shape) #Returns (9, ). Earlier used to return (None, )

Tests are also added to test the new addition.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pytensor--1302.org.readthedocs.build/en/1302/

Copy link

codecov bot commented Mar 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.00%. Comparing base (2a7f3e1) to head (11a915b).
Report is 40 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1302      +/-   ##
==========================================
+ Coverage   81.99%   82.00%   +0.01%     
==========================================
  Files         188      188              
  Lines       48553    48483      -70     
  Branches     8673     8666       -7     
==========================================
- Hits        39812    39760      -52     
+ Misses       6579     6575       -4     
+ Partials     2162     2148      -14     
Files with missing lines Coverage Δ
pytensor/tensor/basic.py 91.16% <100.00%> (-0.20%) ⬇️

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Abhinav-Khot Abhinav-Khot requested a review from ricardoV94 March 19, 2025 19:06
assert start.ndim == 0
assert stop.ndim == 0
assert step.ndim == 0

shape = (None,)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: put this in an else branch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would become a bit more readable that way, will make this change

Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a nitpick, that we don't need to address if you don't agree

@ricardoV94 ricardoV94 merged commit 9e603cf into pymc-devs:main Mar 24, 2025
73 checks passed
@ricardoV94 ricardoV94 changed the title Modify arange to directly determine the shape from the arguments if possible Provide static output shape for constant arange Mar 24, 2025
@ricardoV94
Copy link
Member

Thanks @Abhinav-Khot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pt.arange(int) has .type.shape set to None
2 participants