Check for Partial Matching between Domain Instances#

import minterpy as mp
import numpy as np

Two instances of Domain may be checked for partial matching via the partial_matching() method as demonstrated in this guide.

Two instances of Domain are partially matching if both their user-defined bounds and their internal bounds, up to the common spatial dimension, are approximately equal as determined by numpy.allclose():

  • User bounds: The rectangular bounds of the domain as specified by the user during instance construction, e.g., \([0, 5] \times [1, 2]\).

  • Internal bounds: The bounds of the reference domain used internally by Minterpy. Currently they are always set to \([-1, 1]^m\).

Two instances of Domain are partially matching if the bounds, both internal and user, up to a common dimension are approximately closed as defined by the NumPy function allclose().

Example: Two equal domains#

As a baseline, two equal instances of Domain are by definition partially matching.

  • \(\Omega_1 = [1, 2] \times [1, 2]\)

  • \(\Omega_2 = [1, 2] \times [1, 2]\)

dom_1 = mp.Domain(np.array([[1, 2], [1, 2]]))
dom_2 = mp.Domain(np.array([[1, 2], [1, 2]]))
dom_1 == dom_2  # True
True
dom_1.partial_matching(dom_2)  # True
True

Example: Two partially matching domains#

The two instances below are not equal in values but partially matching:

  • \(\Omega_3 = [1, 2] \times [3, 4] \times [5, 6]\)

  • \(\Omega_4 = [1, 2] \times [3, 4]\)

dom_3 = mp.Domain(np.array([[1, 2], [3, 4], [5, 6]]))
dom_4 = mp.Domain(np.array([[1, 2], [3, 4]]))
dom_3 == dom_4  # False
False
dom_3.partial_matching(dom_4)  # True
True

This is because up to the common dimension, i.e., \(m = 2\) all the bounds of the two domains are equal or close to each other.

Note that partial_matching() is symmetric; the result is the same regardless of which instance the method is called on, because the common dimension is determined by the minimum of the two spatial dimensions.

dom_4.partial_matching(dom_3)  # True
True

Example: Domains with no partial matching#

The two instances below are not equal in values and has no partial matching:

  • \(\Omega_5 = [1, 2]\)

  • \(\Omega_6 = [5, 6] \times [1, 2]\)

dom_5 = mp.Domain(np.array([[1, 2]]))
dom_6 = mp.Domain(np.array([[5, 6], [1, 2]]))
dom_5 == dom_6  # False
False
dom_5.partial_matching(dom_6)  # False
False

Since the common dimension is \(m = 1\) and the bounds of the first and second domains up to \(m=1\) do not match, the two domains are note partially matching.

Tolerance control#

The comparison uses approximate equality via numpy.allclose(). The default tolerances can be overridden via the rtol and atol parameters.

For example, the two domains below differ by a tiny floating-point amount in the first dimension.

dom_a = mp.Domain(np.array([[1, 2], [3, 4]]))
dom_b = mp.Domain(np.array([[1 + 1e-10, 2], [3, 4]]))

With default tolerances, they are considered partially matching:

dom_a.partial_matching(dom_b)  # True
True
dom_b.partial_matching(dom_a)  # True
True

With a very tight tolerance, they are not:

dom_a.partial_matching(dom_b, rtol=0)  # False
False
dom_b.partial_matching(dom_a, rtol=0)  # False
False