1 #ifndef SOPT_MPI_UTILITIES_H
2 #define SOPT_MPI_UTILITIES_H
4 #include "sopt/config.h"
15 typename real_type<typename T::Scalar>::type
l2_norm(Eigen::MatrixBase<T>
const &x,
16 Communicator
const &comm) {
17 return std::sqrt(comm.all_sum_all(x.squaredNorm()));
21 template <
typename T0,
typename T1>
22 typename real_type<typename T0::Scalar>::type
l2_norm(Eigen::ArrayBase<T0>
const &input,
23 Eigen::ArrayBase<T1>
const &weights,
24 Communicator
const &comm) {
25 if (weights.size() == 1) {
26 auto const weight_2 = std::real(weights(0) * std::conj(weights(0)));
27 return std::sqrt(comm.all_sum_all(input.matrix().squaredNorm() * weight_2));
32 template <
typename T0,
typename T1>
33 typename real_type<typename T0::Scalar>::type
l2_norm(Eigen::MatrixBase<T0>
const &input,
34 Eigen::MatrixBase<T1>
const &weights,
35 Communicator
const &comm) {
40 template <
typename T0,
typename T1>
41 typename real_type<typename T0::Scalar>::type
l1_norm(Eigen::ArrayBase<T0>
const &input,
42 Eigen::ArrayBase<T1>
const &weights,
43 Communicator
const &comm) {
47 template <
typename T0,
typename T1>
48 typename real_type<typename T0::Scalar>::type
l1_norm(Eigen::MatrixBase<T0>
const &input,
49 Eigen::MatrixBase<T1>
const &weights,
50 Communicator
const &comm) {
54 template <
typename T0>
55 typename real_type<typename T0::Scalar>::type
l1_norm(Eigen::ArrayBase<T0>
const &input,
56 Communicator
const &comm) {
60 template <
typename T0>
61 typename real_type<typename T0::Scalar>::type
l1_norm(Eigen::MatrixBase<T0>
const &input,
62 Communicator
const &comm) {
real_type< typename T0::Scalar >::type l1_norm(Eigen::ArrayBase< T0 > const &input, Eigen::ArrayBase< T1 > const &weights)
Computes weighted L1 norm.
real_type< typename T0::Scalar >::type l2_norm(Eigen::ArrayBase< T0 > const &input, Eigen::ArrayBase< T1 > const &weights)
Computes weighted L2 norm.