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

Handle numpy metadata (quadrature arrays) without throwing a warning #293

Closed
wants to merge 1 commit into from
Closed
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 ufl/utils/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import warnings

import numpy as np


def topological_sorting(nodes, edges):
"""Return a topologically sorted list of the nodes.
Expand Down Expand Up @@ -84,6 +86,8 @@ def canonicalize_metadata(metadata):
value = str(value)
elif hasattr(value, "ufl_signature"):
value = value.ufl_signature
elif isinstance(value, np.ndarray):
value = np.array2string(value, separator=" ")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this safe? That array can get quite big.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is what happens for a numpy array as input to metadata atm irregardless (just throws a user warning).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, I'm just nervous about silencing a warning that might have an actual point.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we want to avoid people sending in large arrays of custom quadrature points/weights we should find a better way to let people patch in custom quadrature rules.

Currently they have to be implemented in FINAT/FIAT/basix?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's discuss this in person tomorrow. I have ideas.

else:
warnings.warn(
f"Applying str() to a metadata value of type {type(value).__name__}, "
Expand Down
Loading