Skip to content

Commit f0ca554

Browse files
committed
replace get_elements_with_range
[Clang-tidy] fix get_elements_with_range' is deprecated in PatchDataLayer.hpp - Replace get_elements_with_range by get_ids_vec_where. - Fix ignoring return value of function declared with 'nodiscard' attribute [clang-diagnostic-unused-result] 156 | patch_list.build_local(); updates
1 parent 631650f commit f0ca554

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/shamrock/include/shamrock/patch/PatchDataField.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* @file PatchDataField.hpp
14+
* @author Léodasce Sewanou (leodasce.sewanou@ens-lyon.fr)
1415
* @author Timothée David--Cléris (tim.shamrock@proton.me)
1516
* @brief
1617
*/
@@ -281,14 +282,14 @@ class PatchDataField {
281282
* @return std::vector<u32>
282283
*/
283284
template<class Lambdacd, class... Args>
284-
inline std::vector<u32> get_ids_vec_where(Lambdacd &&cd_true, Args... args) {
285+
inline std::vector<u32> get_ids_vec_where(Lambdacd &&cd_true, Args &&...args) {
285286
StackEntry stack_loc{};
286287
std::vector<u32> idx_cd{};
287288
if (get_obj_cnt() > 0) {
288289
auto acc = buf.copy_to_stdvec();
289290

290291
for (u32 i = 0; i < get_obj_cnt(); i++) {
291-
if (cd_true(acc, i * nvar, args...)) {
292+
if (std::forward<Lambdacd>(cd_true)(acc, i * nvar, std::forward<Args>(args)...)) {
292293
idx_cd.push_back(i);
293294
}
294295
}

src/shamrock/include/shamrock/patch/PatchDataLayer.hpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* @file PatchDataLayer.hpp
14+
* @author Léodasce Sewanou (leodasce.sewanou@ens-lyon.fr)
1415
* @author Timothée David--Cléris (tim.shamrock@proton.me)
1516
* @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) --no git blame--
1617
* @brief
@@ -539,10 +540,13 @@ namespace shamrock::patch {
539540

540541
PatchDataField<T> &main_field = pdat.get_field<T>(0);
541542

543+
// Note that using get_ids_vec_where here is safe since nvar for main_field is equal to 1
544+
// hence the Lambda cd_true will be applied to each block on the patch. e.g : i * nvar = i
542545
auto get_vec_idx = [&](T vmin, T vmax) -> std::vector<u32> {
543-
return main_field.get_elements_with_range(
544-
[&](T val, T vmin, T vmax) {
546+
return main_field.get_ids_vec_where(
547+
[&](const auto &acc, u32 idx, T vmin, T vmax) {
545548
if (shambase::VectorProperties<T>::dimension == 3) {
549+
T val = acc[idx];
546550
return shammath::is_in_half_open(val, vmin, vmax);
547551
} else {
548552
throw shambase::make_except_with_loc<std::runtime_error>(
@@ -553,6 +557,20 @@ namespace shamrock::patch {
553557
vmax);
554558
};
555559

560+
// auto get_vec_idx = [&](T vmin, T vmax) -> std::vector<u32> {
561+
// return main_field.get_elements_with_range(
562+
// [&](T val, T vmin, T vmax) {
563+
// if (shambase::VectorProperties<T>::dimension == 3) {
564+
// return shammath::is_in_half_open(val, vmin, vmax);
565+
// } else {
566+
// throw shambase::make_except_with_loc<std::runtime_error>(
567+
// "dimension != 3 is not handled");
568+
// }
569+
// },
570+
// vmin,
571+
// vmax);
572+
// };
573+
556574
std::vector<u32> idx_lst = get_vec_idx(bmin, bmax);
557575

558576
shamlog_debug_sycl_ln("PatchDataLayer", "inserting element cnt =", idx_lst.size());

src/shamrock/src/scheduler/PatchScheduler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ std::vector<u64> PatchScheduler::add_root_patches(
153153
//);
154154
}
155155

156-
patch_list.build_local();
156+
// build_local() is declared as nodiscard
157+
(void) patch_list.build_local();
157158
patch_list.reset_local_pack_index();
158159
patch_list.build_local_idx_map();
159160
patch_list.build_global_idx_map();

0 commit comments

Comments
 (0)