Skip to content

Commit

Permalink
change name back to is_reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbybp committed Jan 14, 2021
1 parent d886b72 commit 98eb6fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions pyomo/core/base/indexed_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def is_indexed(self):
"""Return true if this component is indexed"""
return self._index is not UnindexedComponent_set

def owns_data(self):
""" Return True if this component owns its data. """
return self._data is None or type(self._data) is dict
def is_reference(self):
""" Return True if this component is a reference. """
return self._data is not None and type(self._data) is not dict

def dim(self):
"""Return the dimension of the index"""
Expand Down Expand Up @@ -290,7 +290,7 @@ def __iter__(self):
# user iterates over the set when the _data dict is empty.
#
return self._data.__iter__()
elif not self.owns_data():
elif self.is_reference():
return self._data.__iter__()
elif len(self._data) == len(self._index):
#
Expand Down
7 changes: 3 additions & 4 deletions pyomo/core/pyomoobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def is_logical_type(self):
"""Return True if this class is a Pyomo Boolean value, variable, or expression."""
return False

def owns_data(self):
"""Return True if this object is the owner of its data. Each data
object should have exactly one owner."""
return True
def is_reference(self):
"""Return True if this object is a reference."""
return False
4 changes: 2 additions & 2 deletions pyomo/core/tests/unit/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def test_component_data_pprint(self):
'2 : None : None : None : False : True : Reals\n'
self.assertEqual(correct_s, stream.getvalue())

def test_owns_data(self):
def test_is_reference(self):
m = ConcreteModel()
class _NotSpecified(object):
pass
m.comp = Component(ctype=_NotSpecified)
self.assertTrue(m.comp.owns_data())
self.assertFalse(m.comp.is_reference())

class TestEnviron(unittest.TestCase):

Expand Down
12 changes: 6 additions & 6 deletions pyomo/core/tests/unit/test_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,22 +804,22 @@ def test_reference_to_list(self):
KeyError, "Index '1' is not valid for indexed component 'r'"):
m.r[1] = m.x

def test_owns_data(self):
def test_is_reference(self):
m = ConcreteModel()
m.v0 = Var()
m.v1 = Var([1,2,3])

m.ref0 = Reference(m.v0)
m.ref1 = Reference(m.v1)

self.assertTrue(m.v0.owns_data())
self.assertTrue(m.v1.owns_data())
self.assertFalse(m.v0.is_reference())
self.assertFalse(m.v1.is_reference())

self.assertFalse(m.ref0.owns_data())
self.assertFalse(m.ref1.owns_data())
self.assertTrue(m.ref0.is_reference())
self.assertTrue(m.ref1.is_reference())

unique_vars = list(
v for v in m.component_objects(Var) if v.owns_data())
v for v in m.component_objects(Var) if not v.is_reference())
self.assertEqual(len(unique_vars), 2)

def test_referent(self):
Expand Down

0 comments on commit 98eb6fd

Please sign in to comment.