jwood000 / rcppalgos Goto Github PK
View Code? Open in Web Editor NEWTool for Solving Problems in Combinatorics and Computational Mathematics
License: GNU General Public License v2.0
Tool for Solving Problems in Combinatorics and Computational Mathematics
License: GNU General Public License v2.0
When trying to replicate the results of this question: Remove repeating numbers from for loop, I found an issue with how version 2.3.5
handles multisets and their respective frequencies when the vector passed isn't sorted. Observe:
set.seed(42)
vals <- sample(-50:50, 20)
vals
[1] 42 43 -22 31 12 -1 19 -38 11 14 -9 41 33 -28 -10 30
[17] 38 -41 -11 -5
vals <- c(0L, vals)
myfreqs <- c(length(vals) - 1, rep(1, length(vals) - 1))
myfreqs
[1] 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
combs <- comboGeneral(vals, length(vals), freqs = myfreqs,
constraintFun = "sum",
comparisonFun = "==",
limitConstraints = 170)
dim(combs)
[1] 6561 21
## Brute force verification
allCombs <- comboGeneral(sort(vals), length(vals),
freqs = myfreqs[order(vals)], constraintFun = "sum")
verifiedCombs <- allCombs[which(allCombs[,22] == 170), ]
dim(verifiedCombs)
[1] 2135 22
Clearly, something is not right. We obtained 2135
solutions with brute force and 6561
with the constraint algorithm. Let's have a look at the actual results.
head(combs[,1:12])
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] -41 -38 -28 -22 -11 -10 -5 0 11 11 11 11
[2,] -41 -38 -28 -22 -11 -10 -5 11 11 11 11 11
[3,] -41 -38 -28 -22 -11 -10 -5 11 11 11 11 11
[4,] -41 -38 -28 -22 -11 -10 -1 11 11 11 11 11
[5,] -41 -38 -28 -22 -11 -10 0 11 11 11 11 11
[6,] -41 -38 -28 -22 -11 -10 0 11 11 11 11 11
head(verifiedCombs)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] -41 -38 -28 -22 -10 -5 0 0 0 0 11 12
[2,] -41 -38 -28 -22 -9 -5 -1 0 0 0 11 12
[3,] -41 -38 -28 -22 -1 0 0 0 0 0 0 11
[4,] -41 -38 -28 -11 -10 -5 0 0 0 0 0 12
[5,] -41 -38 -28 -11 -9 -5 -1 0 0 0 0 12
[6,] -41 -38 -28 -11 -9 -5 0 0 0 0 0 11
[,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22]
[1,] 14 19 30 31 33 38 41 42 43 170
[2,] 14 19 30 31 33 38 41 42 43 170
[3,] 12 19 30 31 33 38 41 42 43 170
[4,] 14 19 30 31 33 38 41 42 43 170
[5,] 14 19 30 31 33 38 41 42 43 170
[6,] 14 19 30 31 33 38 41 42 43 170
We can see that the brute force solution correctly repeats zero multiple times whereas the constraint algo repeats 11
multiple times. This sorting is taken care of in GetPartitionCase
:
RcppAlgos/src/ConstraintsUtils.cpp
Lines 397 to 408 in 8364c46
And we see that it is a templated function that can accept vectors of different types:
RcppAlgos/src/ConstraintsUtils.cpp
Lines 377 to 382 in 8364c46
Now, ConstraintsMaster.cpp
calls GetPartitionCase
here:
RcppAlgos/src/ConstraintsMaster.cpp
Lines 150 to 156 in 8364c46
And here is the problem. We are only taking care of numeric vectors (vNum
and targetVals
are vectors of type double
). We can verify this by simply wrapping vals
above with as.numeric
:
combsNum <- comboGeneral(as.numeric(vals), length(vals),
freqs = myfreqs,
constraintFun = "sum",
comparisonFun = "==",
limitConstraints = 170)
dim(combsNum)
[1] 2135 21
all.equal(combsNum, verifiedCombs[, 1:21])
[1] TRUE
We simply need to ensure we handle the integer case appropriately.
Hello,
I'm debugging a colleague's R code and am perplexed by what exactly is causing the following error. I'm running this on Red Hat 8.6 with R/4.3.0 and RcppAlgos_2.7.2.
library(RcppAlgos)
ng=16;
aa = permuteGeneral(v = c(0:ng), m=31-ng, repetition = TRUE, constraintFun = "sum", comparisonFun = c(">","<"), limitConstraints = c((ng)-1,(ng)+1))
Error in permuteGeneral(v = c(0:ng), m = 31 - ng, repetition = TRUE, constraintFun = "sum", :
negative extents to matrix
No traceback available
`
ng=17
aa = permuteGeneral(v = c(0:ng), m=31-ng, repetition = TRUE, constraintFun = "sum", comparisonFun = c(">","<"), limitConstraints = c((ng)-1,(ng)+1))`
Question :
I feel like I may be reaching the bounds of an integer overflow, given how large the numbers are, but I'm perplexed about why ng=17
works fine.
The argument upper
works properly on standard combinations/permutations however when a constraint is applied and the total number of results exceeds 2^31 - 1
, it does not have the proper affect. Observe:
Working examples:
## Example 1
a1 <- permuteGeneral(0:100, 25, T, upper = 1e5)
dim(a1)
[1] 100000 25
permuteCount(0:100, 25, T)
Big Integer ('bigz') :
[1] 128243199501723361359275202929838997632567303002501
## Example 2
a2 <- permuteGeneral(0:100, 25, T,
constraintFun = "sum",
comparisonFun = "==",
limitConstraints = 200,
upper = 1e5)
dim(a2)
[1] 100000 25
all(rowSums(a2) == 200)
[1] TRUE
And now the special case when we have an integer partition set up (i.e. limitConstraints = 100
in the above):
a3 <- permuteGeneral(0:100, 25, T,
constraintFun = "sum",
comparisonFun = "==",
limitConstraints = 100,
upper = 1e5)
Error in CombinatoricsRcpp(v, m, repetition, freqs, lower, upper, constraintFun, :
The number of rows cannot exceed 2^31 - 1.
Hello, this may be a bug:
> y <- as.integer(RcppAlgos::permuteGeneral(1:4, m = 13, repetition = TRUE))
> head(y[y == 0])
integer(0)
> y <- as.integer(RcppAlgos::permuteGeneral(1:4, m = 14, repetition = TRUE))
# should not generate zeros
> head(y[y == 0])
[1] 0 0 0 0 0 0
> length(y[y == 0])
[1] 2617245696
Just wanna mention that RcppAlgos requires something newer than gcc 4.8.5 (see error below), which is the default on the RHEL/CentOS 7 distro. I've confirmed that gcc 5.3.1 is sufficient.
Maybe you could add a note on this in the DESCRIPTION file? It'll help people on RHEL/CentOS.
With
RedHat/CentOS users: If you're on RHEL/CentOS and have CentOS Software Collections (SCL) installed - check with scl --list
, you can compile RcppAlgos using one of them. This is what I did on an up-to-date CentOS 7 distro:
## Too old
$ gcc --version | head -1
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
## Use a less old gcc version
$ scl enable devtoolset-4
$ gcc --version | head
gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)
## Now we can compile RcppAlgos
$ Rscript -e "install.packages('RcppAlgos')"
* installing *source* package ‘RcppAlgos’ ...
** package ‘RcppAlgos’ successfully unpacked and MD5 sums checked
** using staged installation
...
** testing if installed package keeps a record of temporary installation path
* DONE (RcppAlgos)
## Done; disable the SCL again
$ exit
## Back too old setup, ...
$ gcc --version | head -1
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
## ... but it doesn't matter when it comes using RcppAlgos
$ Rscript -e "packageVersion('RcppAlgos')" -e "loadNamespace('RcppAlgos')"
[1] ‘2.3.6’
<environment: namespace:RcppAlgos>
The error you get with gcc 4.8.5 is:
* installing *source* package ‘RcppAlgos’ ... ** package ‘RcppAlgos’ successfully unpacked and MD5 sums checked ** using staged installation ** libs g++ -std=gnu++11 -I"/wynton/home/cbi/shared/software/CBI/R-3.6.2/lib64/R/include" -DNDEBUG -I../inst/include/ -I"/wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/Rcpp/include" -I"/wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include" -I/usr/local/include -fpic -g -O2 -c BigNumCount.cpp -o BigNumCount.o g++ -std=gnu++11 -I"/wynton/home/cbi/shared/software/CBI/R-3.6.2/lib64/R/include" -DNDEBUG -I../inst/include/ -I"/wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/Rcpp/include" -I"/wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include" -I/usr/local/include -fpic -g -O2 -c CheckReturn.cpp -o CheckReturn.o g++ -std=gnu++11 -I"/wynton/home/cbi/shared/software/CBI/R-3.6.2/lib64/R/include" -DNDEBUG -I../inst/include/ -I"/wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/Rcpp/include" -I"/wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include" -I/usr/local/include -fpic -g -O2 -c CombPermMaster.cpp -o CombPermMaster.o In file included from /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread.h:11:0, from ../inst/include/Permutations.h:7, from ../inst/include/CombPermPtr.h:5, from CombPermMaster.cpp:2: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/Thread.hpp: In lambda function: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/Thread.hpp:42:19: error: parameter packs not expanded with ‘...’: f(args...); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/Thread.hpp:42:19: note: ‘args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/Thread.hpp:42:23: error: expansion pattern ‘args’ contains no argument packs f(args...); ^ In file included from /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread.h:13:0, from ../inst/include/Permutations.h:7, from ../inst/include/CombPermPtr.h:5, from CombPermMaster.cpp:2: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In member function ‘void RcppThread::ThreadPool::push(F&&, Args&& ...)’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:31: error: expected ‘,’ before ‘...’ token jobs_.emplace([f, args...] { f(args...); }); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:31: error: expected identifier before ‘...’ token /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:34: error: parameter packs not expanded with ‘...’: jobs_.emplace([f, args...] { f(args...); }); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:34: note: ‘args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In lambda function: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:44: error: expansion pattern ‘args’ contains no argument packs jobs_.emplace([f, args...] { f(args...); }); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In member function ‘std::future RcppThread::ThreadPool::pushReturn(F&&, Args&& ...)’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:54: error: expected ‘,’ before ‘...’ token auto job = std::make_shared([&f, args...] { ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:54: error: expected identifier before ‘...’ token /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:57: error: parameter packs not expanded with ‘...’: auto job = std::make_shared([&f, args...] { ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:57: note: ‘args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In lambda function: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:145:22: error: expansion pattern ‘args’ contains no argument packs return f(args...); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::referenc\ e_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::referenc\ e_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]’ CombPermMaster.cpp:46:17: required from ‘void MasterReturn(typeRcpp&, std::vector, int, int, bool, bool, bool, bool, bool, const std::vector&, std::vector, const std::vector&, double, __mpz_struct (&)[1], int, int, bool, int) [with typeRcpp = Rcpp::Matrix<10>; T = int; mpz_t = __mpz_struct [1]]’ CombPermMaster.cpp:145:70: required from here /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’ jobs_.emplace([f, args...] { f(args...); }); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::re\ ference_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::re\ ference_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]’ CombPermMaster.cpp:46:17: required from ‘void MasterReturn(typeRcpp&, std::vector, int, int, bool, bool, bool, bool, bool, const std::vector&, std::vector, const std::vector&, double, __mpz_struct (&)[1], int, int, bool, int) [with typeRcpp = Rcpp::Matrix<14>; T = double; mpz_t = __mpz_struct [1]]’ CombPermMaster.cpp:158:70: required from here /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const int*, std::vector, int, int, int, int, int, int, bool)>; Args = {std::reference_wrapper >, int*, std::vector >&, int&, int&, int&, int&, const int&, int&, bool&}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const int*, std::vector, int, int, int, int, int, int, bool)>; Args = {std::reference_wrapper >, int*, std::vector >&, int&, int&, int&, int&, const int&, int&, bool&}]’ ../inst/include/Permutations.h:135:13: required from ‘void PermuteParallel(typeMatrix&, typeVector, std::vector, int, int, int, int, int, bool) [with typeMatrix = RcppParallel::RMatrix; typeVector = std::vector]’ CombPermMaster.cpp:58:81: required from ‘void MasterReturn(typeRcpp&, std::vector, int, int, bool, bool, bool, bool, bool, const std::vector&, std::vector, const std::vector&, double, __mpz_struct (&)[1], int, int, bool, int) [with typeRcpp = Rcpp::Matrix<10>; T = int; mpz_t = __mpz_struct [1]]’ CombPermMaster.cpp:145:70: required from here /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const int*, std::vector, int, int, int, int, int, int, bool)>; Args = {std::reference_wrapper >, int*, std::vector >&, int&, int&, int&, int&, const int&, int&, bool&}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:31: error: expected identifier before ‘...’ token /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:34: error: parameter packs not expanded with ‘...’: jobs_.emplace([f, args...] { f(args...); }); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:34: note: ‘args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In lambda function: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:44: error: expansion pattern ‘args’ contains no argument packs jobs_.emplace([f, args...] { f(args...); }); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In member function ‘std::future RcppThread::ThreadPool::pushReturn(F&&, Args&& ...)’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:54: error: expected ‘,’ before ‘...’ token auto job = std::make_shared([&f, args...] { ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:54: error: expected identifier before ‘...’ token /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:57: error: parameter packs not expanded with ‘...’: auto job = std::make_shared([&f, args...] { ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:144:57: note: ‘args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In lambda function: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:145:22: error: expansion pattern ‘args’ contains no argument packs return f(args...); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::referenc\ e_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::referenc\ e_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]’ CombPermMaster.cpp:46:17: required from ‘void MasterReturn(typeRcpp&, std::vector, int, int, bool, bool, bool, bool, bool, const std::vector&, std::vector, const std::vector&, double, __mpz_struct (&)[1], int, int, bool, int) [with typeRcpp = Rcpp::Matrix<10>; T = int; mpz_t = __mpz_struct [1]]’ CombPermMaster.cpp:145:70: required from here /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’ jobs_.emplace([f, args...] { f(args...); }); ^ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::re\ ference_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const std::vector&, std::vector, int, int, int, int, const std::vector&)>; Args = {std::re\ ference_wrapper >, std::reference_wrapper > >, std::vector >&, int&, int&, int&, int&, std::reference_wrapper > >}]’ CombPermMaster.cpp:46:17: required from ‘void MasterReturn(typeRcpp&, std::vector, int, int, bool, bool, bool, bool, bool, const std::vector&, std::vector, const std::vector&, double, __mpz_struct (&)[1], int, int, bool, int) [with typeRcpp = Rcpp::Matrix<14>; T = double; mpz_t = __mpz_struct [1]]’ CombPermMaster.cpp:158:70: required from here /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const int*, std::vector, int, int, int, int, int, int, bool)>; Args = {std::reference_wrapper >, int*, std::vector >&, int&, int&, int&, int&, const int&, int&, bool&}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const int*, std::vector, int, int, int, int, int, int, bool)>; Args = {std::reference_wrapper >, int*, std::vector >&, int&, int&, int&, int&, const int&, int&, bool&}]’ ../inst/include/Permutations.h:135:13: required from ‘void PermuteParallel(typeMatrix&, typeVector, std::vector, int, int, int, int, int, bool) [with typeMatrix = RcppParallel::RMatrix; typeVector = std::vector]’ CombPermMaster.cpp:58:81: required from ‘void MasterReturn(typeRcpp&, std::vector, int, int, bool, bool, bool, bool, bool, const std::vector&, std::vector, const std::vector&, double, __mpz_struct (&)[1], int, int, bool, int) [with typeRcpp = Rcpp::Matrix<10>; T = int; mpz_t = __mpz_struct [1]]’ CombPermMaster.cpp:145:70: required from here /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’ /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const int*, std::vector, int, int, int, int, int, int, bool)>; Args = {std::reference_wrapper >, int*, std::vector >&, int&, int&, int&, int&, const int&, int&, bool&}]::__lambda5’: /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper&, const int*, std::vector, int, int, int, int, int, int, bool)>; Args = {std::reference_wrapper >, int*, std::vector >&, int&, int&, int&, int&, const int&, int&, bool&}]’ ../inst/include/Permutations.h:135:13: required from ‘void PermuteParallel(typeMatrix&, typeVector, std::vector, int, int, int, int, int, bool) [with typeMatrix = RcppParallel::RMatrix; typeVector = std::vector]’ CombPermMaster.cpp:58:81: required from ‘void MasterReturn(typeRcpp&, std::vector, int, int, bool, bool, bool, bool, bool, const std::vector&, std::vector, const std::vector&, double, __mpz_struct (&)[1], int, int, bool, int) [with typeRcpp = Rcpp::Matrix<14>; T = double; mpz_t = __mpz_struct [1]]’ CombPermMaster.cpp:158:70: required from here /wynton/home/cbi/hb/R/x86_64-pc-linux-gnu-library/3.6-CBI-revdepcheck/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’ make: *** [CombPermMaster.o] Error 1 ERROR: compilation failed for package ‘RcppAlgos’
This works:
library(RcppAlgos)
x <- c("a", "b", "b")
tab <- table(x)
permuteGeneral(v = names(tab), freq = tab)
but it would be nice if it directly accepted "table" objects.
permuteGeneral(tab)
Hello,
First of all, fantastic library, and incredibly fast. Thank you so much for sharing it.
I'm really terrible at combinatorics, so my problem may have an obvious answer. Is there a straightforward way that I can partition a set into multiple subsets with each its own number of elements and constraint sum?
For instance, say that I have a vector v
with 11 elements, and I would like to find all partitions in three, such as the subsets have 5, 3, and 3 elements respectively, and sum to 6, 7, and 8 respectively.
v <- c(1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4)
sum(v) # 21 = 6 + 7 + 8
multiComboGeneral(v, m=c(5, 3, 3), limitConstraints=c(6, 7, 8))
# list(list(c(1, 1, 1, 1, 2), c(1, 2, 4), c(2, 3, 3)), ...)
Another output shape would be fine, of course. It's worth noting that I need all elements of v
to be selected once and only once.
I can think of a recursive approach using comboGeneral
with m=5
and limitConstraints=6
, then for each partition repeat on remaining elements with m=3
and limitConstraints=7
, then m=3
and limitConstraints=8
, and drop the cases that do not work. But, this seems highly inefficient, with a larger vector especially.
Is there a more direct way to do this? Any pointers would be greatly appreciated.
library(RcppAlgos)
valuesSet <- c(10, 5, 2, 1, -1, -2, -5, -10)
partitionsGeneral(valueSet, m=2, target=3)
produces
As a first time user of RcppAlgos
, I may be misusing the function, but even if so, I feel any error on my part could be more elegantly handled.
I am attempting to find combinations of pairs of values in valueSet
that sum to 3
. The solution should be c(5, -2)
.
Environment details:
OS: MacOS Mojave 10.14.6
IDE: RStudio 2021.09.2 Build 382
R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
RcppAlgos version: 2.6.0
Hello, it's this bug?
# not ok
> x <- permuteGeneral(c("A", "C", "G", "T"), m = 14, repetition = TRUE)
Error in permuteGeneral(c("A", "C", "G", "T"), m = 14, repetition = TRUE) :
attempt to set index -2147483648/3758096384 in SET_STRING_ELT
# works
> x <- permuteGeneral(4, m = 14, repetition = TRUE)
> 4^14 - 2147483647
[1] -1879048191
RcppAlgos::permuteSample(100, 100, sampleVec=2)
It returns 1:100
instead of the second permutation. I assume it is due to round off error.
I was wondering if this is possible to implement or something you have thought a bit about?
For example, say I make a grid and want to constraints to it (e.g. each row must be greater or less than some value).
I have been trying this with expand.grid (because order does matter in my case) and data.table and finding it very time consuming and the required memory is quite large. I really liked the implementation in comboGeneral but it only applies to vectors.
The FUN
argument in comboGeneral()
and similar RcppAlgos
functions could be more useful if the user is allowed to provide the expected value, similar to vapply()
. Currently, a list is allocated which can take up a lot of memory.
library(RcppAlgos)
ans = comboGeneral(15L, 3L, FUN = sum)
object.size(ans)
#> 29168 bytes
object.size(unlist(ans, use.names = FALSE))
#> 1872 bytes
## Proposed API
## comboGeneral(15L, 3L, FUN = sum, FUN.VALUE = 1L)
I would be happy to work up something to allow for atomic vectors as the FUN.VALUE
if you are interested - likely just a proof-of-concept for you do proper programming with.
Thanks so much for the great package!
You could simply compute NumCombsWithRep
with choose(n+r-1, r)
.
https://github.com/jwood000/RcppAlgos/blob/master/src/CombPermUtils.cpp#L84-L101
I got stuck in this error when installing the package
g++ -std=c++14 -I/opt/microsoft/ropen/3.5.2/lib64/R/include -DNDEBUG -I../inst/include/ -DU_STATIC_IMPLEMENTATION -I"/opt/microsoft/ropen/3.5.2/lib64/R/library/Rcpp/include" -I"/home/schen/R/x86_64-pc-linux-gnu-library/3.5/RcppThread/include" -Wno-unused-variable -Wno-unused-function -fPIC -c importExportMPZ.cpp -o importExportMPZ.o
-L/opt/microsoft/ropen/3.5.2/lib64/R/lib -o RcppAlgos.so CombPermUtils.o Combinatorics.o CountGmp.o DivNumSieve.o NthResult.o PollardRho.o Primes.o RcppExports.o SampCombPerm.o importExportMPZ.o -lgmp -L/opt/microsoft/ropen/3.5.2/lib64/R/lib -lR
/opt/microsoft/ropen/3.5.2/lib64/R/share/make/shlib.mk:6: recipe for target 'RcppAlgos.so' failed
Error in i.p(...) :
(converted from warning) installation of package ‘/tmp/RtmpU81uWD/file2734a21c3bf/RcppAlgos_2.3.4.tar.gz’ had non-zero exit status
This is the shlib.mk
file:
## ${R_HOME}/share/make/shlib.mk
all: $(SHLIB)
$(SHLIB): $(OBJECTS)
@if test "z$(OBJECTS)" != "z"; then \
echo $(SHLIB_LINK) -o $@ $(OBJECTS) $(ALL_LIBS); \
$(SHLIB_LINK) -o $@ $(OBJECTS) $(ALL_LIBS); \
fi
.PHONY: all shlib-clean
shlib-clean:
@rm -Rf .libs _libs
@rm -f $(OBJECTS) symbols.rds
## FIXME: why not Rscript?
symbols.rds: $(OBJECTS)
@$(ECHO) "tools:::.shlib_objects_symbol_tables()" | \
$(R_HOME)/bin/R --vanilla --slave --args $(OBJECTS)
And this is my MakeVars
file:
CXX11 = g++
CXX11FLAGS = -O2 -g $(LTO)
CXX1XPICFLAGS = -fpic
CXX11STD = -std=c++11
CXX14 = g++
CXX14STD = -std=c++14
CXX14FLAGS = -Wno-unused-variable -Wno-unused-function -fPIC
Please advise. Thanks!
Hey
Firstly, I tried to use the package from install.packages(), and this process went fine but when I try to load some function with RcppAlgos:: just after write that Rstudio crashes even though when I use library(RcppAlgos).
After that, I tried to build from the source with devtools::install_github("jwood000/RcppAlgos") and got this output.
R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
devtools::install_github("jwood000/RcppAlgos")
Downloading GitHub repo jwood000/RcppAlgos@HEAD
Skipping 1 packages ahead of CRAN: Rcpp
✓ checking for file ‘/private/var/folders/dc/phdn9gtj0h7dmwcy9jqy3cjh0000gn/T/Rtmp09Spn5/remotesa11b592f028c/jwood000-RcppAlgos-ff30f9f/DESCRIPTION’ ...
─ preparing ‘RcppAlgos’:
✓ checking DESCRIPTION meta-information ...
─ cleaning src
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘RcppAlgos_2.4.2.tar.gz’
Currently, in the many examples involving combo/permuteIter
, we take advantage of the fact that they return FALSE
when iteration is complete, however it isn't documented anywhere.
Could we explicitly document this and maybe add more explanation behind the motivation of this design?
Using ComboGroups for combination of 4 letter, group into 3 group with size (1, 1, 2).
The out put generate the results below.
comboGroups(letters[1:4],grpSizes = c(1, 1, 2))
Grp1 Grp2 Grp3 Grp3
[1,] "a" "b" "c" "d"
[2,] "a" "c" "b" "d"
[3,] "a" "d" "b" "c"
However, three more possible combination are missing. They are not the same combination with the above.
Grp1 Grp2 Grp3 Grp3
[4,] "b" "c" "a" "d"
[5,] "b" "d" "a" "b"
[6,] "c" "d" "a" "c"
Hi @jwood000,
Thank you for your excellent job. I love the sampling functions comboSample
and permSample
. Those are the things I wanted to implement for a long time. Though I don't want to admit, your package is far more "useful" than arrangements
👍. Now, the only time I need to call arrangements
is when I need to compute the numbers of permutations and combinations with gmp big integer (it may happens if n
is large).
Do you have any plans to also expose the nth results to R ? I believe there is a significant overhead to call RcppAlgos::comboGeneral(10, 3, lower = 3, upper = 3)
when we just need nthCombination.
This is a fantastic package with some super useful tools! I just noticed a small bug - R crashes when an NA
or NULL
value is passed to comboGrid
. The following example crashes my R session:
library(RcppAlgos)
comboGrid(1:10, NA)
session info:
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.0 tools_4.1.0
I'm using permuteGeneral to generate all permutations for N subjects to be distributed across M categories, which requires the constraint that the sum of all elements is N. However, adding such constraint reduces the dimension of the output, where it does not seem to consider zeroes in different positions as unique permutations:
permuteGeneral(v = 0:2, m = 3, repetition = TRUE)
## Works, but needs constraint (only desired rows shown)
[,1] [,2] [,3]
[3,] 0 0 2
[5,] 0 1 1
[7,] 0 2 0
[11,] 1 0 1
...
permuteGeneral(v = 0:2, m = 3, repetition = TRUE, constraintFun = "sum", comparisonFun = "==", limitConstraints = 2)
## No longer returns 3-element permutations?
[,1] [,2]
[1,] 0 2
[2,] 2 0
[3,] 1 1
Is this intended behaviour?
What is the reason behind row limit to 2^31 - 1?
Thank you!
Hi Everyone,
It looks like the std::make_unique issue has returned in a new install of R 4.4.0.
Any advice on how to proceed would be much appreciated.
Best,
John
`
devtools::install_github('jwood000/RcppAlgos')
Downloading GitHub repo jwood000/RcppAlgos@HEAD
── R CMD build ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔ checking for file ‘/tmp/RtmpEpvtTp/remotes11e9563eda43e9/jwood000-RcppAlgos-c92abf9/DESCRIPTION’ (403ms)
─ preparing ‘RcppAlgos’:
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories (766ms)
─ building ‘RcppAlgos_2.8.3.tar.gz’
Installing package into ‘/home/everett/R/x86_64-pc-linux-gnu-library/4.4’
(as ‘lib’ is unspecified)
`
sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /home/opt/R-4.4.0/lib/R/lib/libRlapack.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8
[8] LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
time zone: America/New_York
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.4.0 tools_4.4.0
`
After passing a source vector from a dataframe to permuteGeneral, the source dataframe is altered.
# compare mydf before and after running permuteGeneral
> name <- c('first', 'second', 'third')
> rank <- c('1st', '2nd', '3rd')
> mydf <- data.frame(name, rank, stringsAsFactors = FALSE)
> mydf
name rank
1 first 1st
2 second 2nd
3 third 3rd
> permutations <- permuteGeneral(mydf[,"name"], 3)
> mydf
name rank
1 third 1st
2 first 2nd
3 second 3rd
My R package jdreyf/PANTS uses RcppAlgos and R CMD check passess, but I'm getting Travis-CI errors. I have already debugged Travis-CI issues with "Error in .shlib_internal(args): C++14 standard requested but CXX14 is not defined" (http://dirk.eddelbuettel.com/blog/2017/06/13/) but am now getting:
* installing *source* package ‘RcppAlgos’ ...
** package ‘RcppAlgos’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=c++1y -fPIC -I"/home/travis/R-bin/lib/R/include" -DNDEBUG -I../inst/include/ -I"/home/travis/R/Library/Rcpp/include" -I"/home/travis/R/Library/RcppThread/include" -I/home/travis/R-bin/include -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined -c CombPermUtils.cpp -o CombPermUtils.o
g++ -std=c++1y -fPIC -I"/home/travis/R-bin/lib/R/include" -DNDEBUG -I../inst/include/ -I"/home/travis/R/Library/Rcpp/include" -I"/home/travis/R/Library/RcppThread/include" -I/home/travis/R-bin/include -O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined -c Combinatorics.cpp -o Combinatorics.o
In file included from ../inst/include/Combinatorics.h:5:0,
from Combinatorics.cpp:1:
../inst/include/Permutations.h: In function ‘void PermuteGeneral(int, int, typeVector&, bool, int, std::vector<int>&, int, bool, typeMatrix&)’:
../inst/include/Permutations.h:40:24: error: ‘make_unique’ is not a member of ‘std’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/Permutations.h:40:41: error: expected primary-expression before ‘int’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/Permutations.h:72:29: error: ‘make_unique’ is not a member of ‘std’
auto indexMat = std::make_unique<int[]>(phaseOne * uR);
^
../inst/include/Permutations.h:72:46: error: expected primary-expression before ‘int’
auto indexMat = std::make_unique<int[]>(phaseOne * uR);
^
../inst/include/Permutations.h:73:28: error: ‘make_unique’ is not a member of ‘std’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/Permutations.h:73:45: error: expected primary-expression before ‘int’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/Permutations.h: In function ‘void MultisetPermutation(int, int, typeVector&, int, std::vector<int>&, int, typeMatrix&)’:
../inst/include/Permutations.h:131:20: error: ‘make_unique’ is not a member of ‘std’
auto arrPerm = std::make_unique<int[]>(lenFreqs);
^
../inst/include/Permutations.h:131:37: error: expected primary-expression before ‘int’
auto arrPerm = std::make_unique<int[]>(lenFreqs);
^
../inst/include/Permutations.h: In function ‘void PermutationApplyFun(int, int, typeVector&, bool, int, bool, std::vector<int>&, int, SEXP, SEXP, SEXPREC*&)’:
../inst/include/Permutations.h:203:24: error: ‘make_unique’ is not a member of ‘std’
auto arrPerm = std::make_unique<int[]>(arrLength);
^
../inst/include/Permutations.h:203:41: error: expected primary-expression before ‘int’
auto arrPerm = std::make_unique<int[]>(arrLength);
^
In file included from ../inst/include/Combinatorics.h:8:0,
from Combinatorics.cpp:1:
../inst/include/PermuteResults.h: In function ‘void PermuteGenRes(int, int, std::vector<typeVector>&, bool, int, std::vector<int>&, long unsigned int, bool, typeMatrix&, funcPtr<typeVector>)’:
../inst/include/PermuteResults.h:45:24: error: ‘make_unique’ is not a member of ‘std’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/PermuteResults.h:45:41: error: expected primary-expression before ‘int’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/PermuteResults.h:87:29: error: ‘make_unique’ is not a member of ‘std’
auto indexMat = std::make_unique<int[]>(phaseOne * uR);
^
../inst/include/PermuteResults.h:87:46: error: expected primary-expression before ‘int’
auto indexMat = std::make_unique<int[]>(phaseOne * uR);
^
../inst/include/PermuteResults.h:88:28: error: ‘make_unique’ is not a member of ‘std’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/PermuteResults.h:88:45: error: expected primary-expression before ‘int’
auto arrPerm = std::make_unique<int[]>(uN);
^
../inst/include/PermuteResults.h: In function ‘void MultisetPermRes(int, int, std::vector<typeVector>&, int, long unsigned int, std::vector<int>&, typeMatrix&, funcPtr<typeVector>)’:
../inst/include/PermuteResults.h:150:20: error: ‘make_unique’ is not a member of ‘std’
auto arrPerm = std::make_unique<int[]>(lenFreqs);
^
../inst/include/PermuteResults.h:150:37: error: expected primary-expression before ‘int’
auto arrPerm = std::make_unique<int[]>(lenFreqs);
^
In file included from Combinatorics.cpp:2:0:
../inst/include/CleanConvert.h: In function ‘void CleanConvert::convertVector(SEXP, std::vector<_RealType>&, std::string, bool, bool, bool)’:
../inst/include/CleanConvert.h:161:29: error: ‘make_unique’ is not a member of ‘std’
auto temp = std::make_unique<mpz_t[]>(total);
^
../inst/include/CleanConvert.h:161:51: error: expected primary-expression before ‘[’ token
auto temp = std::make_unique<mpz_t[]>(total);
^
../inst/include/CleanConvert.h:161:52: error: expected primary-expression before ‘]’ token
auto temp = std::make_unique<mpz_t[]>(total);
^
In file included from /home/travis/R/Library/RcppThread/include/RcppThread.h:11:0,
from Combinatorics.cpp:4:
/home/travis/R/Library/RcppThread/include/RcppThread/Thread.hpp: In lambda function:
/home/travis/R/Library/RcppThread/include/RcppThread/Thread.hpp:42:19: error: parameter packs not expanded with ‘...’:
f(args...);
^
/home/travis/R/Library/RcppThread/include/RcppThread/Thread.hpp:42:19: note: ‘args’
/home/travis/R/Library/RcppThread/include/RcppThread/Thread.hpp:42:23: error: expansion pattern ‘args’ contains no argument packs
f(args...);
^
In file included from /home/travis/R/Library/RcppThread/include/RcppThread.h:13:0,
from Combinatorics.cpp:4:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp: In member function ‘void RcppThread::ThreadPool::push(F&&, Args&& ...)’:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:31: error: expected ‘,’ before ‘...’ token
jobs_.emplace([f, args...] { f(args...); });
^
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:31: error: expected identifier before ‘...’ token
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:34: error: parameter packs not expanded with ‘...’:
jobs_.emplace([f, args...] { f(args...); });
^
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:34: note: ‘args’
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp: In lambda function:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:44: error: expansion pattern ‘args’ contains no argument packs
jobs_.emplace([f, args...] { f(args...); });
^
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp: In member function ‘std::future<decltype (f(args ...))> RcppThread::ThreadPool::pushReturn(F&&, Args&& ...)’:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:144:54: error: expected ‘,’ before ‘...’ token
auto job = std::make_shared<jobPackage>([&f, args...] {
^
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:144:54: error: expected identifier before ‘...’ token
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:144:57: error: parameter packs not expanded with ‘...’:
auto job = std::make_shared<jobPackage>([&f, args...] {
^
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:144:57: note: ‘args’
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp: In lambda function:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:145:22: error: expansion pattern ‘args’ contains no argument packs
return f(args...);
^
Combinatorics.cpp: In function ‘typeRcpp CombinatoricsConstraints(int, int, std::vector<typeVector>&, bool, std::string, std::vector<std::basic_string<char> >, std::vector<typeVector>, int, bool, bool, std::vector<int>&, bool)’:
Combinatorics.cpp:313:32: error: ‘make_unique’ is not a member of ‘std’
auto indexMatrix = std::make_unique<int[]>(indexRows * r);
^
Combinatorics.cpp:313:49: error: expected primary-expression before ‘int’
auto indexMatrix = std::make_unique<int[]>(indexRows * r);
^
In file included from /home/travis/R/Library/RcppThread/include/RcppThread.h:13:0,
from Combinatorics.cpp:4:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper<void(int, int, std::vector<int>, bool, int, bool, std::vector<int>, std::vector<int>, std::vector<int>, bool, bool, int (*)(const std::vector<int>&, long unsigned int), bool, RcppParallel::RMatrix<int>&, int)>; Args = {int&, int&, std::vector<int, std::allocator<int> >&, bool&, int&, bool&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, bool&, bool&, int (*&)(const std::vector<int, std::allocator<int> >&, long unsigned int), bool&, std::reference_wrapper<RcppParallel::RMatrix<int> >, int&}]::__lambda5’:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper<void(int, int, std::vector<int>, bool, int, bool, std::vector<int>, std::vector<int>, std::vector<int>, bool, bool, int (*)(const std::vector<int>&, long unsigned int), bool, RcppParallel::RMatrix<int>&, int)>; Args = {int&, int&, std::vector<int, std::allocator<int> >&, bool&, int&, bool&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, bool&, bool&, int (*&)(const std::vector<int, std::allocator<int> >&, long unsigned int), bool&, std::reference_wrapper<RcppParallel::RMatrix<int> >, int&}]’
Combinatorics.cpp:974:106: required from here
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’
jobs_.emplace([f, args...] { f(args...); });
^
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp: In instantiation of ‘struct RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper<void(int, int, std::vector<double>, bool, int, bool, std::vector<int>, std::vector<int>, std::vector<int>, bool, bool, double (*)(const std::vector<double>&, long unsigned int), bool, RcppParallel::RMatrix<double>&, int)>; Args = {int&, int&, std::vector<double, std::allocator<double> >&, bool&, int&, bool&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, bool&, bool&, double (*&)(const std::vector<double, std::allocator<double> >&, long unsigned int), bool&, std::reference_wrapper<RcppParallel::RMatrix<double> >, int&}]::__lambda5’:
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:9: required from ‘void RcppThread::ThreadPool::push(F&&, Args&& ...) [with F = std::reference_wrapper<void(int, int, std::vector<double>, bool, int, bool, std::vector<int>, std::vector<int>, std::vector<int>, bool, bool, double (*)(const std::vector<double>&, long unsigned int), bool, RcppParallel::RMatrix<double>&, int)>; Args = {int&, int&, std::vector<double, std::allocator<double> >&, bool&, int&, bool&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, std::vector<int, std::allocator<int> >&, bool&, bool&, double (*&)(const std::vector<double, std::allocator<double> >&, long unsigned int), bool&, std::reference_wrapper<RcppParallel::RMatrix<double> >, int&}]’
Combinatorics.cpp:1023:105: required from here
/home/travis/R/Library/RcppThread/include/RcppThread/ThreadPool.hpp:127:27: error: using invalid field ‘RcppThread::ThreadPool::push(F&&, Args&& ...)::__lambda5::__args’
At global scope:
cc1plus: warning: unrecognized command line option "-Wno-macro-redefined" [enabled by default]
make: *** [Combinatorics.o] Error 1
ERROR: compilation failed for package ‘RcppAlgos’
* removing ‘/home/travis/R/Library/RcppAlgos’
Error in i.p(...) :
(converted from warning) installation of package ‘RcppAlgos’ had non-zero exit status
Calls: <Anonymous> ... with_rprofile_user -> with_envvar -> force -> force -> i.p
Execution halted
The command "Rscript -e 'deps <- remotes::dev_package_deps(dependencies = NA);remotes::install_deps(dependencies = TRUE);if (!all(deps$package %in% installed.packages())) { message("missing: ", paste(setdiff(deps$package, installed.packages()), collapse=", ")); q(status = 1, save = "no")}'" failed and exited with 1 during .
Your build has been stopped.
My Travis YML file is:
language: r
script: ./travis-config.bash
sudo: false
warnings_are_errors: false
cache: packages
r_github_packages: jdreyf/ezlimma
bioc_packages: limma
# from https://github.com/stan-dev/rstan/issues/569
before_install:
- mkdir -p ~/.R
- echo "CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined" >> ~/.R/Makevars
- echo "CXX14=g++ -std=c++1y -fPIC" >> ~/.R/Makevars
- Rscript -e 'update.packages(ask = FALSE)'
output:
pdf_document:
latex_engine: xelatex
after_success:
- Rscript -e 'covr::codecov()'
Thanks for this valuable package.
I reached this repo while looking for R packages for computing multiset partitions, but I may be misunderstanding the documentation. I tried with partitionsGeneral
, but I don't understand the output.
To set a common ground, let me use an example. Let's take the multiset
Is it possible to get this with this package?
There are many issues in the logic that assumes positive values. For example, there are many places where we check if the first element is zero. The vector is first sorted, thus when we have negative values, this check not valid. This causes strange behavior as we see below.
comboGeneral(-5:0, repetition = TRUE, constraintFun = "sum",
comparisonFun = "==",
limitConstraints = -5)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] -5 0 0 0 0 0
[2,] -4 -1 0 0 0 0
[3,] -3 -2 0 0 0 0
[4,] -3 -1 -1 0 0 0
[5,] -2 -2 -1 0 0 0
[6,] -2 -1 -1 -1 0 0
[7,] -1 -1 -1 -1 -1 0
The above example should look only have 5 columns. Observe:
comboGeneral(5:0, repetition = TRUE, constraintFun = "sum",
comparisonFun = "==",
limitConstraints = 5)
[,1] [,2] [,3] [,4] [,5]
[1,] 0 0 0 0 5
[2,] 0 0 0 1 4
[3,] 0 0 0 2 3
[4,] 0 0 1 1 3
[5,] 0 0 1 2 2
[6,] 0 1 1 1 2
[7,] 1 1 1 1 1
Lastly, there is a significant performance penalty by all of those incorrect assumptions. The general algorithm (which is still efficient) is utilized in these situations when a much more efficient algorithm could be used.
## Optimized algorithm
system.time(comboGeneral(0:60, repetition = TRUE, constraintFun = "sum",
comparisonFun = "==",
limitConstraints = 60))
user system elapsed
0.086 0.061 0.147
## General algorithm
system.time(comboGeneral(0:-60, repetition = TRUE, constraintFun = "sum",
comparisonFun = "==",
limitConstraints = -60))
user system elapsed
0.718 0.348 1.066
Can you provide some references or documentation how comboSample
is implemented? I admit only taking a glance at the source.
I'm genuinely curious how to approach this problem of getting a random combination. It works amazingly fast for the sample sizes I had to sample, e.g. 300k choose 300 (I don't even want to think how big the search space is :D but I suppose this does not matter).
edit: I suppose it could be the one mentioned here https://stackoverflow.com/questions/2394246/algorithm-to-select-a-single-random-combination-of-values ?
Hello!
Thanks for writing a great package! When exploring combinations I have found some unexpected results. I have all of the scenarios below.
library(RcppAlgos)
v <- c(95, 99, 106, 109, 111, 116, 121, 132, 150, 162, 163, 193, 199,
215, 232, 304, 307, 313, 388, 1045)
sum(v)
#> [1] 4560
## I expect this to return no values, the sum of all 20 numbers is > 2000
comboGeneral(
v = v,
m = length(v),
constraintFun = "sum",
comparisonFun = c(">=", "<="),
limitConstraints = c(1900, 2000),
)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] 95 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [,15] [,16] [,17] [,18] [,19] [,20]
#> [1,] 95 95 95 95 95 95
## If m is NULL, length(v) is used or sum(freq). This returns the expected no values
comboGeneral(
v = v,
m = NULL,
constraintFun = "sum",
comparisonFun = c(">=", "<="),
limitConstraints = c(1900, 2000)
)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [,15] [,16] [,17] [,18] [,19] [,20]
## This ends up repeating the 95 18 times for all rows. I do not expect the 95 to repeat since repitition defaults to FALSE
comboGeneral(
v = v,
m = length(v) - 1,
constraintFun = "sum",
comparisonFun = c(">=", "<="),
limitConstraints = c(1900, 2000)
)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#> [1,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [2,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [3,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [4,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [5,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [6,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [7,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [8,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [9,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [10,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [11,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [12,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [13,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [14,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [15,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [16,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [17,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [18,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [19,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [20,] 95 95 95 95 95 95 95 95 95 95 95 95 95
#> [,14] [,15] [,16] [,17] [,18] [,19]
#> [1,] 95 95 95 95 95 193
#> [2,] 95 95 95 95 95 199
#> [3,] 95 95 95 95 95 215
#> [4,] 95 95 95 95 95 232
#> [5,] 95 95 95 95 99 193
#> [6,] 95 95 95 95 99 199
#> [7,] 95 95 95 95 99 215
#> [8,] 95 95 95 95 99 232
#> [9,] 95 95 95 95 106 193
#> [10,] 95 95 95 95 106 199
#> [11,] 95 95 95 95 106 215
#> [12,] 95 95 95 95 106 232
#> [13,] 95 95 95 95 109 193
#> [14,] 95 95 95 95 109 199
#> [15,] 95 95 95 95 109 215
#> [16,] 95 95 95 95 109 232
#> [17,] 95 95 95 95 111 193
#> [18,] 95 95 95 95 111 199
#> [19,] 95 95 95 95 111 215
#> [20,] 95 95 95 95 111 232
## The dupes dont happen at 14, this is the expected and wanted response
comboGeneral(
v = v,
m = 14,
constraintFun = "sum",
comparisonFun = c(">=", "<="),
limitConstraints = c(1900, 2000)
)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] 95 99 106 109 111 116 121 132 150 162 163 193 199 215
#> [2,] 95 99 106 109 111 116 121 132 150 162 163 193 199 232
## Dupes begin at 15, and at this number theres 15k+ rows. Note: There should be no result here
## Storing this in a variable to reduce the long output
d <- comboGeneral(
v = v,
m = 15,
constraintFun = "sum",
comparisonFun = c(">=", "<="),
limitConstraints = c(1900, 2000)
)
nrow(d)
#> [1] 15504
head(d)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] 95 95 95 95 95 95 95 95 95 95 95 95 95 304
#> [2,] 95 95 95 95 95 95 95 95 95 95 95 95 95 307
#> [3,] 95 95 95 95 95 95 95 95 95 95 95 95 95 313
#> [4,] 95 95 95 95 95 95 95 95 95 95 95 95 99 304
#> [5,] 95 95 95 95 95 95 95 95 95 95 95 95 99 307
#> [6,] 95 95 95 95 95 95 95 95 95 95 95 95 99 313
#> [,15]
#> [1,] 388
#> [2,] 388
#> [3,] 388
#> [4,] 388
#> [5,] 388
#> [6,] 388
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 4.1.3 (2022-03-10)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate English_United States.1252
#> ctype English_United States.1252
#> tz UTC
#> date 2022-07-19
#>
#> - Packages -------------------------------------------------------------------
#> package * version date lib source
#> backports 1.2.1 2020-12-09 [1] RSPM (R 4.1.0)
#> cli 3.2.0 2022-02-14 [1] RSPM (R 4.1.0)
#> crayon 1.4.1 2021-02-08 [1] RSPM (R 4.1.0)
#> digest 0.6.28 2021-09-23 [1] RSPM (R 4.1.0)
#> ellipsis 0.3.2 2021-04-29 [1] RSPM (R 4.1.0)
#> evaluate 0.15 2022-02-18 [1] RSPM (R 4.1.0)
#> fansi 0.5.0 2021-05-25 [1] RSPM (R 4.1.0)
#> fastmap 1.1.0 2021-01-25 [1] RSPM (R 4.1.0)
#> fs 1.5.2 2021-12-08 [1] RSPM (R 4.1.0)
#> glue 1.6.1 2022-01-22 [1] RSPM (R 4.1.0)
#> gmp 0.6-4 2022-02-24 [1] RSPM (R 4.1.0)
#> highr 0.9 2021-04-16 [1] RSPM (R 4.1.0)
#> htmltools 0.5.2 2021-08-25 [1] RSPM (R 4.1.0)
#> knitr 1.39 2022-04-26 [1] RSPM (R 4.1.0)
#> lifecycle 1.0.1 2021-09-24 [1] RSPM (R 4.1.0)
#> magrittr 2.0.3 2022-03-30 [1] RSPM (R 4.1.0)
#> pillar 1.7.0 2022-02-01 [1] RSPM (R 4.1.0)
#> pkgconfig 2.0.3 2019-09-22 [1] RSPM (R 4.1.0)
#> purrr 0.3.4 2020-04-17 [1] RSPM (R 4.1.0)
#> R.cache 0.15.0 2021-04-30 [1] RSPM (R 4.1.0)
#> R.methodsS3 1.8.1 2020-08-26 [1] RSPM (R 4.1.0)
#> R.oo 1.24.0 2020-08-26 [1] RSPM (R 4.1.0)
#> R.utils 2.11.0 2021-09-26 [1] RSPM (R 4.1.0)
#> RcppAlgos * 2.5.3 2022-03-31 [1] RSPM (R 4.1.0)
#> reprex 2.0.1 2021-08-05 [1] RSPM (R 4.1.0)
#> rlang 1.0.1 2022-02-03 [1] RSPM (R 4.1.0)
#> rmarkdown 2.11 2021-09-14 [1] RSPM (R 4.1.0)
#> rstudioapi 0.13 2020-11-12 [1] RSPM (R 4.1.0)
#> sessioninfo 1.1.1 2018-11-05 [1] RSPM (R 4.1.0)
#> stringi 1.7.5 2021-10-04 [1] RSPM (R 4.1.0)
#> stringr 1.4.0 2019-02-10 [1] RSPM (R 4.1.0)
#> styler 1.6.2 2021-09-23 [1] RSPM (R 4.1.0)
#> tibble 3.1.6 2021-11-07 [1] RSPM (R 4.1.0)
#> utf8 1.2.2 2021-07-24 [1] RSPM (R 4.1.0)
#> vctrs 0.3.8 2021-04-29 [1] RSPM (R 4.1.0)
#> withr 2.5.0 2022-03-03 [1] RSPM (R 4.1.0)
#> xfun 0.30 2022-03-02 [1] RSPM (R 4.1.0)
#> yaml 2.2.1 2020-02-01 [1] RSPM (R 4.1.0)
#>
#> [1] C:/Users/kow/Documents/R/win-library/4.1
#> [2] C:/Program Files/R/R-4.1.3/library
Created on 2022-07-19 by the reprex package (v2.0.1)
I am not sure if this is a bug or if I am misusing the function. Appreciate your time!
Here is 00check.log
* using log directory ‘/data/gannet/ripley/R/packages/tests-clang-SAN/RcppAlgos.Rcheck’
* using R Under development (unstable) (2018-06-14 r74898)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* using option ‘--no-stop-on-test-error’
* checking for file ‘RcppAlgos/DESCRIPTION’ ... OK
* this is package ‘RcppAlgos’ version ‘2.0.2’
* package encoding: UTF-8
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking whether package ‘RcppAlgos’ can be installed ... [225s/127s] OK
* checking package directory ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking compiled code ... OK
* checking examples ... [16s/16s] OK
* checking tests ... [41s/42s] OK
Running ‘testthat.R’ [40s/40s]
* DONE
Status: OK
And here is the testthat.Rout
R Under development (unstable) (2018-06-14 r74898) -- "Unsuffered Consequences"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(testthat)
> library(RcppAlgos)
>
> test_check("RcppAlgos")
/usr/local/bin/../include/c++/v1/memory:1805:35: runtime error: nan is outside the range of representable values of type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/local/bin/../include/c++/v1/memory:1805:35 in
══ testthat results ═══════════════════════════════════════════════════════════
OK: 395 SKIPPED: 0 FAILED: 0
>
> proc.time()
user system elapsed
38.829 1.306 40.290
I was working a full search of Combinatorial caculation, the population about 4000, and I want to find 2 or 3 Combinatorial that satisfy certain condition. I thought RcppAlgos might help, but when I parallel , it not working!
example:
select_n_shr=2
shrs=1:4000
itc <- comboIter(shrs, select_n_shr)
AllPairs <- foreach(i = itc, .packages = c("data.table","urca","vars"), .combine = 'rbind') %dopar% {
print(i)}
the output:
AllPairs
[1] 1 2
Is it possible to achieve the results below using either comboGeneral
or comboGroups
? (I'm not sure which one is the right function based on the few attempts I've made so far). I would like the end result to have no repetitions
and duplications
from any of the sets. Using expand.grid
is too slow as I have to manually adjust for repetitions
and duplications
and I would also like to take advantage of the FUN
argument in your library to do some other things to the result. Thank you for this great library!
set1 <- c("Paul G","Mike B","Steph D","Ron B","Ryan R")
set2 <- c("Ron B","Ryan R","Matt B","Joe D")
set3 <- c("Ryan R","Steven Z","Dennis D","Mike A")
set4 <- c("Mike A","Steven Z","Luka E","Francis B","Tom A")
set5 <- c("Ross U","Bobby A","Max Z","Flori A")
all_combos <- expand.grid(set1, set1, set2, set2, set3, set3, set4, set4, set5)
all_combos <- all_combos[1:25000,]
all_combos <- all_combos[!duplicated(t(apply(all_combos, 1, sort))), ]
all_combos$dups <- apply(all_combos, 1, function(i) any(duplicated(i[!is.na(i)])))
all_combos <- all_combos[all_combos$dups==FALSE,][,-c(10)]
> all_combos[1:2,]
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8 Var9
7252 Mike B Paul G Matt B Ron B Dennis D Ryan R Steven Z Mike A Ross U
7253 Steph D Paul G Matt B Ron B Dennis D Ryan R Steven Z Mike A Ross U
Hi,
Was working with your implementation, doing some detailed calculations. Thought had bug in my code, but tracked it to the prime counting function; specifically to region [110^9,1.110^9]. The start is hard to find, has somewhat gradual increase, but the end is not, a sharper fall. The end jump is in [1.07210^9,1.07410^9] with an error of about 12,400.
Attached some code showing this, and a plot of my function's output which alerted me. For the paper I'm working on, plan to show output for entire computable range; I can skip over this region, but would look strange in plots w/o explanation. Have not decide how to proceed; skip & explain or show & explain. Either way, it's still a good implementation. Don't think there a too many such regions, < 10^16, especially that far off. At least from what I could tell so far.
If you can fix it within the next month, at most, then I can redo calculations in my paper before submission.
Thanks,
Shaun
PrimeCounting_ErrorDeviations.txt
There are serious memory issues reported by CRAN (https://CRAN.R-project.org/package=RcppAlgos) for version 2.3.3 on 2019-06-30.
Hi!
I'm working on a project where I have to create a weight matrix consisting of 9 variables. V1 must have a min weight of 1 and max weight of 5, while V2:V9 can have min weight 0 and max weight 3. I have tried to find an optimal solution to this problem by reading and implementing examples from the documentation, but as of now, the only way I can solve it is to create a "complete" weight matrix where all variables can have weights between 0 and 5, -then I remove all instances where V1==0 or V2:V9 >3.
Is there some functionality in RcppAlgo that would allow we to specify these variable-dependent constraint?
I'm attempting to install RcppAlgos on a MacOS 12.4 (Monterey), Intel Core 7 machine and it is failing.
When I installed the compiled version (2.5.0) from CRAN, library("RcppAlgos")
fails because it is unable to load RcppAlgos.so (the file is there).
When I try to compile from 2.5.3 source, the compilation fails with multiple errors like ClassUtils.cpp:264:33: error: call to 'abs' is ambiguous
How do I get this to install?
Thank you.
I have a problem for selecting the best treatment levels and their related weights. How can I consider a situation when a frequency is zero in some points?
x=c(0,20,40,60,80,100)
w=N*(w1,w2,w3,w4,w5)
w is in a loop and can get the value of zero in some situations. how can I handle it?
multiPerm <- permuteGeneral(c(x1,x2,x3,x4), freqs = c(round(Nw1,digits=0),round(Nw2,digits=0),round(Nw3,digits=0),N-round(Nw1)-round(Nw2)-round(Nw3))
)
Hi Joseph, thanks for the great package. Trying to install the developer version so I can use the parallel options. However, having issue, see below. Note that i do have gmp installed already...Thanks for any advice.
devtools::install_github("jwood000/RcppAlgos")
Downloading GitHub repo jwood000/RcppAlgos@master
Installing 1 packages: gmp
Installing package into ‘C:/Users/Daniel Lyons/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.5/gmp_0.5-13.2.zip'
Content type 'application/zip' length 1054538 bytes (1.0 MB)
downloaded 1.0 MB
package ‘gmp’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\Daniel Lyons\AppData\Local\Temp\RtmpasCkIh\downloaded_packages
√ checking for file 'C:\Users\Daniel Lyons\AppData\Local\Temp\RtmpasCkIh\remotes9bc5f615e25\jwood000-RcppAlgos-8cff1e8/DESCRIPTION' ...
Installing package into ‘C:/Users/Daniel Lyons/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
Hi, I was following your instructions here (https://stackoverflow.com/questions/73992417/itertools-combinations-find-if-a-combination-is-divisible) and I'm losing the order of the combinations, is this expected? i.e.:
comb =c(78, 45, 21, 100, 74, 38, 22, 22, 85, 78, 45)
idx <- comboRank(comb, v = 100, repetition=TRUE)
check_comb = comboSample(100, 11, sampleVec = idx, repetition=TRUE)
identical(as.vector(check_comb), comb)
> comb
[1] 78 45 21 100 74 38 22 22 85 78 45
> as.vector(check_comb)
[1] 21 22 22 38 45 45 74 78 78 85 100
Is there a way to unrank idx and recover comb including the order
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.