Skip to content

Commit

Permalink
final set of tests + xfail a few tests on numpy 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp committed Apr 19, 2024
1 parent 50e27ff commit 1642243
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/compute/sympy/lorentz/test_boostX_gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2019-2024, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/vector for details.

from __future__ import annotations

import pytest

import vector

sympy = pytest.importorskip("sympy")

pytestmark = pytest.mark.sympy

x, y, z, t = sympy.symbols("x y z t", real=True)
values = {x: 3, y: 2, z: 1, t: 10}


def test():
vec = vector.VectorSympy4D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
longitudinal=vector.backends.sympy.LongitudinalSympyZ(z),
temporal=vector.backends.sympy.TemporalSympyT(t),
)
out = vec.boostX(gamma=3)
assert out.x == 2 * sympy.sqrt(2) * t + 3 * x
assert out.y == y
assert out.z == z
assert out.t == 3 * t + 2 * sympy.sqrt(2) * x

for t1 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
tvec = getattr(vec, "to_" + t1)()
out = tvec.boostX(gamma=3)
assert out.x.subs(values).evalf() == pytest.approx(37.2842712474619)
assert out.y.subs(values).evalf() == pytest.approx(2)
assert out.z.subs(values).evalf() == pytest.approx(1)
assert out.t.subs(values).evalf() == pytest.approx(38.4852813742386)
51 changes: 51 additions & 0 deletions tests/compute/sympy/lorentz/test_boostY_gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2019-2024, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/vector for details.

from __future__ import annotations

import pytest

import vector

sympy = pytest.importorskip("sympy")

pytestmark = pytest.mark.sympy

x, y, z, t = sympy.symbols("x y z t", real=True)
values = {x: 2, y: 3, z: 1, t: 4}


def test():
vec = vector.VectorSympy4D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
longitudinal=vector.backends.sympy.LongitudinalSympyZ(z),
temporal=vector.backends.sympy.TemporalSympyT(t),
)
out = vec.boostY(gamma=3)
assert out.x == x
assert out.y == 2 * sympy.sqrt(2) * t + 3 * y
assert out.z == z
assert out.t == 3 * t + 2 * sympy.sqrt(2) * y

for t1 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
tvec = getattr(vec, "to_" + t1)()
out = tvec.boostY(gamma=3)
assert out.x.subs(values).evalf() == pytest.approx(2)
assert out.y.subs(values).evalf() == pytest.approx(20.3137084989848)
assert out.z.subs(values).evalf() == pytest.approx(1)
assert out.t.subs(values).evalf() == pytest.approx(20.4852813742386)
51 changes: 51 additions & 0 deletions tests/compute/sympy/lorentz/test_boostZ_gamma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2019-2024, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/vector for details.

from __future__ import annotations

import pytest

import vector

sympy = pytest.importorskip("sympy")

pytestmark = pytest.mark.sympy

x, y, z, t = sympy.symbols("x y z t", real=True)
values = {x: 1, y: 2, z: 3, t: 4}


def test():
vec = vector.VectorSympy4D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
longitudinal=vector.backends.sympy.LongitudinalSympyZ(z),
temporal=vector.backends.sympy.TemporalSympyT(t),
)
out = vec.boostZ(gamma=3)
assert out.x == x
assert out.y == y
assert out.z.subs(values).evalf() == pytest.approx(20.3137084989848)
assert out.t.subs(values).evalf() == pytest.approx(20.4852813742386)

for t1 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
tvec = getattr(vec, "to_" + t1)()
out = tvec.boostZ(gamma=3)
assert out.x.subs(values).evalf() == pytest.approx(1)
assert out.y.subs(values).evalf() == pytest.approx(2)
assert out.z.subs(values).evalf() == pytest.approx(20.3137084989848)
assert out.t.subs(values).evalf() == pytest.approx(20.4852813742386)
16 changes: 16 additions & 0 deletions tests/compute/sympy/test_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

from __future__ import annotations

import importlib.metadata

import packaging.version
import pytest

import vector
Expand All @@ -16,7 +19,13 @@
x, y, z, t = sympy.symbols("x y z t", real=True)
values = {x: 1, y: 2, z: 3, t: 10}

# mpmath does not support numpy 2.0 yet
numpy_2 = packaging.version.Version(
importlib.metadata.version("numpy")
) >= packaging.version.Version("2.0.0")


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_planar_posfactor():
vec = vector.VectorSympy2D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand All @@ -34,6 +43,7 @@ def test_planar_posfactor():
assert out.y.subs(values).evalf() == pytest.approx(2 * 1.75)


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_planar_negfactor():
vec = vector.VectorSympy2D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand All @@ -51,6 +61,7 @@ def test_planar_negfactor():
assert out.y.subs(values).evalf() == pytest.approx(2 * -1.75)


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_spatial_posfactor():
vec = vector.VectorSympy3D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand Down Expand Up @@ -80,6 +91,7 @@ def test_spatial_posfactor():
assert out.z.subs(values).evalf() == pytest.approx(3 * 1.75)


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_spatial_negfactor():
vec = vector.VectorSympy3D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand Down Expand Up @@ -109,6 +121,7 @@ def test_spatial_negfactor():
assert out.z.subs(values).evalf() == pytest.approx(3 * -1.75)


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_lorentz_postime_posfactor():
vec = vector.VectorSympy4D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand Down Expand Up @@ -149,6 +162,7 @@ def test_lorentz_postime_posfactor():
assert out.t.subs(values).evalf() == pytest.approx(10 * 1.75)


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_lorentz_postime_negfactor():
vec = vector.VectorSympy4D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand Down Expand Up @@ -201,6 +215,7 @@ def test_lorentz_postime_negfactor():
assert out.t.subs(values).evalf() == pytest.approx(10 * 1.75)


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_lorentz_negtime_posfactor():
vec = vector.VectorSympy4D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand Down Expand Up @@ -253,6 +268,7 @@ def test_lorentz_negtime_posfactor():
assert out.t.subs(values).evalf() == pytest.approx(10 * 1.75)


@pytest.mark.xfail(numpy_2, reason="mpmath does not support numpy 2.0 yet")
def test_lorentz_negtime_negfactor():
vec = vector.VectorSympy4D(
azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
Expand Down

0 comments on commit 1642243

Please sign in to comment.