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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use std::fmt;
pub use array::*;
pub use coords::*;
pub use ext::*;
pub use stream::*;
mod array;
mod coords;
mod ext;
mod stream;
pub type Complex<T> = num_complex::Complex<T>;
pub trait Sum {
fn sum(self, other: Self) -> Self;
}
impl Sum for bool {
fn sum(self, other: Self) -> Self {
self || other
}
}
macro_rules! sum {
($t:ty) => {
impl Sum for $t {
fn sum(self, other: Self) -> Self {
self + other
}
}
};
}
sum!(u8);
sum!(u16);
sum!(u32);
sum!(u64);
sum!(i16);
sum!(i32);
sum!(i64);
sum!(f32);
sum!(f64);
sum!(Complex<f32>);
sum!(Complex<f64>);
pub trait Product {
fn product(self, other: Self) -> Self;
}
impl Product for bool {
fn product(self, other: Self) -> Self {
self && other
}
}
macro_rules! product {
($t:ty) => {
impl Product for $t {
fn product(self, other: Self) -> Self {
self * other
}
}
};
}
product!(u8);
product!(u16);
product!(u32);
product!(u64);
product!(i16);
product!(i32);
product!(i64);
product!(f32);
product!(f64);
product!(Complex<f32>);
product!(Complex<f64>);
pub struct ArrayError {
message: String,
}
impl fmt::Debug for ArrayError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
impl fmt::Display for ArrayError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.message)
}
}
pub type Result<T> = std::result::Result<T, ArrayError>;
pub fn print_af_info() {
arrayfire::info()
}
fn error<I: fmt::Display>(message: I) -> ArrayError {
ArrayError {
message: message.to_string(),
}
}
#[inline]
fn dim4(size: usize) -> arrayfire::Dim4 {
arrayfire::Dim4::new(&[size as u64, 1, 1, 1])
}
#[inline]
fn coord_bounds(shape: &[u64]) -> Vec<u64> {
(0..shape.len())
.map(|axis| shape[axis + 1..].iter().product())
.collect()
}