Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_SVD_Serial_Impl.hpp

raw
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 #ifndef KOKKOSBATCHED_SVD_SERIAL_IMPL_HPP
17 #define KOKKOSBATCHED_SVD_SERIAL_IMPL_HPP
18
19 /// \author Brian Kelley ([email protected])
20
21 #include "KokkosBatched_SVD_Serial_Internal.hpp"
22
23 namespace KokkosBatched {
24 // Version which computes the full factorization
25 template <typename AViewType, typename UViewType, typename VViewType, typename SViewType, typename WViewType>
26 KOKKOS_INLINE_FUNCTION int SerialSVD::invoke(SVD_USV_Tag, const AViewType &A, const UViewType &U,
27 const SViewType &sigma, const VViewType &Vt, const WViewType &work,
28 typename AViewType::const_value_type tol) {
29 static_assert(Kokkos::is_view_v<AViewType> && AViewType::rank == 2, "SVD: A must be a rank-2 view");
30 static_assert(Kokkos::is_view_v<UViewType> && UViewType::rank == 2, "SVD: U must be a rank-2 view");
31 static_assert(Kokkos::is_view_v<SViewType> && SViewType::rank == 1, "SVD: s must be a rank-1 view");
32 static_assert(Kokkos::is_view_v<VViewType> && VViewType::rank == 2, "SVD: V must be a rank-2 view");
33 static_assert(Kokkos::is_view_v<WViewType> && WViewType::rank == 1, "SVD: W must be a rank-1 view");
34 static_assert(!std::is_same_v<typename WViewType::array_layout, Kokkos::LayoutStride>,
35 "SVD: W must be contiguous (not LayoutStride)");
36 using value_type = typename AViewType::non_const_value_type;
37 return KokkosBatched::SerialSVDInternal::invoke<value_type>(
38 A.extent(0), A.extent(1), A.data(), A.stride(0), A.stride(1), U.data(), U.stride(0), U.stride(1), Vt.data(),
39 Vt.stride(0), Vt.stride(1), sigma.data(), sigma.stride(0), work.data(), tol);
40 }
41
42 // Version which computes only singular values
43 template <typename AViewType, typename SViewType, typename WViewType>
44 KOKKOS_INLINE_FUNCTION int SerialSVD::invoke(SVD_S_Tag, const AViewType &A, const SViewType &sigma,
45 const WViewType &work, typename AViewType::const_value_type tol) {
46 static_assert(Kokkos::is_view_v<AViewType> && AViewType::rank == 2, "SVD: A must be a rank-2 view");
47 static_assert(Kokkos::is_view_v<SViewType> && SViewType::rank == 1, "SVD: s must be a rank-1 view");
48 static_assert(Kokkos::is_view_v<WViewType> && WViewType::rank == 1, "SVD: W must be a rank-1 view");
49 static_assert(!std::is_same_v<typename WViewType::array_layout, Kokkos::LayoutStride>,
50 "SVD: W must be contiguous (not LayoutStride)");
51 using value_type = typename AViewType::non_const_value_type;
52 return KokkosBatched::SerialSVDInternal::invoke<value_type>(A.extent(0), A.extent(1), A.data(), A.stride(0),
53 A.stride(1), nullptr, 0, 0, nullptr, 0, 0, sigma.data(),
54 sigma.stride(0), work.data(), tol);
55 }
56
57 } // namespace KokkosBatched
58
59 #endif