Skip to content

Comments

fix[cartesian]: don't upcast arguments of power function#2489

Open
romanc wants to merge 1 commit intoGridTools:mainfrom
romanc:romanc/gtir-upcaster-leave-integer-exponents-alone
Open

fix[cartesian]: don't upcast arguments of power function#2489
romanc wants to merge 1 commit intoGridTools:mainfrom
romanc:romanc/gtir-upcaster-leave-integer-exponents-alone

Conversation

@romanc
Copy link
Contributor

@romanc romanc commented Feb 20, 2026

Description

@FlorianDeconinck / @twicki here's the branch/PR which adds an exception for casting exponent and base of the power function to the same type.

Background: This came up in physics validation where we noticed that the current rule set will translate the following stencil code

bquad = (
    2.0
    * rbuoy
    * constants.MAPL_GRAV
    * cridis
    * (thv_x1 - thv_x0)
    / thv0j
    - 2.0 * wue**2
)

into

bquad_gen_0 = ( ( ( ( ( ( np.float32(2.0) * np.float32(1.0) ) * np.float32(9.80665) ) * cridis_gen_0 ) * ( thv_x1_gen_0 - thv_x0_gen_0 ) ) / thv0j_gen_0 ) - ( np.float32(2.0) * ufuncs.power(wue[i + 0,j + 0,k + 0],np.float32(np.int32(2))) ) )
gtOUT__bquad_gen_0 = ((((((float(2.0) * float(1.0)) * float(9.80665)) * gtIN__cridis_gen_0) * (gtIN__thv_x1_gen_0 - gtIN__thv_x0_gen_0)) / gtIN__thv0j_gen_0) - (float(2.0) * dace::math::pow(gtIN__wue, float(int(2)))));

with the debug and dace:cpu_kfirst backends respectively.

The PR attempts to avoid casting the exponent (2) into a 32-bit float just because the base value wue is a FloatField.

Requirements

  • All fixes and/or new features come with corresponding tests.
  • Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder.
    N/A

@FlorianDeconinck
Copy link
Contributor

This is looking good to me. Should we move it in?

@romanc romanc marked this pull request as ready for review February 20, 2026 22:28
@romanc
Copy link
Contributor Author

romanc commented Feb 20, 2026

This is looking good to me. Should we move it in?

Sure, feel free to go ahead. Then let's see next week if this helps with physics stability on MacOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants