Banish an unneeded use of our custom containers.

This commit is contained in:
Ryan Pavlik 2021-12-23 11:17:40 -06:00 committed by phkahler
parent 2521dcadc4
commit 42f5d3ab0d
3 changed files with 13 additions and 7 deletions

View File

@ -400,13 +400,16 @@ Expr *Expr::PartialWrt(hParam p) const {
ssassert(false, "Unexpected operation");
}
void Expr::ParamsUsedList(List<hParam> *list) const {
void Expr::ParamsUsedList(std::vector<hParam> *list) const {
if(op == Op::PARAM || op == Op::PARAM_PTR) {
// leaf: just add ourselves if we aren't already there
hParam param = (op == Op::PARAM) ? parh : parp->h;
for(hParam &p : *list) {
if(p.v == param.v) return;
if(list->end() != std::find_if(list->begin(), list->end(),
[=](const hParam &p) { return p.v == param.v; })) {
// We found ourselves in the list already, early out.
return;
}
list->Add(&param);
list->push_back(param);
return;
}

View File

@ -70,7 +70,7 @@ public:
Expr *PartialWrt(hParam p) const;
double Eval() const;
void ParamsUsedList(List<hParam> *list) const;
void ParamsUsedList(std::vector<hParam> *list) const;
bool DependsOn(hParam p) const;
static bool Tol(double a, double b);
bool IsZeroConst() const;

View File

@ -45,13 +45,16 @@ bool System::WriteJacobian(int tag) {
if(mat.eq.size() >= MAX_UNKNOWNS) {
return false;
}
std::vector<hParam> paramsUsed;
// A single possibly-too-large allocation is probably preferred here?
mat.B.sym.reserve(mat.eq.size());
for(size_t i = 0; i < mat.eq.size(); i++) {
Equation *e = mat.eq[i];
if(e->tag != tag) continue;
Expr *f = e->e->FoldConstants();
f = f->DeepCopyWithParamsAsPointers(&param, &(SK.param));
List<hParam> paramsUsed = {};
paramsUsed.clear();
f->ParamsUsedList(&paramsUsed);
for(hParam &p : paramsUsed) {
@ -63,7 +66,7 @@ bool System::WriteJacobian(int tag) {
continue;
mat.A.sym->insert(i, j->second) = pd;
}
paramsUsed.Clear();
paramsUsed.clear();
mat.B.sym.push_back(f);
}
return true;