Skip to content

Commit

Permalink
Expose/test kepF and kepDE.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Oct 22, 2023
1 parent a8fbce7 commit d0198d1
Show file tree
Hide file tree
Showing 10 changed files with 657 additions and 406 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

project(heyoka.py VERSION 3.0.0 LANGUAGES CXX C)
project(heyoka.py VERSION 3.1.0 LANGUAGES CXX C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/yacma")

Expand Down Expand Up @@ -118,7 +118,7 @@ find_package(fmt REQUIRED CONFIG)
message(STATUS "fmt version: ${fmt_VERSION}")

# heyoka.
find_package(heyoka 3.0.0 REQUIRED CONFIG)
find_package(heyoka 3.1.0 REQUIRED CONFIG)

# Python.

Expand Down
9 changes: 8 additions & 1 deletion doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
Changelog
=========

3.0.1 (unreleased)
3.1.0 (unreleased)
------------------

Changes
~~~~~~~

- heyoka.py now requires version 3.1.0 of the
heyoka C++ library
(`#140 <https://github.com/bluescarni/heyoka.py/pull/140>`__).

Fix
~~~

Expand Down
2 changes: 2 additions & 0 deletions heyoka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ set(HEYOKA_PY_PYTHON_FILES
_test_batch_integrator.py
_test_ensemble.py
_test_memcache.py
_test_celmec.py
_test_sympy.py
model/__init__.py
)

Expand Down
2 changes: 2 additions & 0 deletions heyoka/_sympy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def mul_wrapper(*args):
retval[_spy.Mul] = mul_wrapper

retval[_spy.Function("heyoka_kepE")] = core.kepE
retval[_spy.Function("heyoka_kepF")] = core.kepF
retval[_spy.Function("heyoka_kepDE")] = core.kepDE
retval[_spy.Function("heyoka_time")] = lambda: core.time

return retval
Expand Down
165 changes: 165 additions & 0 deletions heyoka/_test_celmec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# Copyright 2020, 2021, 2022, 2023 Francesco Biscani ([email protected]), Dario Izzo ([email protected])
#
# This file is part of the heyoka.py library.
#
# This Source Code Form is subject to the terms of the Mozilla
# Public License v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.


import unittest as _ut


class kepE_test_case(_ut.TestCase):
def test_expr(self):
from . import kepE, diff, make_vars, sin, cos, core
from .core import _ppc_arch
import numpy as np

x, y = make_vars("x", "y")

# Try a few overloads.
kepE(x, y)
kepE(0.1, y)
kepE(e=x, M=0.2)

self.assertEqual(
diff(kepE(x, y), x), sin(kepE(x, y)) / (1.0 - x * cos(kepE(x, y)))
)
self.assertEqual(diff(kepE(x, y), y), 1.0 / (1.0 - x * cos(kepE(x, y))))

if not _ppc_arch:
self.assertEqual(
diff(kepE(x, np.longdouble("1.1")), x),
sin(kepE(x, np.longdouble("1.1")))
/ (1.0 - x * cos(kepE(x, np.longdouble("1.1")))),
)
self.assertEqual(
diff(kepE(np.longdouble("1.1"), y), y),
1.0 / (1.0 - np.longdouble("1.1") * cos(kepE(np.longdouble("1.1"), y))),
)

kepE(np.longdouble(0.1), y)
kepE(x, np.longdouble(0.2))

with self.assertRaises(TypeError) as cm:
kepE(0.1, np.longdouble("1.1"))
self.assertTrue(
"At least one of the arguments of kepE() must be an expression"
in str(cm.exception)
)

with self.assertRaises(TypeError) as cm:
kepE(0.1, 0.2)
self.assertTrue(
"At least one of the arguments of kepE() must be an expression"
in str(cm.exception)
)

if not hasattr(core, "real128"):
return

from .core import real128

self.assertEqual(
diff(kepE(x, real128("1.1")), x),
sin(kepE(x, real128("1.1"))) / (1.0 - x * cos(kepE(x, real128("1.1")))),
)
self.assertEqual(
diff(kepE(real128("1.1"), y), y),
1.0 / (1.0 - real128("1.1") * cos(kepE(real128("1.1"), y))),
)


class kepF_test_case(_ut.TestCase):
def test_expr(self):
from . import kepF, make_vars, core
from .core import _ppc_arch
import numpy as np

x, y, z = make_vars("x", "y", "z")

# Try a few overloads.
kepF(x, y, z)
kepF(0.1, y, z)
kepF(h=0.1, k=0.2, lam=z)

if not _ppc_arch:
kepF(x, y, np.longdouble("1.1"))
kepF(x, np.longdouble(".1"), np.longdouble("1.1"))

with self.assertRaises(TypeError) as cm:
kepF(x, 0.1, np.longdouble("1.1"))
self.assertTrue(
"The numerical arguments of kepF() must be all of the same type"
in str(cm.exception)
)

with self.assertRaises(TypeError) as cm:
kepF(0.1, 0.2, 0.3)
self.assertTrue(
"At least one of the arguments of kepF() must be an expression"
in str(cm.exception)
)

if not hasattr(core, "real128"):
return

from .core import real128

kepF(real128(0.1), y, z)
kepF(real128(0.1), real128(0.2), z)

with self.assertRaises(TypeError) as cm:
kepF(x, 0.1, real128("1.1"))
self.assertTrue(
"The numerical arguments of kepF() must be all of the same type"
in str(cm.exception)
)


class kepDE_test_case(_ut.TestCase):
def test_expr(self):
from . import kepDE, make_vars, core
from .core import _ppc_arch
import numpy as np

x, y, z = make_vars("x", "y", "z")

# Try a few overloads.
kepDE(x, y, z)
kepDE(0.1, y, z)
kepDE(s0=0.1, c0=0.2, DM=z)

if not _ppc_arch:
kepDE(x, y, np.longdouble("1.1"))
kepDE(x, np.longdouble(".1"), np.longdouble("1.1"))

with self.assertRaises(TypeError) as cm:
kepDE(x, 0.1, np.longdouble("1.1"))
self.assertTrue(
"The numerical arguments of kepDE() must be all of the same type"
in str(cm.exception)
)

with self.assertRaises(TypeError) as cm:
kepDE(0.1, 0.2, 0.3)
self.assertTrue(
"At least one of the arguments of kepDE() must be an expression"
in str(cm.exception)
)

if not hasattr(core, "real128"):
return

from .core import real128

kepDE(real128(0.1), y, z)
kepDE(real128(0.1), real128(0.2), z)

with self.assertRaises(TypeError) as cm:
kepDE(x, 0.1, real128("1.1"))
self.assertTrue(
"The numerical arguments of kepDE() must be all of the same type"
in str(cm.exception)
)
8 changes: 7 additions & 1 deletion heyoka/_test_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_expression(self):
if not hasattr(core, "real"):
return

from . import expression as ex, real, kepE, atan2
from . import expression as ex, real, kepE, kepF, kepDE, atan2

self.assertEqual(
str(ex(real("1.1", 128))), "1.100000000000000000000000000000000000001"
Expand Down Expand Up @@ -415,6 +415,12 @@ def test_expression(self):
kepE(ex("x"), real("1.1", 128))
kepE(real("1.1", 128), ex("x"))

kepF(ex("x"), real("1.1", 128), ex("y"))
kepF(real("1.1", 128), ex("y"), ex("x"))

kepDE(ex("x"), real("1.1", 128), ex("y"))
kepDE(real("1.1", 128), ex("y"), ex("x"))

atan2(ex("x"), real("1.1", 128))
atan2(real("1.1", 128), ex("x"))

Expand Down
Loading

0 comments on commit d0198d1

Please sign in to comment.