16template <Config Conf,
class Weight =
typename Conf::real_t>
17 requires(std::is_same_v<Weight, typename Conf::real_t> ||
18 std::is_same_v<Weight, typename Conf::vec> ||
19 std::is_same_v<Weight, typename Conf::rvec> ||
20 std::is_same_v<Weight, typename Conf::crvec>)
24 static constexpr bool scalar_weight = std::is_same_v<weight_t, real_t>;
27 const char *
msg =
"L1Norm::λ must be nonnegative";
28 if constexpr (scalar_weight) {
29 if (λ < 0 || !std::isfinite(λ))
30 throw std::invalid_argument(
msg);
32 if ((λ.array() < 0).any() || !λ.allFinite())
33 throw std::invalid_argument(
msg);
38 requires(scalar_weight)
41 requires(!scalar_weight)
52 if constexpr (scalar_weight) {
58 auto step = vec::Constant(n, λ * γ);
59 out = vec::Zero(n).cwiseMax(
in -
step).cwiseMin(
in +
step);
60 return λ * norm_1(out.reshaped());
62 if constexpr (std::is_same_v<weight_t, vec>)
64 λ = weight_t::Ones(n);
67 assert((λ.array() >= 0).all());
69 out = vec::Zero(n).cwiseMax(
in -
step).cwiseMin(
in +
step);
70 return norm_1(out.cwiseProduct(λ).reshaped());
76 return self.
prox(std::move(
in), std::move(out), γ);
84template <Config Conf,
class Weight =
typename Conf::real_t>
85 requires(std::is_same_v<Weight, typename Conf::real_t> ||
86 std::is_same_v<Weight, typename Conf::vec> ||
87 std::is_same_v<Weight, typename Conf::rvec> ||
88 std::is_same_v<Weight, typename Conf::crvec>)
92 static constexpr bool scalar_weight = std::is_same_v<weight_t, real_t>;
95 const char *
msg =
"L1NormComplex::λ must be nonnegative";
96 if constexpr (scalar_weight) {
97 if (λ < 0 || !std::isfinite(λ))
98 throw std::invalid_argument(
msg);
100 if ((λ.array() < 0).any() || !λ.allFinite())
101 throw std::invalid_argument(
msg);
106 requires(scalar_weight)
109 requires(!scalar_weight)
120 if constexpr (scalar_weight) {
127 auto mag2 = x.real() * x.real() + x.imag() * x.imag();
131 return λ * norm_1(out);
133 if constexpr (std::is_same_v<weight_t, vec>)
135 λ = weight_t::Ones(n);
138 assert((λ.array() >= 0).all());
141 auto mag2 = x.real() * x.real() + x.imag() * x.imag();
145 return norm_1(out.cwiseProduct(λ));
152 assert(out.rows() % 2 == 0);
154 util::start_lifetime_as_array<cplx_t>(
in.data(),
in.size() / 2),
159 util::start_lifetime_as_array<cplx_t>(out.data(), out.size() / 2),
168 return self.
prox(std::move(
in), std::move(out), γ);
#define USING_ALPAQA_CONFIG(Conf)
struct alpaqa::prox_fn prox
Compute the proximal mapping.
auto norm_1(const Eigen::MatrixBase< Derived > &v)
Get the 1-norm of the given vector.
std::decay_t< decltype(Tag)> tag_t
typename Conf::crcmat crcmat
typename Conf::crmat crmat
typename Conf::cmcmat cmcmat
typename Conf::real_t real_t
typename Conf::rcmat rcmat
typename Conf::length_t length_t
typename Conf::cplx_t cplx_t
typename Conf::mcmat mcmat
ℓ₁-norm of complex numbers.
real_t prox(crmat in, rmat out, real_t γ=1)
Note: a complex vector in ℂⁿ is represented by a real vector in ℝ²ⁿ.
friend real_t alpaqa_tag_invoke(tag_t< alpaqa::prox >, L1NormComplex &self, crmat in, rmat out, real_t γ)
real_t prox(crcmat in, rcmat out, real_t γ=1)
L1NormComplex(weight_t λ)
real_t prox(crmat in, rmat out, real_t γ=1)
friend real_t alpaqa_tag_invoke(tag_t< alpaqa::prox >, L1Norm &self, crmat in, rmat out, real_t γ)