1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#[macro_export]
macro_rules! declare_array_complex{
( $name:ident, $N:expr) => {
#[derive(Copy, Clone, Default, Debug, PartialEq)]
pub struct $name{
pub data: [num::complex::Complex<i32>; $N],
}
impl integer_array::trait_definitions::NewComplex for $name {
fn new( real:i32, imag:i32 ) -> Self {
let item = num::complex::Complex::new(real, imag);
$name {
data: [item;$N],
}
}
}
impl integer_array::trait_definitions::Len for $name {
fn len( &self ) -> usize {
return $N;
}
}
impl integer_array::trait_definitions::ArrayIndexingComplex for $name {
fn at( &self, index:usize) -> num::complex::Complex<i32> {
if( $N <= index)
{
return self.data[$N - 1];
}
return self.data[index];
}
fn front( &self ) -> num::complex::Complex<i32> {
return self.data[0];
}
fn back( &self ) -> num::complex::Complex<i32> {
return self.data[$N-1];
}
}
impl core::ops::Index<usize> for $name {
type Output = num::complex::Complex<i32>;
#[inline]
fn index(&self, index: usize) -> &num::complex::Complex<i32> {
return &self.data[index];
}
}
impl core::ops::IndexMut<usize> for $name {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut num::complex::Complex<i32> {
return &mut self.data[index];
}
}
}
}
#[cfg(test)]
mod tests {
#[test]
fn new() {
use crate as integer_array;
use integer_array::trait_definitions::*;
declare_array_complex!( CArr4, 4 );
let x = CArr4::new( 1, 2 );
assert_eq!{ x[1], num::complex::Complex{re:1, im:2} };
}
}