text:
/**
 * \file libs/numeric/ublasx/min.cpp
 *
 * \brief Test suite for the \c min operation.
 *
 * Copyright (c) 2010, Marco Guazzone
 *
 * Distributed under the Boost Software License, Version 1.0. (See
 * accompanying file LICENSE_1_0.txt or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 *
 * \author Marco Guazzone, marco.guazzone@gmail.com
 */

#include <boost/numeric/ublas/fwd.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_expression.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/vector_expression.hpp>
#include <boost/numeric/ublasx/operation/min.hpp>
#include <boost/numeric/ublasx/tags.hpp>
#include <cstddef>
#include <functional>
#include <iostream>
#include "libs/numeric/ublasx/test/utils.hpp"

static const double tol = 1.0e-5;

namespace ublas = ::boost::numeric::ublas;
namespace ublasx = ::boost::numeric::ublasx;

BOOST_UBLASX_TEST_DEF( real_vector )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Real Vector" );

	typedef double value_type;
	typedef ublas::vector<value_type> vector_type;

	vector_type v(5);

	v(0) = 0.0;
	v(1) = 0.108929;
	v(2) = 0.0;
	v(3) = 0.0;
	v(4) = 1.023787;

	value_type expect(0);
	value_type res(0);
	ublas::vector<value_type> vexpect(0);
	ublas::vector<value_type> vres(0);

	// min(v)
	expect = value_type(0);
	res = ublasx::min(v);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min<1>(v)
	vexpect = ublas::vector<value_type>(1, 0);
	vres = ublasx::min<1>(v);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << v << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, 1, tol );
}

BOOST_UBLASX_TEST_DEF( complex_vector )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Complex Vector" );

	typedef double real_type;
	typedef ::std::complex<real_type> value_type;
	typedef ublas::vector<value_type> vector_type;

	vector_type v(5);

	v(0) = value_type( 0.000000,-0.54000);
	v(1) = value_type(-0.108929, 2.43000);
	v(2) = value_type( 0.000000, 1.00030);
	v(3) = value_type(-0.050000, 1.00030);
	v(4) = value_type( 1.023787,-4.24959);;

	value_type expect;
	value_type res;
	ublas::vector<value_type> vexpect;
	ublas::vector<value_type> vres;

	// min(v)
	expect = value_type(0.00000,-0.54000);
	res = ublasx::min(v);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min<1>(v)
	vexpect = ublas::vector<value_type>(1, value_type(0.00000,-0.54000));
	vres = ublasx::min<1>(v);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << v << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, 1, tol );
}

BOOST_UBLASX_TEST_DEF( vector_container )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Vector Container" );

	typedef double value_type;
	typedef ublas::vector<value_type> vector_type;
	typedef ublas::zero_vector<value_type> zero_vector_type;

	vector_type v(5);

	v(0) = 0.0;
	v(1) = 0.108929;
	v(2) = 0.0;
	v(3) = 0.0;
	v(4) = 1.023787;

	zero_vector_type z(5);

	value_type expect(0);
	value_type res(0);
	ublas::vector<value_type> vexpect(0);
	ublas::vector<value_type> vres(0);

	// min(z)
	expect = value_type(0);
	res = ublasx::min(z);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK( res == expect );

	// min(v)
	expect = value_type(0);
	res = ublasx::min(v);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min<1>(v)
	vexpect = ublas::vector<value_type>(1, 0);
	vres = ublasx::min<1>(v);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << v << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, 1, tol );
}

BOOST_UBLASX_TEST_DEF( vector_expression )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Vector Expression" );

	typedef double value_type;
	typedef ublas::vector<value_type> vector_type;

	vector_type v(5);

	v(0) = 0.0;
	v(1) = 0.108929;
	v(2) = 0.0;
	v(3) = 0.0;
	v(4) = 1.023787;

	value_type expect(0);
	value_type res(0);
	ublas::vector<value_type> vexpect(0);
	ublas::vector<value_type> vres(0);

	// min(-v)
	expect = value_type(-1.023787);
	res = ublasx::min(-v);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << -v << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min<1>(-v)
	vexpect = ublas::vector<value_type>(1, -1.023787);
	vres = ublasx::min<1>(-v);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << -v << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, 1, tol );
}

BOOST_UBLASX_TEST_DEF( vector_reference )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Vector Reference" );

	typedef double value_type;
	typedef ublas::vector<value_type> vector_type;
	typedef ublas::vector_reference<vector_type> vector_reference_type;

	vector_type v(5);

	v(0) = 0.0;
	v(1) = 0.108929;
	v(2) = 0.0;
	v(3) = 0.0;
	v(4) = 1.023787;

	value_type expect(0);
	value_type res(0);
	ublas::vector<value_type> vexpect(0);
	ublas::vector<value_type> vres(0);

	// min(ref(v))
	expect = value_type(0);
	res = ublasx::min(vector_reference_type(v));
	BOOST_UBLASX_DEBUG_TRACE( "min(" << vector_reference_type(v) << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min<1>(ref(v))
	vexpect = ublas::vector<value_type>(1, 0);
	vres = ublasx::min<1>(vector_reference_type(v));
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << vector_reference_type(v) << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, 1, tol );
}

