Skip to content

Commit

Permalink
Support matrix-valued complex ℓ₁-norm
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Mar 30, 2024
1 parent e33ada1 commit c3414ff
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/alpaqa/include/alpaqa/functions/l1-norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ template <Config Conf, class Weight = typename Conf::real_t>
requires(std::is_same_v<Weight, typename Conf::real_t> ||
std::is_same_v<Weight, typename Conf::vec> ||
std::is_same_v<Weight, typename Conf::rvec> ||
std::is_same_v<Weight, typename Conf::crvec>)
std::is_same_v<Weight, typename Conf::crvec> ||
std::is_same_v<Weight, typename Conf::mat> ||
std::is_same_v<Weight, typename Conf::rmat> ||
std::is_same_v<Weight, typename Conf::crmat>)
struct L1Norm {
USING_ALPAQA_CONFIG(Conf);
using weight_t = Weight;
Expand Down Expand Up @@ -85,7 +88,10 @@ template <Config Conf, class Weight = typename Conf::real_t>
requires(std::is_same_v<Weight, typename Conf::real_t> ||
std::is_same_v<Weight, typename Conf::vec> ||
std::is_same_v<Weight, typename Conf::rvec> ||
std::is_same_v<Weight, typename Conf::crvec>)
std::is_same_v<Weight, typename Conf::crvec> ||
std::is_same_v<Weight, typename Conf::mat> ||
std::is_same_v<Weight, typename Conf::rmat> ||
std::is_same_v<Weight, typename Conf::crmat>)
struct L1NormComplex {
USING_ALPAQA_CONFIG(Conf);
using weight_t = Weight;
Expand Down Expand Up @@ -128,7 +134,7 @@ struct L1NormComplex {
return mag2 <= γλ * γλ ? 0 : x * (1 - γλ / std::sqrt(mag2));
};
out = in.unaryExpr(soft_thres);
return λ * norm_1(out);
return λ * norm_1(out.reshaped());
} else {
if constexpr (std::is_same_v<weight_t, vec>)
if (λ.size() == 0)
Expand All @@ -142,7 +148,7 @@ struct L1NormComplex {
return mag2 <= γλ * γλ ? 0 : x * (1 - γλ / std::sqrt(mag2));
};
out = in.binaryExpr(λ, soft_thres);
return norm_1(out.cwiseProduct(λ));
return norm_1(out.cwiseProduct(λ).reshaped());
}
}

Expand Down

0 comments on commit c3414ff

Please sign in to comment.