Skip to content

Gmres#360

Open
inducer wants to merge 3 commits into
mainfrom
gmres
Open

Gmres#360
inducer wants to merge 3 commits into
mainfrom
gmres

Conversation

@inducer
Copy link
Copy Markdown
Owner

@inducer inducer commented Jun 4, 2026

Since I want access to a solve in grudge, I figured moving GMRES from pytential would be the easiest. Once this is merged, I'll remove the one in pytential (with deprecation blah). This one isn't totally compatible, fwiw: The pytential one had some actx autodiscovery "stuff" that I'll probably have to re-add.

This also brings sumpy's build_matrix here.

@inducer inducer force-pushed the gmres branch 2 times, most recently from 1afaaaa to ca1a922 Compare June 4, 2026 16:44
Copy link
Copy Markdown
Collaborator

@alexfikl alexfikl left a comment

Choose a reason for hiding this comment

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

Left a few comments, but overall this looks like a good place for it to me.

class InnerProduct(Protocol, Generic[T]):
"""A :class:`~typing.Protocol` for the inner product used by :func:`gmres`."""

def __call__(self, a: T, b: T) -> T: ...
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def __call__(self, a: T, b: T) -> T: ...
def __call__(self, a: T, b: T) -> float: ...

?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Not really: GPU array contexts return reduction results as device scalars, i.e. arrays. And numpy is forgiving enough that it sort-of fits.

Comment on lines +106 to +108
if (isinstance(x, Number)
or (isinstance(x, np.ndarray) and x.dtype.char != "O")):
return np.vdot(x, y)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seeing as we have a NumpyArrayContext now, does this make sense (the isinstance(x, ndarray) part)? Not quite sure where this was used in pytential either..

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

It does make sense to me. 😁 This gets used on object arrays that look like [DOFArray, scalar], e.g. when there are scalar degrees of freedom floating around somewhere.

Comment thread arraycontext/linalg/solve.py
Comment thread arraycontext/linalg/solve.py
Comment on lines +443 to +447
if show_spectrum:
ev = la.eigvals(mat)
import matplotlib.pyplot as pt
pt.plot(ev.real, ev.imag, "o")
pt.show()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would remove this?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Don't know. It's not meant for serious use because of the inherent inefficiency, so it doesn't matter? And six times out of ten, the reason I'm reaching for this is because the iterative solve died because of some issue in the spectrum. Compromise: _show_spectrum?

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