diff --git a/python/tests/test_swig_interface.py b/python/tests/test_swig_interface.py index 6a7cfec855..e8dd478cab 100644 --- a/python/tests/test_swig_interface.py +++ b/python/tests/test_swig_interface.py @@ -471,3 +471,19 @@ def test_expdata_and_expdataview_are_deepcopyable(): ev2 = copy.deepcopy(ev1) assert ev2._swigptr.this != ev1._swigptr.this assert ev1 == ev2 + + +def test_solvers_are_deepcopyable(): + for solver_type in (amici.CVodeSolver, amici.IDASolver): + for solver1 in (solver_type(), amici.SolverPtr(solver_type())): + solver2 = copy.deepcopy(solver1) + assert solver1.this != solver2.this + assert ( + solver1.getRelativeTolerance() + == solver2.getRelativeTolerance() + ) + solver2.setRelativeTolerance(100 * solver2.getRelativeTolerance()) + assert ( + solver1.getRelativeTolerance() + != solver2.getRelativeTolerance() + ) diff --git a/swig/solver.i b/swig/solver.i index 992842c409..20641ba31f 100644 --- a/swig/solver.i +++ b/swig/solver.i @@ -113,9 +113,18 @@ def __repr__(self): %pythoncode %{ def __repr__(self): return _solver_repr(self) + +def __deepcopy__(self, memo): + return self.clone() %} }; +%extend amici::Solver { +%pythoncode %{ +def __deepcopy__(self, memo): + return self.clone() +%} +}; %newobject amici::Solver::clone; // Process symbols in header diff --git a/swig/std_unique_ptr.i b/swig/std_unique_ptr.i index 1063bd75b1..c44513bcee 100644 --- a/swig/std_unique_ptr.i +++ b/swig/std_unique_ptr.i @@ -6,8 +6,11 @@ namespace std { struct unique_ptr { typedef Type* pointer; + %apply SWIGTYPE *DISOWN { pointer Ptr }; explicit unique_ptr( pointer Ptr ); + %clear pointer Ptr; unique_ptr (unique_ptr&& Right); + template unique_ptr( unique_ptr&& Right ); unique_ptr( const unique_ptr& Right) = delete;