SimiLie
Loading...
Searching...
No Matches
determinant.hpp
1// SPDX-FileCopyrightText: 2024 Baptiste Legouix
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#pragma once
5
6#include <ddc/ddc.hpp>
7
8#include <similie/misc/macros.hpp>
9#include <similie/misc/small_matrix.hpp>
10#include <similie/misc/specialization.hpp>
11#include <similie/tensor/tensor_impl.hpp>
12
13namespace sil::tensor {
14
15template <misc::Specialization<Kokkos::View> ViewType>
16KOKKOS_FUNCTION typename ViewType::value_type determinant(const ViewType& matrix)
17{
18 return misc::math::determinant(matrix);
19}
20
21template <misc::Specialization<Tensor> TensorType>
22TensorType::element_type determinant(TensorType const& tensor)
23{
24 static_assert(TensorType::natural_domain_t::rank() == 2);
25 auto const extents = ddc::detail::array(tensor.natural_domain().extents());
26 assert(extents[0] == extents[1] && "Matrix should be squared to compute its determinant");
27 const std::size_t n = extents[0];
28
29 Kokkos::View<typename TensorType::element_type**, Kokkos::LayoutRight, Kokkos::HostSpace>
30 buffer("determinant_buffer", n, n);
31 SIMILIE_DEBUG_LOG("similie_compute_determinant");
32 ddc::parallel_for_each(
33 "similie_compute_determinant",
34 Kokkos::DefaultHostExecutionSpace(),
35 tensor.accessor().natural_domain(),
36 [&](auto index) {
37 buffer(ddc::detail::array(index)[0], ddc::detail::array(index)[1])
38 = tensor(tensor.access_element(index));
39 });
40 return determinant(buffer);
41}
42
43} // namespace sil::tensor
KOKKOS_FUNCTION MatrixView::non_const_value_type determinant(MatrixView const &matrix)
KOKKOS_FUNCTION ViewType::value_type determinant(const ViewType &matrix)