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/exposition.hpp>
9#include <etl/_utility/swap.hpp>
10
11namespace etl::linalg {
12
13/// \ingroup linalg
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 index_type = detail::common_index_type_t<InOutObj1, InOutObj2>;
21
22 if constexpr (InOutObj1::rank() == 1) {
23 static_assert(detail::compatible_static_extents<InOutObj1, InOutObj2>(0, 0));
24
25 for (index_type i{0}; i < static_cast<index_type>(x.extent(0)); ++i) {
26 using etl::swap;
27 swap(x(i), y(i));
28 }
29 } else {
30 static_assert(InOutObj1::rank() == 2);
31 static_assert(detail::compatible_static_extents<InOutObj1, InOutObj2>(0, 0));
32 static_assert(detail::compatible_static_extents<InOutObj1, InOutObj2>(1, 1));
33
34 for (index_type i{0}; i < static_cast<index_type>(x.extent(0)); ++i) {
35 for (index_type j{0}; j < static_cast<index_type>(x.extent(1)); ++j) {
36 using etl::swap;
37 swap(x(i, j), y(i, j));
38 }
39 }
40 }
41}
42
43} // namespace etl::linalg
44
45#endif // TETL_LINALG_BLAS1_SWAP_ELEMENTS_HPP
constexpr auto swap_elements(InOutObj1 x, InOutObj2 y) -> void
Definition blas1_swap_elements.hpp:16
Definition accessor_conjugate.hpp:13
Definition adjacent_find.hpp:9