Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:38:15: error: cannot implicitly convert 'IntLiteral[0]' value to 'DType'
res = 0
^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:54:24: error: cannot implicitly convert 'SIMD[dtype, __init__[::Origin[::Bool(IntTuple(1), IntTuple(1
)).size()]' value to 'DType'
res = intersection / union
~~~~~~~~~~~~~^~~~~~~
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:111:70: error: invalid call to 'iou': argument #0 cannot be converted from 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0),
MutableAnyOrigin, layout_int_type=_get_layout_type(corners_layout, AddressSpace(0)), linear_idx_type=_get_index_type(corners_layout, AddressSpace(0)), masked=_tile_is_masked[::Layout,*::I
nt]()]' to 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0), MutableAnyOrigin]'
var overlap = iou[dtype, first.layout, second.layout](
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:112:21: note: types parameters include unfolded expression at parser time; try rebinding to a consistent type?
first, second
^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:22:4: note: function declared here
fn iou[
^
/home/marius/dev/nms.mojo/.magic/envs/default/bin/mojo: error: failed to parse the provided Mojo source module
m
I was trying to use an out parameter but got stuck half-way to the transition. Setting the return type of the iou function to first.element_type magically fixed the errors. I pushed one commit with that change.
I still have the errors on the call site, any advice there?
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:38:15: error: cannot implicitly convert 'IntLiteral[0]' value to 'DType'
res = 0
^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:54:24: error: cannot implicitly convert 'SIMD[dtype, __init__[::Origin[::Bool(IntTuple(1), IntTuple(1
)).size()]' value to 'DType'
res = intersection / union
~~~~~~~~~~~~~^~~~~~~
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:111:70: error: invalid call to 'iou': argument #0 cannot be converted from 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0),
MutableAnyOrigin, layout_int_type=_get_layout_type(corners_layout, AddressSpace(0)), linear_idx_type=_get_index_type(corners_layout, AddressSpace(0)), masked=_tile_is_masked[::Layout,*::I
nt]()]' to 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0), MutableAnyOrigin]'
var overlap = iou[dtype, first.layout, second.layout](
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:112:21: note: types parameters include unfolded expression at parser time; try rebinding to a consistent type?
first, second
^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:22:4: note: function declared here
fn iou[
^
/home/marius/dev/nms.mojo/.magic/envs/default/bin/mojo: error: failed to parse the provided Mojo source module
Because the output type of iou is of first.element_type, you will need to wrap the 0 with that type. So, essentially instead of return 0, do return first.element_type(0) in line 37.
BTW, doing out res: first.element_type like what you did originally is fine. out indicates the output type. That is why you will need to return a value. If you want a mutable variable, you need to do mut instead.
Sorry I copy pasted the wrong compiler output (I am ssh-ing into my GPU server and the mouse is playing tricks), Here is the actual output after fixing the function definition
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:109:70: error: invalid call to 'iou': argument #0 cannot be converted from 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0),
MutableAnyOrigin, layout_int_type=_get_layout_type(corners_layout, AddressSpace(0)), linear_idx_type=_get_index_type(corners_layout, AddressSpace(0)), masked=_tile_is_masked[::Layout,*::I
nt]()]' to 'LayoutTensor[dtype, _compute_tile_layout[*::Int]().__getitem__(0), MutableAnyOrigin]'
var overlap = iou[dtype, first.layout, second.layout](
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:110:21: note: types parameters include unfolded expression at parser time; try rebinding to a consistent type?
first, second
^
Included from /home/marius/dev/nms.mojo/test_correctness.mojo:18:
/home/marius/dev/nms.mojo/operations/nms.mojo:22:4: note: function declared here
fn iou[