Skip to content

Commit fd137bf

Browse files
committed
Adapt get_combinations
1 parent ce5a5ca commit fd137bf

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

src/ctapipe/reco/stereo_combination.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def _combine_altaz(self, event):
613613
ids.append(tel_id)
614614

615615
if len(fov_lon_values) > 0:
616-
index_tel_combs = get_combinations(range(len(ids)), self.n_tel_combinations)
616+
index_tel_combs = get_combinations(len(ids), self.n_tel_combinations)
617617
fov_lons, fov_lats, comb_weights = calc_combs_min_distances_event(
618618
index_tel_combs,
619619
np.array(fov_lon_values),

src/ctapipe/reco/telescope_event_handling.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,26 +175,26 @@ def weighted_mean_std_ufunc(
175175

176176

177177
@lru_cache(maxsize=4096)
178-
def get_combinations(iterable, size):
178+
def get_combinations(array_length, comb_size):
179179
"""
180-
Generate all possible combinations of elements of a given `size` from
181-
the given `iterable`.
180+
Generate all possible index combinations of elements of a given `comb_size`
181+
from an array with a given `array_length`.
182182
183183
Uses ``itertools.combinations`` and caching to speed up repeated calls.
184184
185185
Parameters
186186
----------
187-
iterable: iterable
188-
Input iterable from which to generate combinations.
187+
array_length: int
188+
Length of the list or array to generate index combinations from.
189189
size : int
190190
The size of each combination.
191191
192192
Returns
193193
-------
194194
np.ndarray
195-
Array of combinations of the specified size.
195+
Array of indey combinations of the specified size.
196196
"""
197-
return np.array(list(combinations(iterable, size)))
197+
return np.array(list(combinations(range(array_length), comb_size)))
198198

199199

200200
@njit
@@ -470,9 +470,9 @@ def create_combs_array(max_multiplicity, k):
470470
- An array of all k-combinations for different multiplicities.
471471
- An array mapping each combination to its respective multiplicity.
472472
"""
473-
combs_array = get_combinations(range(k), k)
473+
combs_array = get_combinations(k, k)
474474
for i in range(k + 1, max_multiplicity + 1):
475-
combs = get_combinations(range(i), k)
475+
combs = get_combinations(i, k)
476476
combs_array = np.concatenate([combs_array, combs])
477477

478478
n_combs = _calc_n_combs(np.arange(k, max_multiplicity + 1), k)

src/ctapipe/reco/tests/test_telescope_event_handling.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ def test_get_combinations():
5656
from ctapipe.reco.telescope_event_handling import get_combinations
5757

5858
tel_ids = [1, 2, 3]
59+
comb_size = 2
5960
get_combinations.cache_clear()
60-
combinations = get_combinations(tel_ids)
61+
index_combinations = get_combinations(len(tel_ids), comb_size)
6162

62-
expected_combinations = np.array([[1, 2], [1, 3], [2, 3]])
63+
expected_combinations = np.array([[0, 1], [0, 2], [1, 2]])
6364

64-
assert np.allclose(combinations, expected_combinations)
65+
assert np.allclose(index_combinations, expected_combinations)
6566

6667

6768
def test_calc_combs_min_distances():

0 commit comments

Comments
 (0)