| I will agree about the 'on the balance' in the context of speed of prototyping and interactive sessions. When rubber is about to hit the road, i.e. near deployment with money at stake, I would have love an option to freeze the types, at least in many places. Cython comes in handy, but its clunky and its syntax and semantics is not super obvious to a beginner (I am no longer one, but I remember my days of confusion regarding cyimporting std headers, python headers, how do you use python arrays (not numpy arrays) etc etc). I am curious, have you put money at stake supported only by dynamic types ? Regarding int32 vs int64, its not a precision issue its about sparse matrices with more than 1<<31 nonzeros. I am equally surprised that you have not run into this given your practical experience with matrices. My case involves more than just numpy. There's hdf5, scipy.sparse, some memory mapped arrays and of course numpy. Given the amount of time I spent to debug this, I would have killed for static type checks. |
But I do see that counting nnz boils down to a call to np.count_nonzero, which treats bools as np.intp, which is either going to be int32 or int64 (very weird that it chooses signed types), then calls np.sum.
The best solution would be to use np.seterr to warn exactly at call sites with int32 overflow, but amazingly, there seems to be an open numpy issue saying that seterr is not guaranteed for sum.
I do think seterr + logging would be better for this than roping in static typing everywhere just to get a one off benefit like this.