Skip to content

Commit ec74058

Browse files
committed
Further improve bin1d_vec (2): replace .min(bins) with bins[0]
... due to assuming/requiring sorted bins - as mentioned in the docstring; "`bins [...] must be monotonically increasing`". This is not checked, presumably because pyCSEP itself never passes unsorted bins to this method (they always originate from ranges). --> Added a check at the top, but commented it out; we may activate it in the future if there is need - for now, it only serves as an additional hint.
1 parent 79c08dd commit ec74058

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

csep/utils/calc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def bin1d_vec(p, bins, tol=None, right_continuous=False):
7070
7171
Args:
7272
p (array-like): Point(s) to be placed into b
73-
bins (array-like): bins to considering for binning, must be monotonically increasing
73+
bins (array-like): bin edges; must be sorted (monotonically increasing)
7474
right_continuous (bool): if true, consider last bin extending to infinity
7575
7676
Returns:
@@ -82,7 +82,9 @@ def bin1d_vec(p, bins, tol=None, right_continuous=False):
8282
bins = numpy.array(bins)
8383
p = numpy.array(p)
8484

85-
a0 = numpy.min(bins)
85+
# if not np.all(bins[:-1] <= bins[1:]): # check for sorted bins, which is a requirement
86+
# raise ValueError("Bin edges are not sorted.") # (pyCSEP always passes sorted bins)
87+
a0 = bins[0]
8688
if bins.size == 1:
8789
# for a single bin, set `right_continuous` to true; h is now arbitrary
8890
right_continuous = True

0 commit comments

Comments
 (0)