Skip to content

Commit c45ff2e

Browse files
authored
Merge pull request pytorch#915 from pavanky/convert
Macros to convert between real and accreal
2 parents e67b525 + fef2b15 commit c45ff2e

File tree

4 files changed

+43
-89
lines changed

4 files changed

+43
-89
lines changed

THGenerateAllTypes.h

Lines changed: 4 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,95 +2,10 @@
22
#error "You must define TH_GENERIC_FILE before including THGenerateAllTypes.h"
33
#endif
44

5-
#define real unsigned char
6-
#define accreal long
7-
#define Real Byte
8-
#define THInf UCHAR_MAX
9-
#define TH_REAL_IS_BYTE
10-
#line 1 TH_GENERIC_FILE
11-
#include TH_GENERIC_FILE
12-
#undef real
13-
#undef accreal
14-
#undef Real
15-
#undef THInf
16-
#undef TH_REAL_IS_BYTE
5+
#define THGenerateAllTypes
176

18-
#define real char
19-
#define accreal long
20-
#define Real Char
21-
#define THInf CHAR_MAX
22-
#define TH_REAL_IS_CHAR
23-
#line 1 TH_GENERIC_FILE
24-
#include TH_GENERIC_FILE
25-
#undef real
26-
#undef accreal
27-
#undef Real
28-
#undef THInf
29-
#undef TH_REAL_IS_CHAR
30-
31-
#define real short
32-
#define accreal long
33-
#define Real Short
34-
#define THInf SHRT_MAX
35-
#define TH_REAL_IS_SHORT
36-
#line 1 TH_GENERIC_FILE
37-
#include TH_GENERIC_FILE
38-
#undef real
39-
#undef accreal
40-
#undef Real
41-
#undef THInf
42-
#undef TH_REAL_IS_SHORT
43-
44-
#define real int
45-
#define accreal long
46-
#define Real Int
47-
#define THInf INT_MAX
48-
#define TH_REAL_IS_INT
49-
#line 1 TH_GENERIC_FILE
50-
#include TH_GENERIC_FILE
51-
#undef real
52-
#undef accreal
53-
#undef Real
54-
#undef THInf
55-
#undef TH_REAL_IS_INT
56-
57-
#define real long
58-
#define accreal long
59-
#define Real Long
60-
#define THInf LONG_MAX
61-
#define TH_REAL_IS_LONG
62-
#line 1 TH_GENERIC_FILE
63-
#include TH_GENERIC_FILE
64-
#undef real
65-
#undef accreal
66-
#undef Real
67-
#undef THInf
68-
#undef TH_REAL_IS_LONG
69-
70-
#define real float
71-
#define accreal double
72-
#define Real Float
73-
#define THInf FLT_MAX
74-
#define TH_REAL_IS_FLOAT
75-
#line 1 TH_GENERIC_FILE
76-
#include TH_GENERIC_FILE
77-
#undef real
78-
#undef accreal
79-
#undef Real
80-
#undef THInf
81-
#undef TH_REAL_IS_FLOAT
82-
83-
#define real double
84-
#define accreal double
85-
#define Real Double
86-
#define THInf DBL_MAX
87-
#define TH_REAL_IS_DOUBLE
88-
#line 1 TH_GENERIC_FILE
89-
#include TH_GENERIC_FILE
90-
#undef real
91-
#undef accreal
92-
#undef Real
93-
#undef THInf
94-
#undef TH_REAL_IS_DOUBLE
7+
#include "THGenerateFloatTypes.h"
8+
#include "THGenerateIntTypes.h"
959

10+
#undef THGenerateAllTypes
9611
#undef TH_GENERIC_FILE

THGenerateFloatTypes.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#define real float
66
#define accreal double
7+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val)
8+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val)
79
#define Real Float
810
#define THInf FLT_MAX
911
#define TH_REAL_IS_FLOAT
@@ -14,9 +16,13 @@
1416
#undef Real
1517
#undef THInf
1618
#undef TH_REAL_IS_FLOAT
19+
#undef TH_CONVERT_REAL_TO_ACCREAL
20+
#undef TH_CONVERT_ACCREAL_TO_REAL
1721

