Skip to content

refactor: remove Array_Pool in favor of std::vector<double>#7234

Open
dzzz2001 wants to merge 2 commits intodeepmodeling:developfrom
dzzz2001:remove-array-pool
Open

refactor: remove Array_Pool in favor of std::vector<double>#7234
dzzz2001 wants to merge 2 commits intodeepmodeling:developfrom
dzzz2001:remove-array-pool

Conversation

@dzzz2001
Copy link
Copy Markdown
Collaborator

@dzzz2001 dzzz2001 commented Apr 10, 2026

Summary

  • Delete ModuleBase::Array_Pool<double> — a bespoke 2D container — and replace every use with contiguous std::vector<double>.
  • Change Ylm::grad_rl_sph_harm to take a flat double* (size n*3) instead of double**. Inside the function body, a one-line reinterpret_cast<double(*)[3]> aliases the buffer so the 120+ existing grly[lm][xyz] accesses stay untouched — memory layout and generated code are unchanged, so there is no performance impact.
  • Update all call sites (gint_atom, set_ddphi, two_center_integrator, math_ylmreal, center2_orb-orb11, and the two Ylm tests) to allocate a flat std::vector<double>(n*3) and index as grly[lm*3 + k].
  • In set_ddphi.cpp, the constant Array_Pool<double> displ(6,3) initialized element-by-element becomes a constexpr double displ[6][3] literal — simpler and cheaper.
  • Delete source/source_base/array_pool.h.

Why

Array_Pool was a hand-rolled 2D container (new T[nr*nc] + a separate row-pointer array) used only to back the double** parameter of Ylm::grad_rl_sph_harm. Its only consumers indexed it as arr[i][j] where j ∈ {0,1,2}, so the row-pointer array was pure overhead with no benefit over a flat std::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.

dzzz2001 and others added 2 commits April 10, 2026 22:42
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant