tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas1_add.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_LINALG_BLAS1_ADD_HPP
4#define TETL_LINALG_BLAS1_ADD_HPP
5
9
10namespace etl::linalg {
11
13template <in_object InObj1, in_object InObj2, out_object OutObj>
14 requires(InObj1::rank() == OutObj::rank() and InObj2::rank() == OutObj::rank())
15constexpr auto add(InObj1 x, InObj2 y, OutObj z) -> void
16{
17 TETL_PRECONDITION(x.extents() == y.extents());
18 TETL_PRECONDITION(x.extents() == z.extents());
19
20 using size_type = detail::common_size_type_t<InObj1, InObj2, OutObj>;
21
22 if constexpr (OutObj::rank() == 1) {
23 for (size_type row{0}; etl::cmp_less(row, x.extent(0)); ++row) {
24 z(row) = x(row) + y(row);
25 }
26 } else {
27 static_assert(OutObj::rank() == 2);
28 for (size_type row{0}; etl::cmp_less(row, x.extent(0)); ++row) {
29 for (size_type col{0}; etl::cmp_less(col, x.extent(1)); ++col) {
30 z(row, col) = x(row, col) + y(row, col);
31 }
32 }
33 }
34}
35
36} // namespace etl::linalg
37
38#endif // TETL_LINALG_BLAS1_ADD_HPP
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto add(InObj1 x, InObj2 y, OutObj z) -> void
Definition blas1_add.hpp:15
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