rust-ndarray / ndarray-stats

Statistical routines for ndarray
https://docs.rs/ndarray-stats
Apache License 2.0
201 stars 25 forks source link

Remove redundant call to abs in sq_l2_dist #57

Closed munckymagik closed 5 years ago

munckymagik commented 5 years ago

What?

Removes a redundant call to abs in sq_l2_dist.

Why?

Calling abs is unnecessary, as the difference is squared immediately afterwards, which always results in a positive number.

Impact?

For simple Copy scalar types, benchmarking showed no consistent performance difference. So the only impact is code reduction / simplification.

Even though we support Clone types the only type in any way supported right now is num-bigint. I tried to benchmark this to see if that showed a performance improvement, but gave up due to dependency version incompatibilities between num-bigint and ndarray-*.

Currently, the module does not work at all with num-complex, so there is no cost in this respect.