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

Generalize aesara.tensor.linalg.cholesky beyond 2D arrays #1012

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

purna135
Copy link
Contributor

Thank you for opening a PR!

Here are a few important guidelines and requirements to check before your PR can be merged:

  • There is an informative high-level description of the changes.
  • The description and/or commit message(s) references the relevant GitHub issue(s).
  • pre-commit is installed and set up.
  • The commit messages follow these guidelines.
  • The commits correspond to relevant logical changes, and there are no commits that fix changes introduced by other commits in the same branch/BR.
  • There are tests covering the changes introduced in the PR.

Don't worry, your PR doesn't need to be in perfect order to submit it. As development progresses and/or reviewers request changes, you can always rewrite the history of your feature/PR branches.

If your PR is an ongoing effort and you would like to involve us in the process, simply make it a draft PR.

@purna135 purna135 marked this pull request as draft June 24, 2022 09:11
@ricardoV94
Copy link
Contributor

ricardoV94 commented Jun 25, 2022

How does the numpy implementation perform compared to scipy (including the lower version that is being removed)?

If it's vastly different we could keep using it for 2D cases. For higher cases is numpy faster than a Python loop calling the scipy function?

@ricardoV94
Copy link
Contributor

Besides performance concerns, the other thing you need to check is if there are any rewrites in Aesara that rely on the assumption that this Op is always 2-dimensional.

If that's the case you might need to add a new check in the rewrites or generalize them to be higher-dimensional if that's already possible (and open a Aesara issue if not)

@@ -451,23 +421,6 @@ def test_solve_dtype(self):
assert x.dtype == x_result.dtype


def test_cho_solve():
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this test removed?



cho_solve = CholeskySolve()


def cho_solve(c_and_lower, b, check_finite=True):
def cho_solve(a, b):
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs some care, as it will simply break people's code.

check_finite=self.check_finite,
)
out_dtype = aes.upcast(a.dtype, b.dtype)
broadcastable = [
Copy link
Contributor

Choose a reason for hiding this comment

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

We can do better than broadcastable. Have a look at https://aesara.readthedocs.io/en/latest/extending/type.html

@@ -39,10 +40,9 @@ class Cholesky(Op):
# TODO: for specific dtypes
# TODO: LAPACK wrapper with in-place behavior, for solve also

__props__ = ("lower", "destructive", "on_error")
__props__ = ("destructive", "on_error")

Choose a reason for hiding this comment

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

Do we need destructive attribute here?

According to the Op docs, __props__ lists the attributes which influence the computation performed. And I am not sure how destructive attribute is used in perform method.

Copy link
Contributor

Choose a reason for hiding this comment

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

My guess is that this was added for some functionality that was never implemented (e.g., a faster method that alters the input variables in place). Looking around the library I don't think this is being used anywhere so maybe we can remove it.

@ricardoV94
Copy link
Contributor

By the way, the rewrites involving linalg Ops are found here: https://github.com/aesara-devs/aesara/blob/main/aesara/sandbox/linalg/ops.py

We should probably bring them over to this module (CC @brandonwillard).

Importantly, some rewrites may need to be updated with the new Op's signatures... and the same performance concerns should be at least briefly investigated.

@brandonwillard brandonwillard changed the title Generalize linalg.cholesky beyond 2D arrays Generalize aesara.tensor.linalg.cholesky beyond 2D arrays Jul 7, 2022
@brandonwillard brandonwillard added enhancement New feature or request new operator refactor This issue involves refactoring Op implementation Involves the implementation of an Op and removed new operator labels Jul 7, 2022
@brandonwillard
Copy link
Member

By the way, the rewrites involving linalg Ops are found here: https://github.com/aesara-devs/aesara/blob/main/aesara/sandbox/linalg/ops.py

We should probably bring them over to this module (CC @brandonwillard).

Importantly, some rewrites may need to be updated with the new Op's signatures... and the same performance concerns should be at least briefly investigated.

See #499.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Op implementation Involves the implementation of an Op refactor This issue involves refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants