-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup clang tidy #882
base: main
Are you sure you want to change the base?
Cleanup clang tidy #882
Changes from 6 commits
133e334
0f8a9d5
3909008
862dffd
af6a46e
a9799ff
ff5638c
762160d
cca35b0
9c136ad
75b8802
8d594ce
a9a560a
0ed9ac1
10937a8
423ff5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,7 +281,7 @@ inline void add_diag(Eigen::ArrayBase<DerivedA>& x, Eigen::ArrayBase<DerivedB> c | |
} | ||
template <rk2_tensor DerivedA, column_vector DerivedB> | ||
inline void add_diag(Eigen::ArrayBase<DerivedA>&& x, Eigen::ArrayBase<DerivedB> const& y) { | ||
x.matrix().diagonal() += y.matrix(); | ||
std::move(x).matrix().diagonal() += y.matrix(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is very strange There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not a perfect forwarding because it contains Alternatively, we can decide to not capture by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now this (and other places) is indeed a nasty one. For this function, we have a add_diag(real(complex_tensor), diag_value); Where We can silence the warning locally. We can also choose to define a named variable in all the caller side, so auto& real_value_proxy = real(complex_tensor);
add_diag(real_value_proxy , diag_value); Then we just need the |
||
} | ||
|
||
// zero tensor | ||
|
@@ -351,13 +351,14 @@ template <symmetry_tag sym, class Proxy> | |
inline void update_real_value(RealValue<sym> const& new_value, Proxy&& current_value, double scalar) { | ||
if constexpr (is_symmetric_v<sym>) { | ||
if (!is_nan(new_value)) { | ||
current_value = scalar * new_value; | ||
std::forward<Proxy>(current_value) = scalar * new_value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also this seems to be very strange. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is how a perfectly forwarded proxy works: the std::forward<Proxy>.operator=(scalar * new_value); which can be rewritten as This deliberately consumes the If we do not want to do perfect forwarding, can you please explain why we went for this solution in the first place here? I do understand that this implementation creates a modifiable view of the 3-phase tensor by value, while taking mutable reference for other objects, but it this really the way that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #882 (comment) |
||
} | ||
} else { | ||
for (size_t i = 0; i != 3; ++i) { | ||
if (!is_nan(new_value(i))) { | ||
current_value(i) = scalar * new_value(i); | ||
current_value(i) = scalar * new_value(i); // can't forward due to runtime element access | ||
} | ||
(void)std::forward<Proxy>(current_value); | ||
Comment on lines
+359
to
+361
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. runtime access; can't move in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #882 (comment) |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ inline void iterate_component_sequence(Func&& func, ForwardIterator begin, Forwa | |
// get component directly using sequence id | ||
func(*it, sequence_idx[seq]); | ||
} | ||
(void)std::forward<Func>(func); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function captures There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here for #882 (comment).
|
||
} | ||
|
||
template <typename T> bool check_id_na(T const& obj) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,7 @@ inline void calculate_load_gen_result(IdxRange const& load_gens, Idx bus_number, | |
} | ||
output.load_gen[load_gen].i = conj(output.load_gen[load_gen].s / output.u[bus_number]); | ||
} | ||
(void)std::forward<LoadGenFunc>(load_gen_func); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function captures There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the other for file Lambdas in function argument should be passed by value unless there is a strong reason of not to do. If we change that to |
||
} | ||
|
||
template <symmetry_tag sym, typename LoadGenFunc> | ||
|
@@ -191,6 +192,7 @@ inline void calculate_pf_result(YBus<sym> const& y_bus, PowerFlowInput<sym> cons | |
calculate_load_gen_result<sym>(load_gens, bus_number, input, output, load_gen_func); | ||
calculate_source_result<sym>(sources, bus_number, y_bus, input, output, load_gens); | ||
} | ||
(void)std::forward<LoadGenFunc>(load_gen_func); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function captures There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #882 (comment) |
||
} | ||
|
||
template <symmetry_tag sym> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,6 +138,7 @@ template <rk2_tensor Matrix> class DenseLUFactor { | |
throw SparseMatrixError{}; // can not specify error code | ||
} | ||
} | ||
(void)std::move(matrix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function captures There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean not allowed by standard? I do not think standard forbid you to capture a |
||
} | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -329,7 +329,7 @@ class Topology { | |
permuted_node_indices[reordered[idx]] = n_non_cyclic_nodes + idx; | ||
} | ||
|
||
std::ranges::copy(reordered, std::back_inserter(dfs_node)); | ||
dfs_node.insert(dfs_node.end(), reordered.begin(), reordered.end()); | ||
for (auto [from, to] : fills) { | ||
auto from_reordered = permuted_node_indices[from]; | ||
auto to_reordered = permuted_node_indices[to]; | ||
|
@@ -530,6 +530,7 @@ class Topology { | |
coupling[topo_comp_i] = Idx2D{topo_idx, new_math_comp_i}; | ||
} | ||
} | ||
(void)std::forward<GetMathTopoComponent>(get_component_topo); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this happening? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function captures There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #882 (comment). The argument |
||
} | ||
|
||
void couple_all_appliance() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and below: the capture is correct: this should work on any type and zero-copy, regardless of whether it is a value, an lvalue or a prvalue. However, there is nothing to forward to, so it must be a
(void)
sinkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you doing this instead of the original? Have a unnamed argument will not trigger an unused argument warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After re-thinking about it, the original implementation is not correct. We do not do anything with the argument so it does not make sense to make it universal reference. Just define as unnamed const lvalue reference and throw them away.