Skip to content

Commit 1f795ba

Browse files
authored
Merge pull request #537 from xtensor-stack/fix/implicit-arch-during-load
Allow ommision of Arch argument for load / load_aligned / load_unaligned
2 parents 0bdffb1 + 82515bf commit 1f795ba

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

include/xsimd/arch/generic/xsimd_generic_memory.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ namespace xsimd {
5555
batch<T_out, A> load_aligned(T_in const* mem, convert<T_out> cvt, requires_arch<generic>) {
5656
return detail::load_aligned<A>(mem, cvt, A{}, detail::conversion_type<A, T_in, T_out>{});
5757
}
58+
template<class A, class T>
59+
batch<std::complex<T>, A> load_aligned(std::complex<T> const* mem, convert<std::complex<T>>, requires_arch<generic>) {
60+
return batch<std::complex<T>, A>::load_aligned(mem);
61+
}
5862

5963
// load_unaligned
6064
namespace detail {
@@ -75,7 +79,10 @@ namespace xsimd {
7579
batch<T_out, A> load_unaligned(T_in const* mem, convert<T_out> cvt, requires_arch<generic>) {
7680
return detail::load_unaligned<A>(mem, cvt, generic{}, detail::conversion_type<A, T_in, T_out>{});
7781
}
78-
82+
template<class A, class T>
83+
batch<std::complex<T>, A> load_unaligned(std::complex<T> const* mem, convert<std::complex<T>>, requires_arch<generic>) {
84+
return batch<std::complex<T>, A>::load_unaligned(mem);
85+
}
7986

8087
// store
8188
template<class T, class A>

include/xsimd/types/xsimd_api.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ batch<From, A> load(From const* ptr, unaligned_mode) {
917917
* @param ptr the memory buffer to read
918918
* @return a new batch instance
919919
*/
920-
template<class A/*=default_arch*/, class From>
920+
template<class A=default_arch, class From>
921921
batch<From, A> load_aligned(From const* ptr) {
922922
return kernel::load_aligned<A>(ptr, kernel::convert<From>{}, A{});
923923
}
@@ -930,7 +930,7 @@ batch<From, A> load_aligned(From const* ptr) {
930930
* @param ptr the memory buffer to read
931931
* @return a new batch instance
932932
*/
933-
template<class A/*=default_arch*/, class From>
933+
template<class A=default_arch, class From>
934934
batch<From, A> load_unaligned(From const* ptr) {
935935
return kernel::load_unaligned<A>(ptr, kernel::convert<From>{}, A{});
936936
}

test/test_arch.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@ TEST(arch, dispatcher)
8787
#endif
8888
}
8989

90+
template<class T>
91+
static bool try_load() {
92+
static_assert(std::is_same<xsimd::batch<T>, decltype(xsimd::load_aligned(std::declval<T*>()))>::value,
93+
"loading the expected type");
94+
static_assert(std::is_same<xsimd::batch<T>, decltype(xsimd::load_unaligned(std::declval<T*>()))>::value,
95+
"loading the expected type");
96+
return true;
97+
}
98+
99+
template<class... Tys>
100+
void try_loads() {
101+
(void)std::initializer_list<bool>{try_load<Tys>()...};
102+
}
103+
104+
TEST(arch, default_load)
105+
{
106+
// make sure load_aligned / load_unaligned work for the default arch and
107+
// return the appropriate type.
108+
using type_list = xsimd::mpl::type_list<short, int, long, float, double, std::complex<float>, std::complex<double>>;
109+
try_loads<type_list>();
110+
111+
}
112+
90113
#ifdef XSIMD_ENABLE_FALLBACK
91114
// FIXME: this should be named scalar
92115
TEST(arch, scalar)

0 commit comments

Comments
 (0)