-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathdefines.rs
643 lines (600 loc) · 18.6 KB
/
defines.rs
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
use num::Complex;
use std::fmt::Error as FmtError;
use std::fmt::{Display, Formatter};
#[cfg(feature = "afserde")]
use serde::{Deserialize, Serialize};
/// Error codes
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum AfError {
/// The function returned successfully
SUCCESS = 0,
// 100-199 Errors in environment
/// The system or device ran out of memory
ERR_NO_MEM = 101,
/// There was an error in the device driver
ERR_DRIVER = 102,
/// There was an error with the runtime environment
ERR_RUNTIME = 103,
// 200-299 Errors in input parameters
/// The input array is not a valid Array object
ERR_INVALID_ARRAY = 201,
/// One of the function arguments is incorrect
ERR_ARG = 202,
/// The size is incorrect
ERR_SIZE = 203,
/// The type is not suppported by this function
ERR_TYPE = 204,
/// The type of the input arrays are not compatible
ERR_DIFF_TYPE = 205,
/// Function does not support GFOR / batch mode
ERR_BATCH = 207,
/// Input does not belong to the current device
ERR_DEVICE = 208,
// 300-399 Errors for missing software features
/// The option is not supported
ERR_NOT_SUPPORTED = 301,
/// This build of ArrayFire does not support this feature
ERR_NOT_CONFIGURED = 302,
// 400-499 Errors for missing hardware features
/// This device does not support double
ERR_NO_DBL = 401,
/// This build of ArrayFire was not built with graphics or this device does
/// not support graphics
ERR_NO_GFX = 402,
// 900-999 Errors from upstream libraries and runtimes
/// There was an internal error either in ArrayFire or in a project
/// upstream
ERR_INTERNAL = 998,
/// Unknown Error
ERR_UNKNOWN = 999,
}
/// Compute/Acceleration Backend
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum Backend {
/// Default backend order: CUDA -> OpenCL -> CPU
DEFAULT = 0,
/// CPU a.k.a sequential algorithms
CPU = 1,
/// CUDA Compute Backend
CUDA = 2,
/// OpenCL Compute Backend
OPENCL = 4,
/// OneAPI Compute Backend
ONEAPI = 8,
}
impl Display for Backend {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
let text = match *self {
Backend::ONEAPI => "OneAPI",
Backend::OPENCL => "OpenCL",
Backend::CUDA => "Cuda",
Backend::CPU => "CPU",
Backend::DEFAULT => "Default",
};
write!(f, "{}", text)
}
}
impl Display for AfError {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
let text = match *self {
AfError::SUCCESS => "Function returned successfully",
AfError::ERR_NO_MEM => "System or Device ran out of memory",
AfError::ERR_DRIVER => "Error in the device driver",
AfError::ERR_RUNTIME => "Error with the runtime environment",
AfError::ERR_INVALID_ARRAY => "Iput Array is not a valid object",
AfError::ERR_ARG => "One of the function arguments is incorrect",
AfError::ERR_SIZE => "Size is incorrect",
AfError::ERR_TYPE => "Type is not suppported by this function",
AfError::ERR_DIFF_TYPE => "Type of the input arrays are not compatible",
AfError::ERR_BATCH => "Function does not support GFOR / batch mode",
AfError::ERR_DEVICE => "Input does not belong to the current device",
AfError::ERR_NOT_SUPPORTED => "Unsupported operation/parameter option",
AfError::ERR_NOT_CONFIGURED => "This build of ArrayFire does not support this feature",
AfError::ERR_NO_DBL => "This device does not support double",
AfError::ERR_NO_GFX => "This build of ArrayFire has no graphics support",
AfError::ERR_INTERNAL => "Error either in ArrayFire or in a project upstream",
AfError::ERR_UNKNOWN => "Unknown Error",
};
write!(f, "{}", text)
}
}
/// Types of Array data type
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum DType {
/// 32 bit float
F32 = 0,
/// 32 bit complex float
C32 = 1,
/// 64 bit float
F64 = 2,
/// 64 bit complex float
C64 = 3,
/// 8 bit boolean
B8 = 4,
/// 32 bit signed integer
S32 = 5,
/// 32 bit unsigned integer
U32 = 6,
/// 8 bit unsigned integer
U8 = 7,
/// 64 bit signed integer
S64 = 8,
/// 64 bit unsigned integer
U64 = 9,
/// 16 bit signed integer
S16 = 10,
/// 16 bit unsigned integer
U16 = 11,
/// 16 bit floating point
F16 = 12,
}
/// Dictates the interpolation method to be used by a function
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum InterpType {
/// Nearest Neighbor interpolation method
NEAREST = 0,
/// Linear interpolation method
LINEAR = 1,
/// Bilinear interpolation method
BILINEAR = 2,
/// Cubic interpolation method
CUBIC = 3,
/// Floor indexed
LOWER = 4,
/// Linear interpolation with cosine smoothing
LINEAR_COSINE = 5,
/// Bilinear interpolation with cosine smoothing
BILINEAR_COSINE = 6,
/// Bicubic interpolation
BICUBIC = 7,
/// Cubic interpolation with Catmull-Rom splines
CUBIC_SPLINE = 8,
/// Bicubic interpolation with Catmull-Rom splines
BICUBIC_SPLINE = 9,
}
/// Helps determine how to pad kernels along borders
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum BorderType {
/// Pad using zeros
ZERO = 0,
/// Pad using mirrored values along border
SYMMETRIC = 1,
/// Out of bound values are clamped to the edge
CLAMP_TO_EDGE,
/// Out of bound values are mapped to range of the dimension in cyclic fashion
PERIODIC,
}
/// Used by `regions` function to identify type of connectivity
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum Connectivity {
/// North-East-South-West (N-E-S-W) connectivity from given pixel/point
FOUR = 4,
/// N-NE-E-SE-S-SW-W-NW connectivity from given pixel/point
EIGHT = 8,
}
/// Helps determine the size of output of convolution
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum ConvMode {
/// Default convolution mode where output size is same as input size
DEFAULT = 0,
/// Output of convolution is expanded based on signal and filter sizes
EXPAND = 1,
}
/// Helps determine if convolution is in Spatial or Frequency domain
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum ConvDomain {
/// ArrayFire chooses whether the convolution will be in spatial domain or frequency domain
AUTO = 0,
/// Convoltion in spatial domain
SPATIAL = 1,
/// Convolution in frequency domain
FREQUENCY = 2,
}
/// Error metric used by `matchTemplate` function
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum MatchType {
/// Sum of Absolute Differences
SAD = 0,
/// Zero-mean Sum of Absolute Differences
ZSAD = 1,
/// Locally scaled Sum of Absolute Differences
LSAD = 2,
/// Sum of Squared Differences
SSD = 3,
/// Zero-mean Sum of Squared Differences
ZSSD = 4,
/// Localy scaled Sum of Squared Differences
LSSD = 5,
/// Normalized Cross Correlation
NCC = 6,
/// Zero-mean Normalized Cross Correlation
ZNCC = 7,
/// Sum of Hamming Distances
SHD = 8,
}
/// Identify the color space of given image(Array)
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum ColorSpace {
/// Grayscale color space
GRAY = 0,
/// Red-Green-Blue color space
RGB = 1,
/// Hue-Saturation-value color space
HSV = 2,
}
/// Helps determine the type of a Matrix
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum MatProp {
/// Default (no-op)
NONE = 0,
/// Data needs to be transposed
TRANS = 1,
/// Data needs to be conjugate transposed
CTRANS = 2,
/// Matrix is upper triangular
CONJ = 4,
/// Matrix needs to be conjugate
UPPER = 32,
/// Matrix is lower triangular
LOWER = 64,
/// Matrix diagonal has unitary values
DIAGUNIT = 128,
/// Matrix is symmetric
SYM = 512,
/// Matrix is positive definite
POSDEF = 1024,
/// Matrix is orthogonal
ORTHOG = 2048,
/// Matrix is tri-diagonal
TRIDIAG = 4096,
/// Matrix is block-diagonal
BLOCKDIAG = 8192,
}
/// Norm type
#[allow(non_camel_case_types)]
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum NormType {
/// Treats input as a vector and return sum of absolute values
VECTOR_1 = 0,
/// Treats input as vector and return max of absolute values
VECTOR_INF = 1,
/// Treats input as vector and returns euclidean norm
VECTOR_2 = 2,
/// Treats input as vector and returns the p-norm
VECTOR_P = 3,
/// Return the max of column sums
MATRIX_1 = 4,
/// Return the max of row sums
MATRIX_INF = 5,
/// Returns the max singular value (Currently not supported)
MATRIX_2 = 6,
/// Returns Lpq-norm
MATRIX_L_PQ = 7,
}
/// Dictates what color map is used for Image rendering
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum ColorMap {
/// Default color map is grayscale range [0-1]
DEFAULT = 0,
/// Visible spectrum color map
SPECTRUM = 1,
/// Colors
COLORS = 2,
/// Red hue map
RED = 3,
/// Mood color map
MOOD = 4,
/// Heat color map
HEAT = 5,
/// Blue hue map
BLUE = 6,
}
/// YCbCr Standards
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum YCCStd {
/// ITU-R BT.601 (formerly CCIR 601) standard
YCC_601 = 601,
/// ITU-R BT.709 standard
YCC_709 = 709,
/// ITU-R BT.2020 standard
YCC_2020 = 2020,
}
/// Homography type
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum HomographyType {
/// RANdom SAmple Consensus algorithm
RANSAC = 0,
/// Least Median of Squares
LMEDS = 1,
}
/// Plotting markers
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum MarkerType {
/// No marker
NONE = 0,
/// Pointer marker
POINT = 1,
/// Hollow circle marker
CIRCLE = 2,
/// Hollow Square marker
SQUARE = 3,
/// Hollow Triangle marker
TRIANGLE = 4,
/// Cross-hair marker
CROSS = 5,
/// Plus symbol marker
PLUS = 6,
/// Start symbol marker
STAR = 7,
}
/// Image moment types
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum MomentType {
/// Central moment of order (0 + 0)
M00 = 1, // 1<<0
/// Central moment of order (0 + 1)
M01 = 2, // 1<<1
/// Central moment of order (1 + 0)
M10 = 4, // 1<<2
/// Central moment of order (1 + 1)
M11 = 8, // 1<<3
/// All central moments of order (0,0), (0,1), (1,0) and (1,1)
FIRST_ORDER = 1 | 1 << 1 | 1 << 2 | 1 << 3,
}
/// Sparse storage format type
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum SparseFormat {
/// Dense format
DENSE = 0,
/// Compressed sparse row format
CSR = 1,
/// Compressed sparse coloumn format
CSC = 2,
/// Coordinate list (row, coloumn, value) tuples.
COO = 3,
}
/// Binary operation types for generalized scan functions
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum BinaryOp {
/// Addition operation
ADD = 0,
/// Multiplication operation
MUL = 1,
/// Minimum operation
MIN = 2,
/// Maximum operation
MAX = 3,
}
/// Random engine types
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum RandomEngineType {
///Philox variant with N=4, W=32 and Rounds=10
PHILOX_4X32_10 = 100,
///Threefry variant with N=2, W=32 and Rounds=16
THREEFRY_2X32_16 = 200,
///Mersenne variant with MEXP = 11213
MERSENNE_GP11213 = 300,
}
/// Default Philon RandomEngine that points to [PHILOX_4X32_10](./enum.RandomEngineType.html)
pub const PHILOX: RandomEngineType = RandomEngineType::PHILOX_4X32_10;
/// Default Threefry RandomEngine that points to [THREEFRY_2X32_16](./enum.RandomEngineType.html)
pub const THREEFRY: RandomEngineType = RandomEngineType::THREEFRY_2X32_16;
/// Default Mersenne RandomEngine that points to [MERSENNE_GP11213](./enum.RandomEngineType.html)
pub const MERSENNE: RandomEngineType = RandomEngineType::MERSENNE_GP11213;
/// Default RandomEngine that defaults to [PHILOX](./constant.PHILOX.html)
pub const DEFAULT_RANDOM_ENGINE: RandomEngineType = PHILOX;
#[cfg(feature = "afserde")]
#[derive(Serialize, Deserialize)]
#[serde(remote = "Complex")]
struct ComplexDef<T> {
re: T,
im: T,
}
/// Scalar value types
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum Scalar {
/// 32 bit float
F32(f32),
/// 32 bit complex float
#[cfg_attr(feature = "afserde", serde(with = "ComplexDef"))]
C32(Complex<f32>),
/// 64 bit float
F64(f64),
/// 64 bit complex float
#[cfg_attr(feature = "afserde", serde(with = "ComplexDef"))]
C64(Complex<f64>),
/// 8 bit boolean
B8(bool),
/// 32 bit signed integer
S32(i32),
/// 32 bit unsigned integer
U32(u32),
/// 8 bit unsigned integer
U8(u8),
/// 64 bit signed integer
S64(i64),
/// 64 bit unsigned integer
U64(u64),
/// 16 bit signed integer
S16(i16),
/// 16 bit unsigned integer
U16(u16),
}
/// Canny edge detector threshold operations types
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum CannyThresholdType {
/// User has to define canny thresholds manually
MANUAL = 0,
/// Determine canny algorithm high threshold using Otsu algorithm automatically
OTSU = 1,
}
/// Anisotropic diffusion flux equation types
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum DiffusionEq {
/// Quadratic flux function
QUADRATIC = 1,
/// Exponential flux function
EXPONENTIAL = 2,
/// Default flux function, a.k.a exponential
DEFAULT = 0,
}
/// Diffusion equation types
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum FluxFn {
/// Quadratic flux function
GRADIENT = 1,
/// Modified curvature diffusion equation
MCDE = 2,
/// Default diffusion method, Gradient
DEFAULT = 0,
}
/// topk function ordering
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum TopkFn {
/// Top k min values
MIN = 1,
/// Top k max values
MAX = 2,
/// Default option(max)
DEFAULT = 0,
}
/// Iterative Deconvolution Algorithm
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum IterativeDeconvAlgo {
/// Land-Weber Algorithm
LANDWEBER = 1,
/// Richardson-Lucy Algorithm
RICHARDSONLUCY = 2,
/// Default is Land-Weber algorithm
DEFAULT = 0,
}
/// Inverse Deconvolution Algorithm
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum InverseDeconvAlgo {
/// Tikhonov algorithm
TIKHONOV = 1,
/// Default is Tikhonov algorithm
DEFAULT = 0,
}
/// Gradient mode for convolution
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum ConvGradientType {
/// Filter Gradient
FILTER = 1,
/// Data Gradient
DATA = 2,
/// Biased Gradient
BIAS = 3,
/// Default is Data Gradient
DEFAULT = 0,
}
/// Gradient mode for convolution
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum VarianceBias {
/// Sample variance
SAMPLE = 1,
/// Population variance
POPULATION = 2,
/// Default (Population) variance
DEFAULT = 0,
}
/// Gradient mode for convolution
#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "afserde", derive(Serialize, Deserialize))]
pub enum CublasMathMode {
/// To indicate use of Tensor Cores on CUDA capable GPUs
TENSOR_OP = 1,
/// Default i.e. tensor core operations will be avoided by the library
DEFAULT = 0,
}
#[cfg(test)]
mod tests {
#[cfg(feature = "afserde")]
mod serde_tests {
#[test]
fn test_enum_serde() {
use super::super::AfError;
let err_code = AfError::ERR_NO_MEM;
let serd = match serde_json::to_string(&err_code) {
Ok(serialized_str) => serialized_str,
Err(e) => e.to_string(),
};
assert_eq!(serd, "\"ERR_NO_MEM\"");
let deserd: AfError = serde_json::from_str(&serd).unwrap();
assert_eq!(deserd, AfError::ERR_NO_MEM);
}
#[test]
fn test_scalar_serde() {
use super::super::Scalar;
use num::Complex;
let scalar = Scalar::C32(Complex {
re: 1.0f32,
im: 1.0f32,
});
let serd = match serde_json::to_string(&scalar) {
Ok(serialized_str) => serialized_str,
Err(e) => e.to_string(),
};
let deserd: Scalar = serde_json::from_str(&serd).unwrap();
assert_eq!(deserd, scalar);
}
}
}