The algorithms in RcppAlgos go beyond the traditional integer partition algorithms and can tackle a wide variety of cases.

  • Efficient algorithms for partitioning numbers under various constraints:

    • Standard (with repetition)

    • Distinct

    • Restricted

    • Where each part has a specific multiplicity (i.e. when using freqs for multisets).

    • Arbitrary target and source vector (e.g. partitionsGeneral(sample(1000, 20), 10, TRUE, target = 5000))

  • Produce results in parallel using the nThreads arguments.

  • Alternatively, the arguments lower and upper make it possible to generate partitions/compositions in chunks allowing for parallelization via the parallel package.

  • GMP support allows for exploration of cases where the number of partitions/compositions is large.

  • The output is in lexicographical order.

partitionsGeneral(v, m = NULL, ...)
compositionsGeneral(v, m = NULL, ...)

# S3 method for default
partitionsGeneral(
    v, m = NULL, repetition = FALSE, freqs = NULL, target = NULL,
    lower = NULL, upper = NULL, nThreads = NULL, tolerance = NULL, ...
)
# S3 method for default
compositionsGeneral(
    v, m = NULL, repetition = FALSE, freqs = NULL, target = NULL, weak = FALSE,
    lower = NULL, upper = NULL, nThreads = NULL, tolerance = NULL, ...
)

# S3 method for table
partitionsGeneral(
    v, m = NULL, target = NULL, lower = NULL,
    upper = NULL, nThreads = NULL, tolerance = NULL, ...
)
# S3 method for table
compositionsGeneral(
    v, m = NULL, target = NULL, weak = FALSE, lower = NULL,
    upper = NULL, nThreads = NULL, tolerance = NULL, ...
)

Arguments

v

Source vector. If v is a positive integer, it will be converted to the sequence 1:v. If v is a negative integer, it will be converted to the sequence v:-1. Only integer and numeric vectors are accepted.

m

Width of the partition. If m = NULL, the length will be determined by the partitioning case (e.g. When we are generating distinct partitions of \(n\), the width will be equal to the smallest \(m\) such that sum(1:m) >= n).

...

Further arguments passed to methods.

repetition

Logical value indicating whether partitions/compositions should be with or without repetition. The default is FALSE.

freqs

A vector of frequencies used for producing all partitions of a multiset of v. Each element of freqs represents how many times each element of the source vector, v, is repeated. It is analogous to the times argument in rep. The default value is NULL.

lower

The lower bound. Partitions/compositions are generated lexicographically, thus utilizing this argument will determine which specific partition to start generating from (e.g. partitionsGeneral(15, 3, lower = 6) is equivalent to partitionsGeneral(15, 3)[6:partitionsCount(15, 3), ]). This argument along with upper is very useful for generating partitions/compositions in chunks allowing for easy parallelization.

upper

The upper bound. Similar to lower, however this parameter allows the user to stop generation at a specific partition (e.g. partitionsGeneral(15, 3, upper = 5) is equivalent to partitionsGeneral(15, 3)[1:5, ])

target

Number to be partitioned. If NULL, max(v) will be used.

weak

(Compositions only) Logical flag indicating whether to allow terms of the sequence to be zero.

nThreads

Specific number of threads to be used. The default is NULL.

tolerance

A numeric value greater than or equal to zero. This parameter is utilized when a constraint is applied on a numeric vector. The default value is 0 when it can be determined that whole values are being utilized, otherwise it is sqrt(.Machine$double.eps) which is approximately \(1.5e-8\). N.B. If the input vector is of type integer, this parameter will be ignored and strict equality will be enforced.

Value

A matrix is returned with each row containing a vector of length \(m\).

Note

  • nThreads will be ignored in the following cases (i.e. Generating the \(n^{th}\) partition in these cases are currently unavailable):

    • With standard multisets. If zero is the only element with a non-trivial multiplicity, multithreading is possible (e.g. partitionsGeneral(0:100, freqs = c(100, rep(1, 100)), nThreads = 4)).

    • If the source vector is not isomorphic to 1:length(v) (e.g. v = c(1, 4, 6, 7, 8)).

  • The maximum number of partitions/compositions that can be generated at one time is \(2^{31} - 1\). Utilizing lower and upper makes it possible to generate additional partitions/compositions.

Author

Joseph Wood

Examples

