-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: add unevaluated integral class (#394)
See https://compwa.github.io/report/016#sympy-integral * DOC: explain numerical integral examples * DX: avoid IPython debug warnings * ENH: emit warning if SciPy is not installed
- Loading branch information
Showing
6 changed files
with
291 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import numpy as np | ||
import pytest | ||
import sympy as sp | ||
|
||
from ampform.sympy import UnevaluatableIntegral | ||
|
||
|
||
class TestUnevaluatableIntegral: | ||
def test_real_value_function(self): | ||
x = sp.symbols("x") | ||
integral_expr = UnevaluatableIntegral(x**2, (x, 1, 3)) | ||
func = sp.lambdify(args=[], expr=integral_expr) | ||
assert func() == 26 / 3 | ||
|
||
@pytest.mark.parametrize( | ||
"p_value,expected", | ||
[ | ||
(2, 26 / 3), | ||
(1, 4), | ||
(1j, (1 / 2 - 1j / 2) * (-1 + 3 ** (1 + 1j))), | ||
( | ||
np.array([0, 0.5, 1, 2]), | ||
np.array([2, 2 * 3 ** (1 / 2) - 2 / 3, 4, 8 + 2 / 3]), | ||
), | ||
], | ||
) | ||
def test_vectorized_parameter_function(self, p_value, expected): | ||
x, p = sp.symbols("x,p") | ||
integral_expr = UnevaluatableIntegral(x**p, (x, 1, 3)) | ||
func = sp.lambdify(args=[p], expr=integral_expr) | ||
assert pytest.approx(func(p=p_value)) == expected |