Skip to content

Commit 20cd729

Browse files
committed
use numpy.broadcast_arrays instead of broadcast_to for simplicity
1 parent 8543d5c commit 20cd729

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pymap3d
3-
version = 2.7.1
3+
version = 2.7.2
44
author = Michael Hirsch, Ph.D.
55
author_email = [email protected]
66
description = pure Python (no prereqs) coordinate conversions, following convention of several popular Matlab routines.

src/pymap3d/lox.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@
44
import typing
55

66
try:
7-
from numpy import (
8-
radians,
9-
degrees,
10-
cos,
11-
arctan2 as atan2,
12-
tan,
13-
pi,
14-
array,
15-
atleast_1d,
16-
broadcast_arrays,
17-
broadcast_to,
18-
)
7+
from numpy import radians, degrees, cos, arctan2 as atan2, tan, pi, array, broadcast_arrays
198
except ImportError:
209
from math import radians, degrees, cos, atan2, tan, pi # type: ignore
2110

@@ -227,16 +216,7 @@ def loxodrome_direct(
227216
lat1, lon1, a12 = radians(lat1), radians(lon1), radians(a12)
228217

229218
try:
230-
lat1 = atleast_1d(lat1)
231-
rng = atleast_1d(rng)
232-
233-
if lat1.shape != rng.shape:
234-
if rng.size == 1:
235-
rng = broadcast_to(rng, lat1.shape)
236-
elif lat1.size == 1:
237-
lat1 = broadcast_to(lat1, rng.shape)
238-
else:
239-
raise ValueError("lat1 and rng must each be scalars or same shape")
219+
lat1, rng = broadcast_arrays(lat1, rng)
240220
if (abs(lat1) > pi / 2).any(): # type: ignore
241221
raise ValueError("-90 <= latitude <= 90")
242222
if (rng < 0).any(): # type: ignore

src/pymap3d/tests/test_rhumb.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ def test_numpy_loxodrome_inverse():
7878

7979
def test_numpy_2d_loxodrome_inverse():
8080
pytest.importorskip("numpy")
81-
d, a = lox.loxodrome_inverse(
82-
[[40, 40], [40, 40]], [[-80, -80], [-80, -80]], 65, -148
83-
)
81+
d, a = lox.loxodrome_inverse([[40, 40], [40, 40]], [[-80, -80], [-80, -80]], 65, -148)
8482
assert d == approx(5248666.209)
8583
assert a == approx(302.00567)
8684

@@ -90,9 +88,7 @@ def test_numpy_2d_loxodrome_inverse():
9088
d, a = lox.loxodrome_inverse(
9189
[[40, 40], [40, 40]], [[-80, -80], [-80, -80]], 65, [[-148, -148], [-148, -148]]
9290
)
93-
d, a = lox.loxodrome_inverse(
94-
40, -80, [[65, 65], [65, 65]], [[-148, -148], [-148, -148]]
95-
)
91+
d, a = lox.loxodrome_inverse(40, -80, [[65, 65], [65, 65]], [[-148, -148], [-148, -148]])
9692

9793

9894
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)