MCPcopy Create free account
hub / github.com/anyoptimization/pymoo / set

Method set

pymoo/core/population.py:31–58  ·  view source on GitHub ↗
(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

29 self.collect(func, to_numpy=False)
30
31 def set(self, *args, **kwargs) -> Optional["Population"]:
32
33 # if population is empty just return
34 if self.size == 0:
35 return None
36
37 # done for the old interface with the interleaving variable definition
38 kwargs = interleaving_args(*args, kwargs=kwargs)
39
40 # for each entry in the dictionary set it to each individual
41 for key, values in kwargs.items():
42 is_iterable = hasattr(values, "__len__") and not isinstance(values, str)
43
44 if is_iterable and len(values) != len(self):
45 raise Exception(
46 "Population Set Attribute Error: Number of values and population size do not match!"
47 )
48
49 for i in range(len(self)):
50 val = values[i] if is_iterable else values
51
52 # check for view and make copy to prevent memory leakage (#455)
53 if isinstance(val, np.ndarray) and not val.flags["OWNDATA"]:
54 val = val.copy()
55
56 self[i].set(key, val)
57
58 return self
59
60 def get(self, *args, to_numpy: bool = True, **kwargs) -> Any | tuple[Any, ...]:
61

Callers 1

newMethod · 0.45

Calls 2

interleaving_argsFunction · 0.85
copyMethod · 0.80

Tested by

no test coverage detected