BOOST_UBLASX_TEST_DEF( real_matrix )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Real Matrix" );

	typedef double value_type;
	typedef ublas::matrix<value_type> matrix_type;
	typedef ublas::vector<value_type> vector_type;

	std::size_t nr = 5;
	std::size_t nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	vector_type min_rows(nr);
	min_rows(0) = 0.0;
	min_rows(1) = 0.0;
	min_rows(2) = 0.0;
	min_rows(3) = 0.0;
	min_rows(4) = 1.0;

	vector_type min_cols(nc);
	min_cols(0) = 0.0;
	min_cols(1) = 0.0;
	min_cols(2) = 0.0;
	min_cols(3) = 0.0;

	value_type expect;
	value_type res;
	vector_type vexpect;
	vector_type vres;

	// min(A)
	expect = value_type(0);
	res = ublasx::min(A);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min_rows(A)
	vexpect = min_rows;
	vres = ublasx::min_rows(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_rows(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min_columns(A)
	vexpect = min_cols;
	vres = ublasx::min_columns(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_columns(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<1>(A)
	vexpect = min_rows;
	vres = ublasx::min<1>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<2>(A)
	vexpect = min_cols;
	vres = ublasx::min<2>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<2>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::major>(A)
	vexpect = min_rows;
	vres = ublasx::min_by_tag<ublasx::tag::major>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::major>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::minor>(A)
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::minor>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::minor>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::leading>(A)
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::leading>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::leading>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );
}

BOOST_UBLASX_TEST_DEF( complex_matrix )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Complex Matrix" );

	typedef double real_type;
	typedef ::std::complex<real_type> value_type;
	typedef ublas::matrix<value_type> matrix_type;
	typedef ublas::vector<value_type> vector_type;

	std::size_t nr = 5;
	std::size_t nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = value_type( 0.000000,-1.000000); A(0,1) = value_type(0.274690, 1.231751); A(0,2) = value_type(0.090000, 0.108929); A(0,3) = value_type(0.798938,1.000000);
	A(1,0) = value_type( 0.108929, 0.450332); A(1,1) = value_type(0.000000, 1.400000); A(1,2) = value_type(0.891726, 1.023787); A(1,3) = value_type(0.000000,1.230000);
	A(2,0) = value_type(-0.500000, 0.500000); A(2,1) = value_type(0.000000, 2.100000); A(2,2) = value_type(0.090000,-1.230000); A(2,3) = value_type(0.000000,0.675382);
	A(3,0) = value_type( 0.000000,-0.500000); A(3,1) = value_type(0.675382,-1.230000); A(3,2) = value_type(0.090000, 1.231751); A(3,3) = value_type(0.450332,0.891726);
	A(4,0) = value_type( 1.023787, 0.798938); A(4,1) = value_type(1.000000, 0.891726); A(4,2) = value_type(1.231751, 0.000000); A(4,3) = value_type(1.000000,0.500000);

	vector_type min_rows(nr);
	min_rows(0) = value_type(0.090000, 0.108929);
	min_rows(1) = value_type(0.108929, 0.450332);
	min_rows(2) = value_type(0.000000, 0.675382);
	min_rows(3) = value_type(0.000000,-0.500000);
	min_rows(4) = value_type(1.000000, 0.500000);

	vector_type min_cols(nc);
	min_cols(0) = value_type(0.108929,0.450332);
	min_cols(1) = value_type(0.274690,1.231751);
	min_cols(2) = value_type(0.090000,0.108929);
	min_cols(3) = value_type(0.000000,0.675382);

	value_type expect;
	value_type res;
	vector_type vexpect;
	vector_type vres;

	// min(A)
	expect = value_type(0.090000,0.108929);
	res = ublasx::min(A);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min_rows(A)
	vexpect = min_rows;
	vres = ublasx::min_rows(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_rows(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min_columns(A)
	vexpect = min_cols;
	vres = ublasx::min_columns(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_columns(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<1>(A)
	vexpect = min_rows;
	vres = ublasx::min<1>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<2>(A)
	vexpect = min_cols;
	vres = ublasx::min<2>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<2>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::major>(A)
	vexpect = min_rows;
	vres = ublasx::min_by_tag<ublasx::tag::major>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::major>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::minor>(A)
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::minor>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::minor>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::leading>(A)
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::leading>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::leading>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );
}

BOOST_UBLASX_TEST_DEF( row_major_matrix_container )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Row-major Matrix Container" );

	typedef double value_type;
	typedef ublas::matrix<value_type, ublas::row_major> matrix_type;
	typedef ublas::zero_matrix<value_type> zero_matrix_type;
	typedef ublas::vector<value_type> vector_type;

	std::size_t nr = 5;
	std::size_t nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	zero_matrix_type Z(nr, nc);

	vector_type min_rows(nr);
	min_rows(0) = 0.0;
	min_rows(1) = 0.0;
	min_rows(2) = 0.0;
	min_rows(3) = 0.0;
	min_rows(4) = 1.0;

	vector_type min_cols(nc);
	min_cols(0) = 0.0;
	min_cols(1) = 0.0;
	min_cols(2) = 0.0;
	min_cols(3) = 0.0;

	value_type expect(0);
	value_type res(0);
	vector_type vexpect(0);
	vector_type vres(0);

	// min(Z)
	expect = value_type(0);
	res = ublasx::min(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << Z << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK( res == expect );

	// min_rows(Z)
	vexpect = ublas::vector<value_type>(nr, 0);
	vres = ublasx::min_rows(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min_rows(" << Z << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min_columns(Z)
	vexpect = ublas::vector<value_type>(nc, 0);
	vres = ublasx::min_columns(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min_columns(" << Z << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<1>(Z)
	vexpect = ublas::vector<value_type>(nr, 0);
	vres = ublasx::min<1>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << Z << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<2>(Z)
	vexpect = ublas::vector<value_type>(nc, 0);
	vres = ublasx::min<2>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << Z << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::major>(Z)
	vexpect = ublas::vector<value_type>(nr, 0);
	vres = ublasx::min_by_tag<ublasx::tag::major>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::major>(" << Z << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::minor>(Z)
	vexpect = ublas::vector<value_type>(nc, 0);
	vres = ublasx::min_by_tag<ublasx::tag::minor>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::minor>(" << Z << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::leading>(Z)
	vexpect = ublas::vector<value_type>(nc, 0);
	vres = ublasx::min_by_tag<ublasx::tag::leading>(Z);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::leading>(" << Z << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min(A)
	expect = value_type(0);
	res = ublasx::min(A);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min_rows(A)
	vexpect = min_rows;
	vres = ublasx::min_rows(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_rows(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min_columns(A)
	vexpect = min_cols;
	vres = ublasx::min_columns(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_columns(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<1>(A)
	vexpect = min_rows;
	vres = ublasx::min<1>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<2>(A)
	vexpect = min_cols;
	vres = ublasx::min<2>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<2>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::major>(A)
	vexpect = min_rows;
	vres = ublasx::min_by_tag<ublasx::tag::major>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::major>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::minor>(A)
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::minor>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::minor>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::leading>(A)
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::leading>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::leading>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );
}

BOOST_UBLASX_TEST_DEF( col_major_matrix_container )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Column-major Matrix Container" );

	typedef double value_type;
	typedef ublas::matrix<value_type, ublas::column_major> matrix_type;
	typedef ublas::vector<value_type> vector_type;

	std::size_t nr = 5;
	std::size_t nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	vector_type min_rows(nr);
	min_rows(0) = 0.0;
	min_rows(1) = 0.0;
	min_rows(2) = 0.0;
	min_rows(3) = 0.0;
	min_rows(4) = 1.0;

	vector_type min_cols(nc);
	min_cols(0) = 0.0;
	min_cols(1) = 0.0;
	min_cols(2) = 0.0;
	min_cols(3) = 0.0;

	value_type expect(0);
	value_type res(0);
	vector_type vexpect(0);
	vector_type vres(0);

	// min(A)
	expect = value_type(0);
	res = ublasx::min(A);
	BOOST_UBLASX_DEBUG_TRACE( "min(" << A << ") = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min_rows(A)
	vexpect = min_rows;
	vres = ublasx::min_rows(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_rows(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min_columns(A)
	vexpect = min_cols;
	vres = ublasx::min_columns(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_columns(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<1>(A)
	vexpect = min_rows;
	vres = ublasx::min<1>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<2>(A)
	vexpect = min_cols;
	vres = ublasx::min<2>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min<2>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::major>(A)
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::major>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::major>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::minor>(A)
	vexpect = min_rows;
	vres = ublasx::min_by_tag<ublasx::tag::minor>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::minor>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::leading>(A)
	vexpect = min_rows;
	vres = ublasx::min_by_tag<ublasx::tag::leading>(A);
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::leading>(" << A << ") = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );
}

BOOST_UBLASX_TEST_DEF( matrix_expression )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Matrix Expression" );

	typedef double value_type;
	typedef ublas::matrix<value_type> matrix_type;
	typedef ublas::vector<value_type> vector_type;

	std::size_t nr = 5;
	std::size_t nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	vector_type min_rows(nr);
	min_rows(0) = 0.0;
	min_rows(1) = 0.0;
	min_rows(2) = 0.0;
	min_rows(3) = 0.0;
	min_rows(4) = 1.0;

	vector_type min_cols(nc);
	min_cols(0) = 0.0;
	min_cols(1) = 0.0;
	min_cols(2) = 0.0;
	min_cols(3) = 0.0;

	value_type expect(0);
	value_type res(0);
	vector_type vexpect(0);
	vector_type vres(0);

	// min(A')
	expect = value_type(0);
	res = ublasx::min(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min(" << A << "') = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK_CLOSE( res, expect, tol );

	// min_rows(A')
	vexpect = min_cols;
	vres = ublasx::min_rows(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_rows(" << A << "') = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min_columns(A')
	vexpect = min_rows;
	vres = ublasx::min_columns(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_columns(" << A << "') = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<1>(A')
	vexpect = min_cols;
	vres = ublasx::min<1>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(" << A << "') = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<2>(A')
	vexpect = min_rows;
	vres = ublasx::min<2>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min<2>(" << A << "') = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::major>(A')
	vexpect = min_rows;
	vres = ublasx::min_by_tag<ublasx::tag::major>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::major>(" << A << "') = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::minor>(A')
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::minor>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::minor>(" << A << "') = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::leading>(A')
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::leading>(ublas::trans(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::leading>(" << A << "') = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );
}

BOOST_UBLASX_TEST_DEF( matrix_reference )
{
	BOOST_UBLASX_DEBUG_TRACE( "Test Case: Matrix Reference" );

	typedef double value_type;
	typedef ublas::matrix<value_type> matrix_type;
	typedef ublas::matrix_reference<matrix_type> matrix_reference_type;
	typedef ublas::vector<value_type> vector_type;

	std::size_t nr = 5;
	std::size_t nc = 4;

	matrix_type A(nr, nc);

	A(0,0) = 0.0;      A(0,1) = 0.274690; A(0,2) = 0.0;      A(0,3) = 0.798938;
	A(1,0) = 0.108929; A(1,1) = 0.0;      A(1,2) = 0.891726; A(1,3) = 0.0;
	A(2,0) = 0.0;      A(2,1) = 0.0;      A(2,2) = 0.0;      A(2,3) = 0.0;
	A(3,0) = 0.0;      A(3,1) = 0.675382; A(3,2) = 0.0;      A(3,3) = 0.450332;
	A(4,0) = 1.023787; A(4,1) = 1.0;      A(4,2) = 1.231751; A(4,3) = 1.0;

	vector_type min_rows(nr);
	min_rows(0) = 0.0;
	min_rows(1) = 0.0;
	min_rows(2) = 0.0;
	min_rows(3) = 0.0;
	min_rows(4) = 1.0;

	vector_type min_cols(nc);
	min_cols(0) = 0.0;
	min_cols(1) = 0.0;
	min_cols(2) = 0.0;
	min_cols(3) = 0.0;

	value_type expect(0);
	value_type res(0);
	vector_type vexpect(0);
	vector_type vres(0);

	// min(ref(A))
	expect = value_type(0);
	res = ublasx::min(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min(reference(" << A << ")) = " << res << " ==> " << expect );
	BOOST_UBLASX_TEST_CHECK( res == expect );

	// min_rows(ref(A))
	vexpect = min_rows;
	vres = ublasx::min_rows(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_rows(reference(" << A << ")) = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min_columns(ref(A))
	vexpect = min_cols;
	vres = ublasx::min_columns(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_columns(reference(" << A << ")) = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<1>(ref(A))
	vexpect = min_rows;
	vres = ublasx::min<1>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min<1>(reference(" << A << ")) = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<2>(ref(A))
	vexpect = min_cols;
	vres = ublasx::min<2>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min<2>(reference(" << A << ")) = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::major>(ref(A))
	vexpect = min_rows;
	vres = ublasx::min_by_tag<ublasx::tag::major>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::major>(reference(" << A << ")) = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nr, tol );

	// min<tag::minor>(ref(A))
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::minor>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::minor>(reference(" << A << ")) = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );

	// min<tag::leading>(ref(A))
	vexpect = min_cols;
	vres = ublasx::min_by_tag<ublasx::tag::leading>(matrix_reference_type(A));
	BOOST_UBLASX_DEBUG_TRACE( "min_by_tag<tag::leading>(reference(" << A << ")) = " << vres << " ==> " << vexpect );
	BOOST_UBLASX_TEST_CHECK_VECTOR_CLOSE( vres, vexpect, nc, tol );
}

int main()
{
	BOOST_UBLASX_DEBUG_TRACE("Test Suite: 'min' operation");

	BOOST_UBLASX_TEST_BEGIN();

	BOOST_UBLASX_TEST_DO( real_vector );
	BOOST_UBLASX_TEST_DO( complex_vector );
	BOOST_UBLASX_TEST_DO( vector_container );
	BOOST_UBLASX_TEST_DO( vector_expression );
	BOOST_UBLASX_TEST_DO( vector_reference );
	BOOST_UBLASX_TEST_DO( real_matrix );
	BOOST_UBLASX_TEST_DO( complex_matrix );
	BOOST_UBLASX_TEST_DO( row_major_matrix_container );
	BOOST_UBLASX_TEST_DO( col_major_matrix_container );
	BOOST_UBLASX_TEST_DO( matrix_expression );
	BOOST_UBLASX_TEST_DO( matrix_reference );

	BOOST_UBLASX_TEST_END();
}


text:
// -----------------------------------------------------------------------------
// my_own_wait_for_termination_request.cpp : examples that show how use
// Boost.Application to make a simplest interactive (terminal) application
//
// Note 1: The Boost.Application (Aspects v4) and this sample are in
//         development process.
// -----------------------------------------------------------------------------

// Copyright 2011-2013 Renato Tegon Forti
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//

// -----------------------------------------------------------------------------

#include <iostream>
#include <boost/application.hpp>

using namespace boost;

//[mownwfr
class myapp
{
public:

   myapp(application::context& context)
      : context_(context)
   {
   }

   // param
   int operator()()
   {
      std::cout << "Test" << std::endl;

	  /*<< Use your custon handler >>*/
      context_.find<application::wait_for_termination_request>()->wait();

      return 0;
   }

private:

   application::context& context_;
};

// my made by hand behaviour
class wait_for_termination_request_my_behaviour
   /*<< Inheriting of 'wait_for_termination_request' handler contract abstract class >>*/
   : public application::wait_for_termination_request
{
public:

   /*<< Define your desired operation for 'wait' method >>*/
   void wait(){
      char type;
      do
      {
         std::cout << "Exit? [y/n]" << std::endl;
         std::cin >> type;
      }
      while( !std::cin.fail() && type!='y' );
   }

   void proceed(){
      // do nothing
   }
};

// main

int main(int argc, char *argv[])
{
   application::context app_context;
   myapp app(app_context);

   app_context.insert<application::args>(
      std::make_shared<application::args>(argc, argv));

   // if user do this, the default behavoiur will be ignored,
   // and the user behaviour will be executed by application::server
   /*<< Add your custon handler to context aspect pool of application >>*/
   app_context.insert< application::wait_for_termination_request>(
      std::shared_ptr<application::wait_for_termination_request>(
         new wait_for_termination_request_my_behaviour));

   return application::launch<application::common>(app, app_context);
}
//]

ext: cpp


text:
#include <algorithm>
#include <iostream>
#include <fstream>
#include <numeric>
#include <vector>
#include <NTL/ZZ.h>

NTL::ZZ mortal_fib(uintmax_t n, uintmax_t m)
{
    std::vector<NTL::ZZ> rabbits(m);
    rabbits.at(0) = 1;
    for (decltype(n) i = 0; i < n - 1; ++i) {
        auto tmp = rabbits.at(0), total = NTL::to_ZZ(0);
        for (decltype(m) j = 1; j < m; ++j) {
            total += rabbits.at(j);
            std::swap(rabbits.at(j), tmp);
        }
        rabbits.at(0) = total;
    }
    return std::accumulate(std::begin(rabbits),
            std::end(rabbits),
            NTL::to_ZZ(0));
}

int main()
{
    std::ifstream f("data/rosalind_fibd.txt");
    uintmax_t n, m;
    f >> n;
    f >> m;
    f.close();
    std::cout << mortal_fib(n, m) << std::endl;
    return EXIT_SUCCESS;
}

ext: cc


text:
#include <gtest/gtest.h>

#include "converter/fixml2fix_converter.hxx"
#include "converter/xml_element_helper.hxx"
#include "converter/fix_helper.hxx"
#include "util/fix_env.hxx"
#include "tools/test_util.hxx"

#include <boost/log/trivial.hpp>

#include <quickfix/fix50sp2/MarketDefinitionUpdateReport.h>

#include <list>
#include <set>
#include <string>
#include <utility>

using namespace std;
using namespace fix2xml;

TEST ( MarketDefinitionUpdateReport, set_fields)
{

  fixml2fix_converter converter {"../spec/fix/FIX50SP2.xml", "../spec/xsd/fixml-main-5-0-SP2.xsd"};
  auto& fixml_dict = converter.fixml_dico();
  ASSERT_TRUE(converter.init());
  ASSERT_TRUE(converter.parse_fixt_dico("../spec/fix/FIXT11.xml"));
  FIX50SP2::MarketDefinitionUpdateReport msg;

  list<multiset<string>> all_values;
  multiset<string> all_compo_names;
  multiset<string> MarketDefinitionUpdateReport_0;
  set_field(msg, FIX::Currency{"GBP"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::EncodedMktSegmDesc{"DATA_1002669786"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::EncodedMktSegmDescLen{1529156613}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::EncodedText{"DATA_1098428082"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::EncodedTextLen{1602086042}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::MarketID{"EXCHANGE_1017529712"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::MarketReportID{"STRING_2055537346"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::MarketReqID{"STRING_1250505689"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::MarketSegmentDesc{"STRING_1077957201"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::MarketSegmentID{"STRING_1927956379"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::MarketUpdateAction{'D'}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::ParentMktSegmID{"STRING_1567957610"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::Text{"STRING_1294955318"}, MarketDefinitionUpdateReport_0);
  set_field(msg, FIX::TransactTime{FIX::UTCTIMESTAMP(4, 0, 31, 4, 6, 2006)}, MarketDefinitionUpdateReport_0);
  all_values.push_back(MarketDefinitionUpdateReport_0);

  all_compo_names.insert("MarketDefinitionUpdateReport");

  // ApplicationSequenceControl
  multiset<string> ApplicationSequenceControl_9;
  set_field(msg, FIX::ApplID{"STRING_2013505951"}, ApplicationSequenceControl_9);
  set_field(msg, FIX::ApplLastSeqNum{352440117}, ApplicationSequenceControl_9);
  set_field(msg, FIX::ApplResendFlag{true}, ApplicationSequenceControl_9);
  set_field(msg, FIX::ApplSeqNum{1627930630}, ApplicationSequenceControl_9);
  all_values.push_back(ApplicationSequenceControl_9);
  all_compo_names.insert(".");

  // BaseTradingRules
  multiset<string> BaseTradingRules_4;
  set_field(msg, FIX::ExpirationCycle{1}, BaseTradingRules_4);
  set_field(msg, FIX::ImpliedMarketIndicator{2}, BaseTradingRules_4);
  FIX::MaxPriceVariation MaxPriceVariation_4;
  MaxPriceVariation_4.setString("17216995");
set_field(msg, MaxPriceVariation_4, BaseTradingRules_4);
  FIX::MaxTradeVol MaxTradeVol_4;
  MaxTradeVol_4.setString("18072866");
set_field(msg, MaxTradeVol_4, BaseTradingRules_4);
  FIX::MinTradeVol MinTradeVol_4;
  MinTradeVol_4.setString("9573802");
set_field(msg, MinTradeVol_4, BaseTradingRules_4);
  set_field(msg, FIX::MultilegModel{1}, BaseTradingRules_4);
  set_field(msg, FIX::MultilegPriceMethod{1}, BaseTradingRules_4);
  set_field(msg, FIX::PriceType{7}, BaseTradingRules_4);
  FIX::RoundLot RoundLot_4;
  RoundLot_4.setString("18963782");
set_field(msg, RoundLot_4, BaseTradingRules_4);
  set_field(msg, FIX::TradingCurrency{"USD"}, BaseTradingRules_4);
  all_values.push_back(BaseTradingRules_4);
  all_compo_names.insert(".");

  // LotTypeRules
  // Group LotTypeRules.NoLotTypeRules
  {
    FIX50SP2::MarketDefinitionUpdateReport::NoLotTypeRules noLotTypeRules_0_0;
    // LotTypeRules.NoLotTypeRules
    multiset<string> LotTypeRules_NoLotTypeRules_8;
    set_field(noLotTypeRules_0_0, FIX::LotType{'4'}, LotTypeRules_NoLotTypeRules_8);
    FIX::MinLotSize MinLotSize_8;
    MinLotSize_8.setString("18701888");
set_field(noLotTypeRules_0_0, MinLotSize_8, LotTypeRules_NoLotTypeRules_8);
    all_values.push_back(LotTypeRules_NoLotTypeRules_8);
    all_compo_names.insert("....NoLotTypeRules");

    msg.addGroup(noLotTypeRules_0_0);
  }
  {
    FIX50SP2::MarketDefinitionUpdateReport::NoLotTypeRules noLotTypeRules_0_1;
    // LotTypeRules.NoLotTypeRules
    multiset<string> LotTypeRules_NoLotTypeRules_9;
    set_field(noLotTypeRules_0_1, FIX::LotType{'3'}, LotTypeRules_NoLotTypeRules_9);
    FIX::MinLotSize MinLotSize_9;
    MinLotSize_9.setString("5785949");
set_field(noLotTypeRules_0_1, MinLotSize_9, LotTypeRules_NoLotTypeRules_9);
    all_values.push_back(LotTypeRules_NoLotTypeRules_9);
    all_compo_names.insert("....NoLotTypeRules");

    msg.addGroup(noLotTypeRules_0_1);
  }
  {
    FIX50SP2::MarketDefinitionUpdateReport::NoLotTypeRules noLotTypeRules_0_2;
    // LotTypeRules.NoLotTypeRules
    multiset<string> LotTypeRules_NoLotTypeRules_10;
    set_field(noLotTypeRules_0_2, FIX::LotType{'3'}, LotTypeRules_NoLotTypeRules_10);
    FIX::MinLotSize MinLotSize_10;
    MinLotSize_10.setString("18570237");
set_field(noLotTypeRules_0_2, MinLotSize_10, LotTypeRules_NoLotTypeRules_10);
    all_values.push_back(LotTypeRules_NoLotTypeRules_10);
    all_compo_names.insert("....NoLotTypeRules");

    msg.addGroup(noLotTypeRules_0_2);
  }
  // PriceLimits
  multiset<string> PriceLimits_4;
  FIX::HighLimitPrice HighLimitPrice_4;
  HighLimitPrice_4.setString("21465525");
set_field(msg, HighLimitPrice_4, PriceLimits_4);
  FIX::LowLimitPrice LowLimitPrice_4;
  LowLimitPrice_4.setString("7981332");
set_field(msg, LowLimitPrice_4, PriceLimits_4);
  set_field(msg, FIX::PriceLimitType{0}, PriceLimits_4);
  FIX::TradingReferencePrice TradingReferencePrice_4;
  TradingReferencePrice_4.setString("7957157");
set_field(msg, TradingReferencePrice_4, PriceLimits_4);
  all_values.push_back(PriceLimits_4);
  all_compo_names.insert("..");

  // TickRules
  // Group TickRules.NoTickRules
  {
    FIX50SP2::MarketDefinitionUpdateReport::NoTickRules noTickRules_0_0;
    // TickRules.NoTickRules
    multiset<string> TickRules_NoTickRules_5;
    FIX::EndTickPriceRange EndTickPriceRange_5;
    EndTickPriceRange_5.setString("12309310");
set_field(noTickRules_0_0, EndTickPriceRange_5, TickRules_NoTickRules_5);
    FIX::StartTickPriceRange StartTickPriceRange_5;
    StartTickPriceRange_5.setString("3085545");
set_field(noTickRules_0_0, StartTickPriceRange_5, TickRules_NoTickRules_5);
    FIX::TickIncrement TickIncrement_5;
    TickIncrement_5.setString("10689251");
set_field(noTickRules_0_0, TickIncrement_5, TickRules_NoTickRules_5);
    set_field(noTickRules_0_0, FIX::TickRuleType{1}, TickRules_NoTickRules_5);
    all_values.push_back(TickRules_NoTickRules_5);
    all_compo_names.insert("....NoTickRules");

    msg.addGroup(noTickRules_0_0);
  }
  // ExecInstRules
  // Group ExecInstRules.NoExecInstRules
  {
    FIX50SP2::MarketDefinitionUpdateReport::NoExecInstRules noExecInstRules_0_0;
    // ExecInstRules.NoExecInstRules
    multiset<string> ExecInstRules_NoExecInstRules_16;
    set_field(noExecInstRules_0_0, FIX::ExecInstValue{'1'}, ExecInstRules_NoExecInstRules_16);
    all_values.push_back(ExecInstRules_NoExecInstRules_16);
    all_compo_names.insert("...NoExecInstRules");

    msg.addGroup(noExecInstRules_0_0);
  }
  // OrdTypeRules
  // Group OrdTypeRules.NoOrdTypeRules
  {
    FIX50SP2::MarketDefinitionUpdateReport::NoOrdTypeRules noOrdTypeRules_0_0;
    // OrdTypeRules.NoOrdTypeRules
    multiset<string> OrdTypeRules_NoOrdTypeRules_20;
    set_field(noOrdTypeRules_0_0, FIX::OrdType{'5'}, OrdTypeRules_NoOrdTypeRules_20);
    all_values.push_back(OrdTypeRules_NoOrdTypeRules_20);
    all_compo_names.insert("...NoOrdTypeRules");

    msg.addGroup(noOrdTypeRules_0_0);
  }
  // TimeInForceRules
  // Group TimeInForceRules.NoTimeInForceRules
  {
    FIX50SP2::MarketDefinitionUpdateReport::NoTimeInForceRules noTimeInForceRules_0_0;
    // TimeInForceRules.NoTimeInForceRules
    multiset<string> TimeInForceRules_NoTimeInForceRules_13;
    set_field(noTimeInForceRules_0_0, FIX::TimeInForce{'1'}, TimeInForceRules_NoTimeInForceRules_13);
    all_values.push_back(TimeInForceRules_NoTimeInForceRules_13);
    all_compo_names.insert("...NoTimeInForceRules");

    msg.addGroup(noTimeInForceRules_0_0);
  }
  // header
  multiset<string> header_45;
  set_header_field(msg.getHeader(), FIX::ApplVerID{"STRING_2"}, header_45);
  set_header_field(msg.getHeader(), FIX::BeginString{"STRING_1709011930"}, header_45);
  set_header_field(msg.getHeader(), FIX::BodyLength{2090472103}, header_45);
  set_header_field(msg.getHeader(), FIX::CstmApplVerID{"STRING_122948247"}, header_45);
  set_header_field(msg.getHeader(), FIX::DeliverToCompID{"STRING_810446967"}, header_45);
  set_header_field(msg.getHeader(), FIX::DeliverToLocationID{"STRING_806695566"}, header_45);
  set_header_field(msg.getHeader(), FIX::DeliverToSubID{"STRING_2019326546"}, header_45);
  set_header_field(msg.getHeader(), FIX::LastMsgSeqNumProcessed{1441038618}, header_45);
  set_header_field(msg.getHeader(), FIX::MessageEncoding{"STRING_SHIFT_JIS"}, header_45);
  set_header_field(msg.getHeader(), FIX::MsgSeqNum{1222823591}, header_45);
  set_header_field(msg.getHeader(), FIX::OnBehalfOfCompID{"STRING_941676334"}, header_45);
  set_header_field(msg.getHeader(), FIX::OnBehalfOfLocationID{"STRING_344052353"}, header_45);
  set_header_field(msg.getHeader(), FIX::OnBehalfOfSubID{"STRING_1676826325"}, header_45);
  set_header_field(msg.getHeader(), FIX::OrigSendingTime{FIX::UTCTIMESTAMP(7, 57, 29, 19, 8, 2014)}, header_45);
  set_header_field(msg.getHeader(), FIX::PossDupFlag{true}, header_45);
  set_header_field(msg.getHeader(), FIX::PossResend{true}, header_45);
  set_header_field(msg.getHeader(), FIX::SecureData{"DATA_476126811"}, header_45);
  set_header_field(msg.getHeader(), FIX::SecureDataLen{277515965}, header_45);
  set_header_field(msg.getHeader(), FIX::SenderCompID{"STRING_206574857"}, header_45);
  set_header_field(msg.getHeader(), FIX::SenderLocationID{"STRING_650703706"}, header_45);
  set_header_field(msg.getHeader(), FIX::SenderSubID{"STRING_1698881192"}, header_45);
  set_header_field(msg.getHeader(), FIX::SendingTime{FIX::UTCTIMESTAMP(6, 39, 22, 13, 6, 2004)}, header_45);
  set_header_field(msg.getHeader(), FIX::TargetCompID{"STRING_1805399212"}, header_45);
  set_header_field(msg.getHeader(), FIX::TargetLocationID{"STRING_1972581729"}, header_45);
  set_header_field(msg.getHeader(), FIX::TargetSubID{"STRING_69504956"}, header_45);
  set_header_field(msg.getHeader(), FIX::XmlData{"DATA_1677242110"}, header_45);
  set_header_field(msg.getHeader(), FIX::XmlDataLen{1266136699}, header_45);
  all_values.push_back(header_45);
  all_compo_names.insert(".header");

  xml_element elt;
  converter.fix2fixml(msg, elt);
  BOOST_LOG_TRIVIAL(debug) << "The resulting XML is";
  cout << "////////////////////////////////////////////" << endl;
  cout << elt.to_string() << endl;
  cout << "////////////////////////////////////////////" << endl << endl;

  BOOST_LOG_TRIVIAL(debug) << "Quickfix XML representation is";
  cout << "////////////////////////////////////////////" << endl;
  cout << msg.toXML() << endl;
  cout << "////////////////////////////////////////////" << endl << endl;
  list<multiset<string>> elt_lists;
  elt.to_list(elt_lists);
  EXPECT_EQ(elt_lists.size(), all_values.size());

  if (elt_lists.size() != all_values.size())  {
    multiset<string> elt_compo_name;
    elt.all_components(elt_compo_name);
    BOOST_LOG_TRIVIAL(debug) << "XML Elements are:";
    cout << "	[";
    copy(elt_compo_name.begin(), elt_compo_name.end(), ostream_iterator<string>(cout, " "));    cout << "]" << endl;

    BOOST_LOG_TRIVIAL(debug) << "FIX Components are:";
    cout << "	[";
    copy(all_compo_names.begin(), all_compo_names.end(), ostream_iterator<string>(cout, " "));    cout << "]" << endl;

  }
  BOOST_LOG_TRIVIAL(debug) << "All FIX components";
  for (const auto& l : all_values) {
    cout << "	[";
    copy(l.begin(), l.end(), ostream_iterator<string>(cout, " "));
    cout << "]" << endl;
  }
  BOOST_LOG_TRIVIAL(debug) << "All XML components";
  for (const auto& l : elt_lists) {
    cout << "	[";
    copy(l.begin(), l.end(), ostream_iterator<string>(cout, " "));
    cout << "]" << endl;

  }

  for (const auto& xml_l : elt_lists) {
    bool found = false;
    for (const auto& l : all_values) {
      if (includes(l.begin(), l.end(), xml_l.begin(), xml_l.end())) {
        found = true;
        break;
      } // end if includes
    } // end for all_values
    EXPECT_TRUE(found);
    if ( ! found) {
      BOOST_LOG_TRIVIAL(debug) << "[TO CHECK] This XML component was not found in FIX message";
      cout << "	 ---> [";
      copy(xml_l.begin(), xml_l.end(), ostream_iterator<string>(cout, " "));      cout << "]" << endl << endl;
    } // end if ! found
  } // end for elt_lists
}


text:
#include <boost/program_options.hpp>
#include <cryptoTools/Network/Channel.h>
#include <cryptoTools/Network/Session.h>
#include <cryptoTools/Network/IOService.h>
#include <cryptoTools/Common/Log.h>
#include <cryptoTools/Common/Timer.h>
#include <cryptoTools/Crypto/PRNG.h>

#include <cryptoTools/Network/NetIO.h>

using namespace osuCrypto;
using namespace emp;
using namespace std;
namespace po = boost::program_options;

#define LIBOTE
//#define EMPTOOLS

#ifdef LIBOTE
void __Server(int party, unsigned int port, string server_ip, uint64_t num_thrds, uint64_t num_elems){
	osuCrypto::Timer time;

	IOService ios;
	Session ep(ios, server_ip, port, SessionMode::Server);
	Channel chl = ep.addChannel();
	chl.waitForConnection();

    vector<int64_t> data(num_elems);
	PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
	prng.get(data.data(), data.size());

	auto s = time.setTimePoint("start");
	chl.send(data);
	auto e = time.setTimePoint("finish");
	auto milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Consec: " << milli << " ms" << endl;

	s = time.setTimePoint("start");
	for (uint64_t e = 0; e < num_elems; ++e)
		chl.send(&data[e], 1);
	e = time.setTimePoint("finish");
	milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Seperate: " << milli << " ms" << endl;

	chl.close();
	ep.stop();
	ios.stop();
}

void __Client(int party, unsigned int port, string server_ip, uint64_t num_thrds, uint64_t num_elems){
	osuCrypto::Timer time;

	IOService ios;
	Session ep(ios, server_ip, port, SessionMode::Client);
	Channel chl = ep.addChannel();
	chl.waitForConnection();

    vector<int64_t> data(num_elems);

	auto s = time.setTimePoint("start");
	chl.recv(data);
	auto e = time.setTimePoint("finish");
	auto milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Consec: " << milli << " ms" << endl;

	s = time.setTimePoint("start");
	for (uint64_t e = 0; e < num_elems; ++e)
		chl.recv(&data[e], 1);
	e = time.setTimePoint("finish");
	milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Seperate: " << milli << " ms" << endl;

	for (uint64_t t = 0; t < num_thrds; ++t)
		chl.close();
	ep.stop();
	ios.stop();
}
#else
#ifdef EMPTOOLS
void __Server(int party, unsigned int port, string server_ip, uint64_t num_thrds, uint64_t num_elems){
	osuCrypto::Timer time;

	NetIO* io = new NetIO(party==ALICE ? nullptr:server_ip.c_str(), port, true);
	io->set_nodelay();

    vector<int64_t> data(num_elems);
	PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
	prng.get(data.data(), data.size());

	auto s = time.setTimePoint("start");
	io->send_data(&data[0], num_elems);
	auto e = time.setTimePoint("finish");
	auto milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Consec: " << milli << " ms" << endl;

	io->flush();

	s = time.setTimePoint("start");
	for (uint64_t e = 0; e < num_elems; ++e)
		io->send_data(&data[e], 1);
	e = time.setTimePoint("finish");
	milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Seperate: " << milli << " ms" << endl;

	io->flush();
}

void __Client(int party, unsigned int port, string server_ip, uint64_t num_thrds, uint64_t num_elems){
	osuCrypto::Timer time;

	NetIO* io = new NetIO(party==ALICE ? nullptr:server_ip.c_str(), port, true);
	io->set_nodelay();

    vector<int64_t> data(num_elems);

	auto s = time.setTimePoint("start");
	io->recv_data(&data[0], num_elems);
	auto e = time.setTimePoint("finish");
	auto milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Consec: " << milli << " ms" << endl;

	io->flush();

	s = time.setTimePoint("start");
	for (uint64_t e = 0; e < num_elems; ++e)
		io->recv_data(&data[e], 1);
	e = time.setTimePoint("finish");
	milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Seperate: " << milli << " ms" << endl;

	io->flush();
}
#else
void __Server(int party, unsigned int port, string server_ip, uint64_t num_thrds, uint64_t num_elems){
	osuCrypto::Timer time;

	IOService ios;
	NetIO io{party==ALICE ? nullptr:server_ip.c_str(), port, true};
	io.set_nodelay();

	Channel aChl{ios, new SocketAdapter<NetIO>(io)};
	aChl.waitForConnection();

    vector<int64_t> data(num_elems);
	PRNG prng(_mm_set_epi32(4253465, 3434565, 234435, 23987045));
	prng.get(data.data(), data.size());

	auto s = time.setTimePoint("start");
	aChl.send(data);
	auto e = time.setTimePoint("finish");
	auto milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Consec: " << milli << " ms" << endl;

	io.flush();

	s = time.setTimePoint("start");
	for (uint64_t e = 0; e < num_elems; ++e)
		aChl.send(&data[e], 1);
	e = time.setTimePoint("finish");
	milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Seperate: " << milli << " ms" << endl;

	io.flush();
	aChl.close();
	ios.stop();
}

void __Client(int party, unsigned int port, string server_ip, uint64_t num_thrds, uint64_t num_elems){
	osuCrypto::Timer time;

	IOService ios;
	NetIO io{party==ALICE ? nullptr:server_ip.c_str(), port, true};
	io.set_nodelay();

	Channel aChl(ios, new SocketAdapter<NetIO>(io));
	aChl.waitForConnection();

    vector<int64_t> data(num_elems);

	auto s = time.setTimePoint("start");
	aChl.recv(data);
	auto e = time.setTimePoint("finish");
	auto milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Consec: " << milli << " ms" << endl;

	io.flush();

	s = time.setTimePoint("start");
	for (uint64_t e = 0; e < num_elems; ++e)
		aChl.recv(&data[e], 1);
	e = time.setTimePoint("finish");
	milli = chrono::duration_cast<chrono::milliseconds>(e - s).count();
	cout << "Seperate: " << milli << " ms" << endl;

	io.flush();
	for (uint64_t t = 0; t < num_thrds; ++t)
		aChl.close();
	ios.stop();
}
#endif
#endif

int main(int argc, char** argv) {
	int party, port;
	string server_ip;
	uint64_t num_thrds, num_elems;

	po::options_description desc{"explore OT \nAllowed options"};
	desc.add_options()  //
	("help,h", "produce help message")  //
	("party,k", po::value<int>(&party)->default_value(1), "party id: 1 for garbler, 2 for evaluator")  //
	("port,p", po::value<int>(&port)->default_value(1234), "socket port")  //
	("server_ip,s", po::value<string>(&server_ip)->default_value("127.0.0.1"), "server'c IP.") //
	("thrds,t", po::value<uint64_t>(&num_thrds)->default_value(1), "number of threads") //
	("elems,e", po::value<uint64_t>(&num_elems)->default_value(8192), "inner dim");

	po::variables_map vm;
	try {
		po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
		po::store(parsed, vm);
		if (vm.count("help")) {
			cout << desc << endl;
			return 0;
		}
		po::notify(vm);
	}catch (po::error& e) {
		cout << "ERROR: " << e.what() << endl << endl;
		cout << desc << endl;
		return -1;
	}

	if (party == emp::ALICE) __Server(party, port, server_ip, num_thrds, num_elems);
	else __Client(party, port, server_ip, num_thrds, num_elems);

    return 0;
}


text:
// Copyright 2009 Tarroo, Inc.
// Copyright 2010 Glyn Matthews
// Copyright 2003-2008 Chris Kholhoff
// Copyright 2009-2012 Dean Michael Berris <dberris@gmail.com>
// Copyright 2012 Google, Inc.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef NETWORK_HTTP_SERVER_HPP_
#define NETWORK_HTTP_SERVER_HPP_

#include <boost/shared_ptr.hpp>

namespace network { namespace utils {

struct thread_pool;

}  // namespace utils

}  // namespace network

namespace network { namespace http {

class server_options;
class sync_server_impl;
class async_server_impl;
class async_server_connection;
struct request;
struct response;

template <class SyncHandler>
class sync_server {
 public:
  sync_server(server_options const &options, SyncHandler &handler);
  void run();
  void stop();
  void listen();
  ~sync_server();

  typedef http::request request;
  typedef http::response response;
 private:
  sync_server_impl *pimpl_;
  sync_server(sync_server const &other);  // = delete
  sync_server& operator=(sync_server other);  // = delete
};

template <class AsyncHandler>
class async_server {
 public:
  explicit async_server(server_options const &options, AsyncHandler &handler, utils::thread_pool &pool);
  void run();
  void stop();
  void listen();
  ~async_server();

  typedef http::request request;
  typedef boost::shared_ptr<async_server_connection> connection_ptr;
 private:
  async_server_impl *pimpl_;
  async_server(async_server const &other);  // = delete
  async_server& operator=(async_server other);  // = delete
};

} // namespace http

} // namespace network

// We're hiding the implementation from here, but still explicitly including
// it here. This is mostly a style point, to keep this header clean.
#include <network/protocol/http/server/server.ipp>

#endif // NETWORK_HTTP_SERVER_HPP_

ext: hpp

max_stars_repo_name: iBeacons/cpp-netlib

max_issues_repo_name: iBeacons/cpp-netlib

max_forks_repo_name: iBeacons/cpp-netlib


text: #include <boost/mpl/push_front_fwd.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
//
// Created by Cephas Svosve on 17/6/2021.
//

#include "dividend.h"
#include <iostream>
#include <vector>
#include <math.h>
#include <iostream>
#include <boost/random.hpp>

//get dividend growth rate i.e average of the percentage change in dividend paid-out, dD(t)/D(t-1).

double Div::getGrowthRate(int tickerID)
{
 return growthRate[tickerID];
}

//get volatility i.e stdev of the percentage changes in dividend paid-out, dD(t)/D(t-1).

double Div::getVolatility(int tickerID)
{
    return volatility[tickerID];
}

//we retrieve the autocorrelation of a particular asset by this function

double Div::getAutoCorr(int tickerID)
{
    return autoCorr[tickerID];
}

//this is a setter for the average growth rate of an asset's growth rate

void Div::setGrowthRate(double x)
{
 growthRate.push_back(x);
}

//this is a setter for saving the volatility of an asset's dividend process

void Div::setVolatility(double x)
{
 volatility.push_back(x);
}

//this is a setter for saving the auto-correlation of an asset's dividend process

void Div::setAutoCorr(double x)
{
 autoCorr.push_back(x);
}

//work-in-progress-*the function is meant to retrieve the cross-sectional correlation from the market object

void Div::setCrossCorr()
{
 // std::cout <<  "Div " << crossCorrMat << std::endl;
}

//because our system depends on accuracy of the randomness of the random matrix,
//we create a function that carefully generates a purely random matrix,
//i.e. auto-correlation is 0 precise to the order of e-03 as well as the cross-sectional correlation

MatrixXd Div::generateWhiteNoise(int numOfAssets, int numOfTicks)
{

    MatrixXd randoms(numOfAssets,numOfTicks);
    VectorXd a;

    //algorithm for generating random numbers that are shuffled continuously through seeding them on time

    time_t now = time(0);
    boost::random::mt19937 gen{static_cast<uint32_t>(now)};
    boost::normal_distribution<> nd(0.0, clock.getDt());
    boost::variate_generator<boost::mt19937&,
    boost::normal_distribution<> > var_nor(gen, nd);

    //we generate the matrix of random numbers

    for(int rw=0; rw < numOfAssets; rw++)
    {

        //we make sure the naturally occurring auto-correlation is sufficiently small by using a do-while loop

     do
        {
            //here we load each row with appropriate vector of random numbers
            a = VectorXd(numOfTicks);

            for(int i = 0; i < numOfTicks; ++i)
            {
                a(i) = var_nor();
            }

        }
        while (abs(lateralcorrcoef(a)) > 0.001);

        randoms.row(rw) = a;

    }

    //We then remove any cross-sectional correlation

    return verticallyWhiten(randoms);
}

//this function removes cross-sectional correlation by multiplying a matrix
// by the inverse of the lower cholesky decomposition of its correlation matrix

MatrixXd Div::verticallyWhiten(MatrixXd mx)
{
    Matrix crossCorrs = crossCorr(mx);
    LLT<MatrixXd> llt(crossCorrs);
    MatrixXd L = llt.matrixL();
    MatrixXd vWhite = L.inverse() * mx;

    return vWhite;
}

//this function calculates the coefficient of determination -correlation- between two vectors
//it requires the two vectors x and y, then computes the variables required for the formula
//i.e. variables xx = x^2  ,xy = x*y  and yy = y^2

double Div::corrcoef(VectorXd x, VectorXd y)
{
    if(x.size() == y.size()) {

        int n = x.size();

        //variable xx represents x^2

        double xx[n];
        double xy[n];
        double yy[n];

        //sumx is the sum of random variables x

        double sumx = x.sum();
        double sumy = y.sum();

        //sumxx is the sum of random variables x^2

        double sumxx;
        double sumxy;
        double sumyy;

        for (int i=0; i < x.size(); i++)
        {
            xx[i] = pow(x[i],2);
            xy[i] = x[i] * y[i];
            yy[i] = pow(y[i],2);

            sumxx = sumxx + xx[i];
            sumxy = sumxy + xy[i];
            sumyy = sumyy + yy[i];
        }

        //this is the formula used to calculate coefficient of determination, *see
        //https://www.jstor.org/stable/2965177?seq=6#metadata_info_tab_contents
        //Reed, William Gardner. “The Coefficient of Correlation.” Publications of the American Statistical Association,
        //vol. 15, no. 118, 1917, pp. 675–684. JSTOR, www.jstor.org/stable/2965177. Accessed 20 June 2021.

        double r = (n*sumxy - sumx*sumy)/sqrt((n*sumxx-pow(sumx,2))*(n*sumyy-pow(sumy,2)));

        return r;
    }
    else
    {
     cout << "found vectors of different size on computing correlation";
    }

}

//this function calculates the auto-correlation coefficient of a vector of random numbers
//we use it to verify that the naturally occuring auto-correlation in the random numbers-
//-we are using is sufficiently small i.e. of order e-03

double Div::lateralcorrcoef(VectorXd a){

    int n = a.size()-1;

    double x[n];
    double y[n];
    double xx[n];
    double xy[n];
    double yy[n];

    double sumx;
    double sumy;
    double sumxx;
    double sumxy;
    double sumyy;

    for (int i=0; i < n; i++) {

        x[i] = a[i+1];
        y[i] = a[i];
        xx[i] = pow(x[i],2);
        xy[i] = x[i] * y[i];
        yy[i] = pow(y[i],2);

        sumx = sumx + x[i];
        sumy = sumy + y[i];

        sumxx = sumxx + xx[i];
        sumxy = sumxy + xy[i];
        sumyy = sumyy + yy[i];

    }

    double r = (n*sumxy - sumx*sumy)/sqrt((n*sumxx-pow(sumx,2))*(n*sumyy-pow(sumy,2)));
    return r;

}

//this function calculates the correlation matrix from the random matrix

MatrixXd Div::crossCorr(MatrixXd x){
    int m = x.col(0).size();
    int n = x.row(0).size();

    MatrixXd corrMat(m,m);

    for(int i = 0; i < m; i++){
        for(int j = 0; j <= i; j++){

            corrMat(i,j) = corrcoef( x.row(i),x.row(j));
            corrMat(j,i) = corrMat(i,j);
        }
    }

    return corrMat;
}

//work-in-progress

MatrixXd Div::verticallyColor(MatrixXd x){}

VectorXd Div::laterallyColor(VectorXd x){}

VectorXd Div::standardize(VectorXd x){}

MatrixXd Div::generateColoredNoise(int numOfAssets, int numOfTicks)
{
    MatrixXd X = generateWhiteNoise(numOfAssets, numOfTicks);
    MatrixXd Y = verticallyWhiten(X);

    //vector<double> lC = laterallyColor(Y(0:));
}


text:
#pragma once

#include <regex>
#include <array>
#include <mutex>
#include <atomic>
#include <future>
#include <thread>
#include <vector>
#include <string>
#include <memory>
#include <boost/asio.hpp>
#include "utility.hpp"
#include "connection.hpp"
#include "thread_pool.hpp"
#include "http_router.hpp"
//#include "connection_manager.hpp"

namespace httpc {

    class Server {
    public:
        Server(
            const std::string& address,
            const std::string& port,
            const std::string& document_root,
            std::size_t num_thread = GetCPUCoreNumber()
        )
        : io_context_(1)
        , acceptor_(io_context_)
        //, manager_(io_context_)
        , document_root_(document_root)
        , num_of_thread_(num_thread)
        , http_router_(*this) {
            boost::asio::ip::tcp::resolver resolver(io_context_);
            boost::asio::ip::tcp::endpoint endpoint =
                *(resolver.resolve(address, port)).begin();
            this->acceptor_.open(endpoint.protocol());
            this->acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
            this->acceptor_.bind(endpoint);
            this->acceptor_.listen();

            // Accept();
            //f();

            //this->AssignMultithreadAccept_();
            //this->Accept_();
        }

        void Start() {
            // thread_.reset(new std::thread(
            //     [this] {
            //         io_context_.run();
            //     }
            // ));
            // // should be tested before use.
            // // but that means I should make a exception class
            // // I am lazy...
            // thread_->detach();

            // use std::async instead
            this->Accept_();
            std::async(std::launch::async, [this] {
                io_context_.run();
            });
        }

        template <HttpMethodEnum... Method, typename Function, typename... Aspects>
        void AddRouter(
            const std::string& route,
            Function&& callback,
            Aspects&&... aspects
        ) {
            this->http_router_.RegisterRouter<Method...>(
                route,
                std::forward<Function>(callback),
                std::forward<Aspects>(aspects)...
            );
            // manager_.RegisterRouter<Method...>(
            //     route,
            //     std::forward<Function>(callback),
            //     std::forward<Aspects>(aspects)...
            // );
            // manager_.RegisterRouter(
            //             route,
            //             std::forward<Function>(callback),
            //             std::move(aspects)...
            //         );
        }

        template <HttpMethodEnum... Method, typename Function, typename... Aspects>
        void AddRouter(
            std::regex&& route,
            Function&& callback,
            Aspects&&... aspects
        ) {
            this->http_router_.RegisterRouter<Method...>(
                std::forward<std::regex>(route),
                std::forward<Function>(callback),
                std::forward<Aspects>(aspects)...
            );
            // manager_.RegisterRouter(
            //             route,
            //             std::forward<Function>(callback),
            //             std::move(aspects)...
            //         );
        }

        inline std::string GetDocumentRoot() const noexcept {
            return document_root_;
        }

    private:
        // using io_context_ptr = std::shared_ptr<boost::asio::io_context> io_context_ptr;
        // using work_ptr = std::shared_ptr<boost::asio::io_context::work> work_ptr;

        boost::asio::io_context             io_context_;
        boost::asio::ip::tcp::acceptor      acceptor_;
        std::string                         document_root_;
        //ConnectionManager                   manager_;
        HttpRouter                          http_router_;
        // std::mutex                          acceptor_mutex_;
        // std::atomic<bool>                   atomic_accept_flag_{false};
        std::size_t                         num_of_thread_;
        // std::shared_ptr<ThreadPool>         thread_pool_;

        void AssignMultithreadAccept_() {
            // this->thread_pool_ = std::make_shared<ThreadPool>(num_of_thread_);
            // for (std::size_t i = 0; i < this->num_of_thread_; ++i) {
            //     this->thread_pool_->AddTask([this]{
            //         this->Accept_();
            //     });
            // }
        }

        // std::shared_ptr<std::thread>
        //                     thread_;
        void Accept_() {
            //while (this->atomic_accept_flag_);
            //this->atomic_accept_flag_ = true;

            std::shared_ptr<Connection> ptr_conn(new Connection(this->io_context_, this->http_router_));
            acceptor_.async_accept(
                ptr_conn->Socket(),
                [this, ptr_conn] (boost::system::error_code ec) {
                    if(!ec) {
                        // debug().dg("accept: ").dg(ec.message()).lf();
                        //debug().dg("start").lf();
                        debug().dg("accept and start a connection").lf();
                        ptr_conn->Socket().set_option(boost::asio::ip::tcp::no_delay(true));
                        ptr_conn->Start();
                    } else {
                        // std::cout << "err: " << ec.message() << std::endl;
                    }
                    //this->atomic_accept_flag_ = false;
                    debug().dg("wait for next connection").lf();
                    this->Accept_();
                }
            );
        }
    };

    void HttpRouter::InvokeLocalFileRenderer(
        const std::string& route_directory,
        Response& response
    ) {
        response.RenderFromStaticFile(this->server_.GetDocumentRoot() + route_directory);
    }

} // httpc


text:
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/triangular.hpp>
#include <boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/banded.hpp>
#include <boost/numeric/ublas/io.hpp>

using namespace boost::numeric::ublas;

int main()
{
	std::cout << "\nVector" << std::endl;
	// basic Vector Usage
	vector<double> v(3);
	for (unsigned i = 0; i < v.size(); ++ i)
	{
		v(i) = i;
	}
	std::cout << "vector \t\t" << v << std::endl;

	// unit_vector
	for (int i = 0; i < 3; ++ i)
	{
		unit_vector<double> v_unit(3, i);
		std::cout << "unit_vector \t" << v_unit << std::endl;
	}

	// zero_vector
	zero_vector<double> v_zero(3);
	std::cout << "zero_vector \t" << v_zero << std::endl;

	// scalr_vector
	scalar_vector<double> v_scalar(3,100);
	std::cout << "scalar_vector \t" << v_scalar << std::endl;

	std::cout << "\nMatrix" << std::endl;
	// basic matrix
	matrix<double> m(3, 3);
	for (unsigned i = 0; i < m.size1 (); ++ i)
	{
		for (unsigned j = 0; j < m.size2 (); ++ j)
		{
			m(i, j) = 3 * i + j;
		}
	}
	std::cout << "matrix \t\t" << m << std::endl;

	// identity matrix
	identity_matrix<double> m_identity(3);
    std::cout << "eye matrix\t" << m_identity << std::endl;

    // zero matrix
    zero_matrix<double> m_zero(3, 3);
    std::cout << "zero matrix\t" << m_zero << std::endl;

    // scalar matrix
    scalar_matrix<double> m_scalar(3, 3, 100);
    std::cout << "scalar matrix\t" << m_scalar << std::endl;

    // lower and upper triangular matrix
    triangular_matrix<double, lower> ml(3, 3);
    for (unsigned i = 0; i < ml.size1 (); ++ i)
        for (unsigned j = 0; j <= i; ++ j)
            ml(i, j) = 3 * i + j;
    std::cout << "lower triangular matrix\t" << ml << std::endl;

    triangular_matrix<double, upper> mu(3, 3);
    for (unsigned i = 0; i < mu.size1 (); ++ i)
        for (unsigned j = i; j < mu.size2 (); ++ j)
            mu(i, j) = 3 * i + j;
    std::cout << "upper triangular matrix\t" << mu << std::endl;

    // lower and upper symmetric matrix
    symmetric_matrix<double, lower> ml_symm(3, 3);
    for (unsigned i = 0; i < ml_symm.size1 (); ++ i)
        for (unsigned j = 0; j <= i; ++ j)
            ml_symm(i, j) = 3 * i + j;
    std::cout << "lower symmetric matrix\t" << ml_symm << std::endl;

    symmetric_matrix<double, upper> mu_symm(3, 3);
    for (unsigned i = 0; i < mu_symm.size1 (); ++ i)
        for (unsigned j = i; j < mu_symm.size2 (); ++ j)
            mu_symm(i, j) = 3 * i + j;
    std::cout << "upper symmetric matrix\t" << mu_symm << std::endl;

    // banded matrix
    banded_matrix<double> m_banded (3, 3, 1, 1);
    for (signed i = 0; i < signed (m_banded.size1 ()); ++ i)
        for (signed j = std::max (i - 1, 0); j < std::min (i + 2, signed (m_banded.size2 ())); ++ j)
            m_banded (i, j) = 3 * i + j;
    std::cout << "banded matrix\t" << m_banded << std::endl;
	return 0;
}

max_stars_repo_name: yoon-gu/la-table

max_issues_repo_name: yoon-gu/la-table

max_forks_repo_name: yoon-gu/la-table


text:
// Copyright (c) 2005 - 2012 Marc de Kamps
//						2012 David-Matthias Sichau
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
//
//    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
//      and/or other materials provided with the distribution.
//    * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software
//      without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#ifdef ENABLE_MPI
#include <boost/mpi/communicator.hpp>
namespace mpi = boost::mpi;

mpi::communicator world;
#endif // ENABLE_MPI

#define private public
#define protected public
#include <MPILib/include/utilities/MPIProxy.hpp>
#undef protected
#undef private

#ifdef ENABLE_MPI
#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
#endif // ENABLE_MPI

#include <boost/test/minimal.hpp>
using namespace boost::unit_test;
using namespace MPILib::utilities;

void test_Constructor() {

	MPIProxy_ mpiProxy;
#ifdef ENABLE_MPI

	BOOST_CHECK(mpiProxy._rank == world.rank());
	BOOST_CHECK(mpiProxy._size == world.size());
#endif

}

void test_Getter() {
	MPIProxy_ mpiProxy;
#ifdef ENABLE_MPI

	BOOST_CHECK(mpiProxy.getRank() == world.rank());
	BOOST_CHECK(mpiProxy.getSize() == world.size());
#endif

}

void test_Broadcast(){

	int blub = 0;
	BOOST_CHECK(blub == 0);
#ifdef ENABLE_MPI

	if(world.rank()==0){
		blub = 9;
		BOOST_CHECK(blub == 9);
	}
	MPIProxy_ mpiProxy;
	mpiProxy.broadcast(blub, 0);

	BOOST_CHECK(blub == 9);
#endif

	blub = 0;
	BOOST_CHECK(blub == 0);
#ifdef ENABLE_MPI

	if(world.rank()==0){
		blub = 9;
		BOOST_CHECK(blub == 9);
	}
	mpiProxy.broadcast(blub, 1);

	BOOST_CHECK(blub == 0);
#endif
}

int test_main(int argc, char* argv[]) // note the name!
		{
#ifdef ENABLE_MPI

	mpi::environment env(argc, argv);

	if (world.size() != 2) {
		BOOST_FAIL( "Run the test with two processes!");
	}
#endif
	// we use only two processors for this testing
	test_Constructor();
	test_Getter();
	test_Broadcast();

	return 0;

}

max_stars_repo_name: dekamps/miind

max_issues_repo_name: dekamps/miind

max_forks_repo_name: dekamps/miind