SOPT
Sparse OPTimisation
positive_quadrant_projection.cc
Go to the documentation of this file.
1 #include "sopt/maths.h"
2 #include "sopt/types.h"
3 
4 int main(int, char const **) {
5  // Create a matrix with a single negative real numbers
7  t_Matrix input = 2 * t_Matrix::Ones(5, 5) + t_Matrix::Random(5, 5);
8 
9  // Apply projection
10  t_Matrix posquad = sopt::positive_quadrant(input);
11  // imaginary part and negative real part becomes zero
12  if ((posquad.array().imag() != 0).any()) throw std::runtime_error("Imaginary part not zero");
13 
14  // positive real part unchanged
15  posquad.real()(2, 3) = input.real()(2, 3);
16  if ((posquad.array().real() != input.array().real()).all())
17  throw std::runtime_error("Real part was modified");
18 
19  return 0;
20 }
sopt::Matrix< Scalar > t_Matrix
Eigen::CwiseUnaryOp< const details::ProjectPositiveQuadrant< typename T::Scalar >, const T > positive_quadrant(Eigen::DenseBase< T > const &input)
Expression to create projection onto positive quadrant.
Definition: maths.h:60
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Definition: types.h:39
int main(int, char const **)