tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas1_swap_elements.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_LINALG_BLAS1_SWAP_ELEMENTS_HPP
4#define TETL_LINALG_BLAS1_SWAP_ELEMENTS_HPP
5
10
11namespace etl::linalg {
12
14template <inout_object InOutObj1, inout_object InOutObj2>
15 requires(InOutObj1::rank() == InOutObj1::rank())
16constexpr auto swap_elements(InOutObj1 x, InOutObj2 y) -> void
17{
18 TETL_PRECONDITION(x.extents() == y.extents());
19
20 using size_type = detail::common_size_type_t<InOutObj1, InOutObj2>;
21
22 if constexpr (InOutObj1::rank() == 1) {
23 for (size_type i{0}; etl::cmp_less(i, x.extent(0)); ++i) {
24 using etl::swap;
25 swap(x(i), y(i));
26 }
27 } else {
28 static_assert(InOutObj1::rank() == 2);
29 for (size_type i{0}; etl::cmp_less(i, x.extent(0)); ++i) {
30 for (size_type j{0}; etl::cmp_less(j, x.extent(1)); ++j) {
31 using etl::swap;
32 swap(x(i, j), y(i, j));
33 }
34 }
35 }
36}
37
38} // namespace etl::linalg
39
40#endif // TETL_LINALG_BLAS1_SWAP_ELEMENTS_HPP
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto swap_elements(InOutObj1 x, InOutObj2 y) -> void
Definition blas1_swap_elements.hpp:16
constexpr auto cmp_less(T t, U u) noexcept -> bool
Compare the values of two integers t and u. Unlike builtin comparison operators, negative signed inte...
Definition cmp_less.hpp:21
Definition accessor_conjugate.hpp:12
auto swap(inplace_function< R(Args...), Capacity, Alignment > &lhs, inplace_function< R(Args...), Capacity, Alignment > &rhs) noexcept -> void
Overloads the etl::swap algorithm for etl::inplace_function. Exchanges the state of lhs with that of ...
Definition inplace_function.hpp:249