From 796e63c22f0d8d7c532f3d66cb278a1c0b3c0c97 Mon Sep 17 00:00:00 2001 From: Fruzsina Agocs Date: Wed, 4 Dec 2024 15:10:45 -0700 Subject: [PATCH] BIE example for merge conflict, updates reqs --- quadutils/bie.py | 41 +++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + tests/test_utils.py | 4 ++++ 3 files changed, 46 insertions(+) create mode 100644 quadutils/bie.py diff --git a/quadutils/bie.py b/quadutils/bie.py new file mode 100644 index 0000000..97f38b4 --- /dev/null +++ b/quadutils/bie.py @@ -0,0 +1,41 @@ +import numpy as np +import scipt as sp + +def Phi(x, y, k = 0.0): + """ + What does this function do? + + Parameters + ---------- + x: np.array + Can have shape (2, n) or (2,). In the latter case, it'll be converted + to (2, 1). + What is this variable? + y: ? + Can have shape (2, m) or (2,). In the latter case, it'll be converted + to (2, 1). + What is this variable? + k: float, optional + Default k = 0. What is this variable? + + Returns + ------- + phi: ? + What's this variable? What's its shape? + """ + # Reshape input vectors if given in the shape (2,). Skip if (2, n). + if x.ndim < 2: + x = x.reshape((2, -1)) + if y.ndim < 2: + y = y.reshape((2, -1)) + # Distance vector(s) between pairs of (x, y). + # If x is (2, n), and y is (2, m), d will still be of shape (2, n, m). + d = x[..., None] - y[:, None] + # What are these two cases? + if k == 0.0: + phi = -1/(2*np.pi)*np.log(np.linalg.norm(d, axis = 0)) + else: + r = np.linalg.norm(d, axis = 0) + phi = 1j/4*sp.hankel1(0, k*r) + return phi + diff --git a/requirements.txt b/requirements.txt index 1cc18fc..f651ca5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ numpy pytest +scipy diff --git a/tests/test_utils.py b/tests/test_utils.py index 547d725..3c60ce0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -14,6 +14,7 @@ def test_quadroots_1(): def test_chebD_1(): n = 16 D, x = ch.chebD(n) + print(x) f = lambda x: x**2 # Test function should be differentiated exactly interval = np.array([0, 0.5]) h = interval[1] - interval[0] @@ -22,3 +23,6 @@ def test_chebD_1(): df_num = 2/h*D@f(x_scaled) df_err = max(np.abs(df_ana(x_scaled) - df_num)) assert df_err < 1e-13 + +def test_phi_1(): + pass