Skip to content

Commit 9e5cf7c

Browse files
committed
doc: update doc and examples for partitions(n::Integer, m::Integer)
1 parent 1ec9e62 commit 9e5cf7c

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

src/partitions.jl

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,47 @@ Base.length(f::FixedPartitions) = npartitions(f.n,f.m)
136136
Base.eltype(f::FixedPartitions) = Vector{Int}
137137

138138
"""
139-
partitions(n, m)
139+
partitions(n::Integer, m::Integer)
140140
141-
Generate all arrays of `m` integers that sum to `n`. Because the number of partitions can
142-
be very large, this function returns an iterator object. Use `collect(partitions(n, m))` to
143-
get an array of all partitions. The number of partitions to generate can be efficiently
144-
computed using `length(partitions(n, m))`.
141+
Generate all integer partitions of `n` into exactly `m` parts, that sum to `n`.
142+
143+
Because the number of partitions can be very large,
144+
this function returns an iterator object.
145+
Use `collect(partitions(n, m))` to get an array of all partitions.
146+
147+
The number of partitions to generate can be efficiently computed using
148+
`length(partitions(n, m))`.
149+
150+
See also: [`partitions(n::Integer)`](@ref)
151+
152+
## Examples
153+
```jldoctest
154+
julia> collect(partitions(4))
155+
5-element Vector{Vector{Int64}}:
156+
[4]
157+
[3, 1]
158+
[2, 2]
159+
[2, 1, 1]
160+
[1, 1, 1, 1]
161+
162+
julia> collect(partitions(4, 2))
163+
2-element Vector{Vector{Int64}}:
164+
[3, 1]
165+
[2, 2]
166+
167+
julia> collect(partitions(4, 4))
168+
1-element Vector{Vector{Int64}}:
169+
[1, 1, 1, 1]
170+
171+
julia> collect(partitions(4, 5))
172+
Vector{Int64}[]
173+
174+
julia> partitions(4, 0)
175+
ERROR: DomainError with (4, 0):
176+
n and m must be positive
177+
Stacktrace:
178+
[...]
179+
```
145180
"""
146181
partitions(n::Integer, m::Integer) =
147182
n >= 1 && m >= 1 ?

0 commit comments

Comments
 (0)