Skip to content

Commit

Permalink
Adds a fix for the period argument
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdsharpe committed Mar 30, 2024
1 parent 0f040d8 commit c7bea0e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions aerosandbox/numpy/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def gradient(
not is_casadi_type(f)
and all([not is_casadi_type(vararg) for vararg in varargs])
and n == 1
and period is None
):
return _onp.gradient(
f,
Expand Down Expand Up @@ -110,7 +111,6 @@ def gradient(
dxes.append(
diff(
vararg,
period=period
)
)

Expand Down Expand Up @@ -172,6 +172,10 @@ def get_slice(slice_obj: slice) -> Tuple[slice]:
- f[get_slice(slice(None, -2))]
)

if period is not None:
dfp = _centered_mod(dfp, period)
dfm = _centered_mod(dfm, period)

if n == 1:
grad_f = (
hm ** 2 * dfp + hp ** 2 * dfm
Expand Down Expand Up @@ -281,7 +285,15 @@ def trapz(x, modify_endpoints=False): # TODO unify with NumPy trapz, this is di

import casadi as cas

print(diff(cas.DM([355, 5]), period=360))
# print(diff(cas.DM([355, 5]), period=360))

print(
gradient(
np.linspace(45, 55, 11) % 50,
period=50
)
)

#
# # a = np.linspace(-500, 500, 21) % 360 - 180
# # print(diff(a, period=360))
Expand Down

0 comments on commit c7bea0e

Please sign in to comment.