traits.hpp (2020-07-07 17:43:34 +0530, (build 218dd2c99))
Go to the documentation of this file.
1 /*******************************************************
2  * Copyright (c) 2014, ArrayFire
3  * All rights reserved.
4  *
5  * This file is distributed under 3-clause BSD license.
6  * The complete license agreement can be obtained at:
7  * https://arrayfire.com/licenses/BSD-3-Clause
8  ********************************************************/
9 
10 #pragma once
11 
12 #ifdef __cplusplus
13 
14 #include <complex>
15 #include <af/defines.h>
16 #include <af/complex.h>
17 #include <af/half.h>
18 
19 namespace af {
20 
21 template<typename T> struct dtype_traits;
22 
23 template<>
24 struct dtype_traits<float> {
25  enum {
26  af_type = f32,
27  ctype = f32
28  };
29  typedef float base_type;
30  static const char* getName() { return "float"; }
31 };
32 
33 template<>
34 struct dtype_traits<af::cfloat> {
35  enum {
36  af_type = c32 ,
37  ctype = c32
38  };
39  typedef float base_type;
40  static const char* getName() { return "std::complex<float>"; }
41 };
42 
43 template<>
44 struct dtype_traits<std::complex<float> > {
45  enum {
46  af_type = c32 ,
47  ctype = c32
48  };
49  typedef float base_type;
50  static const char* getName() { return "std::complex<float>"; }
51 };
52 
53 template<>
54 struct dtype_traits<double> {
55  enum {
56  af_type = f64 ,
57  ctype = f32
58  };
59  typedef double base_type;
60  static const char* getName() { return "double"; }
61 };
62 
63 template<>
64 struct dtype_traits<af::cdouble> {
65  enum {
66  af_type = c64 ,
67  ctype = c64
68  };
69  typedef double base_type;
70  static const char* getName() { return "std::complex<double>"; }
71 };
72 
73 template<>
74 struct dtype_traits<std::complex<double> > {
75  enum {
76  af_type = c64 ,
77  ctype = c64
78  };
79  typedef double base_type;
80  static const char* getName() { return "std::complex<double>"; }
81 };
82 
83 template<>
84 struct dtype_traits<char> {
85  enum {
86  af_type = b8 ,
87  ctype = f32
88  };
89  typedef char base_type;
90  static const char* getName() { return "char"; }
91 };
92 
93 template<>
94 struct dtype_traits<int> {
95  enum {
96  af_type = s32 ,
97  ctype = f32
98  };
99  typedef int base_type;
100  static const char* getName() { return "int"; }
101 };
102 
103 template<>
104 struct dtype_traits<unsigned> {
105  enum {
106  af_type = u32 ,
107  ctype = f32
108  };
109  typedef unsigned base_type;
110  static const char* getName() { return "uint"; }
111 };
112 
113 template<>
114 struct dtype_traits<unsigned char> {
115  enum {
116  af_type = u8 ,
117  ctype = f32
118  };
119  typedef unsigned char base_type;
120  static const char* getName() { return "uchar"; }
121 };
122 
123 template<>
124 struct dtype_traits<long long> {
125  enum {
126  af_type = s64 ,
127  ctype = s64
128  };
129  typedef long long base_type;
130  static const char* getName() { return "long"; }
131 };
132 
133 template<>
134 struct dtype_traits<unsigned long long> {
135  enum {
136  af_type = u64 ,
137  ctype = u64
138  };
139  typedef unsigned long long base_type;
140  static const char* getName() { return "ulong"; }
141 };
142 
143 #if AF_API_VERSION >= 32
144 template<>
145 struct dtype_traits<short> {
146  enum {
147  af_type = s16 ,
148  ctype = s16
149  };
150  typedef short base_type;
151  static const char* getName() { return "short"; }
152 };
153 #endif
154 
155 #if AF_API_VERSION >= 32
156 template<>
157 struct dtype_traits<unsigned short> {
158  enum {
159  af_type = u16 ,
160  ctype = u16
161  };
162  typedef unsigned short base_type;
163  static const char* getName() { return "ushort"; }
164 };
165 #endif
166 
167 #if AF_API_VERSION >= 37
168 template<>
170  enum {
171  af_type = f16 ,
172  ctype = f16
173  };
174  typedef half base_type;
175  static const char* getName() { return "half"; }
176 };
177 #endif
178 }
179 
180 #endif
af::complex
AFAPI array complex(const array &real, const array &imaginary)
af::dtype_traits
Definition: traits.hpp:28
half.h
u64
@ u64
64-bit unsigned integral values
Definition: defines.h:220
af
Definition: algorithm.h:15
u8
@ u8
8-bit unsigned integral values
Definition: defines.h:218
b8
@ b8
8-bit boolean values
Definition: defines.h:215
f64
@ f64
64-bit complex floating point values
Definition: defines.h:213
f16
@ f16
16-bit floating point value
Definition: defines.h:228
s32
@ s32
32-bit signed integral values
Definition: defines.h:216
complex.h
s16
@ s16
16-bit signed integral values
Definition: defines.h:222
af_half
Definition: half.h:12
u16
@ u16
16-bit unsigned integral values
Definition: defines.h:225
u32
@ u32
32-bit unsigned integral values
Definition: defines.h:217
af::af_cdouble
Definition: complex.h:39
af::af_cfloat
Definition: complex.h:31
c64
@ c64
64-bit complex floating point values
Definition: defines.h:214
c32
@ c32
32-bit complex floating point values
Definition: defines.h:212
defines.h
f32
@ f32
32-bit floating point values
Definition: defines.h:211
s64
@ s64
64-bit signed integral values
Definition: defines.h:219