Skip to content

Commit

Permalink
Issue #1741 rr,ss,tt only generated if used
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed Mar 10, 2017
1 parent a76824b commit c081ac3
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion casadi/core/function/mx_function.cpp
Expand Up @@ -1068,7 +1068,7 @@ namespace casadi {
void MXFunction::generateBody(CodeGenerator& g) const {
// Temporary variables and vectors
g << "int i, j, k;\n"
<< "real_t r, s, t, *rr, *ss, *tt;\n"
<< "real_t r, s, t;\n"
<< "const real_t** arg1=arg+" << n_in() << ";\n"
<< "real_t** res1=res+" << n_out() << ";\n";

Expand Down
1 change: 1 addition & 0 deletions casadi/core/mx/binary_mx_impl.hpp
Expand Up @@ -128,6 +128,7 @@ namespace casadi {
// Codegen loop, if needed
if (nnz()>1) {
// Iterate over result
g.local("rr", "real_t", "*");
g << "for (i=0, " << "rr=" << g.work(res[0], nnz());
r = "(*rr++)";

Expand Down
1 change: 1 addition & 0 deletions casadi/core/mx/concat.cpp
Expand Up @@ -79,6 +79,7 @@ namespace casadi {

void Concat::generate(CodeGenerator& g, const std::string& mem,
const std::vector<int>& arg, const std::vector<int>& res) const {
g.local("rr", "real_t", "*");
g << "rr=" << g.work(res[0], nnz()) << ";\n";
for (int i=0; i<arg.size(); ++i) {
int nz = dep(i).nnz();
Expand Down
7 changes: 7 additions & 0 deletions casadi/core/mx/getnonzeros.cpp
Expand Up @@ -440,6 +440,8 @@ namespace casadi {

// Codegen the assignments
g.local("cii", "const int", "*");
g.local("rr", "real_t", "*");
g.local("ss", "real_t", "*");
g << "for (cii=s" << ind << ", rr=" << g.work(res[0], nnz())
<< ", ss=" << g.work(arg[0], dep(0).nnz())
<< "; cii!=s" << ind << "+" << nz_.size()
Expand Down Expand Up @@ -468,13 +470,18 @@ namespace casadi {

void GetNonzerosSlice::generate(CodeGenerator& g, const std::string& mem,
const std::vector<int>& arg, const std::vector<int>& res) const {
g.local("rr", "real_t", "*");
g.local("ss", "real_t", "*");
g << "for (rr=" << g.work(res[0], nnz()) << ", ss=" << g.work(arg[0], dep(0).nnz())
<< "+" << s_.start << "; ss!=" << g.work(arg[0], dep(0).nnz()) << "+" << s_.stop
<< "; ss+=" << s_.step << ") *rr++ = *ss;\n";
}

void GetNonzerosSlice2::generate(CodeGenerator& g, const std::string& mem,
const std::vector<int>& arg, const std::vector<int>& res) const {
g.local("rr", "real_t", "*");
g.local("ss", "real_t", "*");
g.local("tt", "real_t", "*");
g << "for (rr=" << g.work(res[0], nnz()) << ", ss=" << g.work(arg[0], dep(0).nnz())
<< "+" << outer_.start << "; ss!=" << g.work(arg[0], dep(0).nnz()) << "+"
<< outer_.stop << "; ss+=" << outer_.step << ") "
Expand Down
1 change: 1 addition & 0 deletions casadi/core/mx/monitor.cpp
Expand Up @@ -105,6 +105,7 @@ namespace casadi {
void Monitor::generate(CodeGenerator& g, const std::string& mem,
const std::vector<int>& arg, const std::vector<int>& res) const {
// Print comment
g.local("rr", "real_t", "*");
g << g.printf(comment_ + "\\n[") << "\n"
<< " for (i=0, rr=" << g.work(arg[0], dep(0).nnz())
<< "; i!=" << nnz() << "; ++i) {\n"
Expand Down
3 changes: 3 additions & 0 deletions casadi/core/mx/multiplication.cpp
Expand Up @@ -125,6 +125,9 @@ namespace casadi {
}

int nrow_x = dep(1).size1(), nrow_y = dep(2).size1(), ncol_y = dep(2).size2();
g.local("rr", "real_t", "*");
g.local("ss", "real_t", "*");
g.local("tt", "real_t", "*");
g << "for (i=0, rr=" << g.work(res[0], nnz()) <<"; i<" << ncol_y << "; ++i)"
<< " for (j=0; j<" << nrow_x << "; ++j, ++rr)"
<< " for (k=0, ss=" << g.work(arg[1], dep(1).nnz()) << "+j, tt="
Expand Down
7 changes: 7 additions & 0 deletions casadi/core/mx/setnonzeros_impl.hpp
Expand Up @@ -753,6 +753,8 @@ namespace casadi {

// Perform the operation inplace
g.local("cii", "const int", "*");
g.local("rr", "real_t", "*");
g.local("ss", "real_t", "*");
g << "for (cii=s" << ind << ", rr=" << g.work(res[0], this->nnz()) << ", "
<< "ss=" << g.work(arg[1], this->dep(1).nnz()) << "; cii!=s" << ind
<< "+" << this->nz_.size() << "; ++cii, ++ss)"
Expand All @@ -770,6 +772,8 @@ namespace casadi {
}

// Perform the operation inplace
g.local("rr", "real_t", "*");
g.local("ss", "real_t", "*");
g << "for (rr=" << g.work(res[0], this->nnz()) << "+" << s_.start << ", ss="
<< g.work(arg[1], this->dep(1).nnz()) << "; rr!="
<< g.work(res[0], this->nnz()) << "+" << s_.stop
Expand All @@ -788,6 +792,9 @@ namespace casadi {
}

// Perform the operation inplace
g.local("rr", "real_t", "*");
g.local("ss", "real_t", "*");
g.local("tt", "real_t", "*");
g << "for (rr=" << g.work(res[0], this->nnz()) << "+" << outer_.start
<< ", ss=" << g.work(arg[1], this->dep(1).nnz()) << "; rr!="
<< g.work(res[0], this->nnz()) << "+" << outer_.stop
Expand Down
1 change: 1 addition & 0 deletions casadi/core/mx/transpose.cpp
Expand Up @@ -191,6 +191,7 @@ namespace casadi {
void DenseTranspose::generate(CodeGenerator& g, const std::string& mem,
const std::vector<int>& arg, const std::vector<int>& res) const {
g.local("cs", "const real_t", "*");
g.local("rr", "real_t", "*");
g << "for (i=0, rr=" << g.work(res[0], nnz()) << ", "
<< "cs=" << g.work(arg[0], nnz()) << "; i<" << dep().size2() << "; ++i) "
<< "for (j=0; j<" << dep().size1() << "; ++j) "
Expand Down
1 change: 1 addition & 0 deletions casadi/core/mx/unary_mx.cpp
Expand Up @@ -106,6 +106,7 @@ namespace casadi {
} else {
// Vector assignment
g.local("cs", "const real_t", "*");
g.local("rr", "real_t", "*");
g << "for (i=0, rr=" << g.work(res[0], nnz()) << ", cs=" << g.work(arg[0], nnz())
<< "; i<" << sparsity().nnz() << "; ++i) ";
r = "*rr++";
Expand Down

0 comments on commit c081ac3

Please sign in to comment.