Skip to content
Merged
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
22 changes: 11 additions & 11 deletions Sofa/framework/Helper/src/sofa/helper/AdvancedTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ template class SOFA_HELPER_API AdvancedTimer::Id<AdvancedTimer::Val>;
class TimerData
{
public:
AdvancedTimer::IdTimer id;
AdvancedTimer::IdTimer m_id;
type::vector<Record> records;
int nbIter;
int interval;
Expand Down Expand Up @@ -89,7 +89,7 @@ class TimerData

void init(AdvancedTimer::IdTimer id)
{
this->id = id;
this->m_id = id;
const std::string envvar = std::string("SOFA_TIMER_") + (std::string)id;
const char* val = getenv(envvar.c_str());
if (!val || !*val)
Expand Down Expand Up @@ -174,7 +174,7 @@ void AdvancedTimer::clear()
bool AdvancedTimer::isEnabled(IdTimer id)
{
TimerData& data = timers[id];
if (!data.id)
if (!data.m_id)
{
data.init(id);
}
Expand All @@ -184,7 +184,7 @@ bool AdvancedTimer::isEnabled(IdTimer id)
void AdvancedTimer::setEnabled(IdTimer id, bool val)
{
TimerData& data = timers[id];
if (!data.id)
if (!data.m_id)
{
data.init(id);
}
Expand All @@ -197,7 +197,7 @@ void AdvancedTimer::setEnabled(IdTimer id, bool val)
int AdvancedTimer::getInterval(IdTimer id)
{
TimerData& data = timers[id];
if (!data.id)
if (!data.m_id)
{
data.init(id);
}
Expand All @@ -207,7 +207,7 @@ int AdvancedTimer::getInterval(IdTimer id)
void AdvancedTimer::setInterval(IdTimer id, int val)
{
TimerData& data = timers[id];
if (!data.id)
if (!data.m_id)
{
data.init(id);
}
Expand All @@ -220,7 +220,7 @@ void AdvancedTimer::begin(IdTimer id)
std::stack<AdvancedTimer::IdTimer>& curTimer = getCurTimer();
curTimer.push(id);
TimerData& data = timers[curTimer.top()];
if (!data.id)
if (!data.m_id)
{
data.init(id);
}
Expand Down Expand Up @@ -339,7 +339,7 @@ void AdvancedTimer::end(IdTimer id)
std::string AdvancedTimer::end(IdTimer id, double time, double dt)
{
const TimerData& data = timers[id];
if(!data.id)
if(!data.m_id)
{
return std::string("");
}
Expand Down Expand Up @@ -801,7 +801,7 @@ void TimerData::print()
{
static ctime_t tmargin = CTime::getTicksPerSec() / 100000;
std::ostream& out = std::cout;
out << "==== " << id << " ====\n\n";
out << "==== " << m_id << " ====\n\n";
if (!records.empty())
{
out << "Trace of last iteration :\n";
Expand Down Expand Up @@ -955,7 +955,7 @@ void AdvancedTimer::setOutputType(IdTimer id, const std::string& type)
{
// Seek for the timer
TimerData& data = timers[id];
if (!data.id)
if (!data.m_id)
{
data.init(id);
}
Expand Down Expand Up @@ -1101,7 +1101,7 @@ void TimerData::print(std::ostream& result)
{
//static ctime_t tmargin = CTime::getTicksPerSec() / 100000;
std::ostream& out = result;
out << "Timer: " << id << "\n";
out << "Timer: " << m_id << "\n";
if (!steps.empty())
{
//out << "\nSteps Duration Statistics (in ms) :\n";
Expand Down
2 changes: 1 addition & 1 deletion Sofa/framework/Helper/src/sofa/helper/BackTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
namespace sofa::helper
{

BackTrace::StackTrace BackTrace::getTrace(size_t maxEntries)
BackTrace::StackTrace BackTrace::getTrace([[maybe_unused]] size_t maxEntries)
{
BackTrace::StackTrace result;

Expand Down
20 changes: 10 additions & 10 deletions Sofa/framework/Helper/src/sofa/helper/DiffLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <cstring>
#include <queue>
#include <difflib.h>
#include <sofa/helper/DiffLib.h>

#include <cstring>
#include <queue>
#include <utility>

namespace sofa::helper
{

Expand All @@ -35,27 +37,25 @@ std::vector<std::tuple<std::string, SReal>> SOFA_HELPER_API getClosestMatch(cons
{
public:
Tuple(float ratio_, std::string value_)
{
ratio = ratio_;
value = value_;
}
: ratio(ratio_), value(std::move(value_)) {}

float ratio;
std::string value;
};
auto cmp = [](Tuple& left, Tuple& right) { return left.ratio < right.ratio; };
auto cmp = [](const Tuple& left, Tuple& right) { return left.ratio < right.ratio; };
std::priority_queue<Tuple, std::vector<Tuple>, decltype(cmp)> q3(cmp);

for(auto& s : haystack)
{
auto foo = difflib::MakeSequenceMatcher(needle,s);
q3.push(Tuple(foo.ratio(), s));
q3.emplace(foo.ratio(), s);
}
std::vector<std::tuple<std::string, SReal>> result;
while(!q3.empty() && result.size()<=numEntries)
while (!q3.empty() && result.size() <= numEntries)
{
if(q3.top().ratio < threshold)
break;
result.push_back(std::make_tuple(q3.top().value, q3.top().ratio));
result.emplace_back(q3.top().value, q3.top().ratio);
q3.pop();
}
return result;
Expand Down
56 changes: 28 additions & 28 deletions Sofa/framework/Helper/src/sofa/helper/LCPcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1386,8 +1386,8 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to
free(d_coarse);

free(d);
for (int i = 0; i < numContacts; i++)
delete W33[i];
for (int c = 0; c < numContacts; c++)
delete W33[c];
free(W33);

return 0;
Expand Down Expand Up @@ -1525,10 +1525,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to

if(verbose)
{
std::stringstream tmp;
tmp << "Result at the COARSE LEVEL: " << msgendl;
resultToString(tmp, F_coarse,num_group*3);
dmsg_info("LCPcalc") << tmp.str() ;
std::stringstream ss;
ss << "Result at the COARSE LEVEL: " << msgendl;
resultToString(ss, F_coarse,num_group*3);
dmsg_info("LCPcalc") << ss.str() ;
}


Expand All @@ -1551,10 +1551,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to

if(verbose)
{
std::stringstream tmp;
tmp << "projection at the finer LEVEL: " << msgendl ;
resultToString(tmp, f,dim);
dmsg_info("LCPcalc") << tmp.str() ;
std::stringstream ss;
ss << "projection at the finer LEVEL: " << msgendl ;
resultToString(ss, f,dim);
dmsg_info("LCPcalc") << ss.str() ;
}


Expand All @@ -1564,10 +1564,10 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to

if(verbose)
{
std::stringstream tmp;
tmp << "after 10 iteration at the finer LEVEL: " << msgendl ;
resultToString(tmp, f,dim);
dmsg_info("LCPcalc") << tmp.str();
std::stringstream ss;
ss << "after 10 iteration at the finer LEVEL: " << msgendl ;
resultToString(ss, f,dim);
dmsg_info("LCPcalc") << ss.str();
}

free(d_free_coarse);
Expand All @@ -1576,8 +1576,8 @@ int nlcp_multiGrid(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal to
free(d_coarse);

free(d);
for (int i = 0; i < numContacts; i++)
delete W33[i];
for (int c = 0; c < numContacts; c++)
delete W33[c];
free(W33);

return result;
Expand Down Expand Up @@ -1679,9 +1679,9 @@ int nlcp_gaussseidel(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal
for (int c=0; c<numContacts ; c++)
{
dn = dfree[3*c];
for (int i=0; i<dim; i++)
for (int k = 0; k < dim; k++)
{
dn += W[3*c ][i]*f[i];
dn += W[3 * c][k] * f[k];
}
if (dn < 0)
sum_d += -dn;
Expand Down Expand Up @@ -1711,8 +1711,8 @@ int nlcp_gaussseidel(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal
}

free(d);
for (int i = 0; i < numContacts; i++)
delete W33[i];
for (int c = 0; c < numContacts; c++)
delete W33[c];
free(W33);

if (verbose){
Expand All @@ -1725,8 +1725,8 @@ int nlcp_gaussseidel(int dim, SReal *dfree, SReal**W, SReal *f, SReal mu, SReal
sofa::helper::AdvancedTimer::valSet("GS iterations", it);

free(d);
for (int i = 0; i < numContacts; i++)
delete W33[i];
for (int c = 0; c < numContacts; c++)
delete W33[c];
free(W33);

if (verbose)
Expand Down Expand Up @@ -1820,8 +1820,8 @@ int nlcp_gaussseidelTimed(int dim, SReal *dfree, SReal**W, SReal*f, SReal mu, SR
if((t1-t0) > tdiff)
{
free(d);
for (int i = 0; i < numContacts; i++)
delete W33[i];
for (int c = 0; c < numContacts; c++)
delete W33[c];
free(W33);
return 1;
}
Expand All @@ -1830,17 +1830,17 @@ int nlcp_gaussseidelTimed(int dim, SReal *dfree, SReal**W, SReal*f, SReal mu, SR
if (error < tol)
{
free(d);
for (int i = 0; i < numContacts; i++)
delete W33[i];
for (int c = 0; c < numContacts; c++)
delete W33[c];
free(W33);
sofa::helper::AdvancedTimer::valSet("GS iterations", it+1);
return 1;
}
}
sofa::helper::AdvancedTimer::valSet("GS iterations", it);
free(d);
for (int i = 0; i < numContacts; i++)
delete W33[i];
for (int c = 0; c < numContacts; c++)
delete W33[c];
free(W33);

if (verbose)
Expand Down
Loading
Loading