19 ms·
Definitely. However, the equivalent for the array multiplication in numpy looks like this: https://github.com/numpy/numpy/blob/22e683d84f2584a6f9a57b2c58d1def6
by jeroenhd 4y ago
Definitely. However, the equivalent for the array multiplication in numpy looks like this:
https://github.com/numpy/numpy/blob/22e683d84f2584a6f9a57b2c58d1def6743fcf83/numpy/core/src/multiarray/number.c#L37 https://github.com/numpy/numpy/blob/22e683d84f2584a6f9a57b2c... + https://github.com/numpy/numpy/blob/22e683d84f2584a6f9a57b2c58d1def6743fcf83/numpy/core/src/multiarray/number.c#L688 https://github.com/numpy/numpy/blob/22e683d84f2584a6f9a57b2c...
To know what they do, you need the source for INPLACE_GIVE_UP_IF_NEEDED (https://github.com/numpy/numpy/blob/b222eb66c79b8eccba39f46f020ed8303614a87f/numpy/core/src/common/binop_override.h#L190 https://github.com/numpy/numpy/blob/b222eb66c79b8eccba39f46f...) and PyArray_GenericInplaceBinaryFunction (I don't even know where that's coming from, it's not defined in Numpy, maybe it's part of the Python interface?).
In the end, both are unreadable in their own way. I personally prefer the Rust version above to the macrofied C version that's in Numpy but that's a matter of taste. I'd also trust the safe Rust implementations more than the C implementations because of the memory management guarantees Rust provides, though I suppose for simple operations like multiplication it'll be easier to make the program safe enough in C.