Foundation Classes - Precompute Jacobi coefficients#778
Merged
dpasukhi merged 9 commits intoOpen-Cascade-SAS:IRfrom Nov 2, 2025
Merged
Foundation Classes - Precompute Jacobi coefficients#778dpasukhi merged 9 commits intoOpen-Cascade-SAS:IRfrom
dpasukhi merged 9 commits intoOpen-Cascade-SAS:IRfrom
Conversation
Member
dpasukhi
commented
Oct 30, 2025
- Add PLib_JacobiPolynomial_Coeffs.pxx with large constexpr tables and a JacobiCoefficientsCache + GetJacobiCoefficients() fast lookup to serve precomputed TNorm/CofA/CofB/Denom arrays for all constraint levels and degrees.
- Replace several runtime-initialized per-instance arrays/handles with zero-overhead constexpr data; remove myTNorm/myCofA/myCofB/myDenom handles from the class.
- Modernize PLib_JacobiPolynomial implementation:
- Use constructor initializer list and validate inputs there.
- Use constexpr lookup tables for weights/transforms and memcpy/std::fill_n to speed copying into TColStd arrays.
- Replace switch-based pointer selection with indexed arrays for cleaner selection of DB pointers.
- Simplify numerical loops, make offsets/indices const where possible and use clearer variable names.
- Use GetJacobiCoefficients() in D0123 (and callers) to remove on-demand initialization and reduce per-call overhead.
- Change static data types to constexpr double for stronger optimization and clearer intent.
- Various micro-optimizations and safety fixes (avoid NULL, tighten const correctness) to improve performance and reduce runtime allocations.
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the PLib_JacobiPolynomial class by precomputing Jacobi polynomial coefficients and replacing runtime initialization with compile-time constexpr data. The main goals are to eliminate per-instance memory allocations and improve performance through zero-overhead abstractions.
Key changes:
- Replace runtime coefficient computation with precomputed constexpr lookup tables
- Remove dynamic Handle-based member variables (myTNorm, myCofA, myCofB, myDenom) from the class
- Modernize implementation with C++17 features and more efficient memory operations
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| PLib_JacobiPolynomial_Data.pxx | Convert static data arrays from Standard_Real to constexpr double for compile-time optimization |
| PLib_JacobiPolynomial.hxx | Remove Handle-based member variables and make remaining members const |
| PLib_JacobiPolynomial.cxx | Replace runtime initialization with constexpr lookup tables, modernize with C++17 features, and optimize memory operations |
- Add PLib_JacobiPolynomial_Coeffs.pxx with large constexpr tables and a
JacobiCoefficientsCache + GetJacobiCoefficients() fast lookup to serve
precomputed TNorm/CofA/CofB/Denom arrays for all constraint levels and
degrees.
- Replace several runtime-initialized per-instance arrays/handles with
zero-overhead constexpr data; remove myTNorm/myCofA/myCofB/myDenom
handles from the class.
- Modernize PLib_JacobiPolynomial implementation:
- Use constructor initializer list and validate inputs there.
- Use constexpr lookup tables for weights/transforms and memcpy/std::fill_n
to speed copying into TColStd arrays.
- Replace switch-based pointer selection with indexed arrays for cleaner
selection of DB pointers.
- Simplify numerical loops, make offsets/indices const where possible and
use clearer variable names.
- Use GetJacobiCoefficients() in D0123 (and callers) to remove on-demand
initialization and reduce per-call overhead.
- Change static data types to constexpr double for stronger optimization and
clearer intent.
- Various micro-optimizations and safety fixes (avoid NULL, tighten const
correctness) to improve performance and reduce runtime allocations.
…r from the .hxx, and correct several indexing/assignment issues: - Replace unsafe pointer-based fill_n usage on ChangeValue with explicit per-column loops for TabWeights row 0 to ensure proper 2D array access. - Fix coefficient offsets in ToCoefficients to account for array lower bounds (use ibegC and ibegJC), avoiding incorrect indexing into JacCoeff/Coefficients. - Remove duplicate/unused include.
…last computed error when the loop breaks early. This ensures MaxError is up-to-date when NewDegree is set and returned.
Move the assignment of MaxError to occur after the tolerance/convergence check and potential break so MaxError always reflects the last computed Error value.
…strengthen tests - PLib_JacobiPolynomial.cxx: - Remove unused <algorithm> and <cstring> includes. - Replace std::memcpy uses with explicit element-wise loops when filling TabWeights and TabMax to ensure safe 2D/1D array access. - Adjust ordering when populating row 0 in Weights to avoid overwriting database-supplied values. - Keep/ensure WorkDegree validation to fail early for invalid constraints. - PLib_JacobiPolynomial_Test.cxx: - Expand ConstructorEdgeCases to validate minimum WorkDegree for each constraint level (C0, C1, C2) and keep a reasonable max-degree check. These changes remove unsafe memory operations, fix potential out-of-bounds/aliasing issues, and make tests more explicit about valid degree/constraint combinations.
- Implement WorkDegree() and NivConstr() inline in PLib_JacobiPolynomial.hxx. - Remove the #include of PLib_JacobiPolynomial.lxx from the header and delete the .lxx file. - Remove PLib_JacobiPolynomial.lxx and PLib_JacobiPolynomial_Data.pxx entries from FILES.cmake.
Replace the manual ternary mapping (and inline throw for invalid orders) with the centralized PLib::NivConstr helper, simplifying the constructor and reusing existing validation logic.
40ba0ea to
a5feafb
Compare
…lumns with DB values
- Replace magic integers/values with constexpr constants (NB gauss points, invalid value, max degree) and introduce constexpr lookup tables for DB pointers. - Use std::array stack buffer in MaxError to avoid dynamic allocation and compute TabMax once into a local buffer. - Replace ad-hoc pointer arithmetic and duplicated static tables with descriptive aDbPointer / aTrPointer variables and explicit 2D array copies for safe access. - Rename function parameters and many local variables to consistent "the..." / "a..." / "an..." style for clarity; update header prototypes accordingly. - Tighten validation branches, add braces, and normalize return/assignment logic in Points, Weights, MaxValue, MaxError, ReduceDegree, AverageError, ToCoefficients and D0123. - Misc cleanup: move/clarify private section in header and remove hardcoded numeric literals.
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.