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)
51 if constexpr (scalar_weight) {
57 auto step = vec::Constant(n, λ * γ);
58 out = vec::Zero(n).cwiseMax(
in -
step).cwiseMin(
in +
step);
61 if constexpr (std::is_same_v<weight_t, vec>)
63 λ = weight_t::Ones(n);
66 assert((λ.array() >= 0).all());
68 out = vec::Zero(n).cwiseMax(
in -
step).cwiseMin(
in +
step);
69 return out.cwiseProduct(λ).template
lpNorm<1>();
75 return self.
prox(std::move(
in), std::move(out), γ);
83template <Config Conf,
class Weight =
typename Conf::real_t>
84 requires(std::is_same_v<Weight, typename Conf::real_t> ||
85 std::is_same_v<Weight, typename Conf::vec> ||
86 std::is_same_v<Weight, typename Conf::rvec> ||
87 std::is_same_v<Weight, typename Conf::crvec>)
91 static constexpr bool scalar_weight = std::is_same_v<weight_t, real_t>;
94 const char *
msg =
"L1NormComplex::λ must be nonnegative";
95 if constexpr (scalar_weight) {
96 if (λ < 0 || !std::isfinite(λ))
97 throw std::invalid_argument(
msg);
99 if ((λ.array() < 0).any() || !λ.allFinite())
100 throw std::invalid_argument(
msg);
105 requires(scalar_weight)
108 requires(!scalar_weight)
118 if constexpr (scalar_weight) {
125 auto mag = std::abs(x),
arg = std::arg(x);
131 if constexpr (std::is_same_v<weight_t, vec>)
133 λ = weight_t::Ones(n);
136 assert((λ.array() >= 0).all());
139 auto mag = std::abs(x),
arg = std::arg(x);
143 return out.cwiseProduct(λ).template
lpNorm<1>();
150 assert(out.rows() % 2 == 0);
152 util::start_lifetime_as_array<cplx_t>(
in.data(),
in.size() / 2),
157 util::start_lifetime_as_array<cplx_t>(out.data(), out.size() / 2),
166 return self.
prox(std::move(
in), std::move(out), γ);
#define USING_ALPAQA_CONFIG(Conf)
struct alpaqa::prox_fn prox
Compute the proximal mapping.
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 γ)