In [198]: np.float64(1.0).view((np.float32,2))
Out[198]: array([ 0. , 1.875], dtype=float32)
So when
table[y,x] = 1.0
writes a np.float64(1.0)
into table
, table
views the data as np.float32
and interprets it as a 0 and a 1.875.
Notice that the 0 shows up at index location [0,1]
, and 1.875
shows up at index location [0,2]
, whereas the assignment occurred at [y,x] = [0,1]
.
You could fix the dtype mismatch by changing
@numba.jit("void(f8[:,::1],f8[:,::1])")
to
@numba.jit("void(f4[:,::1],f8[:,::1])")
These are the 8 bytes in np.float64(1.0)
:
In [201]: np.float64(1.0).tostring()
Out[201]: '\x00\x00\x00\x00\x00\x00\xf0?'
And when the 4 bytes '\x00\x00\xf0?'
are interpreted as a np.float32
you get 1.875:
In [205]: np.fromstring('\x00\x00\xf0?', dtype='float32')
Out[205]: array([ 1.875], dtype=float32)