Skip to content

Commit

Permalink
test: neg vec
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Mar 1, 2024
1 parent c7236cd commit 0402611
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/vector/_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

_0m = Quantity(0, "meter")
_0d = Quantity(0, "rad")
_pid = Quantity(xp.pi, "rad")
_2pid = Quantity(2 * xp.pi, "rad")
_pid = Quantity(180, "deg")
_2pid = Quantity(360, "deg")


def check_r_non_negative(r: BatchableLength) -> BatchableLength:
Expand Down
38 changes: 37 additions & 1 deletion tests/test_d3.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,42 @@
class Abstract3DVectorTest(AbstractVectorTest):
"""Test :class:`vector.Abstract3DVector`."""

# ==========================================================================
# Unary operations

def test_neg_compare_apy(
self, vector: AbstractVector, apyvector: apyc.BaseRepresentation
):
"""Test negation."""
# To take the negative, Vector converts to Cartesian coordinates, takes
# the negative, then converts back to the original representation.
# This can result in equivalent but different angular coordinates than
# Astropy. AFAIK this only happens at the poles.
cart = convert(-vector, type(apyvector)).represent_as(
apyc.CartesianRepresentation
)
apycart = -apyvector.represent_as(apyc.CartesianRepresentation)
assert np.allclose(cart.x, apycart.x, atol=5e-7)
assert np.allclose(cart.y, apycart.y, atol=5e-7)
assert np.allclose(cart.z, apycart.z, atol=5e-7)

# # Try finding the poles
# if hasattr(vector, "theta"):
# sel = (vector.theta.to_value("deg") != 0) & (
# vector.theta.to_value("deg") != 180
# )
# else:
# sel = slice(None)
# vecsel = convert(-vector[sel], type(apyvector))
# apyvecsel = -apyvector[sel]
# for c in vecsel.components:
# unit = getattr(apyvecsel, c).unit
# assert np.allclose(
# getattr(vecsel, c).to_value(unit),
# getattr(apyvecsel, c).to_value(unit),
# atol=5e-7,
# )


class TestCartesian3DVector(Abstract3DVectorTest):
"""Test :class:`vector.Cartesian3DVector`."""
Expand Down Expand Up @@ -604,7 +640,7 @@ def test_cartesian3d_to_cylindrical(self, difntl, vector):
)
assert array_equal(cylindrical.d_z, Quantity([9, 10, 11, 12], u.km / u.s))

def test_cartesian3d_to_spherical_astropy(
def test_cartesian3d_to_cylindrical_astropy(
self, difntl, vector, apydifntl, apyvector
):
"""Test Astropy equivalence."""
Expand Down

0 comments on commit 0402611

Please sign in to comment.