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

beignet.root_scalar #26

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft

beignet.root_scalar #26

wants to merge 38 commits into from

Conversation

kleinhenz
Copy link
Collaborator

No description provided.

src/beignet/_root.py Outdated Show resolved Hide resolved
@0x00b1
Copy link
Collaborator

0x00b1 commented Jun 10, 2024

Questions we should answer before merging:

  • Can root be used for both scalar and multi-dimensional root finding?
  • Should we provide methods as separate operators (e.g., newton)?
  • What, if anything, do we vmap? Guesses? Tolerances? Iterations? What about functions?
  • What should we return?
  • Should users be able to provide their own Jacobians?

@kleinhenz
Copy link
Collaborator Author

Can root be used for both scalar and multi-dimensional root finding?

Comparing with scipy maybe this should be renamed to root_scalar since the bracketing methods like chandrupatla are only applicable to (arrays of) scalar problems.

x0 = torch.zeros([0])

for iteration in range(maxiter):
b = x0 - torch.linalg.solve(torch.func.jacfwd(func)(x0), func(x0))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

another reason to separate root and root_scalar would be to have an implementation that avoids doing a full linear solve for arrays of scalar problems where the jacobian is diagonal.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep

output = ()

for g, b2 in zip(grad_outputs, b, strict=True):
output = (*output, -g * b2 / a)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why is this style preferred? I don't think the original expression with the generator introduces any mutation right?

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

Successfully merging this pull request may close these issues.

2 participants