ModularM
Modular16mo ago
11 replies
franchesoni

print breaks code

the following isn't catched by the linter but breaks, what am I doing wrong?

from python import Python, PythonObject
from memory import memcpy

alias S: Int = 256
alias S2: Int = S*S
alias CRASH = True

def main():
    np = Python.import_module('numpy')
    pylogits = np.ones((130, 256, 256))
    total_size = Int(pylogits.size)

    # now we have the data in memory
    data = UnsafePointer[Scalar[DType.float32]].alloc(total_size)
    memcpy(data, pylogits.__array_interface__['data'][0].unsafe_get_as_pointer[DType.float32](), total_size)

    # mojomain(data, total_size)
    var masks = UnsafePointer[Scalar[DType.bool]].alloc(total_size)
    for channel in range(total_size / S2):
        offset = S2 * channel
        for ind in range(S2):
            masks[ind + offset] = True if data[ind+offset] > 0.5 else False
        if CRASH:
            print(masks[offset + S])

    print('great!')  # never get here
    
Was this page helpful?