Skip to content

Commit d12de73

Browse files
authored
Merge pull request #60 from jwood000/docs-distinct-compositions
docs: reorganize combinatorics documentation and refresh README Add dedicated vignettes for integer partitions and integer compositions and refactor the constraints vignette to focus on constraint-driven enumeration. Improve README messaging and structure to better highlight key package features and unique algorithms (e.g. multiset partitions, comboGroups, comboGrid, and distinct compositions). Switch vignette output to prettydoc::html_pretty and update vignette metadata. Regenerate documentation outputs. Minor repository housekeeping: * move CRAN release checklist to dev/ * ignore dev/ in .Rbuildignore
2 parents a659d27 + 3ed0c92 commit d12de73

File tree

92 files changed

+4611
-2880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4611
-2880
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ SO_Answers/*
1414
^_pkgdown\.yml$
1515
^CRAN_RELEASE_CHECKLIST\.md$
1616
^\.codacy\.yml$
17+
^dev$

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ Suggests:
3737
knitr,
3838
RcppBigIntAlgos,
3939
rmarkdown,
40+
prettydoc,
4041
covr,
4142
xml2
42-
Config/Needs/website: pkgdown
43+
Config/Needs/website:
44+
pkgdown
4345
License: GPL (>=2)
4446
SystemRequirements: gmp (>= 4.2.3)
4547
VignetteBuilder: knitr

README.md

Lines changed: 52 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,39 @@
1111
[![Codecov test coverage](<https://codecov.io/gh/jwood000/RcppAlgos/branch/main/graph/badge.svg>)](<https://app.codecov.io/gh/jwood000/RcppAlgos?branch=main>)
1212
<!-- badges: end -->
1313

14-
A collection of high performance functions and iterators implemented in C++ for solving problems in combinatorics and computational mathematics.
14+
`RcppAlgos` provides high-performance algorithms for working with combinatorial objects in R. It includes efficient implementations for combinations, permutations, integer partitions, and compositions, with support for multisets, constraints, and extremely large search spaces through memory-efficient iterators.
1515

16-
## Featured Functions
16+
The package also implements specialized algorithms for problems rarely supported by other combinatorics libraries, including partitions of multisets, partitions of groups, and order-invariant Cartesian products. Many routines support ranking and unranking, parallel computation, and reproducible sampling. The package also includes fast prime number utilities built on the excellent work of [Kim Walisch](https://github.com/kimwalisch).
1717

18-
- **`{combo|permute}General`**: Generate all combinations/permutations of a vector (including [multisets](<https://en.wikipedia.org/wiki/Multiset>)) meeting specific criteria.
19-
- **`{partitions|compositions}General`**: Efficient algorithms for partitioning numbers under various constraints
20-
- **`{expandGrid|comboGrid}`**: Generate traditional Cartesian product as well as the product where order does not matter.
21-
- **`{combo|permute|partitions|compositions|expandGrid|comboGroups}Sample`**: Generate reproducible random samples
22-
- **`{combo|permute|partitions|compositions|expandGrid|comboGroups}Iter`**: Flexible iterators allow for bidirectional iteration as well as random access.
23-
- **`primeSieve`**: Fast prime number generator
24-
- **`primeCount`**: Prime counting function using [Legendre's formula](<https://mathworld.wolfram.com/LegendresFormula.html>)
18+
## Key Features
2519

26-
The `primeSieve` function and the `primeCount` function are both based off of the excellent work by [Kim Walisch](<https://github.com/kimwalisch>). The respective repos can be found here: [kimwalisch/primesieve](<https://github.com/kimwalisch/primesieve>); [kimwalisch/primecount](<https://github.com/kimwalisch/primecount>)
20+
- High-performance generation of combinations and permutations
21+
- Integer partitions and compositions under flexible constraints
22+
- Support for multisets and restricted combinatorial structures
23+
- Memory-efficient iterators for exploring very large combinatorial spaces
24+
- Ranking and unranking algorithms
25+
- Parallel computation support
26+
- Fast prime number utilities:
27+
- `primeSieve` for generating primes
28+
- `primeCount` for counting primes using Legendre’s formula
29+
- `primeFactorize` for prime factorization
30+
31+
RcppAlgos is designed to handle combinatorial problems ranging from small enumerations to extremely large search spaces where generating all results at once would be impractical.
2732

28-
Additionally, many of the sieving functions make use of the fast integer division library [libdivide](<https://github.com/ridiculousfish/libdivide>) by [ridiculousfish](<https://github.com/ridiculousfish>).
33+
## What Makes `RcppAlgos` Unique
2934

30-
## Benchmarks
35+
RcppAlgos implements several combinatorial algorithms that are uncommon or unavailable in most R libraries, including:
3136

32-
* [High Performance Benchmarks](<https://jwood000.github.io/RcppAlgos/articles/HighPerformanceBenchmarks.html>)
37+
- partitions of multisets
38+
- partitions of groups (`comboGroups`)
39+
- order-invariant Cartesian products (`comboGrid`)
40+
- compositions with distinct parts
41+
42+
## Performance
43+
44+
Detailed benchmarks can be found here:
45+
46+
[High Performance Benchmarks](<https://jwood000.github.io/RcppAlgos/articles/HighPerformanceBenchmarks.html>)
3347

3448
## Installation
3549

@@ -55,7 +69,7 @@ comboGeneral(4, 3)
5569

5670

5771
## Alternatively, iterate over combinations
58-
a = comboIter(4, 3)
72+
a <- comboIter(4, 3)
5973
a@nextIter()
6074
#> [1] 1 2 3
6175

@@ -85,7 +99,7 @@ comboSample(10, 8, TRUE, n = 5, seed = 84)
8599
#> [5,] 1 2 2 3 3 4 4 7
86100
```
87101

88-
### Integer Partitions and Constraints
102+
### Integer Partitions and Compositions
89103

90104
``` r
91105
## Flexible partitioning algorithms
@@ -123,99 +137,42 @@ comboGeneral(5, 7, TRUE, constraintFun = "prod",
123137
#> [7,] 3 3 3 3 3 4 4 3888
124138

125139

126-
## We can even iterate over constrained cases. These are
127-
## great when we don't know how many results there are upfront.
128-
## Save on memory and still at the speed of C++!!
129-
p = permuteIter(5, 7, TRUE, constraintFun = "prod",
130-
comparisonFun = c(">=","<"),
131-
limitConstraints = c(3600, 4000),
132-
keepResults = TRUE)
133-
134-
## Get the next n results
135-
t = p@nextNIter(1048)
136-
137-
## N.B. keepResults = TRUE adds the 8th column
138-
tail(t)
139-
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
140-
#> [1043,] 5 4 4 3 4 1 4 3840
141-
#> [1044,] 5 4 4 3 4 4 1 3840
142-
#> [1045,] 5 4 4 4 1 3 4 3840
143-
#> [1046,] 5 4 4 4 1 4 3 3840
144-
#> [1047,] 5 4 4 4 3 1 4 3840
145-
#> [1048,] 5 4 4 4 3 4 1 3840
146-
147-
## Continue iterating from where we left off
148-
p@nextIter()
149-
#> [1] 5 4 4 4 4 1 3 3840
150-
151-
p@nextIter()
152-
#> [1] 5 4 4 4 4 3 1 3840
140+
## We can also iterate over constrained cases. This is useful when we do not
141+
## know the total number of results upfront, while still avoiding the cost of
142+
## generating the full result set in memory.
143+
p <- permuteIter(
144+
5, 7, TRUE,
145+
constraintFun = "prod",
146+
comparisonFun = c(">=", "<"),
147+
limitConstraints = c(3600, 4000)
148+
)
153149

154150
p@nextIter()
155-
#> [1] 2 2 3 3 4 5 5 3600
156-
157-
## N.B. totalResults and totalRemaining are NA because there is no
158-
## closed form solution for determining this.
159-
p@summary()
160-
#> $description
161-
#> [1] "Permutations with repetition of 5 choose 7 where the prod is between 3600 and 4000"
162-
#>
163-
#> $currentIndex
164-
#> [1] 1051
165-
#>
166-
#> $totalResults
167-
#> [1] NA
168-
#>
169-
#> $totalRemaining
170-
#> [1] NA
151+
#> [1] 1 2 3 5 5 5 5
171152
```
172153

173154
### Cartesian Products
174155

175156
``` r
176157
## Base R expand.grid returns a data.frame by default
177158
## and varies the first column the fastest
178-
bR = expand.grid(rep(list(1:3), 3))
159+
bR <- expand.grid(rep(list(1:3), 3))
179160
head(bR, n = 3)
180161
#> Var1 Var2 Var3
181162
#> 1 1 1 1
182163
#> 2 2 1 1
183164
#> 3 3 1 1
184165

185-
tail(bR, n = 3)
186-
#> Var1 Var2 Var3
187-
#> 25 1 3 3
188-
#> 26 2 3 3
189-
#> 27 3 3 3
190166

191-
192-
## RcppAlgos::expandGrid returns a matrix if the input is of
193-
## the same class, otherwise it returns a data.frame. Also
194-
## varies the first column the slowest.
195-
algos = expandGrid(rep(list(1:3), 3))
167+
## RcppAlgos::expandGrid returns a matrix if the input is of the same class,
168+
## otherwise it returns a data.frame. Also varies the first column the slowest.
169+
algos <- expandGrid(rep(list(1:3), 3))
196170
head(algos, n = 3)
197171
#> Var1 Var2 Var3
198172
#> [1,] 1 1 1
199173
#> [2,] 1 1 2
200174
#> [3,] 1 1 3
201175

202-
tail(algos, n = 3)
203-
#> Var1 Var2 Var3
204-
#> [25,] 3 3 1
205-
#> [26,] 3 3 2
206-
#> [27,] 3 3 3
207-
208-
209-
## N.B. Since we are passing more than one type, a data.frame is returned
210-
expandGrid(
211-
c(rep(list(letters[1:3]), 3), list(1:3)),
212-
upper = 3
213-
)
214-
#> Var1 Var2 Var3 Var4
215-
#> 1 a a a 1
216-
#> 2 a a a 2
217-
#> 3 a a a 3
218-
219176

220177
## With RcppAlgos::comboGrid order doesn't matter, so c(1, 1, 2),
221178
## c(1, 2, 1), and c(2, 1, 1) are the same.
@@ -231,17 +188,14 @@ comboGrid(rep(list(1:3), 3))
231188
#> [8,] 2 2 3
232189
#> [9,] 2 3 3
233190
#> [10,] 3 3 3
234-
235-
236-
## If you don't want any repeats, set repetition = FALSE
237-
comboGrid(rep(list(1:3), 3), repetition = FALSE)
238-
#> Var1 Var2 Var3
239-
#> [1,] 1 2 3
240191
```
241192

242193
### Partitions of Groups
243194

244-
Efficiently partition a vector into groups with `comboGroups`. For example, the code below finds all possible pairings of groups of size 3 vs groups of size 2 (See this stackoverflow post: [Find all possible team pairing schemes](<https://stackoverflow.com/a/76068476/4408538>)).
195+
Efficiently partition a vector into groups with `comboGroups`. For example, the code below finds all possible partitions into groups of size 2 and 3. See this Stack Overflow post:
196+
197+
[Find all possible team pairing schemes](<https://stackoverflow.com/a/76068476/4408538>)
198+
245199
``` r
246200
players <- c("Ross", "Bobby", "Max", "Casper", "Jake")
247201
comboGroups(players, grpSizes = c(2, 3))
@@ -267,7 +221,7 @@ primeSieve(50)
267221

268222
## Many of the functions can produce results in
269223
## parallel for even greater performance
270-
p = primeSieve(1e15, 1e15 + 1e8, nThreads = 4)
224+
p <- primeSieve(1e15, 1e15 + 1e8, nThreads = 4)
271225

272226
head(p)
273227
#> [1] 1000000000000037 1000000000000091 1000000000000159
@@ -299,15 +253,17 @@ primeFactorize(sample(1e15, 3), namedList = TRUE)
299253
* [Function Documentation](<https://jwood000.github.io/RcppAlgos/reference/index.html>)
300254
* [Computational Mathematics Overview](<https://jwood000.github.io/RcppAlgos/articles/ComputationalMathematics.html>)
301255
* [Combination and Permutation Basics](<https://jwood000.github.io/RcppAlgos/articles/GeneralCombinatorics.html>)
256+
* [Integer Partitions in RcppAlgos](<https://jwood000.github.io/RcppAlgos/articles/IntegerPartitions.html>)
257+
* [Integer Compositions in RcppAlgos](<https://jwood000.github.io/RcppAlgos/articles/IntegerCompositions.html>)
302258
* [Combinatorial Sampling](<https://jwood000.github.io/RcppAlgos/articles/CombinatorialSampling.html>)
303-
* [Constraints, Partitions, and Compositions](<https://jwood000.github.io/RcppAlgos/articles/CombPermConstraints.html>)
259+
* [Constraints in RcppAlgos: Constraint-Driven Combinatorial Enumeration](<https://jwood000.github.io/RcppAlgos/articles/CombPermConstraints.html>)
304260
* [Attacking Problems Related to the Subset Sum Problem](<https://jwood000.github.io/RcppAlgos/articles/SubsetSum.html>)
305261
* [Combinatorial Iterators in RcppAlgos](<https://jwood000.github.io/RcppAlgos/articles/CombinatoricsIterators.html>)
306262
* [Cartesian Products and Partitions of Groups](<https://jwood000.github.io/RcppAlgos/articles/OtherCombinatorics.html>)
307263

308264
## Why **`RcppAlgos`** but no **`Rcpp`**?
309265

310-
Previous versions of `RcppAlgos` relied on [Rcpp](<https://github.com/RcppCore/Rcpp>) to ease the burden of exposing C++ to R. While the current version of `RcppAlgos` does not utilize `Rcpp`, it would not be possible without the myriad of excellent contributions to `Rcpp`.
266+
Earlier versions of `RcppAlgos` relied on [Rcpp](<https://github.com/RcppCore/Rcpp>) to interface C++ with R. The current implementation uses [cpp11](<https://github.com/r-lib/cpp11>), which provides a lightweight interface to R’s C API. While the package no longer depends on `Rcpp`, the project owes much to the excellent work of the `Rcpp` community.
311267

312268
## Contact
313269

ai_git_helpers/commit_msg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"ci"
3030
}
3131

32-
MODEL = os.getenv("AI_REVIEW_MODEL", "gpt-4o-mini")
32+
MODEL = os.getenv("AI_REVIEW_MODEL", "gpt-5.2")
3333
MAX_OUTPUT_TOKENS = 200
3434
TEMPERATURE = 0.2
3535
SUBJECT_MAX = 72

ai_git_helpers/review.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
MAX_FILE_BYTES = 200_000
1414
MAX_DIFF_BYTES_TOTAL = 400_000
15-
MODEL = os.getenv("AI_REVIEW_MODEL", "gpt-4o-mini")
15+
MODEL = os.getenv("AI_REVIEW_MODEL", "gpt-5.2")
1616
MAX_OUTPUT_TOKENS = 4000
1717
TEMPERATURE = 0.2
1818

File renamed without changes.

docs/404.html

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/_config.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)