numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
apply_shrinkage_operator.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 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
24
26
34template <base::concepts::real_scalar_dense_vector Vector>
36 Vector& target, typename Vector::Scalar threshold) {
37 // Determined by benchmarks.
38 constexpr num_collect::index_type parallelized_size = 10000;
39#pragma omp parallel for if (target.size() > parallelized_size)
40 for (num_collect::index_type i = 0; i < target.size(); ++i) {
41 if (target(i) > threshold) {
42 target(i) -= threshold;
43 } else if (target(i) < -threshold) {
44 target(i) += threshold;
45 } else {
46 target(i) = 0.0;
47 }
48 }
49}
50
51} // namespace num_collect::regularization::impl
Definition of index_type type.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
Namespace of internal implementations.
void apply_shrinkage_operator(Vector &target, typename Vector::Scalar threshold)
Apply shrinkage operator to a vector.
Definition of real_scalar_dense_vector concept.