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