"""Target utilities."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfromattrsimportevolve,fieldsfrombaybe.transformations.basicimportIdentityTransformationifTYPE_CHECKING:frombaybe.targets.numericalimportNumericalTargetdef_validate_numerical_target_combination(t1:NumericalTarget,t2:NumericalTarget,/)->None:"""Validate if two numerical targets can be combined."""frombaybe.targets.numericalimportNumericalTargett1_=evolve(t1,transformation=IdentityTransformation())# type: ignore[call-arg]t2_=evolve(t2,transformation=IdentityTransformation())# type: ignore[call-arg]ift1_!=t2_:raiseValueError(f"Two objects of type '{NumericalTarget.__name__}' can only be "f"combined if they are identical in all attributes except for the "f"'{fields(NumericalTarget).transformation.name}'. "f"Given: {t1_!r} and {t2_!r}.")
[docs]defcombine_numerical_targets(t1:NumericalTarget,t2:NumericalTarget,/,operator)->NumericalTarget:"""Combine two numerical targets using a binary operator."""_validate_numerical_target_combination(t1,t2)returnevolve(t1,transformation=operator(t1.transformation,t2.transformation))# type: ignore[call-arg]