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");
|
||||
}
|
||||
|
||||
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(¶m);
|
||||
list->push_back(param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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(¶m, &(SK.param));
|
||||
|
||||
List<hParam> paramsUsed = {};
|
||||
paramsUsed.clear();
|
||||
f->ParamsUsedList(¶msUsed);
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user