1822
#define real double
1923
#define accreal double
24+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val)
25+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val)
2026
#define Real Double
2127
#define THInf DBL_MAX
2228
#define TH_REAL_IS_DOUBLE
@@ -27,5 +33,9 @@
2733
#undef Real
2834
#undef THInf
2935
#undef TH_REAL_IS_DOUBLE
36+
#undef TH_CONVERT_REAL_TO_ACCREAL
37+
#undef TH_CONVERT_ACCREAL_TO_REAL
3038

39+
#ifndef THGenerateAllTypes
3140
#undef TH_GENERIC_FILE
41+
#endif

THGenerateHalfType.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "THHalf.h"
66
#define real THHalf
77
#define accreal float
8+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) TH_half2float(_val)
9+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) TH_float2half(_val)
810
#define Real Half
911
#define THInf TH_HALF_MAX
1012
#define TH_REAL_IS_HALF
@@ -15,5 +17,9 @@
1517
#undef Real
1618
#undef THInf
1719
#undef TH_REAL_IS_HALF
20+
#undef TH_CONVERT_REAL_TO_ACCREAL
21+
#undef TH_CONVERT_ACCREAL_TO_REAL
1822

23+
#ifndef THGenerateAllTypes
1924
#undef TH_GENERIC_FILE
25+
#endif

THGenerateIntTypes.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#define real unsigned char
66
#define accreal long
77
#define Real Byte
8+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val)
9+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val)
810
#define THInf UCHAR_MAX
911
#define TH_REAL_IS_BYTE
1012
#line 1 TH_GENERIC_FILE
@@ -14,11 +16,16 @@
1416
#undef Real
1517
#undef THInf
1618
#undef TH_REAL_IS_BYTE
19+
#undef TH_CONVERT_REAL_TO_ACCREAL
20+
#undef TH_CONVERT_ACCREAL_TO_REAL
21+
1722

1823
#define real char
1924
#define accreal long
2025
#define Real Char
2126
#define THInf CHAR_MAX
27+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val)
28+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val)
2229
#define TH_REAL_IS_CHAR
2330
#line 1 TH_GENERIC_FILE
2431
#include TH_GENERIC_FILE
@@ -27,9 +34,13 @@
2734
#undef Real
2835
#undef THInf
2936
#undef TH_REAL_IS_CHAR
37+
#undef TH_CONVERT_REAL_TO_ACCREAL
38+
#undef TH_CONVERT_ACCREAL_TO_REAL
3039

3140
#define real short
3241
#define accreal long
42+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val)
43+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val)
3344
#define Real Short
3445
#define THInf SHRT_MAX
3546
#define TH_REAL_IS_SHORT
@@ -40,9 +51,13 @@
4051
#undef Real
4152
#undef THInf
4253
#undef TH_REAL_IS_SHORT
54+
#undef TH_CONVERT_REAL_TO_ACCREAL
55+
#undef TH_CONVERT_ACCREAL_TO_REAL
4356

4457
#define real int
4558
#define accreal long
59+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val)
60+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val)
4661
#define Real Int
4762
#define THInf INT_MAX
4863
#define TH_REAL_IS_INT
@@ -53,9 +68,13 @@
5368
#undef Real
5469
#undef THInf
5570
#undef TH_REAL_IS_INT
71+
#undef TH_CONVERT_REAL_TO_ACCREAL
72+
#undef TH_CONVERT_ACCREAL_TO_REAL
5673

5774
#define real long
5875
#define accreal long
76+
#define TH_CONVERT_REAL_TO_ACCREAL(_val) (accreal)(_val)
77+
#define TH_CONVERT_ACCREAL_TO_REAL(_val) (real)(_val)
5978
#define Real Long
6079
#define THInf LONG_MAX
6180
#define TH_REAL_IS_LONG
@@ -66,5 +85,9 @@
6685
#undef Real
6786
#undef THInf
6887
#undef TH_REAL_IS_LONG
88+
#undef TH_CONVERT_REAL_TO_ACCREAL
89+
#undef TH_CONVERT_ACCREAL_TO_REAL
6990

91+
#ifndef THGenerateAllTypes
7092
#undef TH_GENERIC_FILE
93+
#endif

0 commit comments

Comments
 (0)