Skip to content

Commit 66ea4fc

Browse files
authored
fix "expression result unused" warnings (#2910)
See https://en.cppreference.com/w/cpp/error/assert, which shows several ways to avoid unused warnings. --------- Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent fbaf96b commit 66ea4fc

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed

source/api_cc/src/DataModifier.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ void DipoleChargeModifier::run_model(
101101
Tensor output_f = output_tensors[cc++];
102102
Tensor output_v = output_tensors[cc++];
103103
Tensor output_av = output_tensors[cc++];
104-
assert(output_f.dims() == 2), "dim of output tensor should be 2";
105-
assert(output_v.dims() == 2), "dim of output tensor should be 2";
106-
assert(output_av.dims() == 2), "dim of output tensor should be 2";
104+
assert(output_f.dims() == 2 && "dim of output tensor should be 2");
105+
assert(output_v.dims() == 2 && "dim of output tensor should be 2");
106+
assert(output_av.dims() == 2 && "dim of output tensor should be 2");
107107
int nframes = output_f.dim_size(0);
108108
int natoms = output_f.dim_size(1) / 3;
109-
assert(output_f.dim_size(0) == 1), "nframes should match";
110-
assert(natoms == nall), "natoms should be nall";
111-
assert(output_v.dim_size(0) == nframes), "nframes should match";
112-
assert(output_v.dim_size(1) == 9), "dof of virial should be 9";
113-
assert(output_av.dim_size(0) == nframes), "nframes should match";
114-
assert(output_av.dim_size(1) == natoms * 9),
115-
"dof of atom virial should be 9 * natoms";
109+
assert(output_f.dim_size(0) == 1 && "nframes should match");
110+
assert(natoms == nall && "natoms should be nall");
111+
assert(output_v.dim_size(0) == nframes && "nframes should match");
112+
assert(output_v.dim_size(1) == 9 && "dof of virial should be 9");
113+
assert(output_av.dim_size(0) == nframes && "nframes should match");
114+
assert(output_av.dim_size(1) == natoms * 9 &&
115+
"dof of atom virial should be 9 * natoms");
116116

117117
auto of = output_f.flat<MODELTYPE>();
118118
auto ov = output_v.flat<MODELTYPE>();

source/api_cc/src/DeepTensor.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,27 @@ void DeepTensor::run_model(
201201
Tensor output_at = output_tensors[3];
202202
Tensor output_av = output_tensors[4];
203203
// this is the new model, output has to be rank 2 tensor
204-
assert(output_gt.dims() == 2), "dim of output tensor should be 2";
205-
assert(output_f.dims() == 2), "dim of output tensor should be 2";
206-
assert(output_v.dims() == 2), "dim of output tensor should be 2";
207-
assert(output_at.dims() == 2), "dim of output tensor should be 2";
208-
assert(output_av.dims() == 2), "dim of output tensor should be 2";
204+
assert(output_gt.dims() == 2 && "dim of output tensor should be 2");
205+
assert(output_f.dims() == 2 && "dim of output tensor should be 2");
206+
assert(output_v.dims() == 2 && "dim of output tensor should be 2");
207+
assert(output_at.dims() == 2 && "dim of output tensor should be 2");
208+
assert(output_av.dims() == 2 && "dim of output tensor should be 2");
209209
// also check the tensor shapes
210-
assert(output_gt.dim_size(0) == 1), "nframes should match";
211-
assert(output_gt.dim_size(1) == odim), "dof of global tensor should be odim";
212-
assert(output_f.dim_size(0) == 1), "nframes should match";
213-
assert(output_f.dim_size(1) == odim * nall * 3),
214-
"dof of force should be odim * nall * 3";
215-
assert(output_v.dim_size(0) == 1), "nframes should match";
216-
assert(output_v.dim_size(1) == odim * 9), "dof of virial should be odim * 9";
217-
assert(output_at.dim_size(0) == 1), "nframes should match";
218-
assert(output_at.dim_size(1) == nsel * odim),
219-
"dof of atomic tensor should be nsel * odim";
220-
assert(output_av.dim_size(0) == 1), "nframes should match";
221-
assert(output_av.dim_size(1) == odim * nall * 9),
222-
"dof of atomic virial should be odim * nall * 9";
210+
assert(output_gt.dim_size(0) == 1 && "nframes should match");
211+
assert(output_gt.dim_size(1) == odim &&
212+
"dof of global tensor should be odim");
213+
assert(output_f.dim_size(0) == 1 && "nframes should match");
214+
assert(output_f.dim_size(1) == odim * nall * 3 &&
215+
"dof of force should be odim * nall * 3");
216+
assert(output_v.dim_size(0) == 1 && "nframes should match");
217+
assert(output_v.dim_size(1) == odim * 9 &&
218+
"dof of virial should be odim * 9");
219+
assert(output_at.dim_size(0) == 1 && "nframes should match");
220+
assert(output_at.dim_size(1) == nsel * odim &&
221+
"dof of atomic tensor should be nsel * odim");
222+
assert(output_av.dim_size(0) == 1 && "nframes should match");
223+
assert(output_av.dim_size(1) == odim * nall * 9 &&
224+
"dof of atomic virial should be odim * nall * 9");
223225

224226
auto ogt = output_gt.flat<ENERGYTYPE>();
225227
auto of = output_f.flat<MODELTYPE>();

source/api_cc/src/common.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -849,13 +849,13 @@ void deepmd::select_map(std::vector<VT>& out,
849849
const int& nall2) {
850850
for (int kk = 0; kk < nframes; ++kk) {
851851
#ifdef DEBUG
852-
assert(in.size() / stride * stride == in.size()),
853-
"in size should be multiples of stride"
852+
assert(in.size() / stride * stride == in.size() &&
853+
"in size should be multiples of stride")
854854
#endif
855855
for (int ii = 0; ii < in.size() / stride / nframes; ++ii) {
856856
#ifdef DEBUG
857-
assert(ii < idx_map.size()), "idx goes over the idx map size";
858-
assert(idx_map[ii] < out.size()), "mappped idx goes over the out size";
857+
assert(ii < idx_map.size() && "idx goes over the idx map size");
858+
assert(idx_map[ii] < out.size() && "mappped idx goes over the out size");
859859
#endif
860860
if (idx_map[ii] >= 0) {
861861
int to_ii = idx_map[ii];
@@ -896,13 +896,13 @@ void deepmd::select_map_inv(std::vector<VT>& out,
896896
const std::vector<int>& idx_map,
897897
const int& stride) {
898898
#ifdef DEBUG
899-
assert(in.size() / stride * stride == in.size()),
900-
"in size should be multiples of stride"
899+
assert(in.size() / stride * stride == in.size() &&
900+
"in size should be multiples of stride");
901901
#endif
902-
for (int ii = 0; ii < out.size() / stride; ++ii) {
902+
for (int ii = 0; ii < out.size() / stride; ++ii) {
903903
#ifdef DEBUG
904-
assert(ii < idx_map.size()), "idx goes over the idx map size";
905-
assert(idx_map[ii] < in.size()), "from idx goes over the in size";
904+
assert(ii < idx_map.size() && "idx goes over the idx map size");
905+
assert(idx_map[ii] < in.size() && "from idx goes over the in size");
906906
#endif
907907
if (idx_map[ii] >= 0) {
908908
int from_ii = idx_map[ii];

source/lib/include/ComputeDescriptor.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ void compute_descriptor_se_a_extf(std::vector<double> &descrpt_a,
829829
ef[ii] = ef_[ii];
830830
}
831831
}
832-
assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12),
833-
"ef should be a normalized std::vector";
832+
assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 &&
833+
"ef should be a normalized std::vector");
834834

835835
// compute the diff of the neighbors
836836
std::vector<std::vector<double> > sel_a_diff(sec_a.back());
@@ -970,8 +970,8 @@ void compute_descriptor_se_a_ef_para(std::vector<double> &descrpt_a,
970970
ef[ii] = ef_[ii];
971971
}
972972
}
973-
assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12),
974-
"ef should be a normalized vector";
973+
assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 &&
974+
"ef should be a normalized vector");
975975

976976
// compute the diff of the neighbors
977977
std::vector<std::vector<double> > sel_a_diff(sec_a.back());
@@ -1107,8 +1107,8 @@ void compute_descriptor_se_a_ef_vert(std::vector<double> &descrpt_a,
11071107
ef[ii] = ef_[ii];
11081108
}
11091109
}
1110-
assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12),
1111-
"ef should be a normalized vector";
1110+
assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 &&
1111+
"ef should be a normalized vector");
11121112

11131113
// compute the diff of the neighbors
11141114
std::vector<std::vector<double> > sel_a_diff(sec_a.back());

source/lmp/fix_dplr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
127127
break;
128128
}
129129
}
130-
assert(map_vec.size() % 2 == 0),
131-
"number of ints provided by type_associate should be even";
130+
assert(map_vec.size() % 2 == 0 &&
131+
"number of ints provided by type_associate should be even");
132132

133133
// dpt.init(model);
134134
// dtm.init("frozen_model.pb");

0 commit comments

Comments
 (0)