partitionsGeneral(1)
#>      [,1]
#> [1,]    1
partitionsGeneral(-1:0, 1)
#>      [,1]
#> [1,]    0
partitionsGeneral(-1:0, 1, target = -1)
#>      [,1]
#> [1,]   -1
partitionsGeneral(20, 5)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    2    3    4   10
#> [2,]    1    2    3    5    9
#> [3,]    1    2    3    6    8
#> [4,]    1    2    4    5    8
#> [5,]    1    2    4    6    7
#> [6,]    1    3    4    5    7
#> [7,]    2    3    4    5    6
partitionsGeneral(20, 5, repetition = TRUE)
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,]    1    1    1    1   16
#>  [2,]    1    1    1    2   15
#>  [3,]    1    1    1    3   14
#>  [4,]    1    1    1    4   13
#>  [5,]    1    1    1    5   12
#>  [6,]    1    1    1    6   11
#>  [7,]    1    1    1    7   10
#>  [8,]    1    1    1    8    9
#>  [9,]    1    1    2    2   14
#> [10,]    1    1    2    3   13
#> [11,]    1    1    2    4   12
#> [12,]    1    1    2    5   11
#> [13,]    1    1    2    6   10
#> [14,]    1    1    2    7    9
#> [15,]    1    1    2    8    8
#> [16,]    1    1    3    3   12
#> [17,]    1    1    3    4   11
#> [18,]    1    1    3    5   10
#> [19,]    1    1    3    6    9
#> [20,]    1    1    3    7    8
#> [21,]    1    1    4    4   10
#> [22,]    1    1    4    5    9
#> [23,]    1    1    4    6    8
#> [24,]    1    1    4    7    7
#> [25,]    1    1    5    5    8
#> [26,]    1    1    5    6    7
#> [27,]    1    1    6    6    6
#> [28,]    1    2    2    2   13
#> [29,]    1    2    2    3   12
#> [30,]    1    2    2    4   11
#> [31,]    1    2    2    5   10
#> [32,]    1    2    2    6    9
#> [33,]    1    2    2    7    8
#> [34,]    1    2    3    3   11
#> [35,]    1    2    3    4   10
#> [36,]    1    2    3    5    9
#> [37,]    1    2    3    6    8
#> [38,]    1    2    3    7    7
#> [39,]    1    2    4    4    9
#> [40,]    1    2    4    5    8
#> [41,]    1    2    4    6    7
#> [42,]    1    2    5    5    7
#> [43,]    1    2    5    6    6
#> [44,]    1    3    3    3   10
#> [45,]    1    3    3    4    9
#> [46,]    1    3    3    5    8
#> [47,]    1    3    3    6    7
#> [48,]    1    3    4    4    8
#> [49,]    1    3    4    5    7
#> [50,]    1    3    4    6    6
#> [51,]    1    3    5    5    6
#> [52,]    1    4    4    4    7
#> [53,]    1    4    4    5    6
#> [54,]    1    4    5    5    5
#> [55,]    2    2    2    2   12
#> [56,]    2    2    2    3   11
#> [57,]    2    2    2    4   10
#> [58,]    2    2    2    5    9
#> [59,]    2    2    2    6    8
#> [60,]    2    2    2    7    7
#> [61,]    2    2    3    3   10
#> [62,]    2    2    3    4    9
#> [63,]    2    2    3    5    8
#> [64,]    2    2    3    6    7
#> [65,]    2    2    4    4    8
#> [66,]    2    2    4    5    7
#> [67,]    2    2    4    6    6
#> [68,]    2    2    5    5    6
#> [69,]    2    3    3    3    9
#> [70,]    2    3    3    4    8
#> [71,]    2    3    3    5    7
#> [72,]    2    3    3    6    6
#> [73,]    2    3    4    4    7
#> [74,]    2    3    4    5    6
#> [75,]    2    3    5    5    5
#> [76,]    2    4    4    4    6
#> [77,]    2    4    4    5    5
#> [78,]    3    3    3    3    8
#> [79,]    3    3    3    4    7
#> [80,]    3    3    3    5    6
#> [81,]    3    3    4    4    6
#> [82,]    3    3    4    5    5
#> [83,]    3    4    4    4    5
#> [84,]    4    4    4    4    4
partitionsGeneral(20, 5, freqs = rep(1:4, 5))
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,]    1    2    2    3   12
#>  [2,]    1    2    2    4   11
#>  [3,]    1    2    2    5   10
#>  [4,]    1    2    2    6    9
#>  [5,]    1    2    2    7    8
#>  [6,]    1    2    3    3   11
#>  [7,]    1    2    3    4   10
#>  [8,]    1    2    3    5    9
#>  [9,]    1    2    3    6    8
#> [10,]    1    2    3    7    7
#> [11,]    1    2    4    4    9
#> [12,]    1    2    4    5    8
#> [13,]    1    2    4    6    7
#> [14,]    1    2    5    6    6
#> [15,]    1    3    3    3   10
#> [16,]    1    3    3    4    9
#> [17,]    1    3    3    5    8
#> [18,]    1    3    3    6    7
#> [19,]    1    3    4    4    8
#> [20,]    1    3    4    5    7
#> [21,]    1    3    4    6    6
#> [22,]    1    4    4    4    7
#> [23,]    1    4    4    5    6
#> [24,]    2    2    3    3   10
#> [25,]    2    2    3    4    9
#> [26,]    2    2    3    5    8
#> [27,]    2    2    3    6    7
#> [28,]    2    2    4    4    8
#> [29,]    2    2    4    5    7
#> [30,]    2    2    4    6    6
#> [31,]    2    3    3    3    9
#> [32,]    2    3    3    4    8
#> [33,]    2    3    3    5    7
#> [34,]    2    3    3    6    6
#> [35,]    2    3    4    4    7
#> [36,]    2    3    4    5    6
#> [37,]    2    4    4    4    6
#> [38,]    3    3    3    4    7
#> [39,]    3    3    3    5    6
#> [40,]    3    3    4    4    6
#> [41,]    3    4    4    4    5
partitionsGeneral(20, 5, TRUE, target = 80)
#>        [,1] [,2] [,3] [,4] [,5]
#>   [1,]    1   19   20   20   20
#>   [2,]    2   18   20   20   20
#>   [3,]    2   19   19   20   20
#>   [4,]    3   17   20   20   20
#>   [5,]    3   18   19   20   20
#>   [6,]    3   19   19   19   20
#>   [7,]    4   16   20   20   20
#>   [8,]    4   17   19   20   20
#>   [9,]    4   18   18   20   20
#>  [10,]    4   18   19   19   20
#>  [11,]    4   19   19   19   19
#>  [12,]    5   15   20   20   20
#>  [13,]    5   16   19   20   20
#>  [14,]    5   17   18   20   20
#>  [15,]    5   17   19   19   20
#>  [16,]    5   18   18   19   20
#>  [17,]    5   18   19   19   19
#>  [18,]    6   14   20   20   20
#>  [19,]    6   15   19   20   20
#>  [20,]    6   16   18   20   20
#>  [21,]    6   16   19   19   20
#>  [22,]    6   17   17   20   20
#>  [23,]    6   17   18   19   20
#>  [24,]    6   17   19   19   19
#>  [25,]    6   18   18   18   20
#>  [26,]    6   18   18   19   19
#>  [27,]    7   13   20   20   20
#>  [28,]    7   14   19   20   20
#>  [29,]    7   15   18   20   20
#>  [30,]    7   15   19   19   20
#>  [31,]    7   16   17   20   20
#>  [32,]    7   16   18   19   20
#>  [33,]    7   16   19   19   19
#>  [34,]    7   17   17   19   20
#>  [35,]    7   17   18   18   20
#>  [36,]    7   17   18   19   19
#>  [37,]    7   18   18   18   19
#>  [38,]    8   12   20   20   20
#>  [39,]    8   13   19   20   20
#>  [40,]    8   14   18   20   20
#>  [41,]    8   14   19   19   20
#>  [42,]    8   15   17   20   20
#>  [43,]    8   15   18   19   20
#>  [44,]    8   15   19   19   19
#>  [45,]    8   16   16   20   20
#>  [46,]    8   16   17   19   20
#>  [47,]    8   16   18   18   20
#>  [48,]    8   16   18   19   19
#>  [49,]    8   17   17   18   20
#>  [50,]    8   17   17   19   19
#>  [51,]    8   17   18   18   19
#>  [52,]    8   18   18   18   18
#>  [53,]    9   11   20   20   20
#>  [54,]    9   12   19   20   20
#>  [55,]    9   13   18   20   20
#>  [56,]    9   13   19   19   20
#>  [57,]    9   14   17   20   20
#>  [58,]    9   14   18   19   20
#>  [59,]    9   14   19   19   19
#>  [60,]    9   15   16   20   20
#>  [61,]    9   15   17   19   20
#>  [62,]    9   15   18   18   20
#>  [63,]    9   15   18   19   19
#>  [64,]    9   16   16   19   20
#>  [65,]    9   16   17   18   20
#>  [66,]    9   16   17   19   19
#>  [67,]    9   16   18   18   19
#>  [68,]    9   17   17   17   20
#>  [69,]    9   17   17   18   19
#>  [70,]    9   17   18   18   18
#>  [71,]   10   10   20   20   20
#>  [72,]   10   11   19   20   20
#>  [73,]   10   12   18   20   20
#>  [74,]   10   12   19   19   20
#>  [75,]   10   13   17   20   20
#>  [76,]   10   13   18   19   20
#>  [77,]   10   13   19   19   19
#>  [78,]   10   14   16   20   20
#>  [79,]   10   14   17   19   20
#>  [80,]   10   14   18   18   20
#>  [81,]   10   14   18   19   19
#>  [82,]   10   15   15   20   20
#>  [83,]   10   15   16   19   20
#>  [84,]   10   15   17   18   20
#>  [85,]   10   15   17   19   19
#>  [86,]   10   15   18   18   19
#>  [87,]   10   16   16   18   20
#>  [88,]   10   16   16   19   19
#>  [89,]   10   16   17   17   20
#>  [90,]   10   16   17   18   19
#>  [91,]   10   16   18   18   18
#>  [92,]   10   17   17   17   19
#>  [93,]   10   17   17   18   18
#>  [94,]   11   11   18   20   20
#>  [95,]   11   11   19   19   20
#>  [96,]   11   12   17   20   20
#>  [97,]   11   12   18   19   20
#>  [98,]   11   12   19   19   19
#>  [99,]   11   13   16   20   20
#> [100,]   11   13   17   19   20
#> [101,]   11   13   18   18   20
#> [102,]   11   13   18   19   19
#> [103,]   11   14   15   20   20
#> [104,]   11   14   16   19   20
#> [105,]   11   14   17   18   20
#> [106,]   11   14   17   19   19
#> [107,]   11   14   18   18   19
#> [108,]   11   15   15   19   20
#> [109,]   11   15   16   18   20
#> [110,]   11   15   16   19   19
#> [111,]   11   15   17   17   20
#> [112,]   11   15   17   18   19
#> [113,]   11   15   18   18   18
#> [114,]   11   16   16   17   20
#> [115,]   11   16   16   18   19
#> [116,]   11   16   17   17   19
#> [117,]   11   16   17   18   18
#> [118,]   11   17   17   17   18
#> [119,]   12   12   16   20   20
#> [120,]   12   12   17   19   20
#> [121,]   12   12   18   18   20
#> [122,]   12   12   18   19   19
#> [123,]   12   13   15   20   20
#> [124,]   12   13   16   19   20
#> [125,]   12   13   17   18   20
#> [126,]   12   13   17   19   19
#> [127,]   12   13   18   18   19
#> [128,]   12   14   14   20   20
#> [129,]   12   14   15   19   20
#> [130,]   12   14   16   18   20
#> [131,]   12   14   16   19   19
#> [132,]   12   14   17   17   20
#> [133,]   12   14   17   18   19
#> [134,]   12   14   18   18   18
#> [135,]   12   15   15   18   20
#> [136,]   12   15   15   19   19
#> [137,]   12   15   16   17   20
#> [138,]   12   15   16   18   19
#> [139,]   12   15   17   17   19
#> [140,]   12   15   17   18   18
#> [141,]   12   16   16   16   20
#> [142,]   12   16   16   17   19
#> [143,]   12   16   16   18   18
#> [144,]   12   16   17   17   18
#> [145,]   12   17   17   17   17
#> [146,]   13   13   14   20   20
#> [147,]   13   13   15   19   20
#> [148,]   13   13   16   18   20
#> [149,]   13   13   16   19   19
#> [150,]   13   13   17   17   20
#> [151,]   13   13   17   18   19
#> [152,]   13   13   18   18   18
#> [153,]   13   14   14   19   20
#> [154,]   13   14   15   18   20
#> [155,]   13   14   15   19   19
#> [156,]   13   14   16   17   20
#> [157,]   13   14   16   18   19
#> [158,]   13   14   17   17   19
#> [159,]   13   14   17   18   18
#> [160,]   13   15   15   17   20
#> [161,]   13   15   15   18   19
#> [162,]   13   15   16   16   20
#> [163,]   13   15   16   17   19
#> [164,]   13   15   16   18   18
#> [165,]   13   15   17   17   18
#> [166,]   13   16   16   16   19
#> [167,]   13   16   16   17   18
#> [168,]   13   16   17   17   17
#> [169,]   14   14   14   18   20
#> [170,]   14   14   14   19   19
#> [171,]   14   14   15   17   20
#> [172,]   14   14   15   18   19
#> [173,]   14   14   16   16   20
#> [174,]   14   14   16   17   19
#> [175,]   14   14   16   18   18
#> [176,]   14   14   17   17   18
#> [177,]   14   15   15   16   20
#> [178,]   14   15   15   17   19
#> [179,]   14   15   15   18   18
#> [180,]   14   15   16   16   19
#> [181,]   14   15   16   17   18
#> [182,]   14   15   17   17   17
#> [183,]   14   16   16   16   18
#> [184,]   14   16   16   17   17
#> [185,]   15   15   15   15   20
#> [186,]   15   15   15   16   19
#> [187,]   15   15   15   17   18
#> [188,]   15   15   16   16   18
#> [189,]   15   15   16   17   17
#> [190,]   15   16   16   16   17
#> [191,]   16   16   16   16   16
partitionsGeneral(0:10, repetition = TRUE)
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#>  [1,]    0    0    0    0    0    0    0    0    0    10
#>  [2,]    0    0    0    0    0    0    0    0    1     9
#>  [3,]    0    0    0    0    0    0    0    0    2     8
#>  [4,]    0    0    0    0    0    0    0    0    3     7
#>  [5,]    0    0    0    0    0    0    0    0    4     6
#>  [6,]    0    0    0    0    0    0    0    0    5     5
#>  [7,]    0    0    0    0    0    0    0    1    1     8
#>  [8,]    0    0    0    0    0    0    0    1    2     7
#>  [9,]    0    0    0    0    0    0    0    1    3     6
#> [10,]    0    0    0    0    0    0    0    1    4     5
#> [11,]    0    0    0    0    0    0    0    2    2     6
#> [12,]    0    0    0    0    0    0    0    2    3     5
#> [13,]    0    0    0    0    0    0    0    2    4     4
#> [14,]    0    0    0    0    0    0    0    3    3     4
#> [15,]    0    0    0    0    0    0    1    1    1     7
#> [16,]    0    0    0    0    0    0    1    1    2     6
#> [17,]    0    0    0    0    0    0    1    1    3     5
#> [18,]    0    0    0    0    0    0    1    1    4     4
#> [19,]    0    0    0    0    0    0    1    2    2     5
#> [20,]    0    0    0    0    0    0    1    2    3     4
#> [21,]    0    0    0    0    0    0    1    3    3     3
#> [22,]    0    0    0    0    0    0    2    2    2     4
#> [23,]    0    0    0    0    0    0    2    2    3     3
#> [24,]    0    0    0    0    0    1    1    1    1     6
#> [25,]    0    0    0    0    0    1    1    1    2     5
#> [26,]    0    0    0    0    0    1    1    1    3     4
#> [27,]    0    0    0    0    0    1    1    2    2     4
#> [28,]    0    0    0    0    0    1    1    2    3     3
#> [29,]    0    0    0    0    0    1    2    2    2     3
#> [30,]    0    0    0    0    0    2    2    2    2     2
#> [31,]    0    0    0    0    1    1    1    1    1     5
#> [32,]    0    0    0    0    1    1    1    1    2     4
#> [33,]    0    0    0    0    1    1    1    1    3     3
#> [34,]    0    0    0    0    1    1    1    2    2     3
#> [35,]    0    0    0    0    1    1    2    2    2     2
#> [36,]    0    0    0    1    1    1    1    1    1     4
#> [37,]    0    0    0    1    1    1    1    1    2     3
#> [38,]    0    0    0    1    1    1    1    2    2     2
#> [39,]    0    0    1    1    1    1    1    1    1     3
#> [40,]    0    0    1    1    1    1    1    1    2     2
#> [41,]    0    1    1    1    1    1    1    1    1     2
#> [42,]    1    1    1    1    1    1    1    1    1     1
partitionsGeneral(seq(2L, 500L, 23L), 5, target = 1804)
#>        [,1] [,2] [,3] [,4] [,5]
#>   [1,]    2  416  439  462  485
#>   [2,]   25  393  439  462  485
#>   [3,]   48  370  439  462  485
#>   [4,]   48  393  416  462  485
#>   [5,]   71  347  439  462  485
#>   [6,]   71  370  416  462  485
#>   [7,]   71  393  416  439  485
#>   [8,]   94  324  439  462  485
#>   [9,]   94  347  416  462  485
#>  [10,]   94  370  393  462  485
#>  [11,]   94  370  416  439  485
#>  [12,]   94  393  416  439  462
#>  [13,]  117  301  439  462  485
#>  [14,]  117  324  416  462  485
#>  [15,]  117  347  393  462  485
#>  [16,]  117  347  416  439  485
#>  [17,]  117  370  393  439  485
#>  [18,]  117  370  416  439  462
#>  [19,]  140  278  439  462  485
#>  [20,]  140  301  416  462  485
#>  [21,]  140  324  393  462  485
#>  [22,]  140  324  416  439  485
#>  [23,]  140  347  370  462  485
#>  [24,]  140  347  393  439  485
#>  [25,]  140  347  416  439  462
#>  [26,]  140  370  393  416  485
#>  [27,]  140  370  393  439  462
#>  [28,]  163  255  439  462  485
#>  [29,]  163  278  416  462  485
#>  [30,]  163  301  393  462  485
#>  [31,]  163  301  416  439  485
#>  [32,]  163  324  370  462  485
#>  [33,]  163  324  393  439  485
#>  [34,]  163  324  416  439  462
#>  [35,]  163  347  370  439  485
#>  [36,]  163  347  393  416  485
#>  [37,]  163  347  393  439  462
#>  [38,]  163  370  393  416  462
#>  [39,]  186  232  439  462  485
#>  [40,]  186  255  416  462  485
#>  [41,]  186  278  393  462  485
#>  [42,]  186  278  416  439  485
#>  [43,]  186  301  370  462  485
#>  [44,]  186  301  393  439  485
#>  [45,]  186  301  416  439  462
#>  [46,]  186  324  347  462  485
#>  [47,]  186  324  370  439  485
#>  [48,]  186  324  393  416  485
#>  [49,]  186  324  393  439  462
#>  [50,]  186  347  370  416  485
#>  [51,]  186  347  370  439  462
#>  [52,]  186  347  393  416  462
#>  [53,]  186  370  393  416  439
#>  [54,]  209  232  416  462  485
#>  [55,]  209  255  393  462  485
#>  [56,]  209  255  416  439  485
#>  [57,]  209  278  370  462  485
#>  [58,]  209  278  393  439  485
#>  [59,]  209  278  416  439  462
#>  [60,]  209  301  347  462  485
#>  [61,]  209  301  370  439  485
#>  [62,]  209  301  393  416  485
#>  [63,]  209  301  393  439  462
#>  [64,]  209  324  347  439  485
#>  [65,]  209  324  370  416  485
#>  [66,]  209  324  370  439  462
#>  [67,]  209  324  393  416  462
#>  [68,]  209  347  370  393  485
#>  [69,]  209  347  370  416  462
#>  [70,]  209  347  393  416  439
#>  [71,]  232  255  370  462  485
#>  [72,]  232  255  393  439  485
#>  [73,]  232  255  416  439  462
#>  [74,]  232  278  347  462  485
#>  [75,]  232  278  370  439  485
#>  [76,]  232  278  393  416  485
#>  [77,]  232  278  393  439  462
#>  [78,]  232  301  324  462  485
#>  [79,]  232  301  347  439  485
#>  [80,]  232  301  370  416  485
#>  [81,]  232  301  370  439  462
#>  [82,]  232  301  393  416  462
#>  [83,]  232  324  347  416  485
#>  [84,]  232  324  347  439  462
#>  [85,]  232  324  370  393  485
#>  [86,]  232  324  370  416  462
#>  [87,]  232  324  393  416  439
#>  [88,]  232  347  370  393  462
#>  [89,]  232  347  370  416  439
#>  [90,]  255  278  324  462  485
#>  [91,]  255  278  347  439  485
#>  [92,]  255  278  370  416  485
#>  [93,]  255  278  370  439  462
#>  [94,]  255  278  393  416  462
#>  [95,]  255  301  324  439  485
#>  [96,]  255  301  347  416  485
#>  [97,]  255  301  347  439  462
#>  [98,]  255  301  370  393  485
#>  [99,]  255  301  370  416  462
#> [100,]  255  301  393  416  439
#> [101,]  255  324  347  393  485
#> [102,]  255  324  347  416  462
#> [103,]  255  324  370  393  462
#> [104,]  255  324  370  416  439
#> [105,]  255  347  370  393  439
#> [106,]  278  301  324  416  485
#> [107,]  278  301  324  439  462
#> [108,]  278  301  347  393  485
#> [109,]  278  301  347  416  462
#> [110,]  278  301  370  393  462
#> [111,]  278  301  370  416  439
#> [112,]  278  324  347  370  485
#> [113,]  278  324  347  393  462
#> [114,]  278  324  347  416  439
#> [115,]  278  324  370  393  439
#> [116,]  278  347  370  393  416
#> [117,]  301  324  347  370  462
#> [118,]  301  324  347  393  439
#> [119,]  301  324  370  393  416

