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// SPDX-FileCopyrightText: Copyright (C) 2023 Tobias Hienzsch
3
4#ifndef TETL_LINALG_BLAS1_SWAP_ELEMENTS_HPP
5#define TETL_LINALG_BLAS1_SWAP_ELEMENTS_HPP
6
7#include <etl/_contracts/check.hpp>
8#include <etl/_linalg/concepts.hpp>
9#include <etl/_utility/cmp_less.hpp>
10#include <etl/_utility/swap.hpp>
11
12namespace etl::linalg {
13
14/// \ingroup linalg
15template <inout_object InOutObj1, inout_object InOutObj2>
16 requires(InOutObj1::rank() == InOutObj1::rank())
17constexpr auto swap_elements(InOutObj1 x, InOutObj2 y) -> void
18{
19 TETL_PRECONDITION(x.extents() == y.extents());
20
21 using size_type = detail::common_size_type_t<InOutObj1, InOutObj2>;
22
23 if constexpr (InOutObj1::rank() == 1) {
24 for (size_type i{0}; etl::cmp_less(i, x.extent(0)); ++i) {
25 using etl::swap;
26 swap(x(i), y(i));
27 }
28 } else {
29 static_assert(InOutObj1::rank() == 2);
30 for (size_type i{0}; etl::cmp_less(i, x.extent(0)); ++i) {
31 for (size_type j{0}; etl::cmp_less(j, x.extent(1)); ++j) {
32 using etl::swap;
33 swap(x(i, j), y(i, j));
34 }
35 }
36 }
37}
38
39} // namespace etl::linalg
40
41#endif // TETL_LINALG_BLAS1_SWAP_ELEMENTS_HPP
constexpr auto swap_elements(InOutObj1 x, InOutObj2 y) -> void
Definition blas1_swap_elements.hpp:17
Definition accessor_conjugate.hpp:13
Definition adjacent_find.hpp:9