Skip to content

Commit

Permalink
apply R suggestions to pypkg and cpp code
Browse files Browse the repository at this point in the history
  • Loading branch information
pachadotdev committed Nov 13, 2024
1 parent be017f8 commit cef6b69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions pypkg/redatamlib/readers/FuzzyVariableParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ FuzzyVariableParser::FuzzyVariableParser(ByteArrayReader reader,
void FuzzyVariableParser::ParseAllVariables(vector<Entity> &entities) {
vector<pair<size_t, size_t>> searchBounds = GetSearchBounds(entities);

size_t numThreads = std::thread::hardware_concurrency();
numThreads = std::min(entities.size(), numThreads);
// R-devel suggestion: Default to using all available hardware concurrency
size_t maxThreads = std::thread::hardware_concurrency();

size_t numThreads = std::min(entities.size(), maxThreads);

if (numThreads == 0) {
numThreads = 1;
}

size_t chunkSize = entities.size() / numThreads;

Expand All @@ -41,6 +47,10 @@ vector<pair<size_t, size_t>>
FuzzyVariableParser::GetSearchBounds(vector<Entity> entities) {
vector<pair<size_t, size_t>> ret;

if (entities.empty()) {
return ret;
}

for (size_t i = 0; i < entities.size() - 1; ++i) {
ret.push_back(
{entities[i].GetBounds().second, entities[i + 1].GetBounds().first});
Expand Down
14 changes: 12 additions & 2 deletions src/readers/FuzzyVariableParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ FuzzyVariableParser::FuzzyVariableParser(ByteArrayReader reader,
void FuzzyVariableParser::ParseAllVariables(vector<Entity> &entities) {
vector<pair<size_t, size_t>> searchBounds = GetSearchBounds(entities);

size_t numThreads = std::thread::hardware_concurrency();
numThreads = std::min(entities.size(), numThreads);
// R-devel suggestion: Default to using all available hardware concurrency
size_t maxThreads = std::thread::hardware_concurrency();

size_t numThreads = std::min(entities.size(), maxThreads);

if (numThreads == 0) {
numThreads = 1;
}

size_t chunkSize = entities.size() / numThreads;

Expand All @@ -41,6 +47,10 @@ vector<pair<size_t, size_t>>
FuzzyVariableParser::GetSearchBounds(vector<Entity> entities) {
vector<pair<size_t, size_t>> ret;

if (entities.empty()) {
return ret;
}

for (size_t i = 0; i < entities.size() - 1; ++i) {
ret.push_back(
{entities[i].GetBounds().second, entities[i + 1].GetBounds().first});
Expand Down

0 comments on commit cef6b69

Please sign in to comment.