np = Python.import_module('numpy')
logits = np.load('logits.npy') # (C, H, W)
# create data buffer
var channels: Int = logits.shape[0]
var height: Int = logits.shape[1]
var width: Int = logits.shape[2]
pointer_to_data = UnsafePointer[Float32].alloc(channels * height * width)
pointer_to_data.init_pointee_copy(0) # is this needed? idk, doesn't hurt
tensor = NDBuffer[DType.float32, 3](pointer_to_data, DimList(channels, height, width))
var ftensor = tensor.flatten() # I need to create the NDBuffer first as I can't create buffer with a dynamic size
var np_pointer = logits.__array_interface__['data'][0].unsafe_get_as_pointer[DType.float32]() # from some example
start = time.perf_counter() # copy np data to tensor data
for channel in range(channels):
for row in range(height):
for col in range(width):
var posind = channel * height * width + row * width + col
ftensor[posind] = np_pointer[posind]
print("Time elapsed: ", time.perf_counter() - start)
print(ftensor[0]) # breaks here