Skip to content

Commit

Permalink
Remove dependency con pycephes, implement function
Browse files Browse the repository at this point in the history
Alternative until poliastro/pycephes#1 makes
progress.
  • Loading branch information
astrojuanlu committed Mar 6, 2016
1 parent 203cd72 commit 7ab4cca
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ before_install:
- source activate test-environment

# Install project requirements
- conda install numpy=$NUMPY numba>=0.23 astropy>=1.0 matplotlib scipy jplephem pycephes
- conda install numpy=$NUMPY numba>=0.23 astropy>=1.0 matplotlib scipy jplephem
- pip install coverage pytest pytest-cov codecov pytest-benchmark

install:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ install:
- "pip install pytest codecov pytest-benchmark"

# Install dependencies
- "conda install -q numpy=%NUMPY% numba>=0.23 astropy>=1.0 matplotlib scipy jplephem pycephes"
- "conda install -q numpy=%NUMPY% numba>=0.23 astropy>=1.0 matplotlib scipy jplephem"
- "pip install ." # Test installation correctness

build: off
Expand Down
1 change: 0 additions & 1 deletion buildscripts/condarecipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ requirements:
- astropy >=1.0
- jplephem
- matplotlib
- pycephes

test:
imports:
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ dependencies:
- numba
- numpy
- scipy
- pycephes
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"matplotlib",
"jplephem",
"scipy",
"pycephes",
],
tests_require=[
"pytest"
Expand Down
26 changes: 26 additions & 0 deletions src/poliastro/hyper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Utility hypergeometric functions.
"""
import numpy as np

from poliastro.jit import jit


@jit('f8(f8)')
def hyp2f1b(x):
"""Hypergeometric function 2F1(3, 1, 5/2, x), see [Battin].
"""
if x >= 1.0:
return np.inf
else:
res = 1.0
term = 1.0
ii = 0
while True:
term = term * (3 + ii) * (1 + ii) / (5 / 2 + ii) * x / (ii + 1)
res_old = res
res += term
if res_old == res:
return res
ii += 1
3 changes: 1 addition & 2 deletions src/poliastro/iod/izzo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

from poliastro.jit import jit
from poliastro.util import norm

from pycephes.hyper import hyp2f1
from poliastro.hyper import hyp2f1b as hyp2f1


def lambert(k, r0, r, tof, M=0, numiter=35, rtol=1e-8):
Expand Down
15 changes: 15 additions & 0 deletions src/poliastro/tests/test_hyper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest

import numpy as np
from numpy.testing import assert_almost_equal
from scipy import special

from poliastro.hyper import hyp2f1b as hyp2f1


@pytest.mark.parametrize("x", np.linspace(0, 1, num=10))
def test_hyp2f1_battin_scalar(x):
expected_res = special.hyp2f1(3, 1, 5/2, x)

res = hyp2f1(x)
assert_almost_equal(res, expected_res)

0 comments on commit 7ab4cca

Please sign in to comment.