compositionsGeneral(0:10, 5, repetition = TRUE)
#>        [,1] [,2] [,3] [,4] [,5]
#>   [1,]    0    0    0    0   10
#>   [2,]    0    0    0    1    9
#>   [3,]    0    0    0    2    8
#>   [4,]    0    0    0    3    7
#>   [5,]    0    0    0    4    6
#>   [6,]    0    0    0    5    5
#>   [7,]    0    0    0    6    4
#>   [8,]    0    0    0    7    3
#>   [9,]    0    0    0    8    2
#>  [10,]    0    0    0    9    1
#>  [11,]    0    0    1    1    8
#>  [12,]    0    0    1    2    7
#>  [13,]    0    0    1    3    6
#>  [14,]    0    0    1    4    5
#>  [15,]    0    0    1    5    4
#>  [16,]    0    0    1    6    3
#>  [17,]    0    0    1    7    2
#>  [18,]    0    0    1    8    1
#>  [19,]    0    0    2    1    7
#>  [20,]    0    0    2    2    6
#>  [21,]    0    0    2    3    5
#>  [22,]    0    0    2    4    4
#>  [23,]    0    0    2    5    3
#>  [24,]    0    0    2    6    2
#>  [25,]    0    0    2    7    1
#>  [26,]    0    0    3    1    6
#>  [27,]    0    0    3    2    5
#>  [28,]    0    0    3    3    4
#>  [29,]    0    0    3    4    3
#>  [30,]    0    0    3    5    2
#>  [31,]    0    0    3    6    1
#>  [32,]    0    0    4    1    5
#>  [33,]    0    0    4    2    4
#>  [34,]    0    0    4    3    3
#>  [35,]    0    0    4    4    2
#>  [36,]    0    0    4    5    1
#>  [37,]    0    0    5    1    4
#>  [38,]    0    0    5    2    3
#>  [39,]    0    0    5    3    2
#>  [40,]    0    0    5    4    1
#>  [41,]    0    0    6    1    3
#>  [42,]    0    0    6    2    2
#>  [43,]    0    0    6    3    1
#>  [44,]    0    0    7    1    2
#>  [45,]    0    0    7    2    1
#>  [46,]    0    0    8    1    1
#>  [47,]    0    1    1    1    7
#>  [48,]    0    1    1    2    6
#>  [49,]    0    1    1    3    5
#>  [50,]    0    1    1    4    4
#>  [51,]    0    1    1    5    3
#>  [52,]    0    1    1    6    2
#>  [53,]    0    1    1    7    1
#>  [54,]    0    1    2    1    6
#>  [55,]    0    1    2    2    5
#>  [56,]    0    1    2    3    4
#>  [57,]    0    1    2    4    3
#>  [58,]    0    1    2    5    2
#>  [59,]    0    1    2    6    1
#>  [60,]    0    1    3    1    5
#>  [61,]    0    1    3    2    4
#>  [62,]    0    1    3    3    3
#>  [63,]    0    1    3    4    2
#>  [64,]    0    1    3    5    1
#>  [65,]    0    1    4    1    4
#>  [66,]    0    1    4    2    3
#>  [67,]    0    1    4    3    2
#>  [68,]    0    1    4    4    1
#>  [69,]    0    1    5    1    3
#>  [70,]    0    1    5    2    2
#>  [71,]    0    1    5    3    1
#>  [72,]    0    1    6    1    2
#>  [73,]    0    1    6    2    1
#>  [74,]    0    1    7    1    1
#>  [75,]    0    2    1    1    6
#>  [76,]    0    2    1    2    5
#>  [77,]    0    2    1    3    4
#>  [78,]    0    2    1    4    3
#>  [79,]    0    2    1    5    2
#>  [80,]    0    2    1    6    1
#>  [81,]    0    2    2    1    5
#>  [82,]    0    2    2    2    4
#>  [83,]    0    2    2    3    3
#>  [84,]    0    2    2    4    2
#>  [85,]    0    2    2    5    1
#>  [86,]    0    2    3    1    4
#>  [87,]    0    2    3    2    3
#>  [88,]    0    2    3    3    2
#>  [89,]    0    2    3    4    1
#>  [90,]    0    2    4    1    3
#>  [91,]    0    2    4    2    2
#>  [92,]    0    2    4    3    1
#>  [93,]    0    2    5    1    2
#>  [94,]    0    2    5    2    1
#>  [95,]    0    2    6    1    1
#>  [96,]    0    3    1    1    5
#>  [97,]    0    3    1    2    4
#>  [98,]    0    3    1    3    3
#>  [99,]    0    3    1    4    2
#> [100,]    0    3    1    5    1
#> [101,]    0    3    2    1    4
#> [102,]    0    3    2    2    3
#> [103,]    0    3    2    3    2
#> [104,]    0    3    2    4    1
#> [105,]    0    3    3    1    3
#> [106,]    0    3    3    2    2
#> [107,]    0    3    3    3    1
#> [108,]    0    3    4    1    2
#> [109,]    0    3    4    2    1
#> [110,]    0    3    5    1    1
#> [111,]    0    4    1    1    4
#> [112,]    0    4    1    2    3
#> [113,]    0    4    1    3    2
#> [114,]    0    4    1    4    1
#> [115,]    0    4    2    1    3
#> [116,]    0    4    2    2    2
#> [117,]    0    4    2    3    1
#> [118,]    0    4    3    1    2
#> [119,]    0    4    3    2    1
#> [120,]    0    4    4    1    1
#> [121,]    0    5    1    1    3
#> [122,]    0    5    1    2    2
#> [123,]    0    5    1    3    1
#> [124,]    0    5    2    1    2
#> [125,]    0    5    2    2    1
#> [126,]    0    5    3    1    1
#> [127,]    0    6    1    1    2
#> [128,]    0    6    1    2    1
#> [129,]    0    6    2    1    1
#> [130,]    0    7    1    1    1
#> [131,]    1    1    1    1    6
#> [132,]    1    1    1    2    5
#> [133,]    1    1    1    3    4
#> [134,]    1    1    1    4    3
#> [135,]    1    1    1    5    2
#> [136,]    1    1    1    6    1
#> [137,]    1    1    2    1    5
#> [138,]    1    1    2    2    4
#> [139,]    1    1    2    3    3
#> [140,]    1    1    2    4    2
#> [141,]    1    1    2    5    1
#> [142,]    1    1    3    1    4
#> [143,]    1    1    3    2    3
#> [144,]    1    1    3    3    2
#> [145,]    1    1    3    4    1
#> [146,]    1    1    4    1    3
#> [147,]    1    1    4    2    2
#> [148,]    1    1    4    3    1
#> [149,]    1    1    5    1    2
#> [150,]    1    1    5    2    1
#> [151,]    1    1    6    1    1
#> [152,]    1    2    1    1    5
#> [153,]    1    2    1    2    4
#> [154,]    1    2    1    3    3
#> [155,]    1    2    1    4    2
#> [156,]    1    2    1    5    1
#> [157,]    1    2    2    1    4
#> [158,]    1    2    2    2    3
#> [159,]    1    2    2    3    2
#> [160,]    1    2    2    4    1
#> [161,]    1    2    3    1    3
#> [162,]    1    2    3    2    2
#> [163,]    1    2    3    3    1
#> [164,]    1    2    4    1    2
#> [165,]    1    2    4    2    1
#> [166,]    1    2    5    1    1
#> [167,]    1    3    1    1    4
#> [168,]    1    3    1    2    3
#> [169,]    1    3    1    3    2
#> [170,]    1    3    1    4    1
#> [171,]    1    3    2    1    3
#> [172,]    1    3    2    2    2
#> [173,]    1    3    2    3    1
#> [174,]    1    3    3    1    2
#> [175,]    1    3    3    2    1
#> [176,]    1    3    4    1    1
#> [177,]    1    4    1    1    3
#> [178,]    1    4    1    2    2
#> [179,]    1    4    1    3    1
#> [180,]    1    4    2    1    2
#> [181,]    1    4    2    2    1
#> [182,]    1    4    3    1    1
#> [183,]    1    5    1    1    2
#> [184,]    1    5    1    2    1
#> [185,]    1    5    2    1    1
#> [186,]    1    6    1    1    1
#> [187,]    2    1    1    1    5
#> [188,]    2    1    1    2    4
#> [189,]    2    1    1    3    3
#> [190,]    2    1    1    4    2
#> [191,]    2    1    1    5    1
#> [192,]    2    1    2    1    4
#> [193,]    2    1    2    2    3
#> [194,]    2    1    2    3    2
#> [195,]    2    1    2    4    1
#> [196,]    2    1    3    1    3
#> [197,]    2    1    3    2    2
#> [198,]    2    1    3    3    1
#> [199,]    2    1    4    1    2
#> [200,]    2    1    4    2    1
#> [201,]    2    1    5    1    1
#> [202,]    2    2    1    1    4
#> [203,]    2    2    1    2    3
#> [204,]    2    2    1    3    2
#> [205,]    2    2    1    4    1
#> [206,]    2    2    2    1    3
#> [207,]    2    2    2    2    2
#> [208,]    2    2    2    3    1
#> [209,]    2    2    3    1    2
#> [210,]    2    2    3    2    1
#> [211,]    2    2    4    1    1
#> [212,]    2    3    1    1    3
#> [213,]    2    3    1    2    2
#> [214,]    2    3    1    3    1
#> [215,]    2    3    2    1    2
#> [216,]    2    3    2    2    1
#> [217,]    2    3    3    1    1
#> [218,]    2    4    1    1    2
#> [219,]    2    4    1    2    1
#> [220,]    2    4    2    1    1
#> [221,]    2    5    1    1    1
#> [222,]    3    1    1    1    4
#> [223,]    3    1    1    2    3
#> [224,]    3    1    1    3    2
#> [225,]    3    1    1    4    1
#> [226,]    3    1    2    1    3
#> [227,]    3    1    2    2    2
#> [228,]    3    1    2    3    1
#> [229,]    3    1    3    1    2
#> [230,]    3    1    3    2    1
#> [231,]    3    1    4    1    1
#> [232,]    3    2    1    1    3
#> [233,]    3    2    1    2    2
#> [234,]    3    2    1    3    1
#> [235,]    3    2    2    1    2
#> [236,]    3    2    2    2    1
#> [237,]    3    2    3    1    1
#> [238,]    3    3    1    1    2
#> [239,]    3    3    1    2    1
#> [240,]    3    3    2    1    1
#> [241,]    3    4    1    1    1
#> [242,]    4    1    1    1    3
#> [243,]    4    1    1    2    2
#> [244,]    4    1    1    3    1
#> [245,]    4    1    2    1    2
#> [246,]    4    1    2    2    1
#> [247,]    4    1    3    1    1
#> [248,]    4    2    1    1    2
#> [249,]    4    2    1    2    1
#> [250,]    4    2    2    1    1
#> [251,]    4    3    1    1    1
#> [252,]    5    1    1    1    2
#> [253,]    5    1    1    2    1
#> [254,]    5    1    2    1    1
#> [255,]    5    2    1    1    1
#> [256,]    6    1    1    1    1

set.seed(111)
partitionsGeneral(sample(1000, 20), 5, TRUE, target = 2500)
#>       [,1] [,2] [,3] [,4] [,5]
#>  [1,]   45   45  586  904  920
#>  [2,]   45   45  602  904  904
#>  [3,]   45  175  507  794  979
#>  [4,]   45  175  602  699  979
#>  [5,]   45  281  334  920  920
#>  [6,]   45  281  586  794  794
#>  [7,]   45  584  586  586  699
#>  [8,]   69  175  584  793  879
#>  [9,]   69  175  602  675  979
#> [10,]   69  305  507  699  920
#> [11,]   69  334  699  699  699
#> [12,]   69  584  586  586  675
#> [13,]  281  334  507  584  794
#> [14,]  281  334  584  602  699
#> [15,]  305  334  584  602  675

system.time(one_thread  <- partitionsGeneral(80, 10, TRUE))
#>    user  system elapsed 
#>   0.004   0.001   0.005 
system.time(two_threads <- partitionsGeneral(80, 10, TRUE, nThreads = 2))
#>    user  system elapsed 
#>   0.004   0.002   0.003 
identical(one_thread, two_threads)
#> [1] TRUE