Skip to content

Instantly share code, notes, and snippets.

@czotti
Created July 17, 2018 13:05
Show Gist options
  • Save czotti/f71ddcdf23b7163d9820f4b110536df5 to your computer and use it in GitHub Desktop.
Save czotti/f71ddcdf23b7163d9820f4b110536df5 to your computer and use it in GitHub Desktop.
Change num to num-complex with approx
[package]
name = "approx"
version = "0.1.0"
authors = ["Clément Zotti <clement.zotti@imeka.ca>"]
[dependencies]
ndarray = ">=0.10.12,<0.12.0"
num-complex = "0.2.0"
[dependencies.approx]
version = "0.2.1"
features = ["use_complex"]
#[macro_use] extern crate approx;
extern crate ndarray;
extern crate num_complex;
use num_complex::Complex;
use ndarray::{arr2, Array2};
fn main() {
let sh: Array2<Complex<f64>> = arr2(&[
[Complex::new(0.28205, 0.0),
Complex::new(0.38415, 0.04054)],
[Complex::new(0.28205, 0.0),
Complex::new(0.38135, 0.05154)],
[Complex::new(0.28205, 0.0),
Complex::new(0.38095, 0.00784)]]);
let gt : Array2<Complex<f64>> = arr2(&[
[Complex::new(0.2820500000007, 0.0),
Complex::new(0.3841500000007, 0.04054)],
[Complex::new(0.2820500000007, 0.0),
Complex::new(0.3813500000007, 0.05154)],
[Complex::new(0.2820500000007, 0.0),
Complex::new(0.3809500000007, 0.00784)]]);
assert_relative_eq!([1.0f32, 4.01f32][..], [1.0f32, 4.01f32][..]);
assert_relative_eq!(Complex::new(0.2, 0.1), Complex::new(0.2, 0.1));
assert_relative_eq!(sh.as_slice().unwrap(), gt.as_slice().unwrap());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment