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:
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.
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:
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:
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:Clearly, something is not right. We obtained
2135
solutions with brute force and6561
with the constraint algorithm. Let's have a look at the actual results.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 inGetPartitionCase
:https://github.com/jwood000/RcppAlgos/blob/8364c46d275f745c1cde9ad064f9c67f7c86c559/src/ConstraintsUtils.cpp#L397-L408
And we see that it is a templated function that can accept vectors of different types:
https://github.com/jwood000/RcppAlgos/blob/8364c46d275f745c1cde9ad064f9c67f7c86c559/src/ConstraintsUtils.cpp#L377-L382
Now,
ConstraintsMaster.cpp
callsGetPartitionCase
here:https://github.com/jwood000/RcppAlgos/blob/8364c46d275f745c1cde9ad064f9c67f7c86c559/src/ConstraintsMaster.cpp#L150-L156
And here is the problem. We are only taking care of numeric vectors (
vNum
andtargetVals
are vectors of typedouble
). We can verify this by simply wrappingvals
above withas.numeric
:We simply need to ensure we handle the integer case appropriately.