From d3e19c52de01296e86eb06f7088a80b115ee3768 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 10 Oct 2023 15:38:37 -0400 Subject: [PATCH 1/2] fix compiler warning for assert Signed-off-by: Jinzhe Zeng --- source/lib/include/ComputeDescriptor.h | 12 ++++++------ source/lmp/fix_dplr.cpp | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/lib/include/ComputeDescriptor.h b/source/lib/include/ComputeDescriptor.h index 6a0153f17c..7c3eaf4cd2 100644 --- a/source/lib/include/ComputeDescriptor.h +++ b/source/lib/include/ComputeDescriptor.h @@ -829,8 +829,8 @@ void compute_descriptor_se_a_extf(std::vector &descrpt_a, ef[ii] = ef_[ii]; } } - assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12), - "ef should be a normalized std::vector"; + assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 && + "ef should be a normalized std::vector"); // compute the diff of the neighbors std::vector > sel_a_diff(sec_a.back()); @@ -970,8 +970,8 @@ void compute_descriptor_se_a_ef_para(std::vector &descrpt_a, ef[ii] = ef_[ii]; } } - assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12), - "ef should be a normalized vector"; + assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 && + "ef should be a normalized vector"); // compute the diff of the neighbors std::vector > sel_a_diff(sec_a.back()); @@ -1107,8 +1107,8 @@ void compute_descriptor_se_a_ef_vert(std::vector &descrpt_a, ef[ii] = ef_[ii]; } } - assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12), - "ef should be a normalized vector"; + assert(fabs(deepmd::dot3(ef, ef) - 1.0) < 1e-12 && + "ef should be a normalized vector"); // compute the diff of the neighbors std::vector > sel_a_diff(sec_a.back()); diff --git a/source/lmp/fix_dplr.cpp b/source/lmp/fix_dplr.cpp index 77bf0d56c0..628f435bb7 100644 --- a/source/lmp/fix_dplr.cpp +++ b/source/lmp/fix_dplr.cpp @@ -127,8 +127,8 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg) break; } } - assert(map_vec.size() % 2 == 0), - "number of ints provided by type_associate should be even"; + assert(map_vec.size() % 2 == 0 && + "number of ints provided by type_associate should be even"); // dpt.init(model); // dtm.init("frozen_model.pb"); From 6860383422a2b6a632be71314c15d22540d4f125 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Tue, 10 Oct 2023 16:45:11 -0400 Subject: [PATCH 2/2] fix more warnings Signed-off-by: Jinzhe Zeng --- source/api_cc/src/DataModifier.cc | 20 ++++++++-------- source/api_cc/src/DeepTensor.cc | 38 ++++++++++++++++--------------- source/api_cc/src/common.cc | 18 +++++++-------- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/source/api_cc/src/DataModifier.cc b/source/api_cc/src/DataModifier.cc index 8707ad7cb2..658ec68442 100644 --- a/source/api_cc/src/DataModifier.cc +++ b/source/api_cc/src/DataModifier.cc @@ -101,18 +101,18 @@ void DipoleChargeModifier::run_model( Tensor output_f = output_tensors[cc++]; Tensor output_v = output_tensors[cc++]; Tensor output_av = output_tensors[cc++]; - assert(output_f.dims() == 2), "dim of output tensor should be 2"; - assert(output_v.dims() == 2), "dim of output tensor should be 2"; - assert(output_av.dims() == 2), "dim of output tensor should be 2"; + assert(output_f.dims() == 2 && "dim of output tensor should be 2"); + assert(output_v.dims() == 2 && "dim of output tensor should be 2"); + assert(output_av.dims() == 2 && "dim of output tensor should be 2"); int nframes = output_f.dim_size(0); int natoms = output_f.dim_size(1) / 3; - assert(output_f.dim_size(0) == 1), "nframes should match"; - assert(natoms == nall), "natoms should be nall"; - assert(output_v.dim_size(0) == nframes), "nframes should match"; - assert(output_v.dim_size(1) == 9), "dof of virial should be 9"; - assert(output_av.dim_size(0) == nframes), "nframes should match"; - assert(output_av.dim_size(1) == natoms * 9), - "dof of atom virial should be 9 * natoms"; + assert(output_f.dim_size(0) == 1 && "nframes should match"); + assert(natoms == nall && "natoms should be nall"); + assert(output_v.dim_size(0) == nframes && "nframes should match"); + assert(output_v.dim_size(1) == 9 && "dof of virial should be 9"); + assert(output_av.dim_size(0) == nframes && "nframes should match"); + assert(output_av.dim_size(1) == natoms * 9 && + "dof of atom virial should be 9 * natoms"); auto of = output_f.flat(); auto ov = output_v.flat(); diff --git a/source/api_cc/src/DeepTensor.cc b/source/api_cc/src/DeepTensor.cc index 79b4d3d760..30ff99497c 100644 --- a/source/api_cc/src/DeepTensor.cc +++ b/source/api_cc/src/DeepTensor.cc @@ -201,25 +201,27 @@ void DeepTensor::run_model( Tensor output_at = output_tensors[3]; Tensor output_av = output_tensors[4]; // this is the new model, output has to be rank 2 tensor - assert(output_gt.dims() == 2), "dim of output tensor should be 2"; - assert(output_f.dims() == 2), "dim of output tensor should be 2"; - assert(output_v.dims() == 2), "dim of output tensor should be 2"; - assert(output_at.dims() == 2), "dim of output tensor should be 2"; - assert(output_av.dims() == 2), "dim of output tensor should be 2"; + assert(output_gt.dims() == 2 && "dim of output tensor should be 2"); + assert(output_f.dims() == 2 && "dim of output tensor should be 2"); + assert(output_v.dims() == 2 && "dim of output tensor should be 2"); + assert(output_at.dims() == 2 && "dim of output tensor should be 2"); + assert(output_av.dims() == 2 && "dim of output tensor should be 2"); // also check the tensor shapes - assert(output_gt.dim_size(0) == 1), "nframes should match"; - assert(output_gt.dim_size(1) == odim), "dof of global tensor should be odim"; - assert(output_f.dim_size(0) == 1), "nframes should match"; - assert(output_f.dim_size(1) == odim * nall * 3), - "dof of force should be odim * nall * 3"; - assert(output_v.dim_size(0) == 1), "nframes should match"; - assert(output_v.dim_size(1) == odim * 9), "dof of virial should be odim * 9"; - assert(output_at.dim_size(0) == 1), "nframes should match"; - assert(output_at.dim_size(1) == nsel * odim), - "dof of atomic tensor should be nsel * odim"; - assert(output_av.dim_size(0) == 1), "nframes should match"; - assert(output_av.dim_size(1) == odim * nall * 9), - "dof of atomic virial should be odim * nall * 9"; + assert(output_gt.dim_size(0) == 1 && "nframes should match"); + assert(output_gt.dim_size(1) == odim && + "dof of global tensor should be odim"); + assert(output_f.dim_size(0) == 1 && "nframes should match"); + assert(output_f.dim_size(1) == odim * nall * 3 && + "dof of force should be odim * nall * 3"); + assert(output_v.dim_size(0) == 1 && "nframes should match"); + assert(output_v.dim_size(1) == odim * 9 && + "dof of virial should be odim * 9"); + assert(output_at.dim_size(0) == 1 && "nframes should match"); + assert(output_at.dim_size(1) == nsel * odim && + "dof of atomic tensor should be nsel * odim"); + assert(output_av.dim_size(0) == 1 && "nframes should match"); + assert(output_av.dim_size(1) == odim * nall * 9 && + "dof of atomic virial should be odim * nall * 9"); auto ogt = output_gt.flat(); auto of = output_f.flat(); diff --git a/source/api_cc/src/common.cc b/source/api_cc/src/common.cc index 0e2526414d..fad7e374ab 100644 --- a/source/api_cc/src/common.cc +++ b/source/api_cc/src/common.cc @@ -849,13 +849,13 @@ void deepmd::select_map(std::vector& out, const int& nall2) { for (int kk = 0; kk < nframes; ++kk) { #ifdef DEBUG - assert(in.size() / stride * stride == in.size()), - "in size should be multiples of stride" + assert(in.size() / stride * stride == in.size() && + "in size should be multiples of stride") #endif for (int ii = 0; ii < in.size() / stride / nframes; ++ii) { #ifdef DEBUG - assert(ii < idx_map.size()), "idx goes over the idx map size"; - assert(idx_map[ii] < out.size()), "mappped idx goes over the out size"; + assert(ii < idx_map.size() && "idx goes over the idx map size"); + assert(idx_map[ii] < out.size() && "mappped idx goes over the out size"); #endif if (idx_map[ii] >= 0) { int to_ii = idx_map[ii]; @@ -896,13 +896,13 @@ void deepmd::select_map_inv(std::vector& out, const std::vector& idx_map, const int& stride) { #ifdef DEBUG - assert(in.size() / stride * stride == in.size()), - "in size should be multiples of stride" + assert(in.size() / stride * stride == in.size() && + "in size should be multiples of stride"); #endif - for (int ii = 0; ii < out.size() / stride; ++ii) { + for (int ii = 0; ii < out.size() / stride; ++ii) { #ifdef DEBUG - assert(ii < idx_map.size()), "idx goes over the idx map size"; - assert(idx_map[ii] < in.size()), "from idx goes over the in size"; + assert(ii < idx_map.size() && "idx goes over the idx map size"); + assert(idx_map[ii] < in.size() && "from idx goes over the in size"); #endif if (idx_map[ii] >= 0) { int from_ii = idx_map[ii];