def determine_context(definition_context, args): """Determine the Context for a function. Parameters ---------- definition_context: Context object The Context in which the function was defined. args : iterable List of objects to inspect for context. Objects that aren't of type DistArray are skipped. Returns ------- Context If all provided DistArray objects have the same context. Raises ------ ValueError Raised if all DistArray objects don't have the same context. """ contexts = [definition_context] + [arg.context for arg in args if isinstance(arg, DistArray)] if not all_equal(contexts): errmsg = "All DistArray objects must be defined with the same context used for the function: {}" raise ValueError(errmsg.format(contexts)) else: return contexts[0]
def test_all_equal_vacuously_true(self): self.assertTrue(utils.all_equal([])) self.assertTrue(utils.all_equal([99]))
def test_all_equal_true(self): self.assertTrue(utils.all_equal([7, 7, 7, 7, 7]))
def test_all_equal_false(self): self.assertFalse(utils.all_equal([1, 2, 3, 4, 5]))