Python implementations implicitly convert Numpy scalars to native float/int
Numpy scalars, like np.in32(3)
and np.float64(3.2)
behave a lot like normal Python int/float numbers, and since their repr also makes them look that way, its hard to see the difference.
The JSON encoder will fail on such numbers.
The BSDF encoder will encode them, as it sees them as an array with shape ()
. But this causes two problems:
- A common such scalar like
int64
cannot be decoded in JavaScript (there is noInt64Array
). - Such zero-dimension arrays may not behave as scalars in other environments. Even encoding and then decoding in Python gives a slightly different kind of thing (The type will be
np.array
and not e.g.np.int32
).
Therefore, this PR adds the automatic conversion of such numbers to their native variants. It's not very intrusive code and performance wise.
Edited by Almar Klein