Skip to content

Power function causes compilation failure for integer inputs and outputs

A kernel like

knl = lp.make_kernel(
    "{ [i]: 0<=i<4 }",
      """
      out[i] = a[i**4]
      """)

fails to compile producing

error: call to 'pow' is ambiguous
    out[i] = a[pow(i, 4)];

because at least the second argument needs to be a floating point type.

This may be imposed by multiplying the second argument by 1.0f

knl = lp.make_kernel(
    "{ [i]: 0<=i<4 }",
    """
    <float> one = 1.0f
    out[i] = a[i**(4.0*one)]
    """)

but then compilation still fails because

error: array subscript is not an integer
    out[i] = a[pow(i, 4 * one)];

Storing the index in a temporary variable of explicit integer type appears to be a workaround.

knl = lp.make_kernel(
    "{ [i]: 0<=i<4 }",
    """
    <float> one = 1.0f
    <int> index = i**(4.0*one)
    out[i] = a[index]
    """)
Edited by Nicholas Christensen