#include <iostream>
#include <vector>
#include <numeric>
#include <random>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace std;
namespace ublas = boost::numeric::ublas;
void fill_matrix (ublas::matrix<int> & A)
{
random_device rng;
uniform_int_distribution<> gen (-10, 10);
for (int i = 0; i < A.size1(); i++)
for (int j = 0; j < A.size2(); j++)
A(i,j) = gen(rng);
}
int addition (int current_sum, int value)
if (value < 0 && value&1)
return current_sum + value;
return current_sum;
int main()
int n = 4;
ublas::matrix<int> A (n, n);
fill_matrix (A);
cout <<A <<endl;
int sum = accumulate (A.begin2(), A.end2() + A.size2() * (A.size1() - 1), 0,
addition);
cout <<sum <<endl;
#include <iostream>
#include <vector>
#include <numeric>
#include <random>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace std;
namespace ublas = boost::numeric::ublas;
void fill_matrix (ublas::matrix<int> & A)
{
random_device rng;
uniform_int_distribution<> gen (-10, 10);
for (int i = 0; i < A.size1(); i++)
for (int j = 0; j < A.size2(); j++)
A(i,j) = gen(rng);
}
int addition (int current_sum, int value)
{
if (value < 0 && value&1)
return current_sum + value;
return current_sum;
}
int main()
{
int n = 4;
ublas::matrix<int> A (n, n);
fill_matrix (A);
cout <<A <<endl;
int sum = accumulate (A.begin2(), A.end2() + A.size2() * (A.size1() - 1), 0,
addition);
cout <<sum <<endl;
}