A high-performance general-purpose compute library
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#include <af/half.h>
18
19namespace af {
20
21template<typename T> struct dtype_traits;
22
23template<>
24struct 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
33template<>
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
43template<>
44struct 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
53template<>
54struct 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
63template<>
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
73template<>
74struct 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
83template<>
84struct 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
93template<>
94struct 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
103template<>
104struct 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
113template<>
114struct 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
123template<>
124struct 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
133template<>
134struct 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
144template<>
145struct 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
156template<>
157struct 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
168template<>
170 enum {
171 af_type = f16 ,
172 ctype = f16
173 };
175 static const char* getName() { return "half"; }
176};
177#endif
178}
179
180#endif
@ u32
32-bit unsigned integral values
Definition: defines.h:217
@ u64
64-bit unsigned integral values
Definition: defines.h:220
@ s32
32-bit signed integral values
Definition: defines.h:216
@ s64
64-bit signed integral values
Definition: defines.h:219
@ b8
8-bit boolean values
Definition: defines.h:215
@ c64
64-bit complex floating point values
Definition: defines.h:214
@ f32
32-bit floating point values
Definition: defines.h:211
@ s16
16-bit signed integral values
Definition: defines.h:222
@ c32
32-bit complex floating point values
Definition: defines.h:212
@ f64
64-bit floating point values
Definition: defines.h:213
@ u16
16-bit unsigned integral values
Definition: defines.h:225
@ f16
16-bit floating point value
Definition: defines.h:228
@ u8
8-bit unsigned integral values
Definition: defines.h:218
AFAPI array complex(const array &in)
C++ Interface to create a complex array from a single real array.
Definition: algorithm.h:15
static const char * getName()
Definition: traits.hpp:70
static const char * getName()
Definition: traits.hpp:40
static const char * getName()
Definition: traits.hpp:90
static const char * getName()
Definition: traits.hpp:60
static const char * getName()
Definition: traits.hpp:30
static const char * getName()
Definition: traits.hpp:175
static const char * getName()
Definition: traits.hpp:100
static const char * getName()
Definition: traits.hpp:130
static const char * getName()
Definition: traits.hpp:151
static const char * getName()
Definition: traits.hpp:110
static const char * getName()
Definition: traits.hpp:120
static const char * getName()
Definition: traits.hpp:140
static const char * getName()
Definition: traits.hpp:163
Definition: half.h:12