15template <Config Conf,
class Weight =
typename Conf::real_t>
16 requires(std::is_same_v<Weight, typename Conf::real_t> ||
17 std::is_same_v<Weight, typename Conf::vec> ||
18 std::is_same_v<Weight, typename Conf::rvec> ||
19 std::is_same_v<Weight, typename Conf::crvec>)
23 static constexpr bool scalar_weight = std::is_same_v<weight_t, real_t>;
26 const char *msg =
"L1Norm::λ must be nonnegative";
27 if constexpr (scalar_weight) {
28 if (λ < 0 || !std::isfinite(λ))
29 throw std::invalid_argument(msg);
31 if ((λ.array() < 0).any() || !λ.allFinite())
32 throw std::invalid_argument(msg);
37 requires(scalar_weight)
40 requires(!scalar_weight)
46 assert(in.cols() == 1);
47 assert(out.cols() == 1);
48 assert(in.size() == out.size());
50 if constexpr (scalar_weight) {
56 auto step = vec::Constant(n, λ * γ);
57 out = vec::Zero(n).cwiseMax(in - step).cwiseMin(in + step);
58 return λ * γ * out.template lpNorm<1>();
60 if constexpr (std::is_same_v<weight_t, vec>)
62 λ = weight_t::Ones(n);
63 assert(λ.cols() == 1);
64 assert(in.size() == λ.size());
65 assert((λ.array() >= 0).all());
67 out = vec::Zero(n).cwiseMax(in - step).cwiseMin(in + step);
68 return γ * out.cwiseProduct(λ).template lpNorm<1>();
74 return self.
prox(std::move(in), std::move(out), γ);
#define USING_ALPAQA_CONFIG(Conf)
std::decay_t< decltype(Tag)> tag_t
typename Conf::crmat crmat
typename Conf::real_t real_t
typename Conf::length_t length_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 γ)