Skip to content

Commit 437e013

Browse files
author
abacus_fixer
committed
refactor(hsolver_test): replace unique_ptr heap alloc with stack vars in bpcg test
The alpha/beta scaling constants passed to ModuleBase::gemm_op inside hpsi_func were heap-allocated via std::unique_ptr<T>(new T(...)) and then re-exposed through .get(). GEMM only reads these values (const T* alpha / const T* beta in gemm_op::operator()), so heap allocation is unnecessary — the lambda performs a fresh new/delete pair on every call for no semantic benefit. Replace with stack-local const T one(1.0) / const T zero(0.0) and pass &one / &zero directly. The result is fully C++11-compatible (indeed C++98-compatible), shorter, and removes the only std::unique_ptr use in the file, so <memory> is no longer needed even indirectly through this translation unit's own code. Verified by building the MODULE_HSOLVER_bpcg test target: make -j 30 MODULE_HSOLVER_bpcg -> [100%] Built target MODULE_HSOLVER_bpcg
1 parent e1394a6 commit 437e013

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

source/source_hsolver/test/diago_bpcg_test.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,18 @@ class DiagoBPCGPrepare
136136
const std::vector<T> &h_mat = DIAGOTEST::hmatrix_local;
137137
auto hpsi_func = [h_mat, dim](T *psi_in, T *hpsi_out,
138138
const int ld_psi, const int nvec) {
139-
std::unique_ptr<T> one(new T(1.0));
140-
std::unique_ptr<T> zero(new T(0.0));
141-
const T *one_ = one.get();
142-
const T *zero_ = zero.get();
139+
const T one(1.0);
140+
const T zero(0.0);
143141

144142
base_device::DEVICE_CPU *ctx = {};
145143
// hpsi_out(dim * nvec) = h_mat(dim * dim) * psi_in(dim * nvec)
146144
ModuleBase::gemm_op<T, base_device::DEVICE_CPU>()(
147145
'N', 'N',
148146
dim, nvec, dim,
149-
one_,
147+
&one,
150148
h_mat.data(), dim,
151149
psi_in, ld_psi,
152-
zero_,
150+
&zero,
153151
hpsi_out, ld_psi);
154152
};
155153
const int ndim = psi_local.get_current_ngk();

0 commit comments

Comments
 (0)