Squashed 'boost/' content from commit b4feb19f2

git-subtree-dir: boost
git-subtree-split: b4feb19f287ee92d87a9624b5d36b7cf46aeadeb
This commit is contained in:
Bill Somerville
2018-06-09 21:48:32 +01:00
commit 4ebe6417a5
12444 changed files with 2327021 additions and 0 deletions
+100
View File
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2004 Michael Stevens
* Use, modification and distribution are subject to 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)
*/
/*
* Default construct test when possible
*/
template <class E>
struct default_construct
{
static void test() {}
};
template <class VC>
struct default_construct<boost::numeric::ublas::vector_container<VC> >
{
static void test ()
{
VC default_constuct;
initialize_vector (default_constuct);
std::cout << "default construct = " << default_constuct << std::endl;
}
};
template <class MC>
struct default_construct<boost::numeric::ublas::matrix_container<MC> >
{
static void test ()
{
MC default_constuct;
initialize_vector (default_constuct);
std::cout << "default construct = " << default_constuct << std::endl;
}
};
/*
* Initialise test values in vector/matrix
*/
template<class V>
void initialize_vector (V &v) {
typename V::size_type size = v.size ();
for (typename V::size_type i = 0; i < size; ++ i)
v [i] = typename V::value_type ( i + 1.f );
}
template<class M>
void initialize_matrix_impl (M &m, ublas::packed_proxy_tag) {
typename M::size_type size1 = m.size1 ();
#ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
for (typename M::iterator1 i = m.begin1(); i != m.end1(); ++ i)
for (typename M::iterator2 j = i.begin(); j != i.end(); ++ j)
*j = typename M::value_type ( i.index1() * size1 + j.index2() + 1.f );
#else
for (typename M::iterator1 i = m.begin1(); i != m.end1(); ++ i)
for (typename M::iterator2 j = ublas::begin (i, ublas::iterator1_tag ()); j != ublas::end (i, ublas::iterator1_tag ()); ++ j)
*j = typename M::value_type ( i.index1() * size1 + j.index2() + 1.f );
#endif
}
template<class M>
void initialize_matrix_impl (M &m, ublas::sparse_proxy_tag) {
typename M::size_type size1 = m.size1 ();
typename M::size_type size2 = m.size2 ();
for (typename M::size_type i = 0; i < size1; ++ i)
for (typename M::size_type j = 0; j < size2; ++ j)
m (i, j) = typename M::value_type (i * size1 + j + 1.f);
}
template<class M>
void initialize_matrix (M &m) {
initialize_matrix_impl (m, typename M::storage_category());
}
template<class M>
void initialize_matrix (M &m, ublas::lower_tag) {
typename M::size_type size1 = m.size1 ();
typename M::size_type size2 = m.size2 ();
for (typename M::size_type i = 0; i < size1; ++ i) {
typename M::size_type j = 0;
for (; j <= i; ++ j)
m (i, j) = i * size1 + j + 1.f;
for (; j < size2; ++ j)
m (i, j) = 0.f;
}
}
template<class M>
void initialize_matrix (M &m, ublas::upper_tag) {
typename M::size_type size1 = m.size1 ();
typename M::size_type size2 = m.size2 ();
for (typename M::size_type i = 0; i < size1; ++ i) {
typename M::size_type j = 0;
for (; j < i; ++ j)
m (i, j) = 0.f;
for (; j < size2; ++ j)
m (i, j) = i * size1 + j + 1.f;
}
}
@@ -0,0 +1,135 @@
// Copyright 2008 Gunter Winkler <guwi17@gmx.de>
// 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 _HPP_TESTHELPER_
#define _HPP_TESTHELPER_
#include <utility>
#include <iostream>
#include <boost/numeric/ublas/vector_expression.hpp>
#include <boost/numeric/ublas/matrix_expression.hpp>
static unsigned _success_counter = 0;
static unsigned _fail_counter = 0;
static inline
void assertTrue(const char* message, bool condition) {
#ifndef NOMESSAGES
std::cout << message;
#endif
if ( condition ) {
++ _success_counter;
std::cout << "1\n"; // success
} else {
++ _fail_counter;
std::cout << "0\n"; // failed
}
}
template < class T >
void assertEquals(const char* message, T expected, T actual) {
#ifndef NOMESSAGES
std::cout << message;
#endif
if ( expected == actual ) {
++ _success_counter;
std::cout << "1\n"; // success
} else {
#ifndef NOMESSAGES
std::cout << " expected " << expected << " actual " << actual << " ";
#endif
++ _fail_counter;
std::cout << "0\n"; // failed
}
}
inline static
std::pair<unsigned, unsigned> getResults() {
return std::make_pair(_success_counter, _fail_counter);
}
template < class M1, class M2 >
bool compare( const boost::numeric::ublas::matrix_expression<M1> & m1,
const boost::numeric::ublas::matrix_expression<M2> & m2 ) {
if ((m1().size1() != m2().size1()) ||
(m1().size2() != m2().size2())) {
return false;
}
size_t size1 = m1().size1();
size_t size2 = m1().size2();
for (size_t i=0; i < size1; ++i) {
for (size_t j=0; j < size2; ++j) {
if ( m1()(i,j) != m2()(i,j) ) return false;
}
}
return true;
}
template < class M1, class M2 >
bool compare( const boost::numeric::ublas::vector_expression<M1> & m1,
const boost::numeric::ublas::vector_expression<M2> & m2 ) {
if (m1().size() != m2().size()) {
return false;
}
size_t size = m1().size();
for (size_t i=0; i < size; ++i) {
if ( m1()(i) != m2()(i) ) return false;
}
return true;
}
// Compare if two matrices or vectors are equals based on distance.
template <class AE>
typename AE::value_type mean_square(const boost::numeric::ublas::matrix_expression<AE> &me) {
typename AE::value_type s(0);
typename AE::size_type i, j;
for (i=0; i!= me().size1(); i++) {
for (j=0; j!= me().size2(); j++) {
s += boost::numeric::ublas::scalar_traits<typename AE::value_type>::type_abs(me()(i,j));
}
}
return s / (me().size1() * me().size2());
}
template <class AE>
typename AE::value_type mean_square(const boost::numeric::ublas::vector_expression<AE> &ve) {
// We could have use norm2 here, but ublas' ABS does not support unsigned types.
typename AE::value_type s(0);
typename AE::size_type i;
for (i=0; i!= ve().size(); i++) {
s += boost::numeric::ublas::scalar_traits<typename AE::value_type>::type_abs(ve()(i));
}
return s / ve().size();
}
template < class M1, class M2 >
bool compare_to( const boost::numeric::ublas::matrix_expression<M1> & m1,
const boost::numeric::ublas::matrix_expression<M2> & m2,
double tolerance = 0.0 ) {
if ((m1().size1() != m2().size1()) ||
(m1().size2() != m2().size2())) {
return false;
}
return mean_square(m2() - m1()) <= tolerance;
}
template < class M1, class M2 >
bool compare_to( const boost::numeric::ublas::vector_expression<M1> & m1,
const boost::numeric::ublas::vector_expression<M2> & m2,
double tolerance = 0.0 ) {
if (m1().size() != m2().size()) {
return false;
}
return mean_square(m2() - m1()) <= tolerance;
}
#endif