numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
dense_diff_matrix.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <Eigen/Core>
23
26
28
29namespace impl {
30
36template <typename Matrix>
38public:
40 using scalar_type = typename Matrix::Scalar;
41
46
54 [[nodiscard]] auto operator()(num_collect::index_type row,
56 if (row == col) {
57 return static_cast<scalar_type>(1);
58 }
59 if (row + 1 == col) {
60 return static_cast<scalar_type>(-1);
61 }
62 return static_cast<scalar_type>(0);
63 }
64};
65
66} // namespace impl
67
76template <typename Matrix>
77[[nodiscard]] inline auto dense_diff_matrix(
79 -> Eigen::CwiseNullaryOp<impl::dense_diff_matrix_functor<Matrix>, Matrix> {
80 return Matrix::NullaryExpr(
82}
83
91template <typename Matrix>
92[[nodiscard]] inline auto dense_diff_matrix(num_collect::index_type size)
93 -> Eigen::CwiseNullaryOp<impl::dense_diff_matrix_functor<Matrix>, Matrix> {
94 NUM_COLLECT_ASSERT(size > 2);
95 return dense_diff_matrix<Matrix>(size - 1, size);
96}
97
98} // namespace num_prob_collect::regularization
Definition of assertion macros.
#define NUM_COLLECT_ASSERT(CONDITION)
Macro to check whether a condition is satisfied.
Definition assert.h:66
Helper class to create a dense differential matrix.
auto operator()(num_collect::index_type row, num_collect::index_type col) const -> scalar_type
Get an element.
Definition of index_type type.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
Namespace of regularization.
Definition namespaces.h:34
auto dense_diff_matrix(num_collect::index_type rows, num_collect::index_type cols) -> Eigen::CwiseNullaryOp< impl::dense_diff_matrix_functor< Matrix >, Matrix >
Create a dense differential matrix.