Skip to content

Optimize reductions of broadcasting (alloc) #378

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

Open
ricardoV94 opened this issue Jul 13, 2023 · 0 comments
Open

Optimize reductions of broadcasting (alloc) #378

ricardoV94 opened this issue Jul 13, 2023 · 0 comments

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Jul 13, 2023

Description

import pytensor
import pytensor.tensor as pt

x = pt.vector("x")
out = pt.sum(pt.ones((5, 3)) * x)
fn = pytensor.function([x], out)
pytensor.dprint(fn, print_type=True)
Sum{axes=None} [id A] <Scalar(float64, shape=())> 1
 └─ Alloc [id B] <Matrix(float64, shape=(5, 3))> 0
    ├─ x [id C] <Vector(float64, shape=(?,))>
    ├─ 5 [id D] <Scalar(int64, shape=())>
    └─ 3 [id E] <Scalar(int64, shape=())>

Could instead be x * 15. Boolean reductions (all, any) are even simpler.

Maybe something clever can be done with axis, but as a start we can cover just the cases with axis=None

Conceptually related to #59

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

No branches or pull requests

2 participants