Skip to content

Commit

Permalink
Update use of np.ptp()
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnectedSystems committed Jul 14, 2024
1 parent da19e09 commit ddda078
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/SALib/analyze/delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def calc_delta(Y, Ygrid, X, m):

# if not np.all(np.equal(Y_ix, Y_ix[0])):
Y_ix = Y[ix]
if Y_ix.ptp() != 0.0:
if np.ptp(Y_ix) != 0.0:
fyc = gaussian_kde(Y_ix, bw_method="silverman")(Ygrid)
fy_ = np.abs(fy - fyc)
else:
Expand Down Expand Up @@ -168,7 +168,7 @@ def bias_reduced_delta(Y, Ygrid, X, m, num_resamples, conf_level, y_resamples):
def sobol_first(Y, X, m):
# pre-process to catch constant array
# see: https://github.com/numpy/numpy/issues/9631
if Y.ptp() == 0.0:
if np.ptp(Y) == 0.0:
# Catch constant results
# If Y does not change then it is not sensitive to anything...
return 0.0
Expand Down
8 changes: 4 additions & 4 deletions src/SALib/analyze/sobol.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def analyze(
if keep_resamples:
S["S1_conf_all"][:, j] = S1_conf_j

var_diff = np.r_[A[r], B[r]].ptp()
var_diff = np.ptp(np.r_[A[r], B[r]])
if var_diff != 0.0:
S["S1_conf"][j] = Z * S1_conf_j.std(ddof=1)
else:
Expand Down Expand Up @@ -212,7 +212,7 @@ def first_order(A, AB, B):
sample variance
"""
y = np.r_[A, B]
if y.ptp() == 0:
if np.ptp(y) == 0:
warn(CONST_RESULT_MSG)
return np.array([0.0])

Expand All @@ -225,7 +225,7 @@ def total_order(A, AB, B):
sample variance
"""
y = np.r_[A, B]
if y.ptp() == 0:
if np.ptp(y) == 0:
warn(CONST_RESULT_MSG)
return np.array([0.0])

Expand All @@ -235,7 +235,7 @@ def total_order(A, AB, B):
def second_order(A, ABj, ABk, BAj, B):
"""Second order estimator following Saltelli 2002"""
y = np.r_[A, B]
if y.ptp() == 0:
if np.ptp(y) == 0:
warn(CONST_RESULT_MSG)
return np.array([0.0])

Expand Down
4 changes: 2 additions & 2 deletions tests/sample/test_latin.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def test_latin_group_constant(self):
# Group samples should have the same values
# Get (max - min) with the `ptp()` method, the result of which should be
# an array of zeros
diff = samples[:, ::2].ptp(axis=1)
diff = np.ptp(samples[:, ::2], axis=1)
assert np.all(diff == 0), "Grouped samples do not have the same values"

diff = samples[:, 1::2].ptp(axis=1)
diff = np.ptp(samples[:, 1::2], axis=1)
assert np.all(diff == 0), "Grouped samples do not have the same values"

0 comments on commit ddda078

Please sign in to comment.