19
19
///
20
20
/// * `MultiInputError::EmptyInput` if `self` is empty
21
21
/// * `MultiInputError::ShapeMismatch` if `self` and `other` don't have the same shape
22
- fn count_eq ( & self , other : & ArrayBase < S , D > ) -> Result < usize , MultiInputError >
22
+ fn count_eq < T > ( & self , other : & ArrayBase < T , D > ) -> Result < usize , MultiInputError >
23
23
where
24
- A : PartialEq ;
24
+ A : PartialEq ,
25
+ T : Data < Elem = A > ;
25
26
26
27
/// Counts the number of indices at which the elements of the arrays `self`
27
28
/// and `other` are not equal.
30
31
///
31
32
/// * `MultiInputError::EmptyInput` if `self` is empty
32
33
/// * `MultiInputError::ShapeMismatch` if `self` and `other` don't have the same shape
33
- fn count_neq ( & self , other : & ArrayBase < S , D > ) -> Result < usize , MultiInputError >
34
+ fn count_neq < T > ( & self , other : & ArrayBase < T , D > ) -> Result < usize , MultiInputError >
34
35
where
35
- A : PartialEq ;
36
+ A : PartialEq ,
37
+ T : Data < Elem = A > ;
36
38
37
39
/// Computes the [squared L2 distance] between `self` and `other`.
38
40
///
50
52
/// * `MultiInputError::ShapeMismatch` if `self` and `other` don't have the same shape
51
53
///
52
54
/// [squared L2 distance]: https://en.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
53
- fn sq_l2_dist ( & self , other : & ArrayBase < S , D > ) -> Result < A , MultiInputError >
55
+ fn sq_l2_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < A , MultiInputError >
54
56
where
55
- A : AddAssign + Clone + Signed ;
57
+ A : AddAssign + Clone + Signed ,
58
+ T : Data < Elem = A > ;
56
59
57
60
/// Computes the [L2 distance] between `self` and `other`.
58
61
///
72
75
/// **Panics** if the type cast from `A` to `f64` fails.
73
76
///
74
77
/// [L2 distance]: https://en.wikipedia.org/wiki/Euclidean_distance
75
- fn l2_dist ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
78
+ fn l2_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
76
79
where
77
- A : AddAssign + Clone + Signed + ToPrimitive ;
80
+ A : AddAssign + Clone + Signed + ToPrimitive ,
81
+ T : Data < Elem = A > ;
78
82
79
83
/// Computes the [L1 distance] between `self` and `other`.
80
84
///
92
96
/// * `MultiInputError::ShapeMismatch` if `self` and `other` don't have the same shape
93
97
///
94
98
/// [L1 distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
95
- fn l1_dist ( & self , other : & ArrayBase < S , D > ) -> Result < A , MultiInputError >
99
+ fn l1_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < A , MultiInputError >
96
100
where
97
- A : AddAssign + Clone + Signed ;
101
+ A : AddAssign + Clone + Signed ,
102
+ T : Data < Elem = A > ;
98
103
99
104
/// Computes the [L∞ distance] between `self` and `other`.
100
105
///
@@ -111,9 +116,10 @@ where
111
116
/// * `MultiInputError::ShapeMismatch` if `self` and `other` don't have the same shape
112
117
///
113
118
/// [L∞ distance]: https://en.wikipedia.org/wiki/Chebyshev_distance
114
- fn linf_dist ( & self , other : & ArrayBase < S , D > ) -> Result < A , MultiInputError >
119
+ fn linf_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < A , MultiInputError >
115
120
where
116
- A : Clone + PartialOrd + Signed ;
121
+ A : Clone + PartialOrd + Signed ,
122
+ T : Data < Elem = A > ;
117
123
118
124
/// Computes the [mean absolute error] between `self` and `other`.
119
125
///
@@ -133,9 +139,10 @@ where
133
139
/// **Panics** if the type cast from `A` to `f64` fails.
134
140
///
135
141
/// [mean absolute error]: https://en.wikipedia.org/wiki/Mean_absolute_error
136
- fn mean_abs_err ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
142
+ fn mean_abs_err < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
137
143
where
138
- A : AddAssign + Clone + Signed + ToPrimitive ;
144
+ A : AddAssign + Clone + Signed + ToPrimitive ,
145
+ T : Data < Elem = A > ;
139
146
140
147
/// Computes the [mean squared error] between `self` and `other`.
141
148
///
@@ -155,9 +162,10 @@ where
155
162
/// **Panics** if the type cast from `A` to `f64` fails.
156
163
///
157
164
/// [mean squared error]: https://en.wikipedia.org/wiki/Mean_squared_error
158
- fn mean_sq_err ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
165
+ fn mean_sq_err < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
159
166
where
160
- A : AddAssign + Clone + Signed + ToPrimitive ;
167
+ A : AddAssign + Clone + Signed + ToPrimitive ,
168
+ T : Data < Elem = A > ;
161
169
162
170
/// Computes the unnormalized [root-mean-square error] between `self` and `other`.
163
171
///
@@ -175,9 +183,10 @@ where
175
183
/// **Panics** if the type cast from `A` to `f64` fails.
176
184
///
177
185
/// [root-mean-square error]: https://en.wikipedia.org/wiki/Root-mean-square_deviation
178
- fn root_mean_sq_err ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
186
+ fn root_mean_sq_err < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
179
187
where
180
- A : AddAssign + Clone + Signed + ToPrimitive ;
188
+ A : AddAssign + Clone + Signed + ToPrimitive ,
189
+ T : Data < Elem = A > ;
181
190
182
191
/// Computes the [peak signal-to-noise ratio] between `self` and `other`.
183
192
///
@@ -196,13 +205,14 @@ where
196
205
/// **Panics** if the type cast from `A` to `f64` fails.
197
206
///
198
207
/// [peak signal-to-noise ratio]: https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
199
- fn peak_signal_to_noise_ratio (
208
+ fn peak_signal_to_noise_ratio < T > (
200
209
& self ,
201
- other : & ArrayBase < S , D > ,
210
+ other : & ArrayBase < T , D > ,
202
211
maxv : A ,
203
212
) -> Result < f64 , MultiInputError >
204
213
where
205
- A : AddAssign + Clone + Signed + ToPrimitive ;
214
+ A : AddAssign + Clone + Signed + ToPrimitive ,
215
+ T : Data < Elem = A > ;
206
216
207
217
private_decl ! { }
208
218
}
@@ -231,9 +241,10 @@ where
231
241
S : Data < Elem = A > ,
232
242
D : Dimension ,
233
243
{
234
- fn count_eq ( & self , other : & ArrayBase < S , D > ) -> Result < usize , MultiInputError >
244
+ fn count_eq < T > ( & self , other : & ArrayBase < T , D > ) -> Result < usize , MultiInputError >
235
245
where
236
246
A : PartialEq ,
247
+ T : Data < Elem = A > ,
237
248
{
238
249
return_err_if_empty ! ( self ) ;
239
250
return_err_unless_same_shape ! ( self , other) ;
@@ -249,16 +260,18 @@ where
249
260
Ok ( count)
250
261
}
251
262
252
- fn count_neq ( & self , other : & ArrayBase < S , D > ) -> Result < usize , MultiInputError >
263
+ fn count_neq < T > ( & self , other : & ArrayBase < T , D > ) -> Result < usize , MultiInputError >
253
264
where
254
265
A : PartialEq ,
266
+ T : Data < Elem = A > ,
255
267
{
256
268
self . count_eq ( other) . map ( |n_eq| self . len ( ) - n_eq)
257
269
}
258
270
259
- fn sq_l2_dist ( & self , other : & ArrayBase < S , D > ) -> Result < A , MultiInputError >
271
+ fn sq_l2_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < A , MultiInputError >
260
272
where
261
273
A : AddAssign + Clone + Signed ,
274
+ T : Data < Elem = A > ,
262
275
{
263
276
return_err_if_empty ! ( self ) ;
264
277
return_err_unless_same_shape ! ( self , other) ;
@@ -274,9 +287,10 @@ where
274
287
Ok ( result)
275
288
}
276
289
277
- fn l2_dist ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
290
+ fn l2_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
278
291
where
279
292
A : AddAssign + Clone + Signed + ToPrimitive ,
293
+ T : Data < Elem = A > ,
280
294
{
281
295
let sq_l2_dist = self
282
296
. sq_l2_dist ( other) ?
@@ -286,9 +300,10 @@ where
286
300
Ok ( sq_l2_dist. sqrt ( ) )
287
301
}
288
302
289
- fn l1_dist ( & self , other : & ArrayBase < S , D > ) -> Result < A , MultiInputError >
303
+ fn l1_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < A , MultiInputError >
290
304
where
291
305
A : AddAssign + Clone + Signed ,
306
+ T : Data < Elem = A > ,
292
307
{
293
308
return_err_if_empty ! ( self ) ;
294
309
return_err_unless_same_shape ! ( self , other) ;
@@ -303,9 +318,10 @@ where
303
318
Ok ( result)
304
319
}
305
320
306
- fn linf_dist ( & self , other : & ArrayBase < S , D > ) -> Result < A , MultiInputError >
321
+ fn linf_dist < T > ( & self , other : & ArrayBase < T , D > ) -> Result < A , MultiInputError >
307
322
where
308
323
A : Clone + PartialOrd + Signed ,
324
+ T : Data < Elem = A > ,
309
325
{
310
326
return_err_if_empty ! ( self ) ;
311
327
return_err_unless_same_shape ! ( self , other) ;
@@ -323,9 +339,10 @@ where
323
339
Ok ( max)
324
340
}
325
341
326
- fn mean_abs_err ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
342
+ fn mean_abs_err < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
327
343
where
328
344
A : AddAssign + Clone + Signed + ToPrimitive ,
345
+ T : Data < Elem = A > ,
329
346
{
330
347
let l1_dist = self
331
348
. l1_dist ( other) ?
@@ -336,9 +353,10 @@ where
336
353
Ok ( l1_dist / n)
337
354
}
338
355
339
- fn mean_sq_err ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
356
+ fn mean_sq_err < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
340
357
where
341
358
A : AddAssign + Clone + Signed + ToPrimitive ,
359
+ T : Data < Elem = A > ,
342
360
{
343
361
let sq_l2_dist = self
344
362
. sq_l2_dist ( other) ?
@@ -349,21 +367,23 @@ where
349
367
Ok ( sq_l2_dist / n)
350
368
}
351
369
352
- fn root_mean_sq_err ( & self , other : & ArrayBase < S , D > ) -> Result < f64 , MultiInputError >
370
+ fn root_mean_sq_err < T > ( & self , other : & ArrayBase < T , D > ) -> Result < f64 , MultiInputError >
353
371
where
354
372
A : AddAssign + Clone + Signed + ToPrimitive ,
373
+ T : Data < Elem = A > ,
355
374
{
356
375
let msd = self . mean_sq_err ( other) ?;
357
376
Ok ( msd. sqrt ( ) )
358
377
}
359
378
360
- fn peak_signal_to_noise_ratio (
379
+ fn peak_signal_to_noise_ratio < T > (
361
380
& self ,
362
- other : & ArrayBase < S , D > ,
381
+ other : & ArrayBase < T , D > ,
363
382
maxv : A ,
364
383
) -> Result < f64 , MultiInputError >
365
384
where
366
385
A : AddAssign + Clone + Signed + ToPrimitive ,
386
+ T : Data < Elem = A > ,
367
387
{
368
388
let maxv_f = maxv. to_f64 ( ) . expect ( "failed cast from type A to f64" ) ;
369
389
let msd = self . mean_sq_err ( & other) ?;
0 commit comments