Skip to content

Add rewrite for diag(A @ B) to avoid materializing the product#2302

Open
jessegrabowski wants to merge 2 commits into
pymc-devs:mainfrom
jessegrabowski:diag-matmul
Open

Add rewrite for diag(A @ B) to avoid materializing the product#2302
jessegrabowski wants to merge 2 commits into
pymc-devs:mainfrom
jessegrabowski:diag-matmul

Conversation

@jessegrabowski

Copy link
Copy Markdown
Member

Closes #2301

@ricardoV94

Copy link
Copy Markdown
Member

@jessegrabowski I generalized the rewrite into (A @ B)[advanced_indexing], which covers the Diagonal and other cases. Same approach we have for other ExtractDiag(of stuff)

assert_allclose(f(np.array([0, 1, 1, 3])), 0.0) # duplicate column -> singular


class TestDiagOfDot:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these tests should be removed/go to the test_subtensor_lift ? I kept them untouched to show no regression from the original commit

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

Labels

graph rewriting linalg Linear algebra memory opt Memory optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewrite diag(A @ B) to (A * B.T).sum(-1) instead of materializing the product

2 participants