Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Apr 16, 2024
1 parent cf95f32 commit 37e84bd
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions swig/edata.i
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ using namespace amici;

%ignore ConditionContext;

%feature("pythonprepend") ExpData::ExpData %{
"""
Convenience wrapper for :py:class:`amici.amici.ExpData` constructors
:param args: arguments
:returns: ExpData Instance
"""
if args:
from amici.numpy import ReturnDataView

# Get the raw pointer if necessary
if isinstance(args[0], (ExpData, ExpDataPtr, ReturnDataView, Model, ModelPtr)):
args[0] = _get_ptr(args[0]["ptr"])
%}

// ExpData.__repr__
%pythoncode %{
def _edata_repr(self: "ExpData"):
Expand Down Expand Up @@ -72,34 +88,6 @@ 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)

from amici.numpy import ReturnDataView

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

if isinstance(args[0], (ExpData, 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], (Model, 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 37e84bd

Please sign in to comment.