declare_array_complex

Macro declare_array_complex 

Source
macro_rules! declare_array_complex {
    ( $name:ident, $real_name:ident, $N:expr, $T:ty ) => { ... };
}
Expand description

This macro implements a type which consists of an array of complex fixed-point numberts of size N. Complete with the traits shown below.

§Arguments

  • name - The name of the array type. E.g. CArr4
  • real_name - The name of the real array type. E.g. Arr4
  • N - The length of the array. E.g 4.
  • T - The fixed type of the elements.

The complex support is currently under development.

§::new

use integer_array as ia;
use ia::trait_definitions::*;
use fixed::{types::extra::U20, FixedI32};
use num::complex::Complex as C;
 
ia::declare_array_complex!( CArr4, Arr4, 4, FixedI32<U20> );
let x = CArr4::new_from_i32( 1, 2 );
assert_eq!{ x.as_array_f32(), [ C{re:1.0, im:2.0}, C{re:1.0, im:2.0}, C{re:1.0, im:2.0}, C{re:1.0, im:2.0} ]};

/// # ::odd and ::even Get the items in the odd or even indexes as an array.

See examples under the declare_array_real macro.

§::real and ::imag

Get the real and imaginary array-components by running the real() and imag() traits. The traits return a real integer-array of the same length.

use integer_array as ia;
use ia::trait_definitions::*;
use fixed::{types::extra::U20, FixedI32};
 
ia::declare_array_complex!( CArr4, Arr4, 4, FixedI32<U20> );
let x = CArr4::new_from_f32( 1.0, 2.0 );
assert_eq!{ x.real(), Arr4::new_from_i32(1) };
assert_eq!{ x.imag(), Arr4::new_from_i32(2) };

§::mag

Get the item-wise magnitude of the complex array.

use integer_array as ia;
use ia::trait_definitions::*;
use fixed::{types::extra::U20, FixedI32};
 
ia::declare_array_complex!( CArr4, Arr4, 4, FixedI32<U20> );
let x = CArr4::new_from_f32( 1.0, 2.0 );
let y = x.mag();
assert_eq!{ y.as_array_f32(), [1.75, 1.75, 1.75, 1.75] };

§::arg

Get the item-wise argumetn of the complex array.

use integer_array as ia;
use ia::trait_definitions::*;
use fixed::{types::extra::U20, FixedI32};
 
ia::declare_array_complex!( CArr4, Arr4, 4, FixedI32<U20> );
let x = CArr4::new_from_f32( 1.0, 2.0 );
let y = x.arg();
assert_eq!{ y.as_array_f32(), [1.1032009, 1.1032009, 1.1032009, 1.1032009] };