Math log SIMD issue with Mojo Mojo 0.26.1.0

If I uncomment the commented out lines - mojo complains with the messages shown at end! Please help. The same used to work in Mojo 0.25.7.

from math import iota, log, log10
from sys import simd_width_of


fn check_log[
    dtype: DType, width: Int, //, simd_width: Int = simd_width_of[dtype]()
](var vector: SIMD[dtype, width],):
    var size = len(vector)
    var orig = vector

    var chunks = size // simd_width
    var start_rest = chunks * simd_width
    for _ in range(chunks):
        var chunk = vector.slice[simd_width]()
        vector = vector.rotate_left[simd_width]()
        # print("chunk log: ", log(chunk))
        print("chunk log: ", log10(chunk) * 2.3025850929)

    for i in range(start_rest, size):
        var val = orig[i]
        # print("Elem log: ", log(val))
        print("Elem log: ", log10(val) * 2.3025850929)


fn main() raises:
    comptime dtype = DType.float16
    var vector = iota[dtype, 24]()
    check_log(vector)
    print(log(Scalar[dtype](10)))
    

Snippet from errors:

error: invalid call to ‘log’: lacking evidence to prove correctness
print("chunk log: ", log(chunk))
^~~
note: cannot prove constraint for candidate

In the recent mojo update, they have added the where clause constraint to many of these math functions. So you’ll have to prove that for log function by adding the following,

fn check_log[
    dtype: DType, width: Int, //, simd_width: Int = simd_width_of[dtype]()
](var vector: SIMD[dtype, width],) where dtype.is_floating_point():
1 Like

Thank you. That solves it. “constrained” does not catch it!