Merged
Conversation
Introduce a templated PopulateMat for writing combination/permutation results directly into a column-major matrix buffer, with explicit instantiations for int and double
Use clearer, more descriptive function names in declarations, definitions, and explicit instantiations
Introduce `CountCompsRepLenCap` (double and GMP) and wire it into dispatch for `CompRepCapped` and `PrmRepCapped` via the new `CompsRepLenCap` count class.
Append CompRepCapped to keep enum values stable, include it in capped type lists, and classify capped repetition compositions in DiscoverPType.
Introduce FillTailRep to rebuild the tail while preserving the total sum, and add a NextCompositionRep overload that advances compositions under a per-part cap.
Introduce `CompsGenRepCapped` overloads for raw pointers and `RMatrix` to generate compositions using `v.size() - 1` as the cap, with explicit template instantiations for `int` and `double`.
- Add `CompRepCapped` and `PrmRepCapped` dispatch paths in `PartitionsManager` - Split permutation-with-repetition generation into `PartsStdPermRep` and a new `PartsGenPermRep` overload - Consolidate population helpers via `PopulateUtils` and `CompositionsUtils` includes
Introduce `nthCompsRepCapped` (double) and `nthCompsRepCappedGmp` (mpz) and wire them into `GetNthPartsFunc`. Also correct the final element computation for positive/offset representations and document the offset and block-scan invariants.
Permutation-partition (Prm*) cases lack a NextPartition-based iterator; dispatch them to the general constraint machinery to avoid invalid partition state and preserve correct output.
Add sum/== permutation cases that validate results against partitionsGeneral + permuteGeneral, and include table-input equivalence checks. This clearly tests all of the permutation PartitionTypes.
Route `PartitionType::CompRepCapped` to a dedicated `NextRepCompCapped` wrapper and initialize only the cap (`pivot`) in `SetPartValues`, documenting why other iterator state is unused for this mode
Introduce `rankCompsRepCapped` and GMP variant, and wire them into `GetRankPartsFunc` for `PartitionType::CompRepCapped`.
mpz_bin_uiui takes unsigned arguments; return 0 for invalid (n < 0, m < 0, m > n) to avoid unintended huge computations and keep combinatorial conventions.
Use the mpz_class implementation for inclusion–exclusion to avoid precision loss from large intermediate binomial terms, and move the detailed formula documentation to the GMP routine.
Compute double counts only when below Significand53 and fall back to mpz implementations when the double result is non-finite or exceeds the limit.
Exercise capped composition generation with repetition, including mapped inputs, parallel execution, GMP bigz lower bounds, and sample/rank round-trips.
Update declarations, definitions, and call sites to use the corrected name.
Introduce `CountCompsRepCapZNotWk` and `CompsRepZeroCap`, and wire the new `PartitionType::CmpRpCapZNotWk` factory case to use it.
Thread one_or_zero through CompsGenRepCapped, NextCompositionRep(cap), and FillTailRep to share logic between 0- and 1-based representations.
Introduce `PartitionType::CmpRpCapZNotWk` and route generation through `CompsGenRepCapped<1>`. Adjust capped start vector discovery to account for `includeZero` and update related type lists and comments.
Extend `PartitionType` and name mappings with `CompRepWeakCap`, and include it in `CappedPTypeArr` while keeping existing numeric values stable.
Route new PartitionType variants through NextCompositionRep and initialize `pivot` (cap) for these modes in Partitions::SetPartValues.
- Implement nth/rank functions for `CmpRpCapZNotWk` (dbl and GMP paths) - Introduce `CompRepWeakCap` partition type and route counting/generation to capped logic - Update partition type discovery and function dispatch tables accordingly
Extend testthat suites to exercise `compositionsGeneral`, `compositionsRank`, and `compositionsSample` across `CmpRpCapZNotWk` and `CompRepWeakCap` (including mapped and bigz/GMP cases, plus parallel execution).
Expand NEWS entries to cover distinct and capped compositions, parallel ranking, performance improvements, bug fixes, and update the 2.10.0 release date.
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
This PR adds end-to-end support for capped (maximum-part) compositions with repetition across counting, generation, ranking, unranking (nth), sampling, and iteration, including weak and mapped-zero variants where applicable. It also hardens binomial coefficient wrappers (double and GMP) against invalid inputs to avoid unsafe signed→unsigned behavior, and fixes
permuteIter()correctness for permutation-of-partition constrained iterator cases.Key Changes
Added capped repetition composition support across
compositionsGeneral(),compositionsRank(),compositionsSample(), andcompositionsIter().Implemented exact inclusion–exclusion counting in the GMP path, with double wrappers computing the full sum exactly before converting to double.
Hardened
nChooseK()andnChooseKGmp()to return 0 for invalid(n, k)and avoid unsafe signed→unsigned conversion into GMP binomial routines.Fixed iterator dispatch for permutation-of-partition constrained iterator cases so
permuteIter()produces correct iteration results.Added tests covering the new capped composition families and permutation-of-partition iterator equivalence checks.
No existing APIs were removed; changes are additive and backward compatible.