tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas1_scale.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_SCALE_HPP
5#define TETL_LINALG_BLAS1_SCALE_HPP
6
7#include <etl/_linalg/concepts.hpp>
8#include <etl/_utility/cmp_less.hpp>
9
10namespace etl::linalg {
11
12/// \ingroup linalg
13template <typename Scalar, inout_object InOutObj>
14constexpr auto scale(Scalar alpha, InOutObj x) -> void
15{
16 using size_type = typename InOutObj::size_type;
17
18 if constexpr (InOutObj::rank() == 1) {
19 for (size_type i{0}; etl::cmp_less(i, x.extent(0)); ++i) {
20 x(i) = x(i) * alpha;
21 }
22 } else {
23 static_assert(InOutObj::rank() == 2);
24 for (size_type i{0}; etl::cmp_less(i, x.extent(0)); ++i) {
25 for (size_type j{0}; etl::cmp_less(j, x.extent(1)); ++j) {
26 x(i, j) = x(i, j) * alpha;
27 }
28 }
29 }
30}
31
32} // namespace etl::linalg
33
34#endif // TETL_LINALG_BLAS1_SCALE_HPP
constexpr auto scale(Scalar alpha, InOutObj x) -> void
Definition blas1_scale.hpp:14
Definition accessor_conjugate.hpp:13
Definition adjacent_find.hpp:9