forked from M-Labs/nac3
core: Reformat and modernize irrt.cpp
- Use anon namespace instead of static - Use using declaration instead of typedef - Align pointers to the type instead of the identifier
This commit is contained in:
parent
bc40a32524
commit
1c56005a01
|
@ -1,29 +1,30 @@
|
|||
typedef _BitInt(8) int8_t;
|
||||
typedef unsigned _BitInt(8) uint8_t;
|
||||
typedef _BitInt(32) int32_t;
|
||||
typedef unsigned _BitInt(32) uint32_t;
|
||||
typedef _BitInt(64) int64_t;
|
||||
typedef unsigned _BitInt(64) uint64_t;
|
||||
using int8_t = _BitInt(8);
|
||||
using uint8_t = unsigned _BitInt(8);
|
||||
using int32_t = _BitInt(32);
|
||||
using uint32_t = unsigned _BitInt(32);
|
||||
using int64_t = _BitInt(64);
|
||||
using uint64_t = unsigned _BitInt(64);
|
||||
|
||||
// NDArray indices are always `uint32_t`.
|
||||
typedef uint32_t NDIndex;
|
||||
using NDIndex = uint32_t;
|
||||
// The type of an index or a value describing the length of a range/slice is always `int32_t`.
|
||||
typedef int32_t SliceIndex;
|
||||
using SliceIndex = int32_t;
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
static T max(T a, T b) {
|
||||
const T& max(const T& a, const T& b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T min(T a, T b) {
|
||||
const T& min(const T& a, const T& b) {
|
||||
return a > b ? b : a;
|
||||
}
|
||||
|
||||
// adapted from GNU Scientific Library: https://git.savannah.gnu.org/cgit/gsl.git/tree/sys/pow_int.c
|
||||
// need to make sure `exp >= 0` before calling this function
|
||||
template <typename T>
|
||||
static T __nac3_int_exp_impl(T base, T exp) {
|
||||
T __nac3_int_exp_impl(T base, T exp) {
|
||||
T res = 1;
|
||||
/* repeated squaring method */
|
||||
do {
|
||||
|
@ -37,7 +38,7 @@ static T __nac3_int_exp_impl(T base, T exp) {
|
|||
}
|
||||
|
||||
template <typename SizeT>
|
||||
static SizeT __nac3_ndarray_calc_size_impl(
|
||||
SizeT __nac3_ndarray_calc_size_impl(
|
||||
const SizeT* list_data,
|
||||
SizeT list_len,
|
||||
SizeT begin_idx,
|
||||
|
@ -55,7 +56,7 @@ static SizeT __nac3_ndarray_calc_size_impl(
|
|||
}
|
||||
|
||||
template <typename SizeT>
|
||||
static void __nac3_ndarray_calc_nd_indices_impl(
|
||||
void __nac3_ndarray_calc_nd_indices_impl(
|
||||
SizeT index,
|
||||
const SizeT* dims,
|
||||
SizeT num_dims,
|
||||
|
@ -71,7 +72,7 @@ static void __nac3_ndarray_calc_nd_indices_impl(
|
|||
}
|
||||
|
||||
template <typename SizeT>
|
||||
static SizeT __nac3_ndarray_flatten_index_impl(
|
||||
SizeT __nac3_ndarray_flatten_index_impl(
|
||||
const SizeT* dims,
|
||||
SizeT num_dims,
|
||||
const NDIndex* indices,
|
||||
|
@ -92,7 +93,7 @@ static SizeT __nac3_ndarray_flatten_index_impl(
|
|||
}
|
||||
|
||||
template <typename SizeT>
|
||||
static void __nac3_ndarray_calc_broadcast_impl(
|
||||
void __nac3_ndarray_calc_broadcast_impl(
|
||||
const SizeT* lhs_dims,
|
||||
SizeT lhs_ndims,
|
||||
const SizeT* rhs_dims,
|
||||
|
@ -123,7 +124,7 @@ static void __nac3_ndarray_calc_broadcast_impl(
|
|||
}
|
||||
|
||||
template <typename SizeT>
|
||||
static void __nac3_ndarray_calc_broadcast_idx_impl(
|
||||
void __nac3_ndarray_calc_broadcast_idx_impl(
|
||||
const SizeT* src_dims,
|
||||
SizeT src_ndims,
|
||||
const NDIndex* in_idx,
|
||||
|
@ -134,6 +135,7 @@ static void __nac3_ndarray_calc_broadcast_idx_impl(
|
|||
out_idx[src_i] = src_dims[src_i] == 1 ? 0 : in_idx[src_i];
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
#define DEF_nac3_int_exp_(T) \
|
||||
|
@ -409,4 +411,4 @@ extern "C" {
|
|||
) {
|
||||
__nac3_ndarray_calc_broadcast_idx_impl(src_dims, src_ndims, in_idx, out_idx);
|
||||
}
|
||||
}
|
||||
} // extern "C"
|
Loading…
Reference in New Issue