Skip to content

Commit

Permalink
#1360 Removed Matrix::set(vector<double>), get(vector<double>)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed Mar 17, 2015
1 parent 397d97a commit b7eda81
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 49 deletions.
6 changes: 0 additions & 6 deletions casadi/core/matrix/matrix.hpp
Expand Up @@ -678,12 +678,6 @@ namespace casadi {
Sparsity getSparsity() const { return sparsity();}

/// \cond INTERNAL
/** \brief Set the non-zero elements, vector */
void set(const std::vector<DataType>& val);

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

#ifdef SWIG
%rename(get) getStridedArray;
%rename(set) setArray;
Expand Down
10 changes: 0 additions & 10 deletions casadi/core/matrix/matrix_impl.hpp
Expand Up @@ -1003,16 +1003,6 @@ namespace casadi {
}
}

template<typename DataType>
void Matrix<DataType>::set(const std::vector<DataType>& val) {
setArray(val.empty() ? 0 : &val.front(), val.size());
}

template<typename DataType>
void Matrix<DataType>::get(std::vector<DataType>& val) const {
getArray(val.empty() ? 0 : &val.front(), val.size());
}

template<typename DataType>
void Matrix<DataType>::setSub(const Matrix<DataType>& val) {
sparsity().set(getPtr(data()), getPtr(val.data()), val.sparsity());
Expand Down
10 changes: 5 additions & 5 deletions casadi/solvers/fixed_step_integrator.cpp
Expand Up @@ -101,8 +101,8 @@ namespace casadi {

// Tape
if (nrx_>0) {
output(INTEGRATOR_XF).get(x_tape_.at(k_+1));
Z_.get(Z_tape_.at(k_));
output(INTEGRATOR_XF).getNZ(x_tape_.at(k_+1));
Z_.getNZ(Z_tape_.at(k_));
}

// Advance time
Expand All @@ -128,8 +128,8 @@ namespace casadi {

// Take step
G.input(RDAE_T).setSub(t_);
G.input(RDAE_X).set(x_tape_.at(k_));
G.input(RDAE_Z).set(Z_tape_.at(k_));
G.input(RDAE_X).setNZ(x_tape_.at(k_));
G.input(RDAE_Z).setNZ(Z_tape_.at(k_));
G.input(RDAE_P).setSub(input(INTEGRATOR_P));
G.input(RDAE_RX).setSub(output(INTEGRATOR_RXF));
G.input(RDAE_RZ).setSub(RZ_);
Expand Down Expand Up @@ -157,7 +157,7 @@ namespace casadi {

// Add the first element in the tape
if (nrx_>0) {
output(INTEGRATOR_XF).get(x_tape_.at(0));
output(INTEGRATOR_XF).getNZ(x_tape_.at(0));
}
}

Expand Down
8 changes: 4 additions & 4 deletions casadi/solvers/scpgen.cpp
Expand Up @@ -800,10 +800,10 @@ namespace casadi {

// Save results to outputs
output(NLP_SOLVER_F).setSub(f_);
output(NLP_SOLVER_X).set(x_opt_);
output(NLP_SOLVER_LAM_G).set(g_lam_);
output(NLP_SOLVER_LAM_X).set(x_lam_);
output(NLP_SOLVER_G).set(g_);
output(NLP_SOLVER_X).setNZ(x_opt_);
output(NLP_SOLVER_LAM_G).setNZ(g_lam_);
output(NLP_SOLVER_LAM_X).setNZ(x_lam_);
output(NLP_SOLVER_G).setNZ(g_);

// Write timers
if (print_time_) {
Expand Down
16 changes: 8 additions & 8 deletions casadi/solvers/sqpmethod.cpp
Expand Up @@ -333,10 +333,10 @@ namespace casadi {
double time1 = clock();

if (!output(NLP_SOLVER_F).isEmpty()) output(NLP_SOLVER_F).setSub(fk_);
if (!output(NLP_SOLVER_X).isEmpty()) output(NLP_SOLVER_X).set(x_);
if (!output(NLP_SOLVER_LAM_G).isEmpty()) output(NLP_SOLVER_LAM_G).set(mu_);
if (!output(NLP_SOLVER_LAM_X).isEmpty()) output(NLP_SOLVER_LAM_X).set(mu_x_);
if (!output(NLP_SOLVER_G).isEmpty()) output(NLP_SOLVER_G).set(gk_);
if (!output(NLP_SOLVER_X).isEmpty()) output(NLP_SOLVER_X).setNZ(x_);
if (!output(NLP_SOLVER_LAM_G).isEmpty()) output(NLP_SOLVER_LAM_G).setNZ(mu_);
if (!output(NLP_SOLVER_LAM_X).isEmpty()) output(NLP_SOLVER_LAM_X).setNZ(mu_x_);
if (!output(NLP_SOLVER_G).isEmpty()) output(NLP_SOLVER_G).setNZ(gk_);

Dictionary iteration;
iteration["iter"] = iter;
Expand Down Expand Up @@ -565,10 +565,10 @@ namespace casadi {

// Save results to outputs
output(NLP_SOLVER_F).setSub(fk_);
output(NLP_SOLVER_X).set(x_);
output(NLP_SOLVER_LAM_G).set(mu_);
output(NLP_SOLVER_LAM_X).set(mu_x_);
output(NLP_SOLVER_G).set(gk_);
output(NLP_SOLVER_X).setNZ(x_);
output(NLP_SOLVER_LAM_G).setNZ(mu_);
output(NLP_SOLVER_LAM_X).setNZ(mu_x_);
output(NLP_SOLVER_G).setNZ(gk_);

if (hasOption("print_time") && static_cast<bool>(getOption("print_time"))) {
// Write timings
Expand Down
16 changes: 8 additions & 8 deletions casadi/solvers/stabilized_sqp.cpp
Expand Up @@ -406,10 +406,10 @@ namespace casadi {
// Call callback function if present
if (!callback_.isNull()) {
if (!output(NLP_SOLVER_F).isEmpty()) output(NLP_SOLVER_F).setSub(fk_);
if (!output(NLP_SOLVER_X).isEmpty()) output(NLP_SOLVER_X).set(x_);
if (!output(NLP_SOLVER_LAM_G).isEmpty()) output(NLP_SOLVER_LAM_G).set(mu_);
if (!output(NLP_SOLVER_LAM_X).isEmpty()) output(NLP_SOLVER_LAM_X).set(mu_x_);
if (!output(NLP_SOLVER_G).isEmpty()) output(NLP_SOLVER_G).set(gk_);
if (!output(NLP_SOLVER_X).isEmpty()) output(NLP_SOLVER_X).setNZ(x_);
if (!output(NLP_SOLVER_LAM_G).isEmpty()) output(NLP_SOLVER_LAM_G).setNZ(mu_);
if (!output(NLP_SOLVER_LAM_X).isEmpty()) output(NLP_SOLVER_LAM_X).setNZ(mu_x_);
if (!output(NLP_SOLVER_G).isEmpty()) output(NLP_SOLVER_G).setNZ(gk_);
int ret = callback_(ref_, user_data_);

if (!ret) {
Expand Down Expand Up @@ -812,10 +812,10 @@ namespace casadi {

// Save results to outputs
output(NLP_SOLVER_F).setSub(fk_);
output(NLP_SOLVER_X).set(x_);
output(NLP_SOLVER_LAM_G).set(mu_);
output(NLP_SOLVER_LAM_X).set(mu_x_);
output(NLP_SOLVER_G).set(gk_);
output(NLP_SOLVER_X).setNZ(x_);
output(NLP_SOLVER_LAM_G).setNZ(mu_);
output(NLP_SOLVER_LAM_X).setNZ(mu_x_);
output(NLP_SOLVER_G).setNZ(gk_);

// Save statistics
stats_["iter_count"] = iter;
Expand Down
12 changes: 6 additions & 6 deletions test/python/function.py
Expand Up @@ -917,7 +917,7 @@ def adj(self,(x,y),(z,),seeds,sens):
bz1 += bz2*cos(z1)
bx0+= bz1;bz0+= bz1
by+= 3*bz0
x_bar.set([bx0,bx1])
x_bar.setSub([bx0,bx1])
y_bar.setSub(by)

Fun = PyFunction(Fun(),[Sparsity.dense(2,1),Sparsity.dense(1,1)], [Sparsity.dense(1,1)])
Expand Down Expand Up @@ -971,27 +971,27 @@ class Squares:
def evaluate(self,(X,),(Y,)):
x = X[0]
y = X[1]
Y.set([x**2+y,x*y])
Y.setSub([x**2+y,x*y])

def fwd(self,(X,),(Y,),seeds,sens):
assert(max_fwd)
x = X[0]
y = X[1]
Y.set([x**2+y,x*y])
Y.setSub([x**2+y,x*y])
for ((Xdot,),(Zdot,)) in zip(seeds,sens):
xdot = Xdot[0]
ydot = Xdot[1]
Zdot.set([2*x*xdot+ydot,y*xdot+x*ydot])
Zdot.setSub([2*x*xdot+ydot,y*xdot+x*ydot])

def adj(self,(X,),(Y,),seeds,sens):
assert(max_adj)
x = X[0]
y = X[1]
Y.set([x**2+y,x*y])
Y.setSub([x**2+y,x*y])
for ((Y_bar,),(X_bar,)) in zip(seeds,sens):
xb = Y_bar[0]
yb = Y_bar[1]
X_bar.set([2*x*xb+y*yb,xb+x*yb])
X_bar.setSub([2*x*xb+y*yb,xb+x*yb])

c = PyFunction(Squares(),[Sparsity.dense(2,1)], [Sparsity.dense(2,1)])
if max_adj and not max_fwd:
Expand Down
13 changes: 11 additions & 2 deletions test/python/typemaps.py
Expand Up @@ -425,14 +425,23 @@ def test_set(self):
"list" : goallist,
"tuple" : tuple(goallist),
"array1ddouble" : array(goallist,dtype=double),
"array2ddouble" : array([goallist],dtype=double).T,
"array1dint" : array(goallist),
"array2dint" : array([goallist]).T,
"mixed" : [1,DMatrix(2),array(3)]
}
w=DMatrix(goal)
self.checkarray(w,goal,"Constructor")

for name, value in test.items():
w.setNZ(value)
self.checkarray(w,goal,"name")

test={
"array2ddouble" : array([goallist],dtype=double).T,
"array2dint" : array([goallist]).T,
}
w=DMatrix(goal)
self.checkarray(w,goal,"Constructor")

for name, value in test.items():
w.set(value)
self.checkarray(w,goal,"name")
Expand Down

0 comments on commit b7eda81

Please sign in to comment.