traits.hpp
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  * http://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 
18 namespace af {
19 
20 template<typename T> struct dtype_traits;
21 
22 template<>
23 struct dtype_traits<float> {
24  enum {
25  af_type = f32,
26  ctype = f32
27  };
28  typedef float base_type;
29  static const char* getName() { return "float"; }
30 };
31 
32 template<>
34  enum {
35  af_type = c32 ,
36  ctype = c32
37  };
38  typedef float base_type;
39  static const char* getName() { return "std::complex<float>"; }
40 };
41 
42 template<>
43 struct dtype_traits<std::complex<float> > {
44  enum {
45  af_type = c32 ,
46  ctype = c32
47  };
48  typedef float base_type;
49  static const char* getName() { return "std::complex<float>"; }
50 };
51 
52 template<>
53 struct dtype_traits<double> {
54  enum {
55  af_type = f64 ,
56  ctype = f32
57  };
58  typedef double base_type;
59  static const char* getName() { return "double"; }
60 };
61 
62 template<>
64  enum {
65  af_type = c64 ,
66  ctype = c64
67  };
68  typedef double base_type;
69  static const char* getName() { return "std::complex<double>"; }
70 };
71 
72 template<>
73 struct dtype_traits<std::complex<double> > {
74  enum {
75  af_type = c64 ,
76  ctype = c64
77  };
78  typedef double base_type;
79  static const char* getName() { return "std::complex<double>"; }
80 };
81 
82 template<>
83 struct dtype_traits<char> {
84  enum {
85  af_type = b8 ,
86  ctype = f32
87  };
88  typedef char base_type;
89  static const char* getName() { return "char"; }
90 };
91 
92 template<>
93 struct dtype_traits<int> {
94  enum {
95  af_type = s32 ,
96  ctype = f32
97  };
98  typedef int base_type;
99  static const char* getName() { return "int"; }
100 };
101 
102 template<>
103 struct dtype_traits<unsigned> {
104  enum {
105  af_type = u32 ,
106  ctype = f32
107  };
108  typedef unsigned base_type;
109  static const char* getName() { return "uint"; }
110 };
111 
112 template<>
113 struct dtype_traits<unsigned char> {
114  enum {
115  af_type = u8 ,
116  ctype = f32
117  };
118  typedef unsigned char base_type;
119  static const char* getName() { return "uchar"; }
120 };
121 
122 template<>
123 struct dtype_traits<long long> {
124  enum {
125  af_type = s64 ,
126  ctype = s64
127  };
128  typedef long long base_type;
129  static const char* getName() { return "long"; }
130 };
131 
132 template<>
133 struct dtype_traits<unsigned long long> {
134  enum {
135  af_type = u64 ,
136  ctype = u64
137  };
138  typedef unsigned long long base_type;
139  static const char* getName() { return "ulong"; }
140 };
141 
142 #if AF_API_VERSION >= 32
143 template<>
144 struct dtype_traits<short> {
145  enum {
146  af_type = s16 ,
147  ctype = s16
148  };
149  typedef short base_type;
150  static const char* getName() { return "short"; }
151 };
152 #endif
153 
154 #if AF_API_VERSION >= 32
155 template<>
156 struct dtype_traits<unsigned short> {
157  enum {
158  af_type = u16 ,
159  ctype = u16
160  };
161  typedef unsigned short base_type;
162  static const char* getName() { return "ushort"; }
163 };
164 #endif
165 
166 }
167 
168 #endif
static const char * getName()
Definition: traits.hpp:109
static const char * getName()
Definition: traits.hpp:119
float base_type
Definition: traits.hpp:38
Definition: traits.hpp:20
Definition: algorithm.h:14
AFAPI array complex(const array &lhs, const array &rhs)
C++ Interface for creating complex array from two inputs.
float base_type
Definition: traits.hpp:28
static const char * getName()
Definition: traits.hpp:89
float base_type
Definition: traits.hpp:48
32-bit signed integral values
Definition: defines.h:201
static const char * getName()
Definition: traits.hpp:162
static const char * getName()
Definition: traits.hpp:150
64-bit signed integral values
Definition: defines.h:204
16-bit signed integral values
Definition: defines.h:207
int base_type
Definition: traits.hpp:98
Definition: complex.h:32
16-bit unsigned integral values
Definition: defines.h:210
static const char * getName()
Definition: traits.hpp:79
unsigned short base_type
Definition: traits.hpp:161
64-bit complex floating point values
Definition: defines.h:198
unsigned char base_type
Definition: traits.hpp:118
unsigned long long base_type
Definition: traits.hpp:138
double base_type
Definition: traits.hpp:78
long long base_type
Definition: traits.hpp:128
unsigned base_type
Definition: traits.hpp:108
static const char * getName()
Definition: traits.hpp:139
static const char * getName()
Definition: traits.hpp:129
64-bit unsigned integral values
Definition: defines.h:205
static const char * getName()
Definition: traits.hpp:39
64-bit complex floating point values
Definition: defines.h:199
32-bit complex floating point values
Definition: defines.h:197
static const char * getName()
Definition: traits.hpp:59
static const char * getName()
Definition: traits.hpp:29
8-bit unsigned integral values
Definition: defines.h:203
Definition: complex.h:24
double base_type
Definition: traits.hpp:68
static const char * getName()
Definition: traits.hpp:99
32-bit unsigned integral values
Definition: defines.h:202
static const char * getName()
Definition: traits.hpp:69
static const char * getName()
Definition: traits.hpp:49
double base_type
Definition: traits.hpp:58
32-bit floating point values
Definition: defines.h:196
char base_type
Definition: traits.hpp:88
8-bit boolean values
Definition: defines.h:200
short base_type
Definition: traits.hpp:149