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

Allow PartialPermutation to accept empty vector #22229

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions multibody/contact_solvers/sap/partial_permutation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace internal {
PartialPermutation::PartialPermutation(std::vector<int> permutation)
: permutation_(std::move(permutation)) {
const int domain_size = permutation_.size();
if (domain_size == 0) return;
// Determine size of the permuted domain.
const int permuted_domain_size =
*std::max_element(permutation_.begin(), permutation_.end()) + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ GTEST_TEST(PartialPermutation, EmptyPermutation) {
EXPECT_EQ(p.permuted_domain_size(), 0);
}

GTEST_TEST(PartialPermutation, EmptyPermutationFromStdVector) {
std::vector<int> permutation;
PartialPermutation p(std::move(permutation));
EXPECT_EQ(p.domain_size(), 0);
EXPECT_EQ(p.permuted_domain_size(), 0);
}

// Creates a permutation of size 6 where none of the indexes participates and
// adds permuted indexes one at a time with push().
GTEST_TEST(PartialPermutation, PushElements) {
Expand Down