tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
blas3_matrix_product.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2025 Tobias Hienzsch
3
4#ifndef TETL_LINALG_BLAS3_MATRIX_PRODUCT_HPP
5#define TETL_LINALG_BLAS3_MATRIX_PRODUCT_HPP
6
7#include <etl/_contracts/check.hpp>
8#include <etl/_linalg/exposition.hpp>
9
10namespace etl::linalg {
11
12/// Computes C = AB
13/// \ingroup linalg
14template <in_matrix InMat1, in_matrix InMat2, out_matrix OutMat>
15constexpr auto matrix_product(InMat1 a, InMat2 b, OutMat c) -> void
16{
17 static_assert(detail::possibly_multipliable<InMat1, InMat2, OutMat>());
18 TETL_PRECONDITION(detail::multipliable(a, b, c));
19
20 using index_type = detail::common_index_type_t<InMat1, InMat2, OutMat>;
21 using sum_type = typename OutMat::element_type;
22
23 for (auto i = index_type{0}; i < static_cast<index_type>(a.extent(0)); ++i) {
24 for (auto j = index_type{0}; j < static_cast<index_type>(b.extent(1)); ++j) {
25 auto acc = sum_type{};
26 for (auto k = index_type{0}; k < static_cast<index_type>(a.extent(1)); ++k) {
27 acc += a(i, k) * b(k, j);
28 }
29 c(i, j) = acc;
30 }
31 }
32}
33
34} // namespace etl::linalg
35
36#endif // TETL_LINALG_BLAS3_MATRIX_PRODUCT_HPP
constexpr auto matrix_product(InMat1 a, InMat2 b, OutMat c) -> void
Computes C = AB.
Definition blas3_matrix_product.hpp:15
Definition accessor_conjugate.hpp:13
Definition adjacent_find.hpp:9