我尝试将基于 Mojo 2 4 .4 的 to_numpy 的 KMeans 教程https://www.modular.com/blog/fast-k-means-clustering-in-mojo-guide-to-porting-python-to-mojo-for-accelerated-k-means-clustering中的方法转换为 Mojo 2 4 .5,但出现以下错误:
error: 'pop.index_to_pointer' op MLIR verification
error: unregistered operation 'pop.index_to_pointer' found in dialect ('pop') that does not allow unknown operations
原始方法实现如下:
fn to_numpy(self) raises -> PythonObject:
var np = Python.import_module("numpy")
var np_arr = np.zeros((self.rows,self.cols))
var npArrayPtr = DTypePointer[dtype](
__mlir_op.`pop.index_to_pointer`[
_type = __mlir_type[`!kgen.pointer<scalar<`, dtype.value, `>>`]
](
SIMD[DType.index,1](np_arr.__array_interface__['data'][0].__index__()).value
)
)
memcpy(npArrayPtr, self._matPtr, len(self))
return np_arr ^
我把 DTypePointer[dtype]
替换成 UnsafePointer[Scalar[dtype]]