It is my understanding that in x = f() * g(), first f() executes, then g(), then results are multiplied, and only then assigned to x. Yet below seems to contradict this:
import numpy as np
print(np.sqrt(2).dtype)
print((np.array([1.], dtype='float32') * np.array([.5], dtype='float64')).dtype)
print((np.array([1.], dtype='float32') * np.sqrt(2)).dtype)
>>> float64
>>> float64
>>> float32
In all my prior experience, Numpy promoted to the greater dtype, but not here. Same behavior if we assign individual arrays and multiply afterwards. I imagine Numpy uses some hidden attribute besides dtype rather than overruling Python execution.
How's it work?