def _convert_type(self, typename: 'up.model.Type', user_types_map: Dict['up.model.Type', pytamer.tamer_type]) -> pytamer.tamer_type:
# Check if the type is a boolean
if typename.is_bool_type():
ttype = self._bool_type
# Check if the type is a user-defined type
elif typename.is_user_type():
ttype = user_types_map[typename]
# Check if the type is an integer
elif typename.is_int_type():
lb = typename.lower_bound # type: ignore
ub = typename.upper_bound # type: ignore
# If no bounds are provided, use a general integer type
if lb is None and ub is None:
ttype = pytamer.tamer_integer_type(self._env)
# If only the lower bound is missing, use an upper-bounded integer type
elif lb is None:
ttype = pytamer.tamer_integer_type_lb(self._env, lb)
# If only the upper bound is missing, use a lower-bounded integer type
elif ub is None:
ttype = pytamer.tamer_integer_type_ub(self._env, ub)
# If both bounds are provided, use a lower-upper-bounded integer type
else:
ttype = pytamer.tamer_integer_type_lub(self._env, lb, ub)
# Check if the type is a real number
elif typename.is_real_type():
lb = typename.lower_bound # type: ignore
ub = typename.upper_bound # type: ignore
# If no bounds are provided, use a general rational type
if lb is None and ub is None:
ttype = pytamer.tamer_rational_type(self._env)
# If only the lower bound is missing, use an upper-bounded rational type
elif lb is None:
ttype = pytamer.tamer_rational_type_lb(self._env, lb)
# If only the upper bound is missing, use a lower-bounded rational type
elif ub is None:
ttype = pytamer.tamer_rational_type_ub(self._env, ub)
# If both bounds are provided, use a lower-upper-bounded rational type
else:
ttype = pytamer.tamer_rational_type_lub(self._env, lb, ub)
# If the type is not recognized, raise an error
else:
raise NotImplementedError
# Return the converted type
return ttype
This Python function, _convert_type, is a method within a class that converts a given type (typename) into a pytamer.tamer_type. The function takes two arguments: typename of type up.model.Type and user_types_map of type Dict['up.model.Type', pytamer.tamer_type].
The function begins by checking if the typename is a boolean type using the is_bool_type() method. If true, it assigns the self._bool_type to the ttype variable.
If the typename is not a boolean type, it checks if it is a user-defined type using the is_user_type() method. If true, it assigns the corresponding pytamer.tamer_type from the user_types_map dictionary to the ttype variable.
If the typename is not a user-defined type, it checks if it is an integer type using the is_int_type() method. If true, it assigns a pytamer.tamer_integer_type to the ttype variable based on the lower and upper bounds of the integer type. If both bounds are None, it assigns a pytamer.tamer_integer_type without bounds. If only the lower bound is None, it assigns a pytamer.tamer_integer_type_lb with the upper bound. If only the upper bound is None, it assigns a pytamer.tamer_integer_type_ub with the lower bound. If both bounds are not None, it assigns a pytamer.tamer_integer_type_lub with both bounds.
If the typename is not an integer type, it checks if it is a real type using the is_real_type() method. If true, it assigns a pytamer.tamer_rational_type to the ttype variable based on the lower and upper bounds of the real type using the same logic as for integer types.
If the typename does not match any of the above conditions, the function raises a NotImplementedError.
Finally, the function returns the ttype variable, which is the converted pytamer.tamer_type.