Skip to content

ArrayContext.solve #192

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions arraycontext/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ class ArrayContext(ABC):
.. automethod:: tag
.. automethod:: tag_axis
.. automethod:: compile
.. automethod:: solve
"""

array_types: Tuple[type, ...] = ()
Expand Down Expand Up @@ -536,6 +537,9 @@ def permits_advanced_indexing(self) -> bool:
*True* if the arrays support :mod:`numpy`'s advanced indexing semantics.
"""


def solve(self,

# }}}


Expand Down
31 changes: 31 additions & 0 deletions test/test_arraycontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,37 @@ class ExampleTag(Tag):
assert not ary.axes[1].tags_of_type(ExampleTag)


# {{{ test_solve_sqrt

class SquareRootSolve(Tag):
pass


def test_solve_sqrt(actx_factory):
actx = actx_factory()

def get_root(b):
def f(x):
return x**2 - b

def jacobian(x):
return 2*x

initial = actx.from_numpy(2)
return actx.solve(f, initial, jacobian=jacobian,
tol=1.48e-08, maxiter=50, rtol=0.0,
tags=(SquareRootSolve(),))

get_root_compiled = actx.compile(get_root)

... test that get_root computes square roots ...

if isinstance(actx, (EagerJAXArrayContext, PytatoJAX...)):
... check that the derivative does what we want ...

# }}}


if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
Expand Down