-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathimplicit.cpp
More file actions
52 lines (41 loc) · 1.59 KB
/
implicit.cpp
File metadata and controls
52 lines (41 loc) · 1.59 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
/*******************************************************
* 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 > schar > 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 == f16) || (rty == f16)) { return f16; }
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 == s8) || (rty == s8)) { return s8; }
if ((lty == b8) && (rty == b8)) { return b8; }
return f32;
}
af_dtype implicit(const af_array lhs, const af_array rhs) {
const ArrayInfo& lInfo = getInfo(lhs);
const ArrayInfo& rInfo = getInfo(rhs);
return implicit(lInfo.getType(), rInfo.getType());
}