Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ jobs:
--extra-index-url https://download.pytorch.org/whl/cpu \
"$(echo ./firedrake-repo/dist/firedrake-*.tar.gz)[ci]"

pip install -I git+https://github.com/firedrakeproject/ufl.git@pbrubeck/hypergeometric
pip install -I git+https://github.com/pbrubeck/loopy.git@pbrubeck/hypergeometric
firedrake-clean
pip list

Expand Down
2 changes: 1 addition & 1 deletion pyop2/global_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def _cppargs(self):
def _ldargs(self):
ldargs = [f"-L{d}/lib" for d in get_petsc_dir()]
ldargs.extend(f"-Wl,-rpath,{d}/lib" for d in get_petsc_dir())
ldargs.extend(["-lpetsc", "-lm"])
ldargs.extend(["-lpetsc", "-lm", "-lgsl", "-lgslcblas"])
ldargs.extend(self.local_kernel.ldargs)
return tuple(ldargs)

Expand Down
23 changes: 23 additions & 0 deletions tests/firedrake/regression/test_hypergeometric_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from firedrake import *
from scipy.special import hyp2f1 as sp_hyp2f1
import numpy as np
import pytest

Check failure on line 4 in tests/firedrake/regression/test_hypergeometric_function.py

View workflow job for this annotation

GitHub Actions / test / Lint codebase

F401

tests/firedrake/regression/test_hypergeometric_function.py:4:1: F401 'pytest' imported but unused


def test_hypergeometric_function():
mesh = UnitDiskMesh(3)
V = FunctionSpace(mesh, "CG", 1)
u = Function(V)
w = Function(V)
x, y = SpatialCoordinate(mesh)

expressions = [((1/3, 1/2, 1), Constant(0.9999) * x),
((1/2, 1/2, 1), Constant(0.9999) * sqrt(x**2+y**2)),
((-1/2, 1/2, 1), Constant(0.4999) * sqrt(x*x + y*y))]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This case is giving a different result for arguments >= 0.5 when compared to scipy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe this is relevant scipy/scipy#8054


for (a, b, c), expr in expressions:
u.interpolate(hyp2f1(a, b, c, expr))
result = u.dat.data
w.interpolate(expr)
expect = sp_hyp2f1(a, b, c, w.dat.data)
assert np.allclose(result, expect)
6 changes: 5 additions & 1 deletion tsfc/loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,11 @@ def _expression_mathfunction(expr, ctx):
else:
return p.Variable(f"{name}n")(nu_, arg_)
else:
if expr.name == "ln":
if expr.name == "hyp2f1":
assert isinstance(ctx.target, lp.target.c.CWithGNULibcTarget)
# Generate right functions calls to gsl hypergeometric function
name = "hyperg_2F1"
elif expr.name == "ln":
name = "log"
else:
name = expr.name
Expand Down
3 changes: 3 additions & 0 deletions tsfc/ufl2gem.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def math_function(self, o, expr):
def atan2(self, o, y, x):
return MathFunction("atan2", y, x)

def hypergeometric2_f1(self, o, a, b, c, arg):
return MathFunction(o._name, a, b, c, arg)

def bessel_i(self, o, nu, arg):
return MathFunction(o._name, nu, arg)

Expand Down
Loading