Skip to content

Commit ebfe9e5

Browse files
committed
Added short (s16) and ushort (u16) types for CPU
* Work in progress. Need to add CUDA and OpenCL * Header files have 16 bit type functions wrapped in AF_API_VERSION
1 parent 8d68ba5 commit ebfe9e5

File tree

169 files changed

+666
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+666
-149
lines changed

include/af/array.h

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ namespace af
8484
ASSIGN(/=)
8585
#undef ASSIGN
8686

87+
#if AF_API_VERSION >= 32
88+
#define ASSIGN(OP) \
89+
array_proxy& operator OP(const short &a); \
90+
array_proxy& operator OP(const unsigned short &a); \
91+
92+
ASSIGN(=)
93+
ASSIGN(+=)
94+
ASSIGN(-=)
95+
ASSIGN(*=)
96+
ASSIGN(/=)
97+
#undef ASSIGN
98+
#endif
99+
87100
// af::array member functions. same behavior as those below
88101
af_array get();
89102
af_array get() const;
@@ -813,7 +826,7 @@ namespace af
813826
/// \ingroup method_mat
814827
array H() const;
815828

816-
#define ASSIGN(OP) \
829+
#define ASSIGN_(OP) \
817830
array& OP(const array &val); \
818831
array& OP(const double &val); /**< \copydoc OP (const array &) */ \
819832
array& OP(const cdouble &val); /**< \copydoc OP (const array &) */ \
@@ -829,6 +842,17 @@ namespace af
829842
array& OP(const long long &val); /**< \copydoc OP (const array &) */ \
830843
array& OP(const unsigned long long &val); /**< \copydoc OP (const array &) */ \
831844

845+
#if AF_API_VERSION >= 32
846+
#define ASSIGN(OP) \
847+
ASSIGN_(OP) \
848+
array& OP(const short &val); /**< \copydoc OP (const array &) */ \
849+
array& OP(const unsigned short &val); /**< \copydoc OP (const array &) */ \
850+
851+
#else
852+
#define ASSIGN(OP) ASSIGN_(OP)
853+
#endif
854+
855+
832856
/// \ingroup array_mem_operator_eq
833857
/// @{
834858
/// \brief Assignes the value(s) of val to the elements of the array.
@@ -892,6 +916,7 @@ namespace af
892916

893917

894918
#undef ASSIGN
919+
#undef ASSIGN_
895920

896921
///
897922
/// \brief Negates the values of the array
@@ -930,7 +955,7 @@ namespace af
930955
};
931956
// end of class array
932957

933-
#define BIN_OP(OP) \
958+
#define BIN_OP_(OP) \
934959
AFAPI array OP (const array& lhs, const array& rhs); \
935960
AFAPI array OP (const bool& lhs, const array& rhs); /**< \copydoc OP (const array&, const array&) */ \
936961
AFAPI array OP (const int& lhs, const array& rhs); /**< \copydoc OP (const array&, const array&) */ \
@@ -959,6 +984,18 @@ namespace af
959984
AFAPI array OP (const array& lhs, const cfloat& rhs); /**< \copydoc OP (const array&, const array&) */ \
960985
AFAPI array OP (const array& lhs, const cdouble& rhs); /**< \copydoc OP (const array&, const array&) */ \
961986

987+
#if AF_API_VERSION >= 32
988+
#define BIN_OP(OP) \
989+
BIN_OP_(OP) \
990+
AFAPI array OP (const short& lhs, const array& rhs); /**< \copydoc OP (const array&, const array&) */ \
991+
AFAPI array OP (const unsigned short& lhs, const array& rhs); /**< \copydoc OP (const array&, const array&) */ \
992+
AFAPI array OP (const array& lhs, const short& rhs); /**< \copydoc OP (const array&, const array&) */ \
993+
AFAPI array OP (const array& lhs, const unsigned short& rhs); /**< \copydoc OP (const array&, const array&) */ \
994+
995+
#else
996+
#define BIN_OP(OP) BIN_OP_(OP)
997+
#endif
998+
962999
/// \ingroup arith_func_add
9631000
/// @{
9641001
/// \brief Adds two arrays or an array and a value.
@@ -1178,6 +1215,7 @@ namespace af
11781215
/// @}
11791216

11801217
#undef BIN_OP
1218+
#undef BIN_OP_
11811219

