From f907e8caf95bf8722a8dc538bf237f0a884c3947 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Sun, 17 Dec 2023 20:29:06 +0100 Subject: [PATCH] SolverPtr --- python/tests/test_swig_interface.py | 18 ++++++++++++------ swig/solver.i | 3 +++ swig/std_unique_ptr.i | 3 +++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/python/tests/test_swig_interface.py b/python/tests/test_swig_interface.py index 189c836506..e8dd478cab 100644 --- a/python/tests/test_swig_interface.py +++ b/python/tests/test_swig_interface.py @@ -475,9 +475,15 @@ def test_expdata_and_expdataview_are_deepcopyable(): def test_solvers_are_deepcopyable(): for solver_type in (amici.CVodeSolver, amici.IDASolver): - solver1 = 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() + 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 f48f3ff71d..20641ba31f 100644 --- a/swig/solver.i +++ b/swig/solver.i @@ -113,6 +113,9 @@ def __repr__(self): %pythoncode %{ def __repr__(self): return _solver_repr(self) + +def __deepcopy__(self, memo): + return self.clone() %} }; 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;