3 ms·
To be honest, that Rust syntax looks pretty horrible for something as simple as multiplying a vector by a scalar.
by amelius 4y ago
To be honest, that Rust syntax looks pretty horrible for something as simple as multiplying a vector by a scalar.
- jeroenhd 4y agoDefinitely. 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.
- Matumio 4y agoPart of that is the ndarray crate, which IMO is too generic often, making syntax complicated. The nalgebra crate is a bit nicer IMO, example: https://github.com/martinxyz/progenitor/blob/85260/crates/progenitor/src/builders/nn.rs#L33-L43 https://github.com/martinxyz/progenitor/blob/85260/crates/pr...