11821220
/// Evaluate an expression (nonblocking).
11831221
/**

include/af/defines.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,16 @@ typedef enum {
173173
c32, ///< 32-bit complex floating point values
174174
f64, ///< 64-bit complex floating point values
175175
c64, ///< 64-bit complex floating point values
176-
b8, ///< 8-bit boolean values
176+
b8 , ///< 8-bit boolean values
177177
s32, ///< 32-bit signed integral values
178178
u32, ///< 32-bit unsigned integral values
179-
u8, ///< 8-bit unsigned integral values
179+
u8 , ///< 8-bit unsigned integral values
180180
s64, ///< 64-bit signed integral values
181-
u64 ///< 64-bit unsigned integral values
181+
u64, ///< 64-bit unsigned integral values
182+
#if AF_API_VERSION >= 32
183+
s16, ///< 16-bit signed integral values
184+
u16, ///< 16-bit unsigned integral values
185+
#endif
182186
} af_dtype;
183187

184188
typedef enum {

include/af/traits.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ struct dtype_traits<unsigned long long> {
139139
static const char* getName() { return "ulong"; }
140140
};
141141

142+
template<>
143+
struct dtype_traits<short> {
144+
enum {
145+
af_type = s16 ,
146+
ctype = s16
147+
};
148+
typedef short base_type;
149+
static const char* getName() { return "short"; }
150+
};
151+
152+
template<>
153+
struct dtype_traits<unsigned short> {
154+
enum {
155+
af_type = u16 ,
156+
ctype = u16
157+
};
158+
typedef unsigned short base_type;
159+
static const char* getName() { return "ushort"; }
160+
};
161+
142162
}
143163

144164
#endif

include/af/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ namespace af
121121

122122
#define af_print(...) GET_PRINT_MACRO(__VA_ARGS__, AF_PRINT2, AF_PRINT1)(__VA_ARGS__)
123123

124-
#else
124+
#else // AF_API_VERSION
125125

126126
#define af_print(exp) af::print(#exp, exp);
127127

128-
#endif
128+
#endif // AF_API_VERSION
129129

130130
#endif //__cplusplus
131131

src/api/c/assign.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ void assign_helper(Array<T> &out, const unsigned &ndims, const af_seq *index, co
105105
case u32: assign<T, uint >(out, ndims, index, getArray<uint >(in_)); break;
106106
case s64: assign<T, intl >(out, ndims, index, getArray<intl >(in_)); break;
107107
case u64: assign<T, uintl >(out, ndims, index, getArray<uintl >(in_)); break;
108+
case s16: assign<T, short >(out, ndims, index, getArray<short >(in_)); break;
109+
case u16: assign<T, ushort >(out, ndims, index, getArray<ushort >(in_)); break;
108110
case u8 : assign<T, uchar >(out, ndims, index, getArray<uchar >(in_)); break;
109111
case b8 : assign<T, char >(out, ndims, index, getArray<char >(in_)); break;
110112
default : TYPE_ERROR(1, iType); break;
@@ -165,6 +167,8 @@ af_err af_assign_seq(af_array *out,
165167
case u32: assign_helper<uint >(getWritableArray<uint >(res), ndims, index, rhs); break;
166168
case s64: assign_helper<intl >(getWritableArray<intl >(res), ndims, index, rhs); break;
167169
case u64: assign_helper<uintl >(getWritableArray<uintl >(res), ndims, index, rhs); break;
170+
case s16: assign_helper<short >(getWritableArray<short >(res), ndims, index, rhs); break;
171+
case u16: assign_helper<ushort >(getWritableArray<ushort >(res), ndims, index, rhs); break;
168172
case u8 : assign_helper<uchar >(getWritableArray<uchar >(res), ndims, index, rhs); break;
169173
case b8 : assign_helper<char >(getWritableArray<char >(res), ndims, index, rhs); break;
170174
default : TYPE_ERROR(1, oType); break;
@@ -332,6 +336,8 @@ af_err af_assign_gen(af_array *out,
332336
case u32: genAssign<uint >(output, idxrs, rhs); break;
333337
case s64: genAssign<intl >(output, idxrs, rhs); break;
334338
case s32: genAssign<int >(output, idxrs, rhs); break;
339+
case s16: genAssign<short >(output, idxrs, rhs); break;
340+
case u16: genAssign<ushort >(output, idxrs, rhs); break;
335341
case u8: genAssign<uchar >(output, idxrs, rhs); break;
336342
case b8: genAssign<char >(output, idxrs, rhs); break;
337343
default: TYPE_ERROR(1, rhsType);

src/api/c/bilateral.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ static af_err bilateral(af_array *out, const af_array &in, const float &s_sigma,
4242
case s32: output = bilateral<int , float, isColor> (in, s_sigma, c_sigma); break;
4343
case u32: output = bilateral<uint , float, isColor> (in, s_sigma, c_sigma); break;
4444
case u8 : output = bilateral<uchar , float, isColor> (in, s_sigma, c_sigma); break;
45+
case s16: output = bilateral<short , float, isColor> (in, s_sigma, c_sigma); break;
46+
case u16: output = bilateral<ushort, float, isColor> (in, s_sigma, c_sigma); break;
4547
default : TYPE_ERROR(1, type);
4648
}
4749
std::swap(*out,output);

src/api/c/binary.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static af_err af_arith(af_array *out, const af_array lhs, const af_array rhs, co
5555
case b8 : res = arithOp<char , op>(lhs, rhs, odims); break;
5656
case s64: res = arithOp<intl , op>(lhs, rhs, odims); break;
5757
case u64: res = arithOp<uintl , op>(lhs, rhs, odims); break;
58+
case s16: res = arithOp<short , op>(lhs, rhs, odims); break;
59+
case u16: res = arithOp<ushort , op>(lhs, rhs, odims); break;
5860
default: TYPE_ERROR(0, otype);
5961
}
6062

@@ -85,6 +87,8 @@ static af_err af_arith_real(af_array *out, const af_array lhs, const af_array rh
8587
case b8 : res = arithOp<char , op>(lhs, rhs, odims); break;
8688
case s64: res = arithOp<intl , op>(lhs, rhs, odims); break;
8789
case u64: res = arithOp<uintl , op>(lhs, rhs, odims); break;
90+
case s16: res = arithOp<short , op>(lhs, rhs, odims); break;
91+
case u16: res = arithOp<ushort , op>(lhs, rhs, odims); break;
8892
default: TYPE_ERROR(0, otype);
8993
}
9094

@@ -260,6 +264,8 @@ static af_err af_logic(af_array *out, const af_array lhs, const af_array rhs, co
260264
case b8 : res = logicOp<char , op>(lhs, rhs, odims); break;
261265
case s64: res = logicOp<intl , op>(lhs, rhs, odims); break;
262266
case u64: res = logicOp<uintl , op>(lhs, rhs, odims); break;
267+
case s16: res = logicOp<short , op>(lhs, rhs, odims); break;
268+
case u16: res = logicOp<ushort , op>(lhs, rhs, odims); break;
263269
default: TYPE_ERROR(0, type);
264270
}
265271

@@ -335,6 +341,8 @@ static af_err af_bitwise(af_array *out, const af_array lhs, const af_array rhs,
335341
case b8 : res = bitOp<char , op>(lhs, rhs, odims); break;
336342
case s64: res = bitOp<intl , op>(lhs, rhs, odims); break;
337343
case u64: res = bitOp<uintl , op>(lhs, rhs, odims); break;
344+
case s16: res = bitOp<short , op>(lhs, rhs, odims); break;
345+
case u16: res = bitOp<ushort , op>(lhs, rhs, odims); break;
338346
default: TYPE_ERROR(0, type);
339347
}
340348

src/api/c/cast.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static af_array cast(const af_array in, const af_dtype type)
3939
case b8 : return getHandle(castArray<char >(in));
4040
case s64: return getHandle(castArray<intl >(in));
4141
case u64: return getHandle(castArray<uintl >(in));
42+
case s16: return getHandle(castArray<short >(in));
43+
case u16: return getHandle(castArray<ushort >(in));
4244
default: TYPE_ERROR(2, type);
4345
}
4446
}

src/api/c/convolve.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ af_err convolve(af_array *out, const af_array signal, const af_array filter)
8585
case f64: output = convolve<double , double, baseDim, expand>(signal, filter, convBT); break;
8686
case u32: output = convolve<uint , float, baseDim, expand>(signal, filter, convBT); break;
8787
case s32: output = convolve<int , float, baseDim, expand>(signal, filter, convBT); break;
88+
case u16: output = convolve<ushort , float, baseDim, expand>(signal, filter, convBT); break;
89+
case s16: output = convolve<short , float, baseDim, expand>(signal, filter, convBT); break;
8890
case u8: output = convolve<uchar , float, baseDim, expand>(signal, filter, convBT); break;
8991
case b8: output = convolve<char , float, baseDim, expand>(signal, filter, convBT); break;
9092
default: TYPE_ERROR(1, stype);
@@ -120,6 +122,8 @@ af_err convolve2_sep(af_array *out, af_array col_filter, af_array row_filter, co
120122
case f64: output = convolve2<double , double, expand>(signal, col_filter, row_filter); break;
121123
case u32: output = convolve2<uint , float, expand>(signal, col_filter, row_filter); break;
122124
case s32: output = convolve2<int , float, expand>(signal, col_filter, row_filter); break;
125+
case u16: output = convolve2<ushort , float, expand>(signal, col_filter, row_filter); break;
126+
case s16: output = convolve2<short , float, expand>(signal, col_filter, row_filter); break;
123127
case u8: output = convolve2<uchar , float, expand>(signal, col_filter, row_filter); break;
124128
case b8: output = convolve2<char , float, expand>(signal, col_filter, row_filter); break;
125129
default: TYPE_ERROR(1, signalType);

src/api/c/corrcoef.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ af_err af_corrcoef(double *realVal, double *imagVal, const af_array X, const af_
7171
case u32: *realVal = corrcoef<uint , float >(X, Y); break;
7272
case s64: *realVal = corrcoef<intl , double>(X, Y); break;
7373
case u64: *realVal = corrcoef<uintl , double>(X, Y); break;
74+
case s16: *realVal = corrcoef<short , float >(X, Y); break;
75+
case u16: *realVal = corrcoef<ushort, float >(X, Y); break;
7476
case u8: *realVal = corrcoef<uchar , float >(X, Y); break;
7577
case b8: *realVal = corrcoef<char , float >(X, Y); break;
7678
default : TYPE_ERROR(1, xType);

0 commit comments

Comments
 (0)