Skip to content

Commit dbcac13

Browse files
authored
Remove backward compability from combinations (#8793)
1 parent 7c294e0 commit dbcac13

File tree

1 file changed

+12
-135
lines changed

1 file changed

+12
-135
lines changed

Framework/Core/include/Framework/ASoAHelpers.h

Lines changed: 12 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -72,85 +72,8 @@ inline bool diffCategory(BinningIndex const& a, BinningIndex const& b)
7272
return a.bin >= b.bin;
7373
}
7474

75-
template <typename T2, typename ARRAY, typename T>
76-
std::vector<BinningIndex> oldGroupTable(const T& table, const std::string& categoryColumnName, int minCatSize, const T2& outsider)
77-
{
78-
auto columnIndex = table.asArrowTable()->schema()->GetFieldIndex(categoryColumnName);
79-
auto chunkedArray = table.asArrowTable()->column(columnIndex);
80-
81-
uint64_t ind = 0;
82-
uint64_t selInd = 0;
83-
gsl::span<int64_t const> selectedRows;
84-
std::vector<BinningIndex> groupedIndices;
85-
86-
// Separate check to account for Filtered size different from arrow table
87-
if (table.size() == 0) {
88-
return groupedIndices;
89-
}
90-
91-
if constexpr (soa::is_soa_filtered_t<T>::value) {
92-
selectedRows = table.getSelectedRows(); // vector<int64_t>
93-
}
94-
95-
for (uint64_t ci = 0; ci < chunkedArray->num_chunks(); ++ci) {
96-
auto chunk = chunkedArray->chunk(ci);
97-
if constexpr (soa::is_soa_filtered_t<T>::value) {
98-
if (selectedRows[ind] >= selInd + chunk->length()) {
99-
selInd += chunk->length();
100-
continue; // Go to the next chunk, no value selected in this chunk
101-
}
102-
}
103-
104-
T2 const* data = std::static_pointer_cast<ARRAY>(chunk)->raw_values();
105-
uint64_t ai = 0;
106-
while (ai < chunk->length()) {
107-
if constexpr (soa::is_soa_filtered_t<T>::value) {
108-
ai += selectedRows[ind] - selInd;
109-
selInd = selectedRows[ind];
110-
}
111-
112-
if (data[ai] != outsider) {
113-
groupedIndices.emplace_back(data[ai], ind);
114-
}
115-
ind++;
116-
117-
if constexpr (soa::is_soa_filtered_t<T>::value) {
118-
if (ind >= selectedRows.size()) {
119-
break;
120-
}
121-
} else {
122-
ai++;
123-
}
124-
}
125-
126-
if constexpr (soa::is_soa_filtered_t<T>::value) {
127-
if (ind == selectedRows.size()) {
128-
break;
129-
}
130-
}
131-
}
132-
133-
// Do a stable sort so that same categories entries are
134-
// grouped together.
135-
std::stable_sort(groupedIndices.begin(), groupedIndices.end());
136-
137-
// Remove categories of too small size
138-
if (minCatSize > 1) {
139-
auto catBegin = groupedIndices.begin();
140-
while (catBegin != groupedIndices.end()) {
141-
auto catEnd = std::upper_bound(catBegin, groupedIndices.end(), *catBegin, sameCategory);
142-
if (std::distance(catBegin, catEnd) < minCatSize) {
143-
catEnd = groupedIndices.erase(catBegin, catEnd);
144-
}
145-
catBegin = catEnd;
146-
}
147-
}
148-
149-
return groupedIndices;
150-
}
151-
15275
template <template <typename... Cs> typename BP, typename T, typename... Cs>
153-
std::vector<BinningIndex> doGroupTable(const T& table, const BP<Cs...>& binningPolicy, int minCatSize, int outsider)
76+
std::vector<BinningIndex> groupTable(const T& table, const BP<Cs...>& binningPolicy, int minCatSize, int outsider)
15477
{
15578
arrow::Table* arrowTable = table.asArrowTable().get();
15679

@@ -242,16 +165,6 @@ std::vector<BinningIndex> doGroupTable(const T& table, const BP<Cs...>& binningP
242165
return groupedIndices;
243166
}
244167

245-
template <typename BP, typename T>
246-
std::vector<BinningIndex> groupTable(const T& table, const BP& binningPolicy, int minCatSize, int outsider)
247-
{
248-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
249-
return doGroupTable(table, binningPolicy, minCatSize, outsider);
250-
} else {
251-
return oldGroupTable<int, arrow::Int32Array>(table, binningPolicy, minCatSize, outsider);
252-
}
253-
}
254-
255168
// Synchronize categories so as groupedIndices contain elements only of categories common to all tables
256169
template <std::size_t K>
257170
void syncCategories(std::array<std::vector<BinningIndex>, K>& groupedIndices)
@@ -1338,86 +1251,50 @@ template <typename BP, typename T1, typename... T2s>
13381251
auto selfCombinations(const BP& binningPolicy, int categoryNeighbours, const T1& outsider, const T2s&... tables)
13391252
{
13401253
static_assert(isSameType<T2s...>(), "Tables must have the same type for self combinations");
1341-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
1342-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>(binningPolicy, categoryNeighbours, outsider, tables...));
1343-
} else {
1344-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2s...>>(CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2s...>(std::string(binningPolicy), categoryNeighbours, outsider, tables...));
1345-
}
1254+
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>(binningPolicy, categoryNeighbours, outsider, tables...));
13461255
}
13471256

