Skip to content

Commit

Permalink
#1360 Return-by-value in SWIG for all Matrix::get* overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeandersson committed Mar 20, 2015
1 parent 972df10 commit 7347188
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
14 changes: 11 additions & 3 deletions casadi/core/matrix/matrix.hpp
Expand Up @@ -240,8 +240,10 @@ namespace casadi {
/** \brief Set all the entries without changing sparsity pattern */
void set(const Matrix<DataType>& val);

#ifndef SWIG
/** \brief Get all the entries without changing sparsity pattern */
void get(Matrix<DataType>& val) const;
#endif // SWIG

///@{
/** \brief Get the elements numerically */
Expand All @@ -252,9 +254,11 @@ namespace casadi {

///@{
/** \brief Get the elements numerically */
#ifndef SWIG
void get(double& val) const;
void get(double* val, bool tr=false) const;
void get(std::vector<double>& val, bool tr=false) const;
#endif // SWIG
void get(std::vector<double>& SWIG_OUTPUT(m), bool tr=false) const;
///@}

///@{
Expand Down Expand Up @@ -308,9 +312,11 @@ namespace casadi {

///@{
/** \brief Get the elements numerically */
#ifndef SWIG
void getNZ(double& val) const;
void getNZ(double* val) const;
void getNZ(std::vector<double>& val) const;
#endif // SWIG
void getNZ(std::vector<double>& SWIG_OUTPUT(m)) const;
///@}

///@{
Expand All @@ -321,8 +327,10 @@ namespace casadi {

///@{
/** \brief Get upper triangular elements */
#ifndef SWIG
void getSym(double* val) const;
void getSym(std::vector<double>& val) const;
#endif // SWIG
void getSym(std::vector<double>& SWIG_OUTPUT(m)) const;
///@}

///@{
Expand Down
6 changes: 3 additions & 3 deletions casadi/core/matrix/matrix_impl.hpp
Expand Up @@ -2914,7 +2914,7 @@ namespace casadi {

template<typename DataType>
void Matrix<DataType>::get(std::vector<double>& val, bool tr) const {
casadi_assert(val.size()==this->numel());
val.resize(this->numel());
get(getPtr(val), tr);
}

Expand Down Expand Up @@ -2959,13 +2959,13 @@ namespace casadi {

template<typename DataType>
void Matrix<DataType>::getNZ(std::vector<double>& val) const {
casadi_assert(val.size()==this->nnz());
val.resize(this->nnz());
getNZ(getPtr(val));
}

template<typename DataType>
void Matrix<DataType>::getSym(std::vector<double>& val) const {
casadi_assert(val.size()==this->sizeU());
val.resize(this->sizeU());
getSym(getPtr(val));
}

Expand Down
3 changes: 1 addition & 2 deletions test/python/matrix.py
Expand Up @@ -634,9 +634,8 @@ def test_sparsesym(self):
self.message("sparsesym")
D = DMatrix([[1,2,-3],[2,-1,0],[-3,0,5]])
D = sparsify(D)
i = DVector([0]*5)

D.getSym(i)
i = D.getSym()
#self.checkarray(list(i),[1,2,-1,-3,5])
A = 2*D
A.setSym(i)
Expand Down

1 comment on commit 7347188

@casadibot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found BROKEN by full.
s (--ignore_memory_light)'
test_jacobian_tools (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_kron (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_matrix_expand (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_mul (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_mul_sparsity (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_mul_zero_wrong (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_mxnull (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_mxnullop (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_mxnulloutput (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_null (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_printLimiting (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_regression491 (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_repmat (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_reshape (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_reshape_sp (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_scalarMX (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_setSparse (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_singularcat (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_sparsity_indexing (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_subsass (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_symbolcheck (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_ticket (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_trans (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_transpose_bug (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_tril2symm (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_truth (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_unite (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_veccats (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_vertcat (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_vertcat_empty (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_vertcat_simp (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_vertsplit (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_vertsplit_derivative (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'
test_vertsplit_simp (main.MXtests) ... skipped 'Ignoring memory_light tests (--ignore_memory_light)'

ERROR: test_MXConstant (main.MXtests)

Traceback (most recent call last):
File "mx.py", line 2014, in test_MXConstant
self.checkarray(f.getOutput(),numpyop([x1_,x2_]),str([sp,sp2,v1,v2,name]))
File "mx.py", line 132, in
self.matrixbinarypool.append(lambda a: mul(a[0],a[1].T),lambda a: dot(a[0],a[1].T),"mul(Matrix,Matrix.T)")
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

ERROR: test_MX_shapes (main.MXtests)

Traceback (most recent call last):
File "mx.py", line 1955, in test_MX_shapes
self.checkarray(f.getOutput(),numpyop([x1_,x2_]),str([sp,sp2,v1,v2,x1_,x2_,name]))
File "mx.py", line 132, in
self.matrixbinarypool.append(lambda a: mul(a[0],a[1].T),lambda a: dot(a[0],a[1].T),"mul(Matrix,Matrix.T)")
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()


Ran 102 tests in 21.588s

FAILED (errors=2, skipped=100)

  1. nlp.py
  2. vectortools.py
  3. function.py
  4. lpsolver.py
  5. ad.py
  6. socpsolver.py
  7. sx.py
  8. mx_jacobian_sparsity.py
    Ran 26 tests, 2 fails.
    make: *** [unittests_py] Error 1

Please sign in to comment.