Skip to content

Commit

Permalink
define s8 interface for AF_API_VERSION 310
Browse files Browse the repository at this point in the history
This also slightly extends the interface macros.
  • Loading branch information
verstatx committed Oct 14, 2023
1 parent 7f63372 commit df24030
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 25 deletions.
78 changes: 54 additions & 24 deletions include/af/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace af
operator array() const;
operator array();

#define ASSIGN(OP) \
#define ASSIGN_(OP) \
array_proxy& operator OP(const array_proxy &a); \
array_proxy& operator OP(const array &a); \
array_proxy& operator OP(const double &a); \
Expand All @@ -82,32 +82,41 @@ namespace af
array_proxy& operator OP(const unsigned &a); \
array_proxy& operator OP(const bool &a); \
array_proxy& operator OP(const char &a); \
array_proxy& operator OP(const signed char &a); \
array_proxy& operator OP(const unsigned char &a); \
array_proxy& operator OP(const long &a); \
array_proxy& operator OP(const unsigned long &a); \
array_proxy& operator OP(const long long &a); \
array_proxy& operator OP(const unsigned long long &a);

ASSIGN(=)
ASSIGN(+=)
ASSIGN(-=)
ASSIGN(*=)
ASSIGN(/=)
#undef ASSIGN

#if AF_API_VERSION >= 32
#define ASSIGN(OP) \
#define ASSIGN_32(OP) \
array_proxy& operator OP(const short &a); \
array_proxy& operator OP(const unsigned short &a);
#else
#define ASSIGN_32(OP)
#endif

#if AF_API_VERSION >= 310
#define ASSIGN_310(OP) \
array_proxy& operator OP(const signed char &a);
#else
#define ASSIGN_310(OP)
#endif

#define ASSIGN(OP) \
ASSIGN_(OP) \
ASSIGN_32(OP) \
ASSIGN_310(OP)

ASSIGN(=)
ASSIGN(+=)
ASSIGN(-=)
ASSIGN(*=)
ASSIGN(/=)
#undef ASSIGN
#endif
#undef ASSIGN_
#undef ASSIGN_32
#undef ASSIGN_310

// af::array member functions. same behavior as those below
af_array get();
Expand Down Expand Up @@ -947,7 +956,7 @@ namespace af

/// \brief Casts the array into another data type
///
/// \note Consecitive casting operations may be may be optimized out if
/// \note Consecutive casting operations may be optimized out if
/// the original type of the af::array is the same as the final type.
/// For example if the original type is f64 which is then cast to f32
/// and then back to f64, then the cast to f32 will be skipped and that
Expand Down Expand Up @@ -999,24 +1008,31 @@ namespace af
array& OP2(const unsigned &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const bool &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const char &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const signed char &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const unsigned char &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const long &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const unsigned long &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const long long &val); /**< \copydoc OP2##(const array &) */ \
array& OP2(const unsigned long long &val);


#if AF_API_VERSION >= 32
#define ASSIGN(OP) \
ASSIGN_(OP) \
array& OP(const short &val); /**< \copydoc OP##(const array &) */ \
array& OP(const unsigned short &val);
#define ASSIGN_32(OP) \
array& OP(const short &val); /**< \copydoc OP##(const array &) */ \
array& OP(const unsigned short &val);
#else
#define ASSIGN_32(OP)
#endif

#if AF_API_VERSION >= 310
#define ASSIGN_310(OP) \
array& OP(const signed char &val); /**< \copydoc OP##(const array &) */
#else
#define ASSIGN(OP) ASSIGN_(OP)
#define ASSIGN_310(OP)
#endif

#define ASSIGN(OP) \
ASSIGN_(OP) \
ASSIGN_32(OP) \
ASSIGN_310(OP)

/// \ingroup array_mem_operator_eq
/// @{
Expand Down Expand Up @@ -1082,6 +1098,8 @@ namespace af

#undef ASSIGN
#undef ASSIGN_
#undef ASSIGN_32
#undef ASSIGN_310

///
/// \brief Negates the values of the array
Expand Down Expand Up @@ -1146,7 +1164,6 @@ namespace af
AFAPI array OP (const int& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const unsigned& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const char& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const signed char& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const unsigned char& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const long& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const unsigned long& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
Expand All @@ -1160,7 +1177,6 @@ namespace af
AFAPI array OP (const array& lhs, const int& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const unsigned& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const char& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const signed char& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const unsigned char& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const long& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const unsigned long& rhs); /**< \copydoc OP##(const array&, const array&) */ \
Expand All @@ -1172,17 +1188,29 @@ namespace af
AFAPI array OP (const array& lhs, const cdouble& rhs);

#if AF_API_VERSION >= 32
#define BIN_OP(OP) \
BIN_OP_(OP) \
#define BIN_OP_32(OP) \
AFAPI array OP (const short& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const unsigned short& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const short& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const unsigned short& rhs);

#else
#define BIN_OP(OP) BIN_OP_(OP)
#define BIN_OP_32(OP)
#endif

#if AF_API_VERSION >= 310
#define BIN_OP_310(OP) \
AFAPI array OP (const signed char& lhs, const array& rhs); /**< \copydoc OP##(const array&, const array&) */ \
AFAPI array OP (const array& lhs, const signed char& rhs); /**< \copydoc OP##(const array&, const array&) */
#else
#define BIN_OP_310(OP)
#endif

#define BIN_OP(OP) \
BIN_OP_(OP) \
BIN_OP_32(OP) \
BIN_OP_310(OP)

/// \ingroup arith_func_add
/// @{
/// \brief Adds two arrays or an array and a value.
Expand Down Expand Up @@ -1376,6 +1404,8 @@ namespace af

#undef BIN_OP
#undef BIN_OP_
#undef BIN_OP_32
#undef BIN_OP_310

/// \ingroup arith_func_bitand
/// @{
Expand Down
4 changes: 3 additions & 1 deletion include/af/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ typedef enum {
#if AF_API_VERSION >= 37
, f16 ///< 16-bit floating point value
#endif
, s8 ///< 8-bit signed integral value /// TODO AF_API_VERSION
#if AF_API_VERSION >= 310
, s8 ///< 8-bit signed integral values
#endif
} af_dtype;

typedef enum {
Expand Down
2 changes: 2 additions & 0 deletions include/af/traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct dtype_traits<half> {
};
#endif

#if AF_API_VERSION >= 310
template<>
struct dtype_traits<signed char> {
enum {
Expand All @@ -185,6 +186,7 @@ struct dtype_traits<signed char> {
typedef signed char base_type;
static const char* getName() { return "schar"; }
};
#endif
}

#endif

0 comments on commit df24030

Please sign in to comment.