Skip to content

Commit 2e7077d

Browse files
committed
Use extent_size to retrieve the number of elements for an extent
1 parent cc08380 commit 2e7077d

File tree

10 files changed

+94
-88
lines changed

10 files changed

+94
-88
lines changed

include/kernel_float/apply.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,14 @@ template<typename F, typename... Args>
175175
KERNEL_FLOAT_INLINE map_type<F, Args...> map(F fun, const Args&... args) {
176176
using Output = result_t<F, vector_value_type<Args>...>;
177177
using E = broadcast_vector_extent_type<Args...>;
178-
vector_storage<Output, E::value> result;
178+
vector_storage<Output, extent_size<E>> result;
179179

180180
// Use the `apply_fastmath_impl` if KERNEL_FLOAT_FAST_MATH is enabled
181181
#if KERNEL_FLOAT_FAST_MATH
182-
using apply_impl = detail::apply_fastmath_impl<F, E::value, Output, vector_value_type<Args>...>;
182+
using apply_impl =
183+
detail::apply_fastmath_impl<F, extent_size<E>, Output, vector_value_type<Args>...>;
183184
#else
184-
using apply_impl = detail::apply_impl<F, E::value, Output, vector_value_type<Args>...>;
185+
using apply_impl = detail::apply_impl<F, extent_size<E>, Output, vector_value_type<Args>...>;
185186
#endif
186187

187188
apply_impl::call(
@@ -202,9 +203,9 @@ template<typename F, typename... Args>
202203
KERNEL_FLOAT_INLINE map_type<F, Args...> fast_map(F fun, const Args&... args) {
203204
using Output = result_t<F, vector_value_type<Args>...>;
204205
using E = broadcast_vector_extent_type<Args...>;
205-
vector_storage<Output, E::value> result;
206+
vector_storage<Output, extent_size<E>> result;
206207

207-
detail::apply_fastmath_impl<F, E::value, Output, vector_value_type<Args>...>::call(
208+
detail::apply_fastmath_impl<F, extent_size<E>, Output, vector_value_type<Args>...>::call(
208209
fun,
209210
result.data(),
210211
(detail::broadcast_impl<vector_value_type<Args>, vector_extent_type<Args>, E>::call(

include/kernel_float/base.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ struct extent;
8585

8686
template<size_t N>
8787
struct extent<N> {
88-
static constexpr size_t value = N;
89-
static constexpr size_t size = N;
88+
static constexpr size_t number_of_elements = N;
9089
};
9190

91+
template<typename E>
92+
static constexpr size_t extent_size = E::number_of_elements;
93+
9294
namespace detail {
9395
// Indicates that elements of type `T` offer less precision than floats, thus operations
9496
// on elements of type `T` can be performed by upcasting them to ` float`.
@@ -215,7 +217,7 @@ KERNEL_FLOAT_DEFINE_VECTOR_TYPE(unsigned long long, ulonglong1, ulonglong2, ulon
215217
KERNEL_FLOAT_DEFINE_VECTOR_TYPE(float, float1, float2, float3, float4)
216218
KERNEL_FLOAT_DEFINE_VECTOR_TYPE(double, double1, double2, double3, double4)
217219

218-
template<typename T, typename E, typename S = vector_storage<T, E::size>>
220+
template<typename T, typename E, typename S = vector_storage<T, E::number_of_elements>>
219221
struct vector;
220222

221223
template<typename T, typename E, typename S>
@@ -224,7 +226,7 @@ struct into_vector_impl<vector<T, E, S>> {
224226
using extent_type = E;
225227

226228
KERNEL_FLOAT_INLINE
227-
static vector_storage<T, E::value> call(const vector<T, E, S>& input) {
229+
static vector_storage<T, extent_size<E>> call(const vector<T, E, S>& input) {
228230
return input.storage();
229231
}
230232
};
@@ -247,13 +249,13 @@ template<typename V>
247249
using vector_extent_type = typename into_vector_impl<V>::extent_type;
248250

249251
template<typename V>
250-
static constexpr size_t vector_extent = vector_extent_type<V>::value;
252+
static constexpr size_t vector_size = extent_size<vector_extent_type<V>>;
251253

252254
template<typename V>
253255
using into_vector_type = vector<vector_value_type<V>, vector_extent_type<V>>;
254256

255257
template<typename V>
256-
using vector_storage_type = vector_storage<vector_value_type<V>, vector_extent<V>>;
258+
using vector_storage_type = vector_storage<vector_value_type<V>, vector_size<V>>;
257259

258260
template<typename... Vs>
259261
using promoted_vector_value_type = promote_t<vector_value_type<Vs>...>;

include/kernel_float/binops.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ KERNEL_FLOAT_INLINE zip_common_type<F, L, R> zip_common(F fun, const L& left, co
5050
using O = result_t<F, T, T>;
5151
using E = broadcast_vector_extent_type<L, R>;
5252

53-
vector_storage<O, E::value> result;
53+
vector_storage<O, extent_size<E>> result;
5454

5555
// Use the `apply_fastmath_impl` if KERNEL_FLOAT_FAST_MATH is enabled
5656
#if KERNEL_FLOAT_FAST_MATH
57-
using apply_impl = detail::apply_fastmath_impl<F, E::value, O, T, T>;
57+
using apply_impl = detail::apply_fastmath_impl<F, extent_size<E>, O, T, T>;
5858
#else
59-
using apply_impl = detail::apply_impl<F, E::value, O, T, T>;
59+
using apply_impl = detail::apply_impl<F, extent_size<E>, O, T, T>;
6060
#endif
6161

6262
apply_impl::call(
@@ -327,9 +327,9 @@ template<typename L, typename R, typename T = promoted_vector_value_type<L, R>>
327327
KERNEL_FLOAT_INLINE zip_common_type<ops::divide<T>, T, T>
328328
fast_divide(const L& left, const R& right) {
329329
using E = broadcast_vector_extent_type<L, R>;
330-
vector_storage<T, E::value> result;
330+
vector_storage<T, extent_size<E>> result;
331331

332-
detail::apply_fastmath_impl<ops::divide<T>, E::value, T, T, T>::call(
332+
detail::apply_fastmath_impl<ops::divide<T>, extent_size<E>, T, T, T>::call(
333333
ops::divide<T> {},
334334
result.data(),
335335
detail::convert_impl<vector_value_type<L>, vector_extent_type<L>, T, E>::call(

include/kernel_float/conversion.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ namespace detail {
1414
template<typename T, typename E, typename T2, typename E2, RoundingMode M = RoundingMode::ANY>
1515
struct convert_impl {
1616
KERNEL_FLOAT_INLINE
17-
static vector_storage<T2, E2::value> call(vector_storage<T, E::value> input) {
17+
static vector_storage<T2, extent_size<E2>> call(vector_storage<T, extent_size<E>> input) {
1818
using F = ops::cast<T, T2, M>;
19-
vector_storage<T2, E::value> intermediate;
20-
detail::apply_impl<F, E::value, T2, T>::call(F {}, intermediate.data(), input.data());
19+
vector_storage<T2, extent_size<E>> intermediate;
20+
detail::apply_impl<F, extent_size<E>, T2, T>::call(F {}, intermediate.data(), input.data());
2121
return detail::broadcast_impl<T2, E, E2>::call(intermediate);
2222
}
2323
};
@@ -26,7 +26,7 @@ struct convert_impl {
2626
template<typename T, typename E, RoundingMode M>
2727
struct convert_impl<T, E, T, E, M> {
2828
KERNEL_FLOAT_INLINE
29-
static vector_storage<T, E::value> call(vector_storage<T, E::value> input) {
29+
static vector_storage<T, extent_size<E>> call(vector_storage<T, extent_size<E>> input) {
3030
return input;
3131
}
3232
};
@@ -35,7 +35,7 @@ struct convert_impl<T, E, T, E, M> {
3535
template<typename T, typename E, typename E2, RoundingMode M>
3636
struct convert_impl<T, E, T, E2, M> {
3737
KERNEL_FLOAT_INLINE
38-
static vector_storage<T, E2::value> call(vector_storage<T, E::value> input) {
38+
static vector_storage<T, extent_size<E2>> call(vector_storage<T, extent_size<E>> input) {
3939
return detail::broadcast_impl<T, E, E2>::call(input);
4040
}
4141
};
@@ -44,11 +44,11 @@ struct convert_impl<T, E, T, E2, M> {
4444
template<typename T, typename E, typename T2, RoundingMode M>
4545
struct convert_impl<T, E, T2, E, M> {
4646
KERNEL_FLOAT_INLINE
47-
static vector_storage<T2, E::value> call(vector_storage<T, E::value> input) {
47+
static vector_storage<T2, extent_size<E>> call(vector_storage<T, extent_size<E>> input) {
4848
using F = ops::cast<T, T2, M>;
4949

50-
vector_storage<T2, E::value> result;
51-
detail::apply_impl<F, E::value, T2, T>::call(F {}, result.data(), input.data());
50+
vector_storage<T2, extent_size<E>> result;
51+
detail::apply_impl<F, extent_size<E>, T2, T>::call(F {}, result.data(), input.data());
5252
return result;
5353
}
5454
};

include/kernel_float/iterate.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ KERNEL_FLOAT_INLINE void for_each(V&& input, F fun) {
2222
auto storage = into_vector_storage(input);
2323

2424
#pragma unroll
25-
for (size_t i = 0; i < vector_extent<V>; i++) {
25+
for (size_t i = 0; i < vector_size<V>; i++) {
2626
fun(storage.data()[i]);
2727
}
2828
}
@@ -86,7 +86,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> range() {
8686
*/
8787
template<typename V>
8888
KERNEL_FLOAT_INLINE into_vector_type<V> range_like(const V& = {}) {
89-
return range<vector_value_type<V>, vector_extent<V>>();
89+
return range<vector_value_type<V>, vector_size<V>>();
9090
}
9191

9292
/**
@@ -111,11 +111,11 @@ KERNEL_FLOAT_INLINE into_vector_type<V> range_like(const V& = {}) {
111111
*/
112112
template<typename T = size_t, typename V>
113113
KERNEL_FLOAT_INLINE vector<T, vector_extent_type<V>> each_index(const V& = {}) {
114-
return range<T, vector_extent<V>>();
114+
return range<T, vector_size<V>>();
115115
}
116116

117117
namespace detail {
118-
template<typename V, typename T = vector_value_type<V>, size_t N = vector_extent<V>>
118+
template<typename V, typename T = vector_value_type<V>, size_t N = vector_size<V>>
119119
struct flatten_impl {
120120
using value_type = typename flatten_impl<T>::value_type;
121121
static constexpr size_t size = N * flatten_impl<T>::size;
@@ -177,7 +177,7 @@ KERNEL_FLOAT_INLINE flatten_type<V> flatten(const V& input) {
177177
namespace detail {
178178
template<typename U, typename V = U, typename T = vector_value_type<V>>
179179
struct concat_base_impl {
180-
static constexpr size_t size = vector_extent<V>;
180+
static constexpr size_t size = vector_size<V>;
181181

182182
KERNEL_FLOAT_INLINE static void call(U* output, const V& input) {
183183
vector_storage<T, size> storage = into_vector_storage(input);
@@ -294,7 +294,7 @@ using select_type = vector<vector_value_type<V>, extent<concat_size<Is...>>>;
294294
template<typename V, typename... Is>
295295
KERNEL_FLOAT_INLINE select_type<V, Is...> select(const V& input, const Is&... indices) {
296296
using T = vector_value_type<V>;
297-
static constexpr size_t N = vector_extent<V>;
297+
static constexpr size_t N = vector_size<V>;
298298
static constexpr size_t M = concat_size<Is...>;
299299

300300
vector_storage<size_t, M> index_set;

include/kernel_float/memory.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct copy_impl<T, N, index_sequence<Is...>> {
3838
*/
3939
template<typename T, typename I, typename M = bool, typename E = broadcast_vector_extent_type<I, M>>
4040
KERNEL_FLOAT_INLINE vector<T, E> read(const T* ptr, const I& indices, const M& mask = true) {
41-
return detail::copy_impl<T, E::value>::load(
41+
return detail::copy_impl<T, extent_size<E>>::load(
4242
ptr,
4343
convert_storage<size_t>(indices, E()).data(),
4444
convert_storage<bool>(mask, E()).data());
@@ -65,7 +65,7 @@ template<
6565
typename M = bool,
6666
typename E = broadcast_vector_extent_type<V, I, M>>
6767
KERNEL_FLOAT_INLINE void write(T* ptr, const I& indices, const V& values, const M& mask = true) {
68-
return detail::copy_impl<T, E::value>::store(
68+
return detail::copy_impl<T, extent_size<E>>::store(
6969
ptr,
7070
convert_storage<T>(values, E()).data(),
7171
convert_storage<size_t>(indices, E()).data(),
@@ -102,7 +102,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> read(const T* ptr) {
102102
*/
103103
template<typename V, typename T>
104104
KERNEL_FLOAT_INLINE void write(T* ptr, const V& values) {
105-
static constexpr size_t N = vector_extent<V>;
105+
static constexpr size_t N = vector_size<V>;
106106
write(ptr, range<size_t, N>(), values);
107107
}
108108

@@ -277,7 +277,7 @@ KERNEL_FLOAT_INLINE vector<T, extent<N>> read_aligned(const T* ptr) {
277277
*/
278278
template<size_t Align, typename V, typename T>
279279
KERNEL_FLOAT_INLINE void write_aligned(T* ptr, const V& values) {
280-
static constexpr size_t N = vector_extent<V>;
280+
static constexpr size_t N = vector_size<V>;
281281
static constexpr size_t alignment = detail::gcd(Align * sizeof(T), KERNEL_FLOAT_MAX_ALIGNMENT);
282282

283283
return detail::copy_aligned_impl<T, N, alignment>::store(

include/kernel_float/reduce.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct reduce_recur_impl<2> {
7373
*/
7474
template<typename F, typename V>
7575
KERNEL_FLOAT_INLINE vector_value_type<V> reduce(F fun, const V& input) {
76-
return detail::reduce_impl<F, vector_extent<V>, vector_value_type<V>>::call(
76+
return detail::reduce_impl<F, vector_size<V>, vector_value_type<V>>::call(
7777
fun,
7878
into_vector_storage(input).data());
7979
}
@@ -203,7 +203,7 @@ struct dot_impl {
203203
template<typename L, typename R, typename T = promoted_vector_value_type<L, R>>
204204
KERNEL_FLOAT_INLINE T dot(const L& left, const R& right) {
205205
using E = broadcast_vector_extent_type<L, R>;
206-
return detail::dot_impl<T, E::value>::call(
206+
return detail::dot_impl<T, extent_size<E>>::call(
207207
convert_storage<T>(left, E {}).data(),
208208
convert_storage<T>(right, E {}).data());
209209
}
@@ -273,7 +273,7 @@ struct magnitude_impl<double, 3> {
273273
*/
274274
template<typename V, typename T = vector_value_type<V>>
275275
KERNEL_FLOAT_INLINE T mag(const V& input) {
276-
return detail::magnitude_impl<T, vector_extent<V>>::call(into_vector_storage(input).data());
276+
return detail::magnitude_impl<T, vector_size<V>>::call(into_vector_storage(input).data());
277277
}
278278
} // namespace kernel_float
279279

include/kernel_float/triops.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ template<
3939
typename E = broadcast_vector_extent_type<C, L, R>>
4040
KERNEL_FLOAT_INLINE vector<T, E> where(const C& cond, const L& true_values, const R& false_values) {
4141
using F = ops::conditional<T>;
42-
vector_storage<T, E::value> result;
42+
vector_storage<T, extent_size<E>> result;
4343

44-
detail::apply_impl<F, E::value, T, bool, T, T>::call(
44+
detail::apply_impl<F, extent_size<E>, T, bool, T, T>::call(
4545
F {},
4646
result.data(),
4747
detail::convert_impl<vector_value_type<C>, vector_extent_type<C>, bool, E>::call(
@@ -124,9 +124,9 @@ template<
124124
typename E = broadcast_vector_extent_type<A, B, C>>
125125
KERNEL_FLOAT_INLINE vector<T, E> fma(const A& a, const B& b, const C& c) {
126126
using F = ops::fma<T>;
127-
vector_storage<T, E::value> result;
127+
vector_storage<T, extent_size<E>> result;
128128

129-
detail::apply_impl<F, E::value, T, T, T, T>::call(
129+
detail::apply_impl<F, extent_size<E>, T, T, T, T>::call(
130130
F {},
131131
result.data(),
132132
detail::convert_impl<vector_value_type<A>, vector_extent_type<A>, T, E>::call(

include/kernel_float/vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct vector: public S {
5454
typename A,
5555
typename B,
5656
typename... Rest,
57-
typename = enable_if_t<sizeof...(Rest) + 2 == E::size>>
57+
typename = enable_if_t<sizeof...(Rest) + 2 == extent_size<E>>>
5858
KERNEL_FLOAT_INLINE vector(const A& a, const B& b, const Rest&... rest) :
5959
storage_type {T(a), T(b), T(rest)...} {}
6060

@@ -63,7 +63,7 @@ struct vector: public S {
6363
*/
6464
KERNEL_FLOAT_INLINE
6565
static constexpr size_t size() {
66-
return E::size;
66+
return extent_size<E>;
6767
}
6868

6969
/**

0 commit comments

Comments
 (0)