Closed annoybot closed 2 years ago
This change means that complex can now be used with operators such as <
, <=
, which needs some rationale, is there a good reason?
Indeed the complex numbers are not an ordered field, so as you point out the <
operation makes no mathematical sense for it.
I actually solved my problem in a different way by creating a temporary struct:
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug, Default, PartialOrd, Ord)]
struct CplxSortAdaptor<T:Float> {
pub re: T,
pub im: T,
}
I was then able to write a function sort_lex<F:Float>(list: &mut[Complex<F>])
which copies the list
to be sorted into a list of CplxSortAdaptor
, sorts it, then copies the results back into list
.
Not super efficient, but OK, since it's only needed in my unit tests.
I don't know why I didn't see this solution sooner.
I propose to close this PR for the reasons you cited. Thanks for your feedback.
Closing, but we can follow up on how to use custom sorting in #106.
Why?
I have a lot of unit tests to write which need to check arrays of complex numbers.
Being able to sort an array of Complex, makes it easier to write these tests (I can just sort the actual results and the expected results and compare).