Skip to content

Commit

Permalink
#1360 Renamed Matrix::set(Matrix), get(Matrix) overload
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed Mar 16, 2015
1 parent 67287a7 commit 81bb14b
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 87 deletions.
4 changes: 2 additions & 2 deletions casadi/core/function/control_simulator_internal.cpp
Expand Up @@ -422,14 +422,14 @@ namespace casadi {

// Copy all inputs
for (int i=0;i<getNumInputs();++i) {
all_output_.input(i).set(input(i));
all_output_.input(i).setSub(input(i));
}

all_output_.evaluate();

// Copy all outputs
for (int i=0;i<getNumOutputs();++i) {
output(i).set(all_output_.output(i));
output(i).setSub(all_output_.output(i));
}

}
Expand Down
2 changes: 1 addition & 1 deletion casadi/core/function/implicit_function_internal.cpp
Expand Up @@ -170,7 +170,7 @@ namespace casadi {
fact_up_to_date_ = false;

// Get initial guess
output(iout_).set(input(iin_));
output(iout_).setSub(input(iin_));

// Solve the nonlinear system of equations
solveNonLinear();
Expand Down
8 changes: 4 additions & 4 deletions casadi/core/function/integrator_internal.cpp
Expand Up @@ -1014,8 +1014,8 @@ namespace casadi {
t_ = t0_;

// Initialize output
xf().set(x0());
zf().set(z0());
xf().setSub(x0());
zf().setSub(z0());

// Reset summation states
qf().set(0.0);
Expand All @@ -1030,8 +1030,8 @@ namespace casadi {
t_ = tf_;

// Initialize output
rxf().set(rx0());
rzf().set(rz0());
rxf().setSub(rx0());
rzf().setSub(rz0());

// Reset summation states
rqf().set(0.0);
Expand Down
51 changes: 39 additions & 12 deletions casadi/core/function/io_interface.hpp
Expand Up @@ -340,7 +340,7 @@ namespace casadi {
/// \endcond


#define SETTERS(T) \
#define SETTERS_NZ(T) \
void setInput(T val, int iind=0) \
{ static_cast<const Derived*>(this)->assertInit(); \
try { input(iind).set(val); } \
Expand All @@ -355,18 +355,34 @@ namespace casadi {
void setOutput(T val, const std::string &oname) \
{ setOutput(val, outputSchemeEntry(oname)); } \

#define SETTERS_SUB(T) \
void setInput(T val, int iind=0) \
{ static_cast<const Derived*>(this)->assertInit(); \
try { input(iind).setSub(val); } \
catch(std::exception& e) { \
casadi_error(e.what() << "Occurred at iind = " << iind << "."); \
} \
} \
void setOutput(T val, int oind=0) \
{ static_cast<const Derived*>(this)->assertInit(); output(oind).setSub(val); } \
void setInput(T val, const std::string &iname) \
{ setInput(val, inputSchemeEntry(iname)); } \
void setOutput(T val, const std::string &oname) \
{ setOutput(val, outputSchemeEntry(oname)); } \

#ifndef DOXYGENPROC
SETTERS(double) // NOLINT(readability/casting) - false positive
SETTERS_NZ(double) // NOLINT(readability/casting) - false positive
#ifndef SWIG
SETTERS(const double*)
SETTERS_NZ(const double*)
#endif // SWIG
SETTERS(const std::vector<double>&)
SETTERS(const Matrix<double>&)
SETTERS_NZ(const std::vector<double>&)
SETTERS_SUB(const Matrix<double>&)
#endif // DOXYGENPROC

#undef SETTERS
#undef SETTERS_NZ
#undef SETTERS_SUB

#define GETTERS(T) \
#define GETTERS_NZ(T) \
void getInput(T val, int iind=0) const \
{ static_cast<const Derived*>(this)->assertInit(); input(iind).get(val);} \
void getOutput(T val, int oind=0) const \
Expand All @@ -376,15 +392,26 @@ namespace casadi {
void getOutput(T val, const std::string &oname) const \
{ getOutput(val, outputSchemeEntry(oname)); } \

#define GETTERS_SUB(T) \
void getInput(T val, int iind=0) const \
{ static_cast<const Derived*>(this)->assertInit(); input(iind).getSub(val);} \
void getOutput(T val, int oind=0) const \
{ static_cast<const Derived*>(this)->assertInit(); output(oind).getSub(val);} \
void getInput(T val, const std::string &iname) const \
{ getInput(val, inputSchemeEntry(iname)); } \
void getOutput(T val, const std::string &oname) const \
{ getOutput(val, outputSchemeEntry(oname)); } \

#ifndef DOXYGENPROC
#ifndef SWIG
GETTERS(double&)
GETTERS(double*) // NOLINT(readability/casting) - false positive
GETTERS(std::vector<double>&)
GETTERS(Matrix<double>&)
GETTERS_NZ(double&)
GETTERS_NZ(double*) // NOLINT(readability/casting) - false positive
GETTERS_NZ(std::vector<double>&)
GETTERS_SUB(Matrix<double>&)
#endif // SWIG
#endif // DOXYGENPROC
#undef GETTERS
#undef GETTERS_NZ
#undef GETTERS_SUB

};

Expand Down
4 changes: 2 additions & 2 deletions casadi/core/function/parallelizer_internal.cpp
Expand Up @@ -176,15 +176,15 @@ namespace casadi {

// Copy inputs to functions
for (int j=inind_[task]; j<inind_[task+1]; ++j) {
fcn.input(j-inind_[task]).set(input(j));
fcn.input(j-inind_[task]).setSub(input(j));
}

// Evaluate
fcn.evaluate();

// Get the results
for (int j=outind_[task]; j<outind_[task+1]; ++j) {
fcn.output(j-outind_[task]).get(output(j));
fcn.output(j-outind_[task]).getSub(output(j));
}
}

Expand Down
12 changes: 6 additions & 6 deletions casadi/core/matrix/matrix.hpp
Expand Up @@ -237,6 +237,12 @@ namespace casadi {
/// Convert to Slice (only for IMatrix)
Slice toSlice(bool ind1=false) const;

/** \brief Set all the entries without changing sparsity pattern */
void setSub(const Matrix<DataType>& val);

/** \brief Get all the entries without changing sparsity pattern */
void getSub(Matrix<DataType>& val) const;

///@{
/** \brief Get the elements numerically */
void setSub(double val);
Expand Down Expand Up @@ -672,12 +678,6 @@ namespace casadi {
/** \brief Get the non-zero elements, vector */
void get(std::vector<DataType>& val, SparsityType sp=SP_SPARSE) const;

/** \brief Set the non-zero elements, Matrix */
void set(const Matrix<DataType>& val);

/** \brief Get the non-zero elements, Matrix */
void get(Matrix<DataType>& val) const;

#ifdef SWIG
%rename(get) getStridedArray;
%rename(set) setArray;
Expand Down
8 changes: 4 additions & 4 deletions casadi/core/matrix/matrix_impl.hpp
Expand Up @@ -1024,7 +1024,7 @@ namespace casadi {
}

template<typename DataType>
void Matrix<DataType>::set(const Matrix<DataType>& val) {
void Matrix<DataType>::setSub(const Matrix<DataType>& val) {
sparsity().set(getPtr(data()), getPtr(val.data()), val.sparsity());
}

Expand Down Expand Up @@ -1070,8 +1070,8 @@ namespace casadi {
}

template<typename DataType>
void Matrix<DataType>::get(Matrix<DataType>& val) const {
val.set(*this);
void Matrix<DataType>::getSub(Matrix<DataType>& val) const {
val.setSub(*this);
}

template<typename DataType>
Expand Down Expand Up @@ -2053,7 +2053,7 @@ namespace casadi {
return setSparse(sp.patternIntersection(sparsity()), false);
} else {
Matrix<DataType> ret(sp);
ret.set(*this);
ret.setSub(*this);
return ret;
}
}
Expand Down
4 changes: 2 additions & 2 deletions casadi/core/sx/sx_element.cpp
Expand Up @@ -1455,9 +1455,9 @@ namespace casadi {

for (int dir=0; dir<vv.size(); ++dir) {
if (transpose_jacobian) {
aseed[dir][0].set(vv[dir]);
aseed[dir][0].setSub(vv[dir]);
} else {
fseed[dir][0].set(vv[dir]);
fseed[dir][0].setSub(vv[dir]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion casadi/core/sx/sx_tools.cpp
Expand Up @@ -36,7 +36,7 @@ namespace casadi {
Matrix<double> evalf(const SX &ex, const SX &v, const Matrix<double> &vdef) {
SXFunction fcn(v, ex);
fcn.init();
fcn.input(0).set(vdef);
fcn.setInput(vdef, 0);
fcn.evaluate();
return fcn.output();
}
Expand Down
2 changes: 1 addition & 1 deletion casadi/interfaces/knitro/knitro_interface.cpp
Expand Up @@ -314,7 +314,7 @@ namespace casadi {
stats_["return_status"] = status;

// Copy constraints
nlp_.output(NL_G).get(output(NLP_SOLVER_G));
nlp_.output(NL_G).getSub(output(NLP_SOLVER_G));

// Copy lagrange multipliers
output(NLP_SOLVER_LAM_G).set(getPtr(lambda));
Expand Down
22 changes: 11 additions & 11 deletions casadi/solvers/fixed_step_integrator.cpp
Expand Up @@ -87,12 +87,12 @@ namespace casadi {
while (k_<k_out) {
// Take step
F.input(DAE_T).set(t_);
F.input(DAE_X).set(output(INTEGRATOR_XF));
F.input(DAE_Z).set(Z_);
F.input(DAE_P).set(input(INTEGRATOR_P));
F.input(DAE_X).setSub(output(INTEGRATOR_XF));
F.input(DAE_Z).setSub(Z_);
F.input(DAE_P).setSub(input(INTEGRATOR_P));
F.evaluate();
F.output(DAE_ODE).get(output(INTEGRATOR_XF));
F.output(DAE_ALG).get(Z_);
F.output(DAE_ODE).getSub(output(INTEGRATOR_XF));
F.output(DAE_ALG).getSub(Z_);
transform(F.output(DAE_QUAD).begin(),
F.output(DAE_QUAD).end(),
output(INTEGRATOR_QF).begin(),
Expand Down Expand Up @@ -130,13 +130,13 @@ namespace casadi {
G.input(RDAE_T).set(t_);
G.input(RDAE_X).set(x_tape_.at(k_));
G.input(RDAE_Z).set(Z_tape_.at(k_));
G.input(RDAE_P).set(input(INTEGRATOR_P));
G.input(RDAE_RX).set(output(INTEGRATOR_RXF));
G.input(RDAE_RZ).set(RZ_);
G.input(RDAE_RP).set(input(INTEGRATOR_RP));
G.input(RDAE_P).setSub(input(INTEGRATOR_P));
G.input(RDAE_RX).setSub(output(INTEGRATOR_RXF));
G.input(RDAE_RZ).setSub(RZ_);
G.input(RDAE_RP).setSub(input(INTEGRATOR_RP));
G.evaluate();
G.output(RDAE_ODE).get(output(INTEGRATOR_RXF));
G.output(RDAE_ALG).get(RZ_);
G.output(RDAE_ODE).getSub(output(INTEGRATOR_RXF));
G.output(RDAE_ALG).getSub(RZ_);
transform(G.output(RDAE_QUAD).begin(),
G.output(RDAE_QUAD).end(),
output(INTEGRATOR_RQF).begin(),
Expand Down
4 changes: 2 additions & 2 deletions casadi/solvers/implicit_to_nlp.cpp
Expand Up @@ -75,7 +75,7 @@ namespace casadi {
}

// Pass initial guess
solver_.input(NLP_SOLVER_X0).set(output(iout_));
solver_.input(NLP_SOLVER_X0).setSub(output(iout_));

// Add auxiliary inputs
vector<double>::iterator nlp_p = solver_.input(NLP_SOLVER_P).begin();
Expand All @@ -91,7 +91,7 @@ namespace casadi {
stats_["solver_stats"] = solver_.getStats();

// Get the implicit variable
output(iout_).set(solver_.output(NLP_SOLVER_X));
output(iout_).setSub(solver_.output(NLP_SOLVER_X));

// Evaluate auxilary outputs, if necessary
if (getNumOutputs()>0) {
Expand Down
20 changes: 10 additions & 10 deletions casadi/solvers/lp_to_qp.cpp
Expand Up @@ -65,14 +65,14 @@ namespace casadi {
void LpToQp::evaluate() {

// Pass inputs of LP to QP form
solver_.input(QP_SOLVER_A).set(input(LP_SOLVER_A));
solver_.input(QP_SOLVER_G).set(input(LP_SOLVER_C));
solver_.input(QP_SOLVER_A).setSub(input(LP_SOLVER_A));
solver_.input(QP_SOLVER_G).setSub(input(LP_SOLVER_C));

solver_.input(QP_SOLVER_LBX).set(input(LP_SOLVER_LBX));
solver_.input(QP_SOLVER_UBX).set(input(LP_SOLVER_UBX));
solver_.input(QP_SOLVER_LBX).setSub(input(LP_SOLVER_LBX));
solver_.input(QP_SOLVER_UBX).setSub(input(LP_SOLVER_UBX));

solver_.input(QP_SOLVER_LBA).set(input(LP_SOLVER_LBA));
solver_.input(QP_SOLVER_UBA).set(input(LP_SOLVER_UBA));
solver_.input(QP_SOLVER_LBA).setSub(input(LP_SOLVER_LBA));
solver_.input(QP_SOLVER_UBA).setSub(input(LP_SOLVER_UBA));

// Delegate computation to NLP Solver
solver_.evaluate();
Expand All @@ -81,10 +81,10 @@ namespace casadi {
stats_["qp_solver_stats"] = solver_.getStats();

// Read the outputs from Ipopt
output(QP_SOLVER_X).set(solver_.output(LP_SOLVER_X));
output(QP_SOLVER_COST).set(solver_.output(LP_SOLVER_COST));
output(QP_SOLVER_LAM_A).set(solver_.output(LP_SOLVER_LAM_A));
output(QP_SOLVER_LAM_X).set(solver_.output(LP_SOLVER_LAM_X));
output(QP_SOLVER_X).setSub(solver_.output(LP_SOLVER_X));
output(QP_SOLVER_COST).setSub(solver_.output(LP_SOLVER_COST));
output(QP_SOLVER_LAM_A).setSub(solver_.output(LP_SOLVER_LAM_A));
output(QP_SOLVER_LAM_X).setSub(solver_.output(LP_SOLVER_LAM_X));
}

void LpToQp::init() {
Expand Down
8 changes: 4 additions & 4 deletions casadi/solvers/old_collocation_integrator.cpp
Expand Up @@ -436,7 +436,7 @@ namespace casadi {

// Pass the inputs
for (int iind=0; iind<INTEGRATOR_NUM_IN; ++iind) {
implicit_solver_.input(1+iind).set(input(iind));
implicit_solver_.input(1+iind).setSub(input(iind));
}

// Pass solution guess (if this is the first integration or if hotstart is disabled)
Expand All @@ -449,7 +449,7 @@ namespace casadi {
// Use supplied integrator, if any
if (has_startup_integrator) {
for (int iind=0; iind<INTEGRATOR_NUM_IN; ++iind) {
startup_integrator_.input(iind).set(input(iind));
startup_integrator_.input(iind).setSub(input(iind));
}

// Reset the integrator
Expand Down Expand Up @@ -514,7 +514,7 @@ namespace casadi {
implicit_solver_.evaluate();

// Save the result
implicit_solver_.output().set(implicit_solver_.input());
implicit_solver_.output().setSub(implicit_solver_.input());

// Write out profiling information
if (CasadiOptions::profiling && !CasadiOptions::profilingBinary) {
Expand All @@ -534,7 +534,7 @@ namespace casadi {

void OldCollocationIntegrator::integrate(double t_out) {
for (int oind=0; oind<INTEGRATOR_NUM_OUT; ++oind) {
output(oind).set(implicit_solver_.output(1+oind));
output(oind).setSub(implicit_solver_.output(1+oind));
}
}

Expand Down
4 changes: 2 additions & 2 deletions casadi/solvers/qcqp_to_socp.cpp
Expand Up @@ -157,8 +157,8 @@ namespace casadi {
stats_["socp_solver_stats"] = solver_.getStats();

// Read the outputs from SOCP Solver
output(SOCP_SOLVER_COST).set(solver_.output(QCQP_SOLVER_COST));
output(SOCP_SOLVER_LAM_A).set(solver_.output(QCQP_SOLVER_LAM_A));
output(SOCP_SOLVER_COST).setSub(solver_.output(QCQP_SOLVER_COST));
output(SOCP_SOLVER_LAM_A).setSub(solver_.output(QCQP_SOLVER_LAM_A));
std::copy(solver_.output(QCQP_SOLVER_X).begin(),
solver_.output(QCQP_SOLVER_X).begin()+n_,
output(SOCP_SOLVER_X).begin());
Expand Down

0 comments on commit 81bb14b

Please sign in to comment.