Skip to content

Instantly share code, notes, and snippets.

@czotti
Last active June 26, 2018 20:07
Show Gist options
  • Save czotti/aa59044dfc1c7d85f3358a9d2fd6b400 to your computer and use it in GitHub Desktop.
Save czotti/aa59044dfc1c7d85f3358a9d2fd6b400 to your computer and use it in GitHub Desktop.
Cargo run with approx for a slice of Complex
[package]
name = "approx"
version = "0.1.0"
authors = ["Clément Zotti <clement.zotti@imeka.ca>"]
[dependencies]
ndarray = ">=0.10.12,<0.12.0"
num = "0.1"
[dependencies.approx]
version = "0.2"
features = ["use_complex"]
#[macro_use] extern crate approx;
extern crate ndarray;
extern crate num;
use num::complex::Complex;
use ndarray::arr2;
fn main() {
let sh = 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 = arr2(&[
[Complex::new(0.28207, 0.0),
Complex::new(0.38417, 0.04056)],
[Complex::new(0.28207, 0.0),
Complex::new(0.38137, 0.05156)],
[Complex::new(0.28207, 0.0),
Complex::new(0.38097, 0.00786)]]);
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