13481257
template <typename BP, typename T1, typename T2>
13491258
auto selfPairCombinations(const BP& binningPolicy, int categoryNeighbours, const T1& outsider)
13501259
{
1351-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
1352-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>(binningPolicy, categoryNeighbours, outsider));
1353-
} else {
1354-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2>(std::string(binningPolicy), categoryNeighbours, outsider));
1355-
}
1260+
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>(binningPolicy, categoryNeighbours, outsider));
13561261
}
13571262

13581263
template <typename BP, typename T1, typename T2>
13591264
auto selfPairCombinations(const BP& binningPolicy, int categoryNeighbours, const T1& outsider, const T2& table)
13601265
{
1361-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
1362-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>(binningPolicy, categoryNeighbours, outsider, table, table));
1363-
} else {
1364-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2>(std::string(binningPolicy), categoryNeighbours, outsider, table, table));
1365-
}
1266+
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2>(binningPolicy, categoryNeighbours, outsider, table, table));
13661267
}
13671268

13681269
template <typename BP, typename T1, typename T2>
13691270
auto selfTripleCombinations(const BP& binningPolicy, int categoryNeighbours, const T1& outsider)
13701271
{
1371-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
1372-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>(binningPolicy, categoryNeighbours, outsider));
1373-
} else {
1374-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2, T2>(std::string(binningPolicy), categoryNeighbours, outsider));
1375-
}
1272+
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>(binningPolicy, categoryNeighbours, outsider));
13761273
}
13771274

13781275
template <typename BP, typename T1, typename T2>
13791276
auto selfTripleCombinations(const BP& binningPolicy, int categoryNeighbours, const T1& outsider, const T2& table)
13801277
{
1381-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
1382-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>(binningPolicy, categoryNeighbours, outsider, table, table, table));
1383-
} else {
1384-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2, T2, T2>(std::string(binningPolicy), categoryNeighbours, outsider, table, table, table));
1385-
}
1278+
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2, T2, T2>(binningPolicy, categoryNeighbours, outsider, table, table, table));
13861279
}
13871280

13881281
template <typename BP, typename T1, typename... T2s>
13891282
auto combinations(const BP& binningPolicy, int categoryNeighbours, const T1& outsider, const T2s&... tables)
13901283
{
1391-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
1392-
if constexpr (isSameType<T2s...>()) {
1393-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>(binningPolicy, categoryNeighbours, outsider, tables...));
1394-
} else {
1395-
return CombinationsGenerator<CombinationsBlockUpperIndexPolicy<BP, T1, T2s...>>(CombinationsBlockUpperIndexPolicy<BP, T1, T2s...>(binningPolicy, categoryNeighbours, outsider, tables...));
1396-
}
1284+
if constexpr (isSameType<T2s...>()) {
1285+
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>>(CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, T2s...>(binningPolicy, categoryNeighbours, outsider, tables...));
13971286
} else {
1398-
if constexpr (isSameType<T2s...>()) {
1399-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2s...>>(CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, T2s...>(std::string(binningPolicy), categoryNeighbours, outsider, tables...));
1400-
} else {
1401-
return CombinationsGenerator<CombinationsBlockUpperIndexPolicy<std::string, T1, T2s...>>(CombinationsBlockUpperIndexPolicy<std::string, T1, T2s...>(std::string(binningPolicy), categoryNeighbours, outsider, tables...));
1402-
}
1287+
return CombinationsGenerator<CombinationsBlockUpperIndexPolicy<BP, T1, T2s...>>(CombinationsBlockUpperIndexPolicy<BP, T1, T2s...>(binningPolicy, categoryNeighbours, outsider, tables...));
14031288
}
14041289
}
14051290

14061291
template <typename BP, typename T1, typename... T2s>
14071292
auto combinations(const BP& binningPolicy, int categoryNeighbours, const T1& outsider, const o2::framework::expressions::Filter& filter, const T2s&... tables)
14081293
{
1409-
if constexpr (framework::is_specialization_v<BP, framework::BinningPolicy> || framework::is_specialization_v<BP, framework::NoBinningPolicy>) {
1410-
if constexpr (isSameType<T2s...>()) {
1411-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, Filtered<T2s>...>>(CombinationsBlockStrictlyUpperSameIndexPolicy(binningPolicy, categoryNeighbours, outsider, tables.select(filter)...));
1412-
} else {
1413-
return CombinationsGenerator<CombinationsBlockUpperIndexPolicy<BP, T1, Filtered<T2s>...>>(CombinationsBlockUpperIndexPolicy(binningPolicy, categoryNeighbours, outsider, tables.select(filter)...));
1414-
}
1294+
if constexpr (isSameType<T2s...>()) {
1295+
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<BP, T1, Filtered<T2s>...>>(CombinationsBlockStrictlyUpperSameIndexPolicy(binningPolicy, categoryNeighbours, outsider, tables.select(filter)...));
14151296
} else {
1416-
if constexpr (isSameType<T2s...>()) {
1417-
return CombinationsGenerator<CombinationsBlockStrictlyUpperSameIndexPolicy<std::string, T1, Filtered<T2s>...>>(CombinationsBlockStrictlyUpperSameIndexPolicy(std::string(binningPolicy), categoryNeighbours, outsider, tables.select(filter)...));
1418-
} else {
1419-
return CombinationsGenerator<CombinationsBlockUpperIndexPolicy<std::string, T1, Filtered<T2s>...>>(CombinationsBlockUpperIndexPolicy(std::string(binningPolicy), categoryNeighbours, outsider, tables.select(filter)...));
1420-
}
1297+
return CombinationsGenerator<CombinationsBlockUpperIndexPolicy<BP, T1, Filtered<T2s>...>>(CombinationsBlockUpperIndexPolicy(binningPolicy, categoryNeighbours, outsider, tables.select(filter)...));
14211298
}
14221299
}
14231300

0 commit comments

Comments
 (0)