Coverage for src/lsqfitgp/_special/_sinc.py: 100%
10 statements
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-15 19:54 +0000
« prev ^ index » next coverage.py v7.6.3, created at 2024-10-15 19:54 +0000
1# lsqfitgp/_special/_sinc.py
2#
3# Copyright (c) 2022, Giacomo Petrillo
4#
5# This file is part of lsqfitgp.
6#
7# lsqfitgp is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# lsqfitgp is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with lsqfitgp. If not, see <http://www.gnu.org/licenses/>.
20from jax import numpy as jnp 1efabcd
21from jax.scipy import special as jspecial 1efabcd
23from . import _taylor 1efabcd
25def coefgen_sinc(s, e): 1efabcd
26 m = jnp.arange(s, e) 1abcd
27 return (-1) ** m / jnp.exp(jspecial.gammaln(2 + 2 * m)) 1abcd
29def sinc(x): 1efabcd
30 nearzero = _taylor.taylor(coefgen_sinc, (), 0, 6, jnp.square(jnp.pi * x)) 1abcd
31 normal = jnp.sinc(x) 1abcd
32 return jnp.where(jnp.abs(x) < 1e-1, nearzero, normal) 1abcd