@@ -152,7 +152,7 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
152152 const SPsiFunc& spsi_func,
153153 const int dim,
154154 const int nband,
155- const int ldPsi ,
155+ const int ld_psi ,
156156 T *psi_in,
157157 Real* eigenvalue_in,
158158 const Real david_diag_thr,
@@ -191,20 +191,20 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
191191 if (this ->use_paw )
192192 {
193193#ifdef USE_PAW
194- GlobalC::paw_cell.paw_nl_psi (1 , reinterpret_cast <const std::complex <double >*> (psi_in + m*ldPsi ),
194+ GlobalC::paw_cell.paw_nl_psi (1 , reinterpret_cast <const std::complex <double >*> (psi_in + m*ld_psi ),
195195 reinterpret_cast <std::complex <double >*>(&this ->spsi [m * dim]));
196196#endif
197197 }
198198 else
199199 {
200- // phm_in->sPsi(psi_in + m*ldPsi , &this->spsi[m * dim], dim, dim, 1);
201- spsi_func (psi_in + m*ldPsi ,&this ->spsi [m*dim],dim,dim,1 );
200+ // phm_in->sPsi(psi_in + m*ld_psi , &this->spsi[m * dim], dim, dim, 1);
201+ spsi_func (psi_in + m*ld_psi ,&this ->spsi [m*dim],dim,dim,1 );
202202 }
203203 }
204204 // begin SchmidtOrth
205205 for (int m = 0 ; m < nband; m++)
206206 {
207- syncmem_complex_op ()(this ->ctx , this ->ctx , basis + dim*m, psi_in + m*ldPsi , dim);
207+ syncmem_complex_op ()(this ->ctx , this ->ctx , basis + dim*m, psi_in + m*ld_psi , dim);
208208
209209 this ->SchmidtOrth (dim,
210210 nband,
@@ -230,7 +230,9 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
230230 // end of SchmidtOrth and calculate H|psi>
231231 // hpsi_info dav_hpsi_in(&basis, psi::Range(true, 0, 0, nband - 1), this->hpsi);
232232 // phm_in->ops->hPsi(dav_hpsi_in);
233- hpsi_func (basis, hpsi, nbase_x, dim, 0 , nband - 1 );
233+ // hpsi[:, 0:nband] = H basis[:, 0:nband]
234+ // slice index in this piece of code is in C manner. i.e. 0:id stands for [0,id)
235+ hpsi_func (basis, hpsi, dim, nband);
234236
235237 this ->cal_elem (dim, nbase, nbase_x, this ->notconv , this ->hpsi , this ->spsi , this ->hcc , this ->scc );
236238
@@ -287,7 +289,7 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
287289
288290 // update eigenvectors of Hamiltonian
289291
290- setmem_complex_op ()(this ->ctx , psi_in, 0 , nband * ldPsi );
292+ setmem_complex_op ()(this ->ctx , psi_in, 0 , nband * ld_psi );
291293 // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
292294 gemm_op<T, Device>()(this ->ctx ,
293295 ' N' ,
@@ -302,7 +304,7 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
302304 nbase_x,
303305 this ->zero ,
304306 psi_in, // C dim * nband
305- ldPsi
307+ ld_psi
306308 );
307309
308310 if (!this ->notconv || (dav_iter == david_maxiter))
@@ -322,7 +324,7 @@ int DiagoDavid<T, Device>::diag_once(const HPsiFunc& hpsi_func,
322324 nbase_x,
323325 eigenvalue_in,
324326 psi_in,
325- ldPsi ,
327+ ld_psi ,
326328 this ->hpsi ,
327329 this ->spsi ,
328330 this ->hcc ,
@@ -601,7 +603,8 @@ void DiagoDavid<T, Device>::cal_grad(const HPsiFunc& hpsi_func,
601603 // psi::Range(true, 0, nbase, nbase + notconv - 1),
602604 // &hpsi[nbase * dim]); // &hp(nbase, 0)
603605 // phm_in->ops->hPsi(dav_hpsi_in);
604- hpsi_func (basis, &hpsi[nbase * dim], nbase_x, dim, nbase, nbase + notconv - 1 );
606+ // hpsi[:, nbase:nbase+notcnv] = H basis[:, nbase:nbase+notcnv]
607+ hpsi_func (basis + nbase * dim, hpsi + nbase * dim, dim, notconv);
605608
606609 delmem_complex_op ()(this ->ctx , lagrange);
607610 delmem_complex_op ()(this ->ctx , vc_ev_vector);
@@ -785,7 +788,7 @@ void DiagoDavid<T, Device>::diag_zhegvx(const int& nbase,
785788 * @param nbase_x The maximum dimension of the reduced basis set.
786789 * @param eigenvalue_in Pointer to the array of eigenvalues.
787790 * @param psi_in Pointer to the array of wavefunctions.
788- * @param ldPsi The leading dimension of the wavefunction array.
791+ * @param ld_psi The leading dimension of the wavefunction array.
789792 * @param hpsi Pointer to the output array for the updated basis set.
790793 * @param spsi Pointer to the output array for the updated basis set (nband-th column).
791794 * @param hcc Pointer to the output array for the updated reduced Hamiltonian.
@@ -800,7 +803,7 @@ void DiagoDavid<T, Device>::refresh(const int& dim,
800803 const int nbase_x, // maximum dimension of the reduced basis set
801804 const Real* eigenvalue_in,
802805 const T *psi_in,
803- const int ldPsi ,
806+ const int ld_psi ,
804807 T* hpsi,
805808 T* spsi,
806809 T* hcc,
@@ -866,7 +869,7 @@ void DiagoDavid<T, Device>::refresh(const int& dim,
866869
867870 for (int m = 0 ; m < nband; m++)
868871 {
869- syncmem_complex_op ()(this ->ctx , this ->ctx , basis + dim*m,psi_in + m*ldPsi , dim);
872+ syncmem_complex_op ()(this ->ctx , this ->ctx , basis + dim*m,psi_in + m*ld_psi , dim);
870873 /* for (int ig = 0; ig < npw; ig++)
871874 basis(m, ig) = psi(m, ig);*/
872875 }
@@ -1149,15 +1152,13 @@ void DiagoDavid<T, Device>::planSchmidtOrth(const int nband, std::vector<int>& p
11491152/* *
11501153 * @brief Performs iterative diagonalization using the David algorithm.
11511154 *
1152- * @warning Please see docs of `HPsiFunc` for more information.
1153- * @warning Please adhere strictly to the requirements of the function pointer
1154- * @warning for the hpsi mat-vec interface; it may seem counterintuitive.
1155+ * @warning Please see docs of `HPsiFunc` for more information about the hpsi mat-vec interface.
11551156 *
11561157 * @tparam T The type of the elements in the matrix.
11571158 * @tparam Device The device type (CPU or GPU).
11581159 * @param hpsi_func The function object that computes the matrix-blockvector product H * psi.
11591160 * @param spsi_func The function object that computes the matrix-blockvector product overlap S * psi.
1160- * @param ldPsi The leading dimension of the psi_in array.
1161+ * @param ld_psi The leading dimension of the psi_in array.
11611162 * @param psi_in The input wavefunction.
11621163 * @param eigenvalue_in The array to store the eigenvalues.
11631164 * @param david_diag_thr The convergence threshold for the diagonalization.
@@ -1172,7 +1173,7 @@ void DiagoDavid<T, Device>::planSchmidtOrth(const int nband, std::vector<int>& p
11721173template <typename T, typename Device>
11731174int DiagoDavid<T, Device>::diag(const HPsiFunc& hpsi_func,
11741175 const SPsiFunc& spsi_func,
1175- const int ldPsi ,
1176+ const int ld_psi ,
11761177 T *psi_in,
11771178 Real* eigenvalue_in,
11781179 const Real david_diag_thr,
@@ -1187,7 +1188,7 @@ int DiagoDavid<T, Device>::diag(const HPsiFunc& hpsi_func,
11871188 int sum_dav_iter = 0 ;
11881189 do
11891190 {
1190- sum_dav_iter += this ->diag_once (hpsi_func, spsi_func, dim, nband, ldPsi , psi_in, eigenvalue_in, david_diag_thr, david_maxiter);
1191+ sum_dav_iter += this ->diag_once (hpsi_func, spsi_func, dim, nband, ld_psi , psi_in, eigenvalue_in, david_diag_thr, david_maxiter);
11911192 ++ntry;
11921193 } while (!check_block_conv (ntry, this ->notconv , ntry_max, notconv_max));
11931194
0 commit comments