hpfracc.special โ architecture, dependencies, and maintenance๏
This note complements CONTRIBUTING.md and ALGORITHMS_ARCHITECTURE.md. It maps special-function modules, import conventions (especially ฮ-related names), optional backends, and how tests should exercise the package.
1. Design goals๏
Foundation layer: ฮ, ฮ, generalized binomials, and MittagโLeffler implementations used by
algorithms,solvers, andmlwithout importing those packages (acyclic).Clear naming: distinguish SciPy-first helpers from JAX-aware shims so call sites pick the right ฮ API (see ยง3).
Graceful degradation: Numba and JAX are optional; modules define no-op
@jitshims when Numba is missing, and gate JAX paths on successfulimport jax.Numerical hygiene: prefer log-gamma (
gammaln/lgamma) ratios in series wherelog(gamma(x))would be invalid or noisy; guard reflection-formula poles in Numba ฮ.
2. Module layout๏
File |
Responsibility |
|---|---|
|
|
|
Generalized binomials, |
|
|
|
Stable public re-exports and |
Internal edge: mittag_leffler โ gamma_beta only. No other special โ algorithms / core imports.
Not the same as :mod:hpfracc.algorithms.fractional_operator_methods (fractional Laplacian, FrFT, Z/Mellin, etc.). That algorithms module was historically reachable as special_methods; use the fractional_operator_methods name to avoid confusion with this package.
3. Which gamma? (API contract)๏
Symbol |
Typical use |
Behaviour |
|---|---|---|
|
Solvers and code that want NumPy/SciPy semantics only. |
Delegates to |
|
Algorithms that may see JAX arrays. |
If JAX is installed and |
Import style:
Prefer
from hpfracc.special import gamma(orgamma_function) for package-level clarity.Submodule imports (
from hpfracc.special.gamma_beta import ...) are acceptable where tests ormlalready use absolute paths; avoid introducing new circular patterns intospecial.
Solvers (ode_solvers, sde_solvers) use gamma_function aliased to gamma locally so ODE/SDE paths stay on the SciPy-first API.
4. Optional dependencies๏
Dependency |
Role |
|---|---|
SciPy / NumPy |
Primary implementations; assumed for normal installs. |
Numba |
JIT for MittagโLeffler loops, binomial paths, Lanczos ฮ scalar; optional. |
JAX |
|
JAX float64: after import jax, call jax.config.update("jax_enable_x64", True) (avoid deprecated from jax.config import config where possible).
5. Upstream coupling (who imports special)๏
hpfracc.algorithms:gammafrom package;mittag_leffler_fastfrommittag_lefflerin extended operators.hpfracc.solvers:gamma_functionfromgamma_beta.hpfracc.ml: e.g.binomial_sequence_fast,gammavia submodule imports.
Direction is always into special, not the reverse.
6. Risks and mitigations๏
Risk |
Mitigation |
|---|---|
Confusing |
This document + docstrings; use solversโ pattern when SciPy-only is required. |
Series using |
Use |
Reflection formula |
Treat near-zeros of |
Heavy optional imports at package import |
|
7. Tests๏
Primary tree: tests/test_special/ (comprehensive, expanded, high-impact, and smoke-style files). Related algorithm tests may touch algorithms/special_methods.py, which is not under hpfracc/special/ but exercises fractional transforms that depend on numerical integration helpers.
python -m pytest tests/test_special/ -q
When changing ฮ or MittagโLeffler numerics, prefer assertions on finiteness and tolerances rather than silencing warnings globally; fix the implementation when warnings indicate a real pole or invalid log.