def test_selection_op(): p1 = MonomOperator(1) select_rhs_functional = GenericParameterFunctional( lambda x: round(float(x["nrrhs"])), ParameterType({"nrrhs": ()})) s1 = SelectionOperator(operators=[p1], boundaries=[], parameter_functional=select_rhs_functional, name="foo") x = np.linspace(-1., 1., num=3) vx = p1.source.make_array(x[:, np.newaxis]) assert np.allclose( p1.apply(vx, mu=0).to_numpy(), s1.apply(vx, mu=0).to_numpy()) s2 = SelectionOperator(operators=[p1, p1, p1, p1], boundaries=[-3, 3, 7], parameter_functional=select_rhs_functional, name="Bar") assert s2._get_operator_number({"nrrhs": -4}) == 0 assert s2._get_operator_number({"nrrhs": -3}) == 0 assert s2._get_operator_number({"nrrhs": -2}) == 1 assert s2._get_operator_number({"nrrhs": 3}) == 1 assert s2._get_operator_number({"nrrhs": 4}) == 2 assert s2._get_operator_number({"nrrhs": 7}) == 2 assert s2._get_operator_number({"nrrhs": 9}) == 3
def __init__(self, parameter_type, minimum=None, maximum=None, ranges=None): assert ranges is None or (minimum is None and maximum is None), 'Must specify minimum, maximum or ranges' assert ranges is not None or (minimum is not None and maximum is not None),\ 'Must specify minimum, maximum or ranges' assert minimum is None or minimum < maximum if ranges is None: ranges = {k: (minimum, maximum) for k in parameter_type} parameter_type = ParameterType(parameter_type) self.__auto_init(locals())
def __init__(self, parameter_type, minimum=None, maximum=None, ranges=None): assert ranges is None or (minimum is None and maximum is None ), 'Must specify minimum, maximum or ranges' assert ranges is not None or (minimum is not None and maximum is not None),\ 'Must specify minimum, maximum or ranges' assert minimum is None or minimum < maximum parameter_type = ParameterType(parameter_type) self.parameter_type = parameter_type self.ranges = {k: (minimum, maximum) for k in parameter_type} if ranges is None else ranges