def test_init(op_list): def validate(x): return isinstance(x, DummyOperation) # Test automatic to_synced_list function generation slist = SyncedList(validation_func=validate) assert slist._validate == validate op = DummyOperation() assert slist._to_synced_list_conversion(op) is op # Test specified to_synced_list def cpp_identity(x): return x._cpp_obj slist = SyncedList(validation_func=validate, to_synced_list=cpp_identity) assert slist._to_synced_list_conversion == cpp_identity op._cpp_obj = 2 assert slist._to_synced_list_conversion(op) == 2 # Test full initialziation slist = SyncedList(validation_func=validate, to_synced_list=cpp_identity, iterable=op_list) assert len(slist._list) == 3 assert all(op._added for op in slist)
def __init__(self): self._compute = list() self._scheduled = False self._updaters = SyncedList(OnlyType(Updater), _triggered_op_conversion) self._writers = SyncedList(OnlyType(Writer), _triggered_op_conversion) self._tuners = SyncedList(OnlyType(Tuner), lambda x: x._cpp_obj) self._computes = SyncedList(OnlyType(Compute), lambda x: x._cpp_obj) self._integrator = None self._tuners.append(ParticleSorter())
def __init__(self, walls=None, to_cpp=identity): self._walls = [] self._backend_list_index = [] self._backend_lists = { Sphere: SyncedList(Sphere, to_synced_list=to_cpp, attach_members=False), Cylinder: SyncedList(Cylinder, to_synced_list=to_cpp, attach_members=False), Plane: SyncedList(Plane, to_synced_list=to_cpp, attach_members=False) } if walls is None: return self.extend(walls)
def __init__(self, forces, constraints, methods): forces = [] if forces is None else forces constraints = [] if constraints is None else constraints methods = [] if methods is None else methods self._forces = SyncedList(lambda x: isinstance(x, Force), to_synced_list=lambda x: x._cpp_obj, iterable=forces) self._constraints = SyncedList( lambda x: isinstance(x, ConstraintForce), to_synced_list=lambda x: x._cpp_obj, iterable=constraints) self._methods = SyncedList(lambda x: isinstance(x, _Method), to_synced_list=lambda x: x._cpp_obj, iterable=methods)
def empty_collection(self, item_cls, attached, attach_items): list_ = SyncedList(validation=_PartialIsInstance(item_cls), attach_members=attach_items) if attached: self._synced_list = [] list_._sync(DummySimulation(), self._synced_list) return list_
def test_synced(self): test_list = SyncedList(lambda x: x) assert not test_list._synced test_list._sync(None, []) assert test_list._synced test_list._unsync() assert not test_list._synced
def test_attach(): triggered_op = DummyTriggeredOp(trigger=1) sim = DummySimulation() slist = SyncedList(lambda x: isinstance(x, DummyTriggeredOp), lambda x: (x._cpp_obj, x.trigger)) slist.append(triggered_op) triggered_op._cpp_obj = DummyCppObj() slist._sync(sim, sim._cpp_sys.dummy_list) assert len(sim._cpp_sys.dummy_list) == 1 assert len(sim._cpp_sys.dummy_list[0]) == 2 assert triggered_op._cpp_obj == sim._cpp_sys.dummy_list[0][0] assert triggered_op.trigger == sim._cpp_sys.dummy_list[0][1]
def test_init(self, generate_plain_collection, item_cls): validate = _PartialIsInstance(item_cls) # Test automatic to_synced_list function generation synced_list = SyncedList(validation=validate) assert synced_list._validate == validate op = item_cls() assert synced_list._to_synced_list_conversion(op) is op # Test specified to_synced_list def cpp_identity(x): return x._cpp_obj # Test full initialziation plain_list = generate_plain_collection(5) synced_list = SyncedList(validation=validate, to_synced_list=cpp_identity, iterable=plain_list) assert synced_list._to_synced_list_conversion == cpp_identity op._cpp_obj = 2 assert synced_list._to_synced_list_conversion(op) == 2 assert all(op._added for op in synced_list) self.check_equivalent(plain_list, synced_list)
def islist(slist_empty): return SyncedList(lambda x: isinstance(x, int), iterable=[OpInt(i) for i in [1, 2, 3]])
def slist_empty(): return SyncedList(lambda x: isinstance(x, Operation))
def islist(slist_empty): return SyncedList(_PartialIsInstance(int), iterable=[OpInt(i) for i in [1, 2, 3]])
def slist_empty(): return SyncedList(_PartialIsInstance(Operation))