Banish an unneeded use of our custom containers.
This commit is contained in:
parent
2521dcadc4
commit
42f5d3ab0d
11
src/expr.cpp
11
src/expr.cpp
@ -400,13 +400,16 @@ Expr *Expr::PartialWrt(hParam p) const {
|
|||||||
ssassert(false, "Unexpected operation");
|
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) {
|
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;
|
hParam param = (op == Op::PARAM) ? parh : parp->h;
|
||||||
for(hParam &p : *list) {
|
if(list->end() != std::find_if(list->begin(), list->end(),
|
||||||
if(p.v == param.v) return;
|
[=](const hParam &p) { return p.v == param.v; })) {
|
||||||
|
// We found ourselves in the list already, early out.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
list->Add(¶m);
|
list->push_back(param);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
|
|
||||||
Expr *PartialWrt(hParam p) const;
|
Expr *PartialWrt(hParam p) const;
|
||||||
double Eval() const;
|
double Eval() const;
|
||||||
void ParamsUsedList(List<hParam> *list) const;
|
void ParamsUsedList(std::vector<hParam> *list) const;
|
||||||
bool DependsOn(hParam p) const;
|
bool DependsOn(hParam p) const;
|
||||||
static bool Tol(double a, double b);
|
static bool Tol(double a, double b);
|
||||||
bool IsZeroConst() const;
|
bool IsZeroConst() const;
|
||||||
|
@ -45,13 +45,16 @@ bool System::WriteJacobian(int tag) {
|
|||||||
if(mat.eq.size() >= MAX_UNKNOWNS) {
|
if(mat.eq.size() >= MAX_UNKNOWNS) {
|
||||||
return false;
|
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++) {
|
for(size_t i = 0; i < mat.eq.size(); i++) {
|
||||||
Equation *e = mat.eq[i];
|
Equation *e = mat.eq[i];
|
||||||
if(e->tag != tag) continue;
|
if(e->tag != tag) continue;
|
||||||
Expr *f = e->e->FoldConstants();
|
Expr *f = e->e->FoldConstants();
|
||||||
f = f->DeepCopyWithParamsAsPointers(¶m, &(SK.param));
|
f = f->DeepCopyWithParamsAsPointers(¶m, &(SK.param));
|
||||||
|
|
||||||
List<hParam> paramsUsed = {};
|
paramsUsed.clear();
|
||||||
f->ParamsUsedList(¶msUsed);
|
f->ParamsUsedList(¶msUsed);
|
||||||
|
|
||||||
for(hParam &p : paramsUsed) {
|
for(hParam &p : paramsUsed) {
|
||||||
@ -63,7 +66,7 @@ bool System::WriteJacobian(int tag) {
|
|||||||
continue;
|
continue;
|
||||||
mat.A.sym->insert(i, j->second) = pd;
|
mat.A.sym->insert(i, j->second) = pd;
|
||||||
}
|
}
|
||||||
paramsUsed.Clear();
|
paramsUsed.clear();
|
||||||
mat.B.sym.push_back(f);
|
mat.B.sym.push_back(f);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user