Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rust-lang/num instead of stainless-steel/complex? #8

Closed
astraw opened this issue Aug 29, 2015 · 3 comments
Closed

Use rust-lang/num instead of stainless-steel/complex? #8

astraw opened this issue Aug 29, 2015 · 3 comments

Comments

@astraw
Copy link
Member

astraw commented Aug 29, 2015

Hi,

It seems that the num crate is quite heavily used, with >100k downloads over all time and thousands in the past weeks alone. In comparison, the complex crate has less than 1.5k downloads over all time. Therefore it seems to me that num is the de-facto standard for complex numbers and another module is likely going to lead to unnecessary code bloat and casting.

Are there any compelling reasons to stick with complex rather than switching to num? I'm not aware of any, but neither have I looked particularly deeply at the issue. Otherwise, I would propose moving to the num create. If there are features missing from num, I suppose the devs would welcome implementation of those missing features.

Another point is that, because num defines their Complex type as a generic for type T, it would be easier to implement support for different types as suggested in #6.

/// A complex number in Cartesian form.
#[derive(PartialEq, Copy, Clone, Hash, Debug)]
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
pub struct Complex<T> {
    /// Real portion of the complex number
    pub re: T,
    /// Imaginary portion of the complex number
    pub im: T
}

Finally, for maintaining compatibility in client code that uses complex::c32 and complex::c64, the following functions or similar could be used to implement the relevant cast:

extern crate num;
extern crate complex;
use std::mem::transmute;

#[inline]
fn to_complex_c32(x: & mut [num::Complex<f32>]) -> & mut [complex::c32] {
    unsafe { transmute(x) }
}

#[inline]
fn to_complex_c64(x: & mut [num::Complex<f64>]) -> & mut [complex::c64] {
    unsafe { transmute(x) }
}
@IvanUkhov
Copy link
Member

Hi,

I knew this issue would come up one day) I originally didn’t want to bring in such a heavy package as num for such a small thing as complex numbers; it seemed heavy, and it was pulling in a lot of unrelated dependencies. I guess I have no choice but acquiesce. num is a de facto standard, as you mentioned, and it indeed makes sense to leverage what has already been widely adopted instead of inventing something that people won’t use anyway.

How about this patch for blas and a similar one for lapack?

Regards,
Ivan

@astraw
Copy link
Member Author

astraw commented Aug 29, 2015

This is great - it simplifies my code a lot to only support one implementation.

@IvanUkhov
Copy link
Member

Published. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants