Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument upper in combo/permuteGeneral does not work under certain constraints #9

Closed
jwood000 opened this issue Jul 15, 2019 · 2 comments
Assignees

Comments

@jwood000
Copy link
Owner

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.
@jwood000 jwood000 changed the title Argument upper in combo/permuteGeneral does not work under certain constraints Argument upper in combo/permuteGeneral does not work under certain constraints Jul 15, 2019
@jwood000 jwood000 self-assigned this Jul 15, 2019
@jwood000
Copy link
Owner Author

The problem code can be traced to GeneralPartions.h:

if (partCountTest > std::numeric_limits<int>::max())

Note that this check takes place before:

numParts = (bUserRows && numRows < partCountTest) ? numRows : partCountTest;

We can easily fix this by refactoring the above.

@jwood000
Copy link
Owner Author

Corrected by: 5d422fa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant