refactor: remove Array_Pool in favor of std::vector<double>#7234
Open
dzzz2001 wants to merge 2 commits intodeepmodeling:developfrom
Open
refactor: remove Array_Pool in favor of std::vector<double>#7234dzzz2001 wants to merge 2 commits intodeepmodeling:developfrom
dzzz2001 wants to merge 2 commits intodeepmodeling:developfrom
Conversation
Replace ModuleBase::Array_Pool<double> — a bespoke 2D container — with contiguous std::vector<double> throughout the Ylm gradient path. Ylm::grad_rl_sph_harm now takes a flat double* (size n*3) instead of double**. Inside the function, a one-line reinterpret_cast aliases the buffer as double(*)[3] so the 120+ existing grly[lm][xyz] accesses stay untouched — memory layout and codegen are unchanged. All call sites (gint, two-center integrator, math_ylmreal, center2_orb, tests) now allocate std::vector<double>(n*3) and index as grly[lm*3+k]. In set_ddphi.cpp, the constant displ(6,3) table becomes a constexpr double[6][3] literal. array_pool.h is deleted. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ModuleBase::Array_Pool<double>— a bespoke 2D container — and replace every use with contiguousstd::vector<double>.Ylm::grad_rl_sph_harmto take a flatdouble*(sizen*3) instead ofdouble**. Inside the function body, a one-linereinterpret_cast<double(*)[3]>aliases the buffer so the 120+ existinggrly[lm][xyz]accesses stay untouched — memory layout and generated code are unchanged, so there is no performance impact.gint_atom,set_ddphi,two_center_integrator,math_ylmreal,center2_orb-orb11, and the two Ylm tests) to allocate a flatstd::vector<double>(n*3)and index asgrly[lm*3 + k].set_ddphi.cpp, the constantArray_Pool<double> displ(6,3)initialized element-by-element becomes aconstexpr double displ[6][3]literal — simpler and cheaper.source/source_base/array_pool.h.Why
Array_Poolwas a hand-rolled 2D container (new T[nr*nc]+ a separate row-pointer array) used only to back thedouble**parameter ofYlm::grad_rl_sph_harm. Its only consumers indexed it asarr[i][j]wherej ∈ {0,1,2}, so the row-pointer array was pure overhead with no benefit over a flatstd::vector<double>. Removing it eliminates a custom container, two raw-pointer allocations per call, and seven#include "source_base/array_pool.h"lines, while keeping memory layout and codegen identical.