combn_fast function

Fast combination of n elements, taken m at a time

Fast combination of n elements, taken m at a time

combn_fast(x, m)

Arguments

  • x: integer vector source for combinations
  • m: number of elements to choose.

Returns

a matrix with m rows.

Details

This is a significantly faster version of combn. For an integer vector x of length 1000 and m of 3 which results in a matrix of size 3 x 166,167,000, the speed improvement is about 9 times (11 secs vs 99 secs). This code is written using Armadillo C++ and 64 bit unsingned integers.

Examples

all.equal(combn(1:10, 3), combn_fast(1:10,3))