forked from hunter-packages/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplicit.cpp
More file actions
71 lines (53 loc) · 1.53 KB
/
implicit.cpp
File metadata and controls
71 lines (53 loc) · 1.53 KB
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
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <implicit.hpp>
/*
Implicit type mimics C/C++ behavior.
Order of precedence:
- complex > real
- double > float > uintl > intl > uint > int > uchar > char
*/
af_dtype implicit(const af_dtype lty, const af_dtype rty)
{
if (lty == rty) {
return lty;
}
if (lty == c64 || rty == c64) {
return c64;
}
if (lty == c32 || rty == c32) {
if (lty == f64 || rty == f64) return c64;
return c32;
}
if (lty == f64 || rty == f64) return f64;
if (lty == f32 || rty == f32) return f32;
if ((lty == u64) ||
(rty == u64)) return u64;
if ((lty == s64) ||
(rty == s64)) return s64;
if ((lty == u32) ||
(rty == u32)) return u32;
if ((lty == s32) ||
(rty == s32)) return s32;
if ((lty == u16) ||
(rty == u16)) return u16;
if ((lty == s16) ||
(rty == s16)) return s16;
if ((lty == u8 ) ||
(rty == u8 )) return u8;
if ((lty == b8 ) &&
(rty == b8 )) return b8;
return f32;
}
af_dtype implicit(const af_array lhs, const af_array rhs)
{
ArrayInfo lInfo = getInfo(lhs);
ArrayInfo rInfo = getInfo(rhs);
return implicit(lInfo.getType(), rInfo.getType());
}