Skip to content

Commit

Permalink
Get rid of amici.swig_wrappers.ExpData
Browse files Browse the repository at this point in the history
The old implementation prevented using e.g. `isinstance(x, amici.ExpData)`.

Closes AMICI-dev#2380
  • Loading branch information
dweindl committed Apr 16, 2024
1 parent d993362 commit 87c34fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
27 changes: 0 additions & 27 deletions python/sdist/amici/swig_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
__all__ = [
"runAmiciSimulation",
"runAmiciSimulations",
"ExpData",
"readSolverSettingsFromHDF5",
"writeSolverSettingsToHDF5",
"set_model_settings",
Expand Down Expand Up @@ -128,32 +127,6 @@ def runAmiciSimulation(
return numpy.ReturnDataView(rdata)


def ExpData(*args) -> "amici_swig.ExpData":
"""
Convenience wrapper for :py:class:`amici.amici.ExpData` constructors
:param args: arguments
:returns: ExpData Instance
"""
if not args:
return amici_swig.ExpData()

if isinstance(args[0], numpy.ReturnDataView):
return amici_swig.ExpData(_get_ptr(args[0]["ptr"]), *args[1:])

if isinstance(args[0], (amici_swig.ExpData, amici_swig.ExpDataPtr)):
# the *args[:1] should be empty, but by the time you read this,
# the constructor signature may have changed, and you are glad this
# wrapper did not break.
return amici_swig.ExpData(_get_ptr(args[0]), *args[1:])

if isinstance(args[0], (amici_swig.Model, amici_swig.ModelPtr)):
return amici_swig.ExpData(_get_ptr(args[0]))

return amici_swig.ExpData(*args)


def runAmiciSimulations(
model: AmiciModel,
solver: AmiciSolver,
Expand Down
26 changes: 26 additions & 0 deletions swig/edata.i
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ def _edata_repr(self: "ExpData"):
%}
%extend amici::ExpData {
%pythoncode %{
def __new__(cls, *args, **kwargs):
"""
Convenience wrapper for :py:class:`amici.amici.ExpData` constructors
:param args: arguments
:returns: ExpData Instance
"""
if not args:
return super().__new__(cls)

if isinstance(args[0], numpy.ReturnDataView):
return super().__new__(cls, _get_ptr(args[0]["ptr"]), *args[1:])

if isinstance(args[0], (amici_swig.ExpData, amici_swig.ExpDataPtr)):
# the *args[:1] should be empty, but by the time you read this,
# the constructor signature may have changed, and you are glad this
# wrapper did not break.
return super().__new__(cls, _get_ptr(args[0]), *args[1:])

if isinstance(args[0], (amici_swig.Model, amici_swig.ModelPtr)):
return super().__new__(cls, _get_ptr(args[0]))

return super().__new__(cls, *args)


def __repr__(self):
return _edata_repr(self)

Expand Down

0 comments on commit 87c34fa

Please sign in to comment.