Skip to content

Commit

Permalink
Merge pull request #274 from HDembinski/issue_272
Browse files Browse the repository at this point in the history
removed copy method, added nicer repr, test repr
  • Loading branch information
HDembinski authored Jul 9, 2018
2 parents 4d9a17d + 0e673f5 commit 5fe1999
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
24 changes: 11 additions & 13 deletions iminuit/_libiminuit.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,11 @@ cdef class BasicView:
cdef int i = key if isinstance(key, (int, long)) else self._minuit.var2pos[key]
self._set(i, value)

def copy(self):
return dict(self)

def __str__(self):
s = "%s{" % self.__class__.__name__
items = [" '{0}'={1}".format(k, v) for (k, v) in self.items()]
s += ",\n".join(items)
s += "\n}"
def __repr__(self):
s = "<%s of Minuit at %x>" % (self.__class__.__name__, id(self._minuit))
for (k, v) in self.items():
s += "\n {0}: {1}".format(k, v)
s += "\n"
return s


Expand All @@ -166,11 +163,12 @@ cdef class ArgsView:
raise IndexError
self._state.SetValue(i, value)

def copy(self):
return tuple(self)

def __str__(self):
return 'ArgsView[' + ', '.join(str(x) for x in self) + ']'
def __repr__(self):
s = "<ArgsView of Minuit at %x>" % id(self._minuit)
for v in self:
s += "\n {0}".format(v)
s += "\n"
return s


cdef class ValueView(BasicView):
Expand Down
14 changes: 14 additions & 0 deletions iminuit/tests/test_iminuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ def test_from_array_func_with_broadcasting():
assert_allclose(np.diag(c), (1, 1))


def test_view_repr():
m = Minuit(func3, print_level=0, errordef=1,
x=1, y=2, error_x=3, error_y=4)
mid = id(m)
assert repr(m.values) == """<ValueView of Minuit at %x>
x: 1.0
y: 2.0
""" % mid
assert repr(m.args) == """<ArgsView of Minuit at %x>
1.0
2.0
""" % mid


def test_no_resume():
m = Minuit(func3, print_level=0, pedantic=False)
m.migrad()
Expand Down

0 comments on commit 5fe1999

Please sign in to comment.