You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following simple example (can be run on the playground), the compiler fails to identify the Dtypepointer.scatter parameters when the code is run within an object method, but works well when called directly. If you remove the fn scatter declaration, the code works well, with a line between comments doing essentially the same. Am I missing something or is it a bug?
Compile error:
/source/prog.mojo:23:42: error: no matching method in call to 'scatter'
self._matPtr.scatter[width=nelts](indices, value, mask)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/source/prog.mojo:1:1: note: candidate not viable: expected at most 3 positional arguments, got 4
struct Matrix2D[dtype : DType= DType.float32]():
^
/source/prog.mojo:1:1: note: candidate not viable: failed to infer implicit parameter 'type' of argument 'offset' type 'SIMD'
struct Matrix2D[dtype : DType= DType.float32]():
^
mojo: error: failed to parse the provided Mojo source module
COMPLETE CODE
struct Matrix2D[dtype : DType= DType.float32]():
var _matPtr: DTypePointer[dtype]
var rows: Int
var cols: Int
@always_inline
fn __init__(inout self, rows: Int, cols: Int):
self._matPtr = DTypePointer[dtype].alloc(rows*cols)
self.rows = rows
self.cols= cols
memset_zero[dtype](self._matPtr, self.rows*self.cols)
@always_inline
fn __getitem__(self, x: Int, y: Int) -> SIMD[dtype,1]:
return self._matPtr.load(x * self.cols + y)
@always_inline
fn __getitem__(self, idx: Int) -> SIMD[dtype,1]:
return self._matPtr.load(idx)
fn scatter[nelts:Int](self, x: SIMD[DType.int8,nelts], y: SIMD[DType.int8,nelts], value: SIMD[DType.int8, nelts], mask: SIMD[DType.bool, nelts]) -> None:
var indices=x * self.cols + y
self._matPtr.scatter[width=nelts](indices, value, mask)
def main():
var values=SIMD[DType.int8,8](10,11,12,13,14,15,16,17)
var x=SIMD[DType.int8,8](0,0,0,1,1,1,2,2)
var y=SIMD[DType.int8,8](0,1,2,0,1,2,0,1)
var mask=SIMD[DType.bool,8](True, False, False, True, True, True, True, True)
var destino=Matrix2D[DType.int8](3,3)
var offset=x*destino.cols + y
#### this line compiles and works well ######################################################
destino._matPtr.scatter[width=8](offset, values, mask)
##############################################################################
for x in range(3):
for y in range(3):
print(destino[x,y])
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In the following simple example (can be run on the playground), the compiler fails to identify the Dtypepointer.scatter parameters when the code is run within an object method, but works well when called directly. If you remove the fn scatter declaration, the code works well, with a line between comments doing essentially the same. Am I missing something or is it a bug?
Compile error:
COMPLETE CODE
Beta Was this translation helpful? Give feedback.
All reactions