diff options
Diffstat (limited to 'libs/multiprecision/test/ublas_interop')
34 files changed, 5195 insertions, 0 deletions
diff --git a/libs/multiprecision/test/ublas_interop/common/init.hpp b/libs/multiprecision/test/ublas_interop/common/init.hpp new file mode 100644 index 0000000000..a9691b4ed0 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/common/init.hpp @@ -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; + } +} diff --git a/libs/multiprecision/test/ublas_interop/common/testhelper.hpp b/libs/multiprecision/test/ublas_interop/common/testhelper.hpp new file mode 100644 index 0000000000..4fbf9c4d15 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/common/testhelper.hpp @@ -0,0 +1,74 @@ +// 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> + +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 + } +} + +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 ) { + size_t size1 = (std::min)(m1().size1(), m2().size1()); + size_t size2 = (std::min)(m1().size2(), m2().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 ) { + size_t size = (std::min)(m1().size(), m2().size()); + for (size_t i=0; i < size; ++i) { + if ( m1()(i) != m2()(i) ) return false; + } + return true; +} + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test1.cpp b/libs/multiprecision/test/ublas_interop/test1.cpp new file mode 100644 index 0000000000..53de790192 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test1.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test1.hpp" + +int main () { + test_vector (); + test_matrix_vector (); + test_matrix (); + return 0; +} diff --git a/libs/multiprecision/test/ublas_interop/test1.hpp b/libs/multiprecision/test/ublas_interop/test1.hpp new file mode 100644 index 0000000000..1bcb024f16 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test1.hpp @@ -0,0 +1,62 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST1_H +#define TEST1_H + +#ifdef _MSC_VER +# pragma warning(disable:4800 4996 4127 4100) +#endif + +#include <boost/multiprecision/cpp_dec_float.hpp> + +#ifdef TEST_ET +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_on> mp_test_type; +#else +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off> mp_test_type; +#endif +//typedef double mp_test_type; + +#define USE_RANGE +#define USE_SLICE +#define USE_FLOAT +#define USE_UNBOUNDED_ARRAY +#define USE_STD_VECTOR +#define USE_BOUNDED_VECTOR USE_MATRIX +#define USE_UNBOUNDED_ARRAY +#define USE_MAP_ARRAY +#define USE_STD_MAP +#define USE_MAPPED_VECTOR +#define USE_COMPRESSED_VECTOR +#define USE_COORDINATE_VECTOR +#define USE_MAPPED_MATRIX +#define USE_COMPRESSED_MATRIX +#define USE_COORDINATE_MATRIX + +#include <iostream> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/vector_proxy.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/matrix_proxy.hpp> +#include <boost/numeric/ublas/io.hpp> + +namespace ublas = boost::numeric::ublas; + +#include "common/init.hpp" + +void test_vector (); +void test_matrix_vector (); +void test_matrix (); + + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test11.cpp b/libs/multiprecision/test/ublas_interop/test11.cpp new file mode 100644 index 0000000000..085bd90c39 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test11.cpp @@ -0,0 +1,265 @@ +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. + +#include "test1.hpp" + +// Test vector expression templates +template<class V, int N> +struct test_my_vector { + typedef typename V::value_type value_type; + typedef typename V::size_type size_type; + typedef typename ublas::type_traits<value_type>::real_type real_type; + + template<class VP> + void test_container_with (VP &v1) const { + // Container type tests in addition to expression types + // Insert and erase + v1.insert_element (0, 55); + v1.erase_element (1); + v1.clear (); + } + + template<class VP> + void test_expression_with (VP &v1, VP &v2, VP &v3) const { + // Expression type tests + value_type t; + size_type i; + real_type n; + + // Default Construct + default_construct<VP>::test (); + + // Copy and swap + initialize_vector (v1); + initialize_vector (v2); + v1 = v2; + std::cout << "v1 = v2 = " << v1 << std::endl; + v1.assign_temporary (v2); + std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl; + v1.swap (v2); + std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl; + + // Zero assignment + v1 = ublas::zero_vector<> (v1.size ()); + std::cout << "v1.zero_vector = " << v1 << std::endl; + v1 = v2; + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + // Project range and slice + initialize_vector (v1); + initialize_vector (v2); + project (v1, ublas::range(0,1)) = project (v2, ublas::range(0,1)); + project (v1, ublas::range(0,1)) = project (v2, ublas::slice(0,1,1)); + project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::slice(0,1,2)); + project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::range(0,2)); + std::cout << "v1 = range/slice " << v1 << std::endl; +#endif + + // Unary vector operations resulting in a vector + initialize_vector (v1); + v2 = - v1; + std::cout << "- v1 = " << v2 << std::endl; + v2 = ublas::conj (v1); + std::cout << "conj (v1) = " << v2 << std::endl; + + // Binary vector operations resulting in a vector + initialize_vector (v1); + initialize_vector (v2); + v3 = v1 + v2; + std::cout << "v1 + v2 = " << v3 << std::endl; + v3 = v1 - v2; + std::cout << "v1 - v2 = " << v3 << std::endl; + v3 = ublas::element_prod (v1, v2); + std::cout << "element_prod (v1, v2) = " << v3 << std::endl; + + // Scaling a vector + t = N; + initialize_vector (v1); + v2 = value_type (1.) * v1; + std::cout << "1. * v1 = " << v2 << std::endl; + v2 = t * v1; + std::cout << "N * v1 = " << v2 << std::endl; + initialize_vector (v1); + v2 = v1 * value_type (1.); + std::cout << "v1 * 1. = " << v2 << std::endl; + v2 = v1 * t; + std::cout << "v1 * value_type(N) = " << v2 << std::endl; + // test interop with integer + v2 = v1 * N; + + std::cout << "v1 * N = " << v2 << std::endl; + + // Some assignments + initialize_vector (v1); + initialize_vector (v2); + v2 += v1; + std::cout << "v2 += v1 = " << v2 << std::endl; + v2 -= v1; + std::cout << "v2 -= v1 = " << v2 << std::endl; + v2 = v2 + v1; + std::cout << "v2 = v2 + v1 = " << v2 << std::endl; + v2 = v2 - v1; + std::cout << "v2 = v2 - v1 = " << v2 << std::endl; + v1 *= value_type (1.); + std::cout << "v1 *= 1. = " << v1 << std::endl; + v1 *= t; + std::cout << "v1 *= value_type(N) = " << v1 << std::endl; + // test interop with integer + v1 *= N; + std::cout << "v1 *= N = " << v1 << std::endl; + + // Unary vector operations resulting in a scalar + initialize_vector (v1); + t = ublas::sum (v1); + std::cout << "sum (v1) = " << t << std::endl; + n = ublas::norm_1 (v1); + std::cout << "norm_1 (v1) = " << n << std::endl; + n = ublas::norm_2 (v1); + std::cout << "norm_2 (v1) = " << n << std::endl; + n = ublas::norm_inf (v1); + std::cout << "norm_inf (v1) = " << n << std::endl; + + i = ublas::index_norm_inf (v1); + std::cout << "index_norm_inf (v1) = " << i << std::endl; + + // Binary vector operations resulting in a scalar + initialize_vector (v1); + initialize_vector (v2); + t = ublas::inner_prod (v1, v2); + std::cout << "inner_prod (v1, v2) = " << t << std::endl; + + // Scalar and Binary vector expression resulting in a vector + initialize_vector (v1); + initialize_vector (v2); + v1 = v1 * ublas::inner_prod (v1, v2); + std::cout << "v1 * inner_prod (v1, v2) = " << v1 << std::endl; + } + + void operator () () const { + V v1 (N), v2 (N), v3 (N); + test_expression_with (v1, v2, v3); + test_container_with (v1); + +#ifdef USE_RANGE + ublas::vector_range<V> vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)), + vr3 (v3, ublas::range (0, N)); + test_expression_with (vr1, vr2, vr3); +#endif + +#ifdef USE_SLICE + ublas::vector_slice<V> vs1 (v1, ublas::slice (0, 1, N)), + vs2 (v2, ublas::slice (0, 1, N)), + vs3 (v3, ublas::slice (0, 1, N)); + test_expression_with (vs1, vs2, vs3); +#endif + } +}; + +// Test vector +void test_vector () { + std::cout << "test_vector" << std::endl; + +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_vector<ublas::vector<double, ublas::unbounded_array<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_vector<ublas::vector<double, std::vector<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_BOUNDED_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded" << std::endl; + test_my_vector<ublas::bounded_vector<mp_test_type, 3>, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded" << std::endl; + test_my_vector<ublas::bounded_vector<double, 3>, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded" << std::endl; + test_my_vector<ublas::bounded_vector<std::complex<mp_test_type>, 3>, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded" << std::endl; + test_my_vector<ublas::bounded_vector<std::complex<double>, 3>, 3> () (); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test12.cpp b/libs/multiprecision/test/ublas_interop/test12.cpp new file mode 100644 index 0000000000..7059fb9e9b --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test12.cpp @@ -0,0 +1,277 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test1.hpp" + +// Test matrix & vector expression templates +template<class V, class M, int N> +struct test_my_matrix_vector { + typedef typename V::value_type value_type; + + template<class VP, class MP> + void test_with (VP &v1, VP &v2, MP &m1) const { + { + // Rows and columns + initialize_matrix (m1); + for (int i = 0; i < N; ++ i) { + v1 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v1 << std::endl; + v1 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v1 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1); + initialize_vector (v1); + v2 = ublas::prod (m1, v1); + std::cout << "prod (m1, v1) = " << v2 << std::endl; + v2 = ublas::prod (v1, m1); + std::cout << "prod (v1, m1) = " << v2 << std::endl; + } + } + void operator () () const { + { + V v1 (N), v2 (N); + M m1 (N, N); + test_with (v1, v2, m1); + + ublas::matrix_row<M> mr1 (m1, 0), mr2 (m1, 1); + test_with (mr1, mr2, m1); + + ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 1); + test_with (mc1, mc2, m1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, m1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, m1); +#endif + } + } +}; + +// Test matrix & vector +void test_matrix_vector () { + std::cout << "test_matrix_vector" << std::endl; + +#ifdef USE_MATRIX +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::matrix<double, ublas::row_major, std::vector<double> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); +#endif +#endif +#endif +#endif + +#ifdef USE_BOUNDED_MATRIX +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded" << std::endl; + test_my_matrix_vector<ublas::bounded_vector<mp_test_type, 3>, + ublas::bounded_matrix<mp_test_type, 3, 3>, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded" << std::endl; + test_my_matrix_vector<ublas::bounded_vector<double, 3>, + ublas::bounded_matrix<double, 3, 3>, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded" << std::endl; + test_my_matrix_vector<ublas::bounded_vector<std::complex<mp_test_type>, 3>, + ublas::bounded_matrix<std::complex<mp_test_type>, 3, 3>, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded" << std::endl; + test_my_matrix_vector<ublas::bounded_vector<std::complex<double>, 3>, + ublas::bounded_matrix<std::complex<double>, 3, 3>, 3> () (); +#endif +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::bounded_array<ublas::bounded_array<mp_test_type, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<mp_test_type>, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<mp_test_type> > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::vector_of_vector<mp_test_type, ublas::row_major, std::vector<std::vector<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, std::vector<std::vector<std::complex<mp_test_type> > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3> () (); +#endif +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test13.cpp b/libs/multiprecision/test/ublas_interop/test13.cpp new file mode 100644 index 0000000000..d2f803777b --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test13.cpp @@ -0,0 +1,321 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test1.hpp" + +// Test matrix expression templates +template<class M, int N> +struct test_my_matrix { + typedef typename M::value_type value_type; + + template<class VP> + void test_container_with (VP &v1) const { + // Container type tests in addition to expression types + // Insert and erase + v1.insert_element (0,0, 55); + v1.erase_element (1,1); + v1.clear (); + } + + template<class MP> + void test_expression_with (MP &m1, MP &m2, MP &m3) const { + value_type t; + + // Default Construct + default_construct<MP>::test (); + + // Copy and swap + initialize_matrix (m1); + initialize_matrix (m2); + m1 = m2; + std::cout << "m1 = m2 = " << m1 << std::endl; + m1.assign_temporary (m2); + std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl; + m1.swap (m2); + std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl; + + // Zero assignment + m1 = ublas::zero_matrix<> (m1.size1 (), m1.size2 ()); + std::cout << "m1.zero_matrix = " << m1 << std::endl; + m1 = m2; + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + // Project range and slice + initialize_matrix (m1); + initialize_matrix (m2); + project (m1, ublas::range(0,1),ublas::range(0,1)) = project (m2, ublas::range(0,1),ublas::range(0,1)); + project (m1, ublas::range(0,1),ublas::range(0,1)) = project (m2, ublas::slice(0,1,1),ublas::slice(0,1,1)); + project (m1, ublas::slice(2,-1,2),ublas::slice(2,-1,2)) = project (m2, ublas::slice(0,1,2),ublas::slice(0,1,2)); + project (m1, ublas::slice(2,-1,2),ublas::slice(2,-1,2)) = project (m2, ublas::range(0,2),ublas::range(0,2)); + std::cout << "m1 = range/slice " << m1 << std::endl; +#endif + + // Unary matrix operations resulting in a matrix + initialize_matrix (m1); + m2 = - m1; + std::cout << "- m1 = " << m2 << std::endl; + m2 = ublas::conj (m1); + std::cout << "conj (m1) = " << m2 << std::endl; + + // Binary matrix operations resulting in a matrix + initialize_matrix (m1); + initialize_matrix (m2); + m3 = m1 + m2; + std::cout << "m1 + m2 = " << m3 << std::endl; + m3 = m1 - m2; + std::cout << "m1 - m2 = " << m3 << std::endl; + m3 = ublas::element_prod (m1, m2); + std::cout << "element_prod (m1, m2) = " << m3 << std::endl; + + // Scaling a matrix + t = N; + initialize_matrix (m1); + m2 = value_type (1.) * m1; + std::cout << "1. * m1 = " << m2 << std::endl; + m2 = t * m1; + std::cout << "N * m1 = " << m2 << std::endl; + initialize_matrix (m1); + m2 = m1 * value_type (1.); + std::cout << "m1 * 1. = " << m2 << std::endl; + m2 = m1 * t; + std::cout << "m1 * N = " << m2 << std::endl; + + // Some assignments + initialize_matrix (m1); + initialize_matrix (m2); + m2 += m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 -= m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; + m2 = m2 + m1; + std::cout << "m2 = m2 + m1 = " << m2 << std::endl; + m2 = m2 - m1; + std::cout << "m2 = m2 - m1 = " << m2 << std::endl; + m1 *= value_type (1.); + std::cout << "m1 *= 1. = " << m1 << std::endl; + m1 *= t; + std::cout << "m1 *= N = " << m1 << std::endl; + + // Transpose + initialize_matrix (m1); + m2 = ublas::trans (m1); + std::cout << "trans (m1) = " << m2 << std::endl; + + // Hermitean + initialize_matrix (m1); + m2 = ublas::herm (m1); + std::cout << "herm (m1) = " << m2 << std::endl; + + // Matrix multiplication + initialize_matrix (m1); + initialize_matrix (m2); + m3 = ublas::prod (m1, m2); + std::cout << "prod (m1, m2) = " << m3 << std::endl; + } + + void operator () () const { + M m1 (N, N), m2 (N, N), m3 (N, N); + test_expression_with (m1, m2, m3); + test_container_with (m1); + +#ifdef USE_RANGE + ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); + test_expression_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_expression_with (ms1, ms2, ms3); +#endif + } +}; + +// Test matrix +void test_matrix () { + std::cout << "test_matrix" << std::endl; + +#ifdef USE_MATRIX +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix<ublas::matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix<ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix<ublas::matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix<ublas::matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix<ublas::matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix<ublas::matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix<ublas::matrix<double, ublas::row_major, std::vector<double> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix<ublas::matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); +#endif +#endif +#endif +#endif + +#ifdef USE_BOUNDED_MATRIX +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded" << std::endl; + test_my_matrix<ublas::bounded_matrix<mp_test_type, 3, 3>, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded" << std::endl; + test_my_matrix<ublas::bounded_matrix<double, 3, 3>, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded" << std::endl; + test_my_matrix<ublas::bounded_matrix<std::complex<mp_test_type>, 3, 3>, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded" << std::endl; + test_my_matrix<ublas::bounded_matrix<std::complex<double>, 3, 3>, 3> () (); +#endif +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::bounded_array<ublas::bounded_array<mp_test_type, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<double, ublas::row_major, ublas::bounded_array<ublas::bounded_array<double, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<mp_test_type>, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<std::complex<double>, 3>, 3 + 1> >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<mp_test_type, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<double, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<double> > >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<mp_test_type> > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<std::complex<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<std::complex<double> > > >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix<ublas::vector_of_vector<mp_test_type, ublas::row_major, std::vector<std::vector<mp_test_type > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix<ublas::vector_of_vector<double, ublas::row_major, std::vector<std::vector<double> > >, 3> () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::vector_of_vector<std::complex<mp_test_type>, ublas::row_major, std::vector<std::vector<std::complex<mp_test_type> > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix<ublas::vector_of_vector<std::complex<double>, ublas::row_major, std::vector<std::vector<std::complex<double> > > >, 3> () (); +#endif +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test2.cpp b/libs/multiprecision/test/ublas_interop/test2.cpp new file mode 100644 index 0000000000..0550dc8018 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test2.cpp @@ -0,0 +1,87 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test2.hpp" + +int main () { +#ifdef USE_FLOAT + std::cout << "mp_test_type" << std::endl; + test_blas_1<ublas::vector<mp_test_type>, 3> ().test (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double" << std::endl; + test_blas_1<ublas::vector<double>, 3> ().test (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>" << std::endl; + test_blas_1<ublas::vector<std::complex<mp_test_type> >, 3> ().test (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>" << std::endl; + test_blas_1<ublas::vector<std::complex<double> >, 3> ().test (); +#endif +#endif + + std::cout << "test_blas_2" << std::endl; + +#ifdef USE_FLOAT + std::cout << "mp_test_type" << std::endl; + test_blas_2<ublas::vector<mp_test_type>, ublas::matrix<mp_test_type>, 3> ().test (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double" << std::endl; + test_blas_2<ublas::vector<double>, ublas::matrix<double>, 3> ().test (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>" << std::endl; + test_blas_2<ublas::vector<std::complex<mp_test_type> >, ublas::matrix<std::complex<mp_test_type> >, 3> ().test (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>" << std::endl; + test_blas_2<ublas::vector<std::complex<double> >, ublas::matrix<std::complex<double> >, 3> ().test (); +#endif +#endif + + std::cout << "test_blas_3" << std::endl; + +#ifdef USE_FLOAT + std::cout << "mp_test_type" << std::endl; + test_blas_3<ublas::matrix<mp_test_type>, 3> ().test (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double" << std::endl; + test_blas_3<ublas::matrix<double>, 3> ().test (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>" << std::endl; + test_blas_3<ublas::matrix<std::complex<mp_test_type> >, 3> ().test (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>" << std::endl; + test_blas_3<ublas::matrix<std::complex<double> >, 3> ().test (); +#endif +#endif + + return 0; +} diff --git a/libs/multiprecision/test/ublas_interop/test2.hpp b/libs/multiprecision/test/ublas_interop/test2.hpp new file mode 100644 index 0000000000..6aca3df9a3 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test2.hpp @@ -0,0 +1,79 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST2_H +#define TEST2_H +#ifdef _MSC_VER +# pragma warning(disable:4800 4996 4127 4100 4018) +#endif + +#include <boost/multiprecision/cpp_dec_float.hpp> + +#ifdef TEST_ET +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_on> mp_test_type; +#else +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off> mp_test_type; +#endif +//typedef double mp_test_type; + +#define USE_RANGE +#define USE_SLICE +#define USE_FLOAT +#define USE_UNBOUNDED_ARRAY +#define USE_STD_VECTOR +#define USE_BOUNDED_VECTOR USE_MATRIX +#define USE_UNBOUNDED_ARRAY +#define USE_MAP_ARRAY +#define USE_STD_MAP +#define USE_MAPPED_VECTOR +#define USE_COMPRESSED_VECTOR +#define USE_COORDINATE_VECTOR +#define USE_MAPPED_MATRIX +#define USE_COMPRESSED_MATRIX +#define USE_COORDINATE_MATRIX + +#include <iostream> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/triangular.hpp> +#include <boost/numeric/ublas/io.hpp> +#include <boost/numeric/ublas/blas.hpp> + +namespace ublas = boost::numeric::ublas; + +#include "common/init.hpp" + +template<class V, int N> +struct test_blas_1 { + typedef typename V::value_type value_type; + typedef typename ublas::type_traits<value_type>::real_type real_type; + + void test (); +}; + +template<class V, class M, int N> +struct test_blas_2 { + typedef typename V::value_type value_type; + + void test (); +}; + +template<class M, int N> +struct test_blas_3 { + typedef typename M::value_type value_type; + + void test (); +}; + + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test21.cpp b/libs/multiprecision/test/ublas_interop/test21.cpp new file mode 100644 index 0000000000..252d1f1c10 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test21.cpp @@ -0,0 +1,95 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test2.hpp" + +template<class V, int N> +void test_blas_1<V, N>::test () { + { + value_type t; + real_type n; + V v1 (N), v2 (N); + + // _asum + initialize_vector (v1); + n = ublas::blas_1::asum (v1); + std::cout << "asum (v1) = " << n << std::endl; + + // _amax + initialize_vector (v1); + n = ublas::blas_1::amax (v1); + std::cout << "amax (v1) = " << n << std::endl; + + // _nrm2 + initialize_vector (v1); + n = ublas::blas_1::nrm2 (v1); + std::cout << "nrm2 (v1) = " << n << std::endl; + + // _dot + // _dotu + // _dotc + initialize_vector (v1); + initialize_vector (v2); + t = ublas::blas_1::dot (v1, v2); + std::cout << "dot (v1, v2) = " << t << std::endl; + t = ublas::blas_1::dot (ublas::conj (v1), v2); + std::cout << "dot (conj (v1), v2) = " << t << std::endl; + + // _copy + initialize_vector (v2); + ublas::blas_1::copy (v1, v2); + std::cout << "copy (v1, v2) = " << v1 << std::endl; + + // _swap + initialize_vector (v1); + initialize_vector (v2); + ublas::blas_1::swap (v1, v2); + std::cout << "swap (v1, v2) = " << v1 << " " << v2 << std::endl; + + // _scal + // csscal + // zdscal + initialize_vector (v1); + ublas::blas_1::scal (v1, value_type (1)); + std::cout << "scal (v1, 1) = " << v1 << std::endl; + + // _axpy + initialize_vector (v1); + initialize_vector (v2); + ublas::blas_1::axpy (v1, value_type (1), v2); + std::cout << "axpy (v1, 1, v2) = " << v1 << std::endl; + + // _rot + initialize_vector (v1); + initialize_vector (v2); + ublas::blas_1::rot (value_type (1), v1, value_type (1), v2); + std::cout << "rot (1, v1, 1, v2) = " << v1 << " " << v2 << std::endl; + } +} + +#ifdef USE_FLOAT +template struct test_blas_1<ublas::vector<mp_test_type>, 3>; +#endif + +#ifdef USE_DOUBLE +template struct test_blas_1<ublas::vector<double>, 3>; +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT +template struct test_blas_1<ublas::vector<std::complex<mp_test_type> >, 3>; +#endif + +#ifdef USE_DOUBLE +template struct test_blas_1<ublas::vector<std::complex<double> >, 3>; +#endif +#endif diff --git a/libs/multiprecision/test/ublas_interop/test22.cpp b/libs/multiprecision/test/ublas_interop/test22.cpp new file mode 100644 index 0000000000..297bb06a8f --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test22.cpp @@ -0,0 +1,147 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test2.hpp" + +template<class V, class M, int N> +void test_blas_2<V, M, N>::test () { + { + V v1 (N), v2 (N); + M m (N, N); + + // _t_mv + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::tmv (v1, m); + std::cout << "tmv (v1, m) = " << v1 << std::endl; + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::tmv (v1, ublas::trans (m)); + std::cout << "tmv (v1, trans (m)) = " << v1 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::tmv (v1, ublas::herm (m)); + std::cout << "tmv (v1, herm (m)) = " << v1 << std::endl; +#endif + + // _t_sv + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::lower_tag ()); + ublas::blas_2::tsv (v1, m, ublas::lower_tag ()); + std::cout << "tsv (v1, m) = " << v1 << " " << ublas::prod (m, v1) - v2 << std::endl; + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::upper_tag ()); + ublas::blas_2::tsv (v1, ublas::trans (m), ublas::lower_tag ()); + std::cout << "tsv (v1, trans (m)) = " << v1 << " " << ublas::prod (ublas::trans (m), v1) - v2 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::upper_tag ()); + ublas::blas_2::tsv (v1, ublas::herm (m), ublas::lower_tag ()); + std::cout << "tsv (v1, herm (m)) = " << v1 << " " << ublas::prod (ublas::herm (m), v1) - v2 << std::endl; +#endif + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::upper_tag ()); + ublas::blas_2::tsv (v1, m, ublas::upper_tag ()); + std::cout << "tsv (v1, m) = " << v1 << " " << ublas::prod (m, v1) - v2 << std::endl; + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::lower_tag ()); + ublas::blas_2::tsv (v1, ublas::trans (m), ublas::upper_tag ()); + std::cout << "tsv (v1, trans (m)) = " << v1 << " " << ublas::prod (ublas::trans (m), v1) - v2 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m, ublas::lower_tag ()); + ublas::blas_2::tsv (v1, ublas::herm (m), ublas::upper_tag ()); + std::cout << "tsv (v1, herm (m)) = " << v1 << " " << ublas::prod (ublas::herm (m), v1) - v2 << std::endl; +#endif + + // _g_mv + // _s_mv + // _h_mv + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::gmv (v1, value_type (1), value_type (1), m, v2); + std::cout << "gmv (v1, 1, 1, m, v2) = " << v1 << std::endl; + ublas::blas_2::gmv (v1, value_type (1), value_type (1), ublas::trans (m), v2); + std::cout << "gmv (v1, 1, 1, trans (m), v2) = " << v1 << std::endl; +#ifdef USE_STD_COMPLEX + ublas::blas_2::gmv (v1, value_type (1), value_type (1), ublas::herm (m), v2); + std::cout << "gmv (v1, 1, 1, herm (m), v2) = " << v1 << std::endl; +#endif + + // _g_r + // _g_ru + // _g_rc + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::gr (m, value_type (1), v1, v2); + std::cout << "gr (m, 1, v1, v2) = " << m << std::endl; + ublas::blas_2::gr (m, value_type (1), v1, ublas::conj (v2)); + std::cout << "gr (m, 1, v1, conj (v2)) = " << m << std::endl; + + // _s_r + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::sr (m, value_type (1), v1); + std::cout << "sr (m, 1, v1) = " << m << std::endl; + +#ifdef USE_STD_COMPLEX + // _h_r + initialize_vector (v1); + initialize_matrix (m); + ublas::blas_2::hr (m, value_type (1), v1); + std::cout << "hr (m, 1, v1) = " << m << std::endl; +#endif + + // _s_r2 + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::sr2 (m, value_type (1), v1, v2); + std::cout << "sr2 (m, 1, v1, v2) = " << m << std::endl; + +#ifdef USE_STD_COMPLEX + // _h_r2 + initialize_vector (v1); + initialize_vector (v2); + initialize_matrix (m); + ublas::blas_2::hr2 (m, value_type (1), v1, v2); + std::cout << "hr2 (m, 1, v1, v2) = " << m << std::endl; +#endif + } +} + +#ifdef USE_FLOAT +template struct test_blas_2<ublas::vector<mp_test_type>, ublas::matrix<mp_test_type>, 3>; +#endif + +#ifdef USE_DOUBLE +template struct test_blas_2<ublas::vector<double>, ublas::matrix<double>, 3>; +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT +template struct test_blas_2<ublas::vector<std::complex<mp_test_type> >, ublas::matrix<std::complex<mp_test_type> >, 3>; +#endif + +#ifdef USE_DOUBLE +template struct test_blas_2<ublas::vector<std::complex<double> >, ublas::matrix<std::complex<double> >, 3>; +#endif +#endif diff --git a/libs/multiprecision/test/ublas_interop/test23.cpp b/libs/multiprecision/test/ublas_interop/test23.cpp new file mode 100644 index 0000000000..d56771c25b --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test23.cpp @@ -0,0 +1,208 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test2.hpp" + +template<class M, int N> +void test_blas_3<M, N>::test () { + { + M m1 (N, N), m2 (N, N), m3 (N, N); + + // _t_mm + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), m2, m1); + std::cout << "tmm (m1, 1, m2, m1) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), m2, ublas::trans (m1)); + std::cout << "tmm (m1, 1, m2, trans (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::trans (m2), m1); + std::cout << "tmm (m1, 1, trans (m2), m1) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::trans (m2), ublas::trans (m1)); + std::cout << "tmm (m1, 1, trans (m2), trans (m1)) = " << m1 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), m2, ublas::herm (m1)); + std::cout << "tmm (m1, 1, m2, herm (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::herm (m2), m1); + std::cout << "tmm (m1, 1, herm (m2), m1) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::trans (m2), ublas::herm (m1)); + std::cout << "tmm (m1, 1, trans (m2), herm (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::herm (m2), ublas::trans (m1)); + std::cout << "tmm (m1, 1, herm (m2), trans (m1)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::tmm (m1, value_type (1), ublas::herm (m2), ublas::herm (m1)); + std::cout << "tmm (m1, 1, herm (m2), herm (m1)) = " << m1 << std::endl; +#endif + + // _t_sm + initialize_matrix (m1); + initialize_matrix (m2, ublas::lower_tag ()); + initialize_matrix (m3); + ublas::blas_3::tsm (m1, value_type (1), m2, ublas::lower_tag ()); + std::cout << "tsm (m1, 1, m2) = " << m1 << " " << ublas::prod (m2, m1) - value_type (1) * m3 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2, ublas::upper_tag ()); + ublas::blas_3::tsm (m1, value_type (1), ublas::trans (m2), ublas::lower_tag ()); + std::cout << "tsm (m1, 1, trans (m2)) = " << m1 << " " << ublas::prod (ublas::trans (m2), m1) - value_type (1) * m3 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_matrix (m1); + initialize_matrix (m2, ublas::upper_tag ()); + ublas::blas_3::tsm (m1, value_type (1), ublas::herm (m2), ublas::lower_tag ()); + std::cout << "tsm (m1, 1, herm (m2)) = " << m1 << " " << ublas::prod (ublas::herm (m2), m1) - value_type (1) * m3 << std::endl; +#endif + initialize_matrix (m1); + initialize_matrix (m2, ublas::upper_tag ()); + ublas::blas_3::tsm (m1, value_type (1), m2, ublas::upper_tag ()); + std::cout << "tsm (m1, 1, m2) = " << m1 << " " << ublas::prod (m2, m1) - value_type (1) * m3 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2, ublas::lower_tag ()); + ublas::blas_3::tsm (m1, value_type (1), ublas::trans (m2), ublas::upper_tag ()); + std::cout << "tsm (m1, 1, trans (m2)) = " << m1 << " " << ublas::prod (ublas::trans (m2), m1) - value_type (1) * m3 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_matrix (m1); + initialize_matrix (m2, ublas::lower_tag ()); + ublas::blas_3::tsm (m1, value_type (1), ublas::herm (m2), ublas::upper_tag ()); + std::cout << "tsm (m1, 1, herm (m2)) = " << m1 << " " << ublas::prod (ublas::herm (m2), m1) - value_type (1) * m3 << std::endl; +#endif + + // _g_mm + // _s_mm + // _h_mm + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), m2, m3); + std::cout << "gmm (m1, 1, 1, m2, m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::trans (m2), m3); + std::cout << "gmm (m1, 1, 1, trans (m2), m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), m2, ublas::trans (m3)); + std::cout << "gmm (m1, 1, 1, m2, trans (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::trans (m2), ublas::trans (m3)); + std::cout << "gmm (m1, 1, 1, trans (m2), trans (m3)) = " << m1 << std::endl; +#ifdef USE_STD_COMPLEX + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::herm (m2), m3); + std::cout << "gmm (m1, 1, 1, herm (m2), m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), m2, ublas::herm (m3)); + std::cout << "gmm (m1, 1, 1, m2, herm (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::herm (m2), ublas::trans (m3)); + std::cout << "gmm (m1, 1, 1, herm (m2), trans (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::trans (m2), ublas::herm (m3)); + std::cout << "gmm (m1, 1, 1, trans (m2), herm (m3)) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::gmm (m1, value_type (1), value_type (1), ublas::herm (m2), ublas::herm (m3)); + std::cout << "gmm (m1, 1, 1, herm (m2), herm (m3)) = " << m1 << std::endl; +#endif + + // s_rk + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::srk (m1, value_type (1), value_type (1), m2); + std::cout << "srk (m1, 1, 1, m2) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::srk (m1, value_type (1), value_type (1), ublas::trans (m2)); + std::cout << "srk (m1, 1, 1, trans (m2)) = " << m1 << std::endl; + +#ifdef USE_STD_COMPLEX + // h_rk + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::hrk (m1, value_type (1), value_type (1), m2); + std::cout << "hrk (m1, 1, 1, m2) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + ublas::blas_3::hrk (m1, value_type (1), value_type (1), ublas::herm (m2)); + std::cout << "hrk (m1, 1, 1, herm (m2)) = " << m1 << std::endl; +#endif + + // s_r2k + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::sr2k (m1, value_type (1), value_type (1), m2, m3); + std::cout << "sr2k (m1, 1, 1, m2, m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::sr2k (m1, value_type (1), value_type (1), ublas::trans (m2), ublas::trans (m3)); + std::cout << "sr2k (m1, 1, 1, trans (m2), trans (m3)) = " << m1 << std::endl; + +#ifdef USE_STD_COMPLEX + // h_r2k + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::hr2k (m1, value_type (1), value_type (1), m2, m3); + std::cout << "hr2k (m1, 1, 1, m2, m3) = " << m1 << std::endl; + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + ublas::blas_3::hr2k (m1, value_type (1), value_type (1), ublas::herm (m2), ublas::herm (m3)); + std::cout << "hr2k (m1, 1, 1, herm (m2), herm (m3)) = " << m1 << std::endl; +#endif + } +} + +#ifdef USE_FLOAT +template struct test_blas_3<ublas::matrix<mp_test_type>, 3>; +#endif + +#ifdef USE_DOUBLE +template struct test_blas_3<ublas::matrix<double>, 3>; +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT +template struct test_blas_3<ublas::matrix<std::complex<mp_test_type> >, 3>; +#endif + +#ifdef USE_DOUBLE +template struct test_blas_3<ublas::matrix<std::complex<double> >, 3>; +#endif +#endif diff --git a/libs/multiprecision/test/ublas_interop/test3.cpp b/libs/multiprecision/test/ublas_interop/test3.cpp new file mode 100644 index 0000000000..fb2b94dadb --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test3.cpp @@ -0,0 +1,20 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test3.hpp" + +int main () { + test_vector (); + test_matrix_vector (); + test_matrix (); + return 0; +} diff --git a/libs/multiprecision/test/ublas_interop/test3.hpp b/libs/multiprecision/test/ublas_interop/test3.hpp new file mode 100644 index 0000000000..d38d1d8647 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test3.hpp @@ -0,0 +1,67 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST3_H +#define TEST3_H + +#ifdef _MSC_VER +# pragma warning(disable:4800 4996 4127 4100) +#endif + +#include <boost/multiprecision/cpp_dec_float.hpp> + +#ifdef TEST_ET +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_on> mp_test_type; +#else +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off> mp_test_type; +#endif +//typedef double mp_test_type; + +#define USE_RANGE +#define USE_SLICE +#define USE_FLOAT +#define USE_UNBOUNDED_ARRAY +#define USE_STD_VECTOR +#define USE_BOUNDED_VECTOR USE_MATRIX +#define USE_UNBOUNDED_ARRAY +#define USE_MAP_ARRAY +#define USE_STD_MAP +#define USE_MAPPED_VECTOR +#define USE_COMPRESSED_VECTOR +#define USE_COORDINATE_VECTOR +#define USE_MAPPED_MATRIX +#define USE_COMPRESSED_MATRIX +#define USE_COORDINATE_MATRIX + +#include <iostream> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/vector_proxy.hpp> +#include <boost/numeric/ublas/vector_sparse.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/matrix_proxy.hpp> +#include <boost/numeric/ublas/matrix_sparse.hpp> +#include <boost/numeric/ublas/vector_sparse.hpp> +#ifdef USE_GENERALIZED_VECTOR_OF_VECTOR +#include <boost/numeric/ublas/vector_of_vector.hpp> +#endif +#include <boost/numeric/ublas/io.hpp> + +namespace ublas = boost::numeric::ublas; + +#include "common/init.hpp" + +void test_vector (); +void test_matrix_vector (); +void test_matrix (); + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test31.cpp b/libs/multiprecision/test/ublas_interop/test31.cpp new file mode 100644 index 0000000000..a1484cfdcd --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test31.cpp @@ -0,0 +1,248 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test3.hpp" + +// Test vector expression templates +template<class V, int N> +struct test_my_vector { + typedef typename V::value_type value_type; + typedef typename V::size_type size_type; + typedef typename ublas::type_traits<value_type>::real_type real_type; + + template<class VP> + void test_with (VP &v1, VP &v2, VP &v3) const { + { + value_type t; + size_type i; + real_type n; + + // Default Construct + default_construct<VP>::test (); + + // Copy and swap + initialize_vector (v1); + initialize_vector (v2); + v1 = v2; + std::cout << "v1 = v2 = " << v1 << std::endl; + v1.assign_temporary (v2); + std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl; + v1.swap (v2); + std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl; + + // Zero assignment + v1 = ublas::zero_vector<> (v1.size ()); + std::cout << "v1.zero_vector = " << v1 << std::endl; + v1 = v2; + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + // Project range and slice + initialize_vector (v1); + initialize_vector (v2); + project (v1, ublas::range(0,1)) = project (v2, ublas::range(0,1)); + project (v1, ublas::range(0,1)) = project (v2, ublas::slice(0,1,1)); + project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::slice(0,1,2)); + project (v1, ublas::slice(2,-1,2)) = project (v2, ublas::range(0,2)); + std::cout << "v1 = range/slice " << v1 << std::endl; +#endif + + // Unary vector operations resulting in a vector + initialize_vector (v1); + v2 = - v1; + std::cout << "- v1 = " << v2 << std::endl; + v2 = ublas::conj (v1); + std::cout << "conj (v1) = " << v2 << std::endl; + + // Binary vector operations resulting in a vector + initialize_vector (v1); + initialize_vector (v2); + initialize_vector (v3); + v3 = v1 + v2; + std::cout << "v1 + v2 = " << v3 << std::endl; + + v3 = v1 - v2; + std::cout << "v1 - v2 = " << v3 << std::endl; + + // Scaling a vector + t = N; + initialize_vector (v1); + v2 = value_type (1.) * v1; + std::cout << "1. * v1 = " << v2 << std::endl; + v2 = t * v1; + std::cout << "N * v1 = " << v2 << std::endl; + initialize_vector (v1); + v2 = v1 * value_type (1.); + std::cout << "v1 * 1. = " << v2 << std::endl; + v2 = v1 * t; + std::cout << "v1 * N = " << v2 << std::endl; + + // Some assignments + initialize_vector (v1); + initialize_vector (v2); + v2 += v1; + std::cout << "v2 += v1 = " << v2 << std::endl; + v2 -= v1; + std::cout << "v2 -= v1 = " << v2 << std::endl; + v2 = v2 + v1; + std::cout << "v2 = v2 + v1 = " << v2 << std::endl; + v2 = v2 - v1; + std::cout << "v2 = v2 - v1 = " << v2 << std::endl; + v1 *= value_type (1.); + std::cout << "v1 *= 1. = " << v1 << std::endl; + v1 *= t; + std::cout << "v1 *= N = " << v1 << std::endl; + + // Unary vector operations resulting in a scalar + initialize_vector (v1); + t = ublas::sum (v1); + std::cout << "sum (v1) = " << t << std::endl; + n = ublas::norm_1 (v1); + std::cout << "norm_1 (v1) = " << n << std::endl; + n = ublas::norm_2 (v1); + std::cout << "norm_2 (v1) = " << n << std::endl; + n = ublas::norm_inf (v1); + std::cout << "norm_inf (v1) = " << n << std::endl; + + i = ublas::index_norm_inf (v1); + std::cout << "index_norm_inf (v1) = " << i << std::endl; + + // Binary vector operations resulting in a scalar + initialize_vector (v1); + initialize_vector (v2); + t = ublas::inner_prod (v1, v2); + std::cout << "inner_prod (v1, v2) = " << t << std::endl; + } + } + void operator () () const { + { + V v1 (N, N), v2 (N, N), v3 (N, N); + test_with (v1, v2, v3); + +#ifdef USE_RANGE + ublas::vector_range<V> vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)), + vr3 (v3, ublas::range (0, N)); + test_with (vr1, vr2, vr3); +#endif + +#ifdef USE_SLICE + ublas::vector_slice<V> vs1 (v1, ublas::slice (0, 1, N)), + vs2 (v2, ublas::slice (0, 1, N)), + vs3 (v3, ublas::slice (0, 1, N)); + test_with (vs1, vs2, vs3); +#endif + } + } +}; + +// Test vector +void test_vector () { + std::cout << "test_vector" << std::endl; + +#ifdef USE_SPARSE_VECTOR +#ifdef USE_MAP_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, map_array" << std::endl; + test_my_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, map_array" << std::endl; + test_my_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, map_array" << std::endl; + test_my_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, map_array" << std::endl; + test_my_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_MAP +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::map" << std::endl; + test_my_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::map" << std::endl; + test_my_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::map" << std::endl; + test_my_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::map" << std::endl; + test_my_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > , 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_COMPRESSED_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type compressed" << std::endl; + test_my_vector<ublas::compressed_vector<mp_test_type>, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double compressed" << std::endl; + test_my_vector<ublas::compressed_vector<double>, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type> compressed" << std::endl; + test_my_vector<ublas::compressed_vector<std::complex<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double> compressed" << std::endl; + test_my_vector<ublas::compressed_vector<std::complex<double> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_COORDINATE_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type coordinate" << std::endl; + test_my_vector<ublas::coordinate_vector<mp_test_type>, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double coordinate" << std::endl; + test_my_vector<ublas::coordinate_vector<double>, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type> coordinate" << std::endl; + test_my_vector<ublas::coordinate_vector<std::complex<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double> coordinate" << std::endl; + test_my_vector<ublas::coordinate_vector<std::complex<double> >, 3 > () (); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test32.cpp b/libs/multiprecision/test/ublas_interop/test32.cpp new file mode 100644 index 0000000000..7240b4ce6f --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test32.cpp @@ -0,0 +1,324 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test3.hpp" + +// Test matrix & vector expression templates +template<class V, class M, int N> +struct test_my_matrix_vector { + typedef typename V::value_type value_type; + + template<class VP, class MP> + void test_with (VP &v1, VP &v2, MP &m1) const { + { + // Rows and columns + initialize_matrix (m1); + for (int i = 0; i < N; ++ i) { + v1 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v1 << std::endl; + v1 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v1 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1); + initialize_vector (v1); + v2 = ublas::prod (m1, v1); + std::cout << "prod (m1, v1) = " << v2 << std::endl; + v2 = ublas::prod (v1, m1); + std::cout << "prod (v1, m1) = " << v2 << std::endl; + } + } + void operator () () const { + { + V v1 (N, N), v2 (N, N); + M m1 (N, N, N * N); + + test_with (v1, v2, m1); + + ublas::matrix_row<M> mr1 (m1, 0), mr2 (m1, N - 1); + test_with (mr1, mr2, m1); + + ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, N - 1); + test_with (mc1, mc2, m1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, m1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, m1); +#endif + } + } +}; + +// Test matrix & vector +void test_matrix_vector () { + std::cout << "test_matrix_vector" << std::endl; + +#ifdef USE_SPARSE_MATRIX +#ifdef USE_MAP_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, + ublas::mapped_matrix<mp_test_type, ublas::row_major, ublas::map_array<std::size_t, mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, + ublas::mapped_matrix<double, ublas::row_major, ublas::map_array<std::size_t, double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, + ublas::mapped_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, + ublas::mapped_matrix<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_MAP +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, + ublas::mapped_matrix<mp_test_type, ublas::row_major, std::map<std::size_t, mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, + ublas::mapped_matrix<double, ublas::row_major, std::map<std::size_t, double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, + ublas::mapped_matrix<std::complex<mp_test_type>, ublas::row_major, std::map<std::size_t, std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, + ublas::mapped_matrix<std::complex<double>, ublas::row_major, std::map<std::size_t, std::complex<double> > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR +#ifdef USE_MAP_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, mapped_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, + ublas::mapped_vector<mp_test_type, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, mapped_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, + ublas::mapped_vector<double, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, double> > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, mapped_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, + ublas::mapped_vector<std::complex<mp_test_type>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<mp_test_type> > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>,mapped_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, + ublas::mapped_vector<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<double> > > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_MAP +#ifdef USE_FLOAT + std::cout << "mp_test_type, mapped_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, + ublas::mapped_vector<mp_test_type, ublas::row_major, std::map<std::size_t, std::map<std::size_t, mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, mapped_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, + ublas::mapped_vector<double, ublas::row_major, std::map<std::size_t, std::map<std::size_t, double> > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, mapped_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, + ublas::mapped_vector<std::complex<mp_test_type>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<mp_test_type> > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, mapped_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, + ublas::mapped_vector<std::complex<double>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<double> > > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_GENERALIZED_VECTOR_OF_VECTOR +#ifdef USE_MAP_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, generalized_vector_of_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, + ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, + ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, ublas::map_array<std::size_t, ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, generalized_vector_of_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, + ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, + ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, ublas::map_array<std::size_t, ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, generalized_vector_of_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, + ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, + ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, generalized_vector_of_vector map_array" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, + ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, + ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_MAP +#ifdef USE_FLOAT + std::cout << "mp_test_type, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, + ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, + ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, std::map<std::size_t, ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, + ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, std::map<std::size_t, double> > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, + ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, std::map<std::size_t, ublas::mapped_vector<double, std::map<std::size_t, double> > > > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, + ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, + ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, + ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > >, 3 > () (); + test_my_matrix_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, + ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_COMPRESSED_MATRIX +#ifdef USE_FLOAT + std::cout << "mp_test_type compressed" << std::endl; + test_my_matrix_vector<ublas::compressed_vector<mp_test_type>, + ublas::compressed_matrix<mp_test_type>, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double compressed" << std::endl; + test_my_matrix_vector<ublas::compressed_vector<double>, + ublas::compressed_matrix<double>, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type> compressed" << std::endl; + test_my_matrix_vector<ublas::compressed_vector<std::complex<mp_test_type> >, + ublas::compressed_matrix<std::complex<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double> compressed" << std::endl; + test_my_matrix_vector<ublas::compressed_vector<std::complex<double> >, + ublas::compressed_matrix<std::complex<double> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_COORDINATE_MATRIX +#ifdef USE_FLOAT + std::cout << "mp_test_type coordinate" << std::endl; + test_my_matrix_vector<ublas::coordinate_vector<mp_test_type>, + ublas::coordinate_matrix<mp_test_type>, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double coordinate" << std::endl; + test_my_matrix_vector<ublas::coordinate_vector<double>, + ublas::coordinate_matrix<double>, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type> coordinate" << std::endl; + test_my_matrix_vector<ublas::coordinate_vector<std::complex<mp_test_type> >, + ublas::coordinate_matrix<std::complex<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double> coordinate" << std::endl; + test_my_matrix_vector<ublas::coordinate_vector<std::complex<double> >, + ublas::coordinate_matrix<std::complex<double> >, 3 > () (); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test33.cpp b/libs/multiprecision/test/ublas_interop/test33.cpp new file mode 100644 index 0000000000..46d735194b --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test33.cpp @@ -0,0 +1,347 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test3.hpp" + +// Test matrix expression templates +template<class M, int N> +struct test_my_matrix { + typedef typename M::value_type value_type; + + template<class MP> + void test_with (MP &m1, MP &m2, MP &m3) const { + { + value_type t; + + // Default Construct + default_construct<MP>::test (); + + // Copy and swap + initialize_matrix (m1); + initialize_matrix (m2); + m1 = m2; + std::cout << "m1 = m2 = " << m1 << std::endl; + m1.assign_temporary (m2); + std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl; + m1.swap (m2); + std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl; + + // Zero assignment + m1 = ublas::zero_matrix<> (m1.size1 (), m1.size2 ()); + std::cout << "m1.zero_matrix = " << m1 << std::endl; + m1 = m2; + +#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING + // Project range and slice + initialize_matrix (m1); + initialize_matrix (m2); + project (m1, ublas::range(0,1),ublas::range(0,1)) = project (m2, ublas::range(0,1),ublas::range(0,1)); + project (m1, ublas::range(0,1),ublas::range(0,1)) = project (m2, ublas::slice(0,1,1),ublas::slice(0,1,1)); + project (m1, ublas::slice(2,-1,2),ublas::slice(2,-1,2)) = project (m2, ublas::slice(0,1,2),ublas::slice(0,1,2)); + project (m1, ublas::slice(2,-1,2),ublas::slice(2,-1,2)) = project (m2, ublas::range(0,2),ublas::range(0,2)); + std::cout << "m1 = range/slice " << m1 << std::endl; +#endif + + // Unary matrix operations resulting in a matrix + initialize_matrix (m1); + m2 = - m1; + std::cout << "- m1 = " << m2 << std::endl; + m2 = ublas::conj (m1); + std::cout << "conj (m1) = " << m2 << std::endl; + + // Binary matrix operations resulting in a matrix + initialize_matrix (m1); + initialize_matrix (m2); + initialize_matrix (m3); + m3 = m1 + m2; + std::cout << "m1 + m2 = " << m3 << std::endl; + m3 = m1 - m2; + std::cout << "m1 - m2 = " << m3 << std::endl; + + // Scaling a matrix + t = N; + initialize_matrix (m1); + m2 = value_type (1.) * m1; + std::cout << "1. * m1 = " << m2 << std::endl; + m2 = t * m1; + std::cout << "N * m1 = " << m2 << std::endl; + initialize_matrix (m1); + m2 = m1 * value_type (1.); + std::cout << "m1 * 1. = " << m2 << std::endl; + m2 = m1 * t; + std::cout << "m1 * N = " << m2 << std::endl; + + // Some assignments + initialize_matrix (m1); + initialize_matrix (m2); + m2 += m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 -= m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; + m2 = m2 + m1; + std::cout << "m2 = m2 + m1 = " << m2 << std::endl; + m2 = m2 - m1; + std::cout << "m2 = m2 - m1 = " << m2 << std::endl; + m1 *= value_type (1.); + std::cout << "m1 *= 1. = " << m1 << std::endl; + m1 *= t; + std::cout << "m1 *= N = " << m1 << std::endl; + + // Transpose + initialize_matrix (m1); + m2 = ublas::trans (m1); + std::cout << "trans (m1) = " << m2 << std::endl; + + // Hermitean + initialize_matrix (m1); + m2 = ublas::herm (m1); + std::cout << "herm (m1) = " << m2 << std::endl; + + // Matrix multiplication + initialize_matrix (m1); + initialize_matrix (m2); + m3 = ublas::prod (m1, m2); + std::cout << "prod (m1, m2) = " << m3 << std::endl; + } + } + void operator () () const { + { + M m1 (N, N, N * N), m2 (N, N, N * N), m3 (N, N, N * N); + test_with (m1, m2, m3); + +#ifdef USE_RANGE + ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif + } + } +}; + +// Test matrix +void test_matrix () { + std::cout << "test_matrix" << std::endl; + +#ifdef USE_SPARSE_MATRIX +#ifdef USE_MAP_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, mapped_matrix map_array" << std::endl; + test_my_matrix<ublas::mapped_matrix<mp_test_type, ublas::row_major, ublas::map_array<std::size_t, mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, mapped_matrix map_array" << std::endl; + test_my_matrix<ublas::mapped_matrix<double, ublas::row_major, ublas::map_array<std::size_t, double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, mapped_matrix map_array" << std::endl; + test_my_matrix<ublas::mapped_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, mapped_matrix map_array" << std::endl; + test_my_matrix<ublas::mapped_matrix<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_MAP +#ifdef USE_FLOAT + std::cout << "mp_test_type, mapped_matrix std::map" << std::endl; + test_my_matrix<ublas::mapped_matrix<mp_test_type, ublas::row_major, std::map<std::size_t, mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, mapped_matrix std::map" << std::endl; + test_my_matrix<ublas::mapped_matrix<double, ublas::row_major, std::map<std::size_t, double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, mapped_matrix std::map" << std::endl; + test_my_matrix<ublas::mapped_matrix<std::complex<mp_test_type>, ublas::row_major, std::map<std::size_t, std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, mapped_matrix std::map" << std::endl; + test_my_matrix<ublas::mapped_matrix<std::complex<double>, ublas::row_major, std::map<std::size_t, std::complex<double> > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_SPARSE_VECTOR_OF_SPARSE_VECTOR +#ifdef USE_MAP_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, mapped_vector_of_mapped_vector map_array" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<mp_test_type, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, mapped_vector_of_mapped_vector map_array" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<double, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, double> > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, mapped_vector_of_mapped_vector map_array" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<mp_test_type>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<mp_test_type> > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, mapped_vector_of_mapped_vectormap_array" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<double>, ublas::row_major, ublas::map_array<std::size_t, ublas::map_array<std::size_t, std::complex<double> > > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_MAP +#ifdef USE_FLOAT + std::cout << "mp_test_type, mapped_vector_of_mapped_vector std::map" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<mp_test_type, ublas::row_major, std::map<std::size_t, std::map<std::size_t, mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, mapped_vector_of_mapped_vector std::map" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<double, ublas::row_major, std::map<std::size_t, std::map<std::size_t, double> > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, mapped_vector_of_mapped_vector std::map" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<mp_test_type>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<mp_test_type> > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, mapped_vector_of_mapped_vector std::map" << std::endl; + test_my_matrix<ublas::mapped_vector_of_mapped_vector<std::complex<double>, ublas::row_major, std::map<std::size_t, std::map<std::size_t, std::complex<double> > > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_GENERALIZED_VECTOR_OF_VECTOR +#ifdef USE_MAP_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type,generalized_vector_of_vector map_array" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> >, ublas::map_array<std::size_t, ublas::mapped_vector<mp_test_type, ublas::map_array<std::size_t, mp_test_type> > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, generalized_vector_of_vector map_array" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, ublas::map_array<std::size_t, double> >, ublas::map_array<std::size_t, ublas::mapped_vector<double, ublas::map_array<std::size_t, double> > > > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, generalized_vector_of_vector map_array" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<mp_test_type>, ublas::map_array<std::size_t, std::complex<mp_test_type> > > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, generalized_vector_of_vector map_array" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > >, ublas::map_array<std::size_t, ublas::mapped_vector<std::complex<double>, ublas::map_array<std::size_t, std::complex<double> > > > > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_MAP +#ifdef USE_FLOAT + std::cout << "mp_test_type, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<mp_test_type, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> >, std::map<std::size_t, ublas::mapped_vector<mp_test_type, std::map<std::size_t, mp_test_type> > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::vector<ublas::mapped_vector<double, std::map<std::size_t, double> > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<double, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<double, std::map<std::size_t, double> >, std::map<std::size_t, ublas::mapped_vector<double, std::map<std::size_t, double> > > > >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<mp_test_type>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<mp_test_type>, std::map<std::size_t, std::complex<mp_test_type> > > > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, generalized_vector_of_vector std::map" << std::endl; + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > >, 3 > () (); + test_my_matrix<ublas::generalized_vector_of_vector<std::complex<double>, ublas::row_major, ublas::mapped_vector<ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > >, std::map<std::size_t, ublas::mapped_vector<std::complex<double>, std::map<std::size_t, std::complex<double> > > > > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_COMPRESSED_MATRIX +#ifdef USE_FLOAT + std::cout << "mp_test_type compressed_matrix" << std::endl; + test_my_matrix<ublas::compressed_matrix<mp_test_type>, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double compressed_matrix" << std::endl; + test_my_matrix<ublas::compressed_matrix<double>, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type> compressed_matrix" << std::endl; + test_my_matrix<ublas::compressed_matrix<std::complex<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double> compressed_matrix" << std::endl; + test_my_matrix<ublas::compressed_matrix<std::complex<double> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_COORDINATE_MATRIX +#ifdef USE_FLOAT + std::cout << "mp_test_type coordinate_matrix" << std::endl; + test_my_matrix<ublas::coordinate_matrix<mp_test_type>, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double coordinate_matrix" << std::endl; + test_my_matrix<ublas::coordinate_matrix<double>, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type> coordinate_matrix" << std::endl; + test_my_matrix<ublas::coordinate_matrix<std::complex<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double> coordinate_matrix" << std::endl; + test_my_matrix<ublas::coordinate_matrix<std::complex<double> >, 3 > () (); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test4.cpp b/libs/multiprecision/test/ublas_interop/test4.cpp new file mode 100644 index 0000000000..bf5816f5e7 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test4.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test4.hpp" + +int main () { + test_matrix_vector (); + test_matrix (); + return 0; +} diff --git a/libs/multiprecision/test/ublas_interop/test4.hpp b/libs/multiprecision/test/ublas_interop/test4.hpp new file mode 100644 index 0000000000..d81e5a28d0 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test4.hpp @@ -0,0 +1,68 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST4_H +#define TEST4_H + +#ifdef _MSC_VER +# pragma warning(disable:4800 4996 4127 4100) +#endif + +#include <boost/multiprecision/cpp_dec_float.hpp> + +#ifdef TEST_ET +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_on> mp_test_type; +#else +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off> mp_test_type; +#endif +//typedef double mp_test_type; + +#define USE_RANGE +#define USE_SLICE +#define USE_FLOAT +#define USE_UNBOUNDED_ARRAY +#define USE_STD_VECTOR +#define USE_BOUNDED_VECTOR USE_MATRIX +#define USE_UNBOUNDED_ARRAY +#define USE_MAP_ARRAY +#define USE_STD_MAP +#define USE_MAPPED_VECTOR +#define USE_COMPRESSED_VECTOR +#define USE_COORDINATE_VECTOR +#define USE_MAPPED_MATRIX +#define USE_COMPRESSED_MATRIX +#define USE_COORDINATE_MATRIX + +#include <iostream> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/matrix_proxy.hpp> +#include <boost/numeric/ublas/banded.hpp> +#include <boost/numeric/ublas/io.hpp> + +namespace ublas = boost::numeric::ublas; + +#include "common/init.hpp" + +//#define USE_BANDED +#define USE_DIAGONAL + + +void test_matrix_vector (); +void test_matrix (); + + +// FIXME slice are failing in assignment to zero elements +#undef USE_SLICE + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test42.cpp b/libs/multiprecision/test/ublas_interop/test42.cpp new file mode 100644 index 0000000000..325d8094dc --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test42.cpp @@ -0,0 +1,361 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test4.hpp" + +// Test matrix & vector expression templates +template<class V, class M, int N> +struct test_my_matrix_vector { + typedef typename V::value_type value_type; + + template<class VP, class MP> + void test_with (VP &v1, VP &v2, MP &m1) const { + { +#ifndef USE_DIAGONAL + // Rows and columns + initialize_matrix (m1); + for (int i = 0; i < N; ++ i) { + v2 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v2 << std::endl; + v2 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v2 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + v1 (0) = 0; + v1 (N - 1) = 0; + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1); + initialize_vector (v1); + v2 = ublas::prod (m1, v1); + std::cout << "prod (m1, v1) = " << v2 << std::endl; + v2 = ublas::prod (v1, m1); + std::cout << "prod (v1, m1) = " << v2 << std::endl; +#endif + } + } + void operator () () const { + { + V v1 (N), v2 (N); +#ifdef USE_BANDED + M m1 (N, N, 1, 1); +#endif +#ifdef USE_DIAGONAL + M m1 (N, N); +#endif + test_with (v1, v2, m1); + + ublas::matrix_row<M> mr1 (m1, 1), mr2 (m1, 1); + test_with (mr1, mr2, m1); + + ublas::matrix_column<M> mc1 (m1, 1), mc2 (m1, 1); + test_with (mc1, mc2, m1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, m1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, m1); +#endif + } + } + + void operator () (int) const { +#ifdef USE_ADAPTOR + { +#ifdef USE_BANDED + V v1 (N), v2 (N); + M m1 (N, N, 1, 1); + ublas::banded_adaptor<M> bam1 (m1, 1, 1); + test_with (v1, v2, bam1); + + ublas::matrix_row<ublas::banded_adaptor<M> > mr1 (bam1, 1), mr2 (bam1, 1); + test_with (mr1, mr2, bam1); + + ublas::matrix_column<ublas::banded_adaptor<M> > mc1 (bam1, 1), mc2 (bam1, 1); + test_with (mc1, mc2, bam1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<ublas::banded_adaptor<M> > mvr1 (bam1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (bam1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, bam1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<ublas::banded_adaptor<M> > mvs1 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, bam1); +#endif +#endif +#ifdef USE_DIAGONAL + V v1 (N), v2 (N); + M m1 (N, N); + ublas::diagonal_adaptor<M> dam1 (m1); + test_with (v1, v2, dam1); + + ublas::matrix_row<ublas::diagonal_adaptor<M> > mr1 (dam1, 1), mr2 (dam1, 1); + test_with (mr1, mr2, dam1); + + ublas::matrix_column<ublas::diagonal_adaptor<M> > mc1 (dam1, 1), mc2 (dam1, 1); + test_with (mc1, mc2, dam1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<ublas::diagonal_adaptor<M> > mvr1 (dam1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (dam1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, dam1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<ublas::diagonal_adaptor<M> > mvs1 (dam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (dam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, dam1); +#endif +#endif + } +#endif + } +}; + +// Test matrix & vector +void test_matrix_vector () { + std::cout << "test_matrix_vector" << std::endl; + +#ifdef USE_BANDED +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::banded_matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::banded_matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::banded_matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::banded_matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::banded_matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::banded_matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif +#endif + +#ifdef USE_DIAGONAL +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::diagonal_matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::diagonal_matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::diagonal_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::diagonal_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::diagonal_matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::diagonal_matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::diagonal_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::diagonal_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::diagonal_matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::diagonal_matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::diagonal_matrix<double, ublas::row_major, std::vector<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::diagonal_matrix<double, ublas::row_major, std::vector<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::diagonal_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::diagonal_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test43.cpp b/libs/multiprecision/test/ublas_interop/test43.cpp new file mode 100644 index 0000000000..82682c9765 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test43.cpp @@ -0,0 +1,326 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test4.hpp" + +// Test matrix expression templates +template<class M, int N> +struct test_my_matrix { + typedef typename M::value_type value_type; + + template<class MP> + void test_with (MP &m1, MP &m2, MP &m3) const { + { + value_type t; + + // Default Construct + default_construct<MP>::test (); + + // Copy and swap + initialize_matrix (m1); + initialize_matrix (m2); + m1 = m2; + std::cout << "m1 = m2 = " << m1 << std::endl; + m1.assign_temporary (m2); + std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl; + m1.swap (m2); + std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl; + + // Zero assignment + m1 = ublas::zero_matrix<> (m1.size1 (), m1.size2 ()); + std::cout << "m1.zero_matrix = " << m1 << std::endl; + m1 = m2; + + // Unary matrix operations resulting in a matrix + initialize_matrix (m1); + m2 = - m1; + std::cout << "- m1 = " << m2 << std::endl; + m2 = ublas::conj (m1); + std::cout << "conj (m1) = " << m2 << std::endl; + + // Binary matrix operations resulting in a matrix + initialize_matrix (m1); + initialize_matrix (m2); + m3 = m1 + m2; + std::cout << "m1 + m2 = " << m3 << std::endl; + m3 = m1 - m2; + std::cout << "m1 - m2 = " << m3 << std::endl; + + // Scaling a matrix + t = N; + initialize_matrix (m1); + m2 = value_type (1.) * m1; + std::cout << "1. * m1 = " << m2 << std::endl; + m2 = t * m1; + std::cout << "N * m1 = " << m2 << std::endl; + initialize_matrix (m1); + m2 = m1 * value_type (1.); + std::cout << "m1 * 1. = " << m2 << std::endl; + m2 = m1 * t; + std::cout << "m1 * N = " << m2 << std::endl; + + // Some assignments + initialize_matrix (m1); + initialize_matrix (m2); + m2 += m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 -= m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; + m2 = m2 + m1; + std::cout << "m2 = m2 + m1 = " << m2 << std::endl; + m2 = m2 - m1; + std::cout << "m2 = m2 - m1 = " << m2 << std::endl; + m1 *= value_type (1.); + std::cout << "m1 *= 1. = " << m1 << std::endl; + m1 *= t; + std::cout << "m1 *= N = " << m1 << std::endl; + + // Transpose + initialize_matrix (m1); + m2 = ublas::trans (m1); + std::cout << "trans (m1) = " << m2 << std::endl; + + // Hermitean + initialize_matrix (m1); + m2 = ublas::herm (m1); + std::cout << "herm (m1) = " << m2 << std::endl; + + // Matrix multiplication + initialize_matrix (m1); + initialize_matrix (m2); + // Banded times banded isn't banded + std::cout << "prod (m1, m2) = " << ublas::prod (m1, m2) << std::endl; + } + } + void operator () () const { + { +#ifdef USE_BANDED + M m1 (N, N, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1); +#endif +#ifdef USE_DIAGONAL + M m1 (N, N), m2 (N, N), m3 (N, N); +#endif + test_with (m1, m2, m3); + +#ifdef USE_RANGE + ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif + } + +#ifdef USE_ADAPTOR + { +#ifdef USE_BANDED + M m1 (N, N, 1, 1), m2 (N, N, 1, 1), m3 (N, N, 1, 1); + ublas::banded_adaptor<M> bam1 (m1, 1, 1), bam2 (m2, 1, 1), bam3 (m3, 1, 1); + test_with (bam1, bam2, bam3); + +#ifdef USE_RANGE + ublas::matrix_range<ublas::banded_adaptor<M> > mr1 (bam1, ublas::range (0, N), ublas::range (0, N)), + mr2 (bam2, ublas::range (0, N), ublas::range (0, N)), + mr3 (bam3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<ublas::banded_adaptor<M> > ms1 (bam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (bam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (bam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif +#endif +#ifdef USE_DIAGONAL + M m1 (N, N), m2 (N, N), m3 (N, N); + ublas::diagonal_adaptor<M> dam1 (m1), dam2 (m2), dam3 (m3); + test_with (dam1, dam2, dam3); + +#ifdef USE_RANGE + ublas::matrix_range<ublas::diagonal_adaptor<M> > mr1 (dam1, ublas::range (0, N), ublas::range (0, N)), + mr2 (dam2, ublas::range (0, N), ublas::range (0, N)), + mr3 (dam3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<ublas::diagonal_adaptor<M> > ms1 (dam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (dam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (dam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif +#endif + } +#endif + + } +}; + +// Test matrix +void test_matrix () { + std::cout << "test_matrix" << std::endl; + +#ifdef USE_BANDED +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix<ublas::banded_matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix<ublas::banded_matrix<double, ublas::row_major, std::vector<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::banded_matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix<ublas::banded_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif +#endif + +#ifdef USE_DIAGONAL +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<mp_test_type, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<mp_test_type, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, ublas::unbounded_array<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix<ublas::diagonal_matrix<mp_test_type, ublas::row_major, std::vector<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix<ublas::diagonal_matrix<double, ublas::row_major, std::vector<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::diagonal_matrix<std::complex<mp_test_type>, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix<ublas::diagonal_matrix<std::complex<double>, ublas::row_major, std::vector<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test5.cpp b/libs/multiprecision/test/ublas_interop/test5.cpp new file mode 100644 index 0000000000..548cd60334 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test5.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test5.hpp" + +int main () { + test_matrix_vector (); + test_matrix (); + return 0; +} diff --git a/libs/multiprecision/test/ublas_interop/test5.hpp b/libs/multiprecision/test/ublas_interop/test5.hpp new file mode 100644 index 0000000000..d867dc5f66 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test5.hpp @@ -0,0 +1,64 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST5_H +#define TEST5_H + +#ifdef _MSC_VER +# pragma warning(disable:4800 4996 4127 4100) +#endif + +#include <boost/multiprecision/cpp_dec_float.hpp> + +#ifdef TEST_ET +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_on> mp_test_type; +#else +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off> mp_test_type; +#endif +//typedef double mp_test_type; + +#define USE_RANGE +#define USE_SLICE +#define USE_FLOAT +#define USE_UNBOUNDED_ARRAY +#define USE_STD_VECTOR +#define USE_BOUNDED_VECTOR USE_MATRIX +#define USE_UNBOUNDED_ARRAY +#define USE_MAP_ARRAY +#define USE_STD_MAP +#define USE_MAPPED_VECTOR +#define USE_COMPRESSED_VECTOR +#define USE_COORDINATE_VECTOR +#define USE_MAPPED_MATRIX +#define USE_COMPRESSED_MATRIX +#define USE_COORDINATE_MATRIX + +#include <iostream> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/matrix_proxy.hpp> +#include <boost/numeric/ublas/triangular.hpp> +#include <boost/numeric/ublas/io.hpp> + +namespace ublas = boost::numeric::ublas; + +#include "common/init.hpp" + +void test_matrix_vector (); +void test_matrix (); + + +// FIXME slice are failing in assignment to zero elements +#undef USE_SLICE + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test52.cpp b/libs/multiprecision/test/ublas_interop/test52.cpp new file mode 100644 index 0000000000..9e13dfde7a --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test52.cpp @@ -0,0 +1,214 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test5.hpp" + +// Test matrix & vector expression templates +template<class V, class M, int N> +struct test_my_matrix_vector { + typedef typename V::value_type value_type; + + template<class VP, class MP> + void test_with (VP &v1, VP &v2, MP &m1) const { + { + // Rows and columns + initialize_matrix (m1); + for (int i = 0; i < N; ++ i) { + v2 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v2 << std::endl; + v2 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v2 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + v1 (0) = 0; + v2 (N - 1) = 0; + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1); + initialize_vector (v1); + v2 = ublas::prod (m1, v1); + std::cout << "prod (m1, v1) = " << v2 << std::endl; + v2 = ublas::prod (v1, m1); + std::cout << "prod (v1, m1) = " << v2 << std::endl; + } + } + void operator () () const { + { + V v1 (N), v2 (N); + M m1 (N, N); + test_with (v1, v2, m1); + + ublas::matrix_row<M> mr1 (m1, N - 1), mr2 (m1, N - 1); + test_with (mr1, mr2, m1); + + ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 0); + test_with (mc1, mc2, m1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, m1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, m1); +#endif + } + } + + void operator () (int) const { +#ifdef USE_ADAPTOR + { + V v1 (N), v2 (N); + M m1 (N, N); + ublas::triangular_adaptor<M> tam1 (m1); + test_with (v1, v2, tam1); + + ublas::matrix_row<ublas::triangular_adaptor<M> > mr1 (tam1, N - 1), mr2 (tam1, N - 1); + test_with (mr1, mr2, tam1); + + ublas::matrix_column<ublas::triangular_adaptor<M> > mc1 (tam1, 0), mc2 (tam1, 0); + test_with (mc1, mc2, tam1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<ublas::triangular_adaptor<M> > mvr1 (tam1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (tam1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, tam1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<ublas::triangular_adaptor<M> > mvs1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, tam1); +#endif + } +#endif + } +}; + +// Test matrix & vector +void test_matrix_vector () { + std::cout << "test_matrix_vector" << std::endl; + +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (0); + + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test53.cpp b/libs/multiprecision/test/ublas_interop/test53.cpp new file mode 100644 index 0000000000..041be1f5b7 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test53.cpp @@ -0,0 +1,223 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test5.hpp" + +// Test matrix expression templates +template<class M, int N> +struct test_my_matrix { + typedef typename M::value_type value_type; + + template<class MP> + void test_with (MP &m1, MP &m2, MP &m3) const { + { + value_type t; + + // Default Construct + default_construct<MP>::test (); + + // Copy and swap + initialize_matrix (m1); + initialize_matrix (m2); + m1 = m2; + std::cout << "m1 = m2 = " << m1 << std::endl; + m1.assign_temporary (m2); + std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl; + m1.swap (m2); + std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl; + + // Zero assignment + m1 = ublas::zero_matrix<> (m1.size1 (), m1.size2 ()); + std::cout << "m1.zero_matrix = " << m1 << std::endl; + m1 = m2; + + // Unary matrix operations resulting in a matrix + initialize_matrix (m1); + m2 = - m1; + std::cout << "- m1 = " << m2 << std::endl; + m2 = ublas::conj (m1); + std::cout << "conj (m1) = " << m2 << std::endl; + + // Binary matrix operations resulting in a matrix + initialize_matrix (m1); + initialize_matrix (m2); + m3 = m1 + m2; + std::cout << "m1 + m2 = " << m3 << std::endl; + m3 = m1 - m2; + std::cout << "m1 - m2 = " << m3 << std::endl; + + // Scaling a matrix + t = N; + initialize_matrix (m1); + m2 = value_type (1.) * m1; + std::cout << "1. * m1 = " << m2 << std::endl; + m2 = t * m1; + std::cout << "N * m1 = " << m2 << std::endl; + initialize_matrix (m1); + m2 = m1 * value_type (1.); + std::cout << "m1 * 1. = " << m2 << std::endl; + m2 = m1 * t; + std::cout << "m1 * N = " << m2 << std::endl; + + // Some assignments + initialize_matrix (m1); + initialize_matrix (m2); + m2 += m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 -= m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; + m2 = m2 + m1; + std::cout << "m2 = m2 + m1 = " << m2 << std::endl; + m2 = m2 - m1; + std::cout << "m2 = m2 - m1 = " << m2 << std::endl; + m1 *= value_type (1.); + std::cout << "m1 *= 1. = " << m1 << std::endl; + m1 *= t; + std::cout << "m1 *= N = " << m1 << std::endl; + + // Transpose + initialize_matrix (m1); + // Transpose of a triangular isn't triangular of the same kind + std::cout << "trans (m1) = " << ublas::trans (m1) << std::endl; + + // Hermitian + initialize_matrix (m1); + // Hermitian of a triangular isn't hermitian of the same kind + std::cout << "herm (m1) = " << ublas::herm (m1) << std::endl; + + // Matrix multiplication + initialize_matrix (m1); + initialize_matrix (m2); + m3 = ublas::prod (m1, m2); + std::cout << "prod (m1, m2) = " << m3 << std::endl; + } + } + void operator () () const { + { + M m1 (N, N), m2 (N, N), m3 (N, N); + test_with (m1, m2, m3); + +#ifdef USE_RANGE + ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif + } + +#ifdef USE_ADAPTOR + { + M m1 (N, N), m2 (N, N), m3 (N, N); + ublas::triangular_adaptor<M> tam1 (m1), tam2 (m2), tam3 (m3); + test_with (tam1, tam2, tam3); + +#ifdef USE_RANGE + ublas::matrix_range<ublas::triangular_adaptor<M> > mr1 (tam1, ublas::range (0, N), ublas::range (0, N)), + mr2 (tam2, ublas::range (0, N), ublas::range (0, N)), + mr3 (tam3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<ublas::triangular_adaptor<M> > ms1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (tam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (tam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif + } +#endif + } +}; + +// Test matrix +void test_matrix () { + std::cout << "test_matrix" << std::endl; + +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix<ublas::triangular_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix<ublas::triangular_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::triangular_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE +std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix<ublas::triangular_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test6.cpp b/libs/multiprecision/test/ublas_interop/test6.cpp new file mode 100644 index 0000000000..61a5c3105e --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test6.cpp @@ -0,0 +1,19 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test6.hpp" + +int main () { + test_matrix_vector (); + test_matrix (); + return 0; +} diff --git a/libs/multiprecision/test/ublas_interop/test6.hpp b/libs/multiprecision/test/ublas_interop/test6.hpp new file mode 100644 index 0000000000..e84c2a0549 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test6.hpp @@ -0,0 +1,62 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST6_H +#define TEST6_H + +#ifdef _MSC_VER +# pragma warning(disable:4800 4996 4127 4100) +#endif + +#include <boost/multiprecision/cpp_dec_float.hpp> + +#ifdef TEST_ET +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_on> mp_test_type; +#else +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off> mp_test_type; +#endif +//typedef double mp_test_type; + +#define USE_RANGE +#define USE_SLICE +#define USE_FLOAT +#define USE_UNBOUNDED_ARRAY +#define USE_BOUNDED_ARRAY +#define USE_STD_VECTOR +#define USE_BOUNDED_VECTOR USE_MATRIX +#define USE_UNBOUNDED_ARRAY +#define USE_MAP_ARRAY +#define USE_STD_MAP +#define USE_MAPPED_VECTOR +#define USE_COMPRESSED_VECTOR +#define USE_COORDINATE_VECTOR +#define USE_MAPPED_MATRIX +#define USE_COMPRESSED_MATRIX +#define USE_COORDINATE_MATRIX + +#include <iostream> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/matrix_proxy.hpp> +#include <boost/numeric/ublas/symmetric.hpp> +#include <boost/numeric/ublas/io.hpp> + +namespace ublas = boost::numeric::ublas; + +#include "common/init.hpp" + +void test_matrix_vector (); +void test_matrix (); + + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test62.cpp b/libs/multiprecision/test/ublas_interop/test62.cpp new file mode 100644 index 0000000000..a7529d2940 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test62.cpp @@ -0,0 +1,218 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test6.hpp" + +// Test matrix & vector expression templates +template<class V, class M, int N> +struct test_my_matrix_vector { + typedef typename V::value_type value_type; + + template<class VP, class MP> + void test_with (VP &v1, VP &v2, MP &m1) const { + { + // Rows and columns + initialize_matrix (m1); + for (int i = 0; i < N; ++ i) { + v2 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v2 << std::endl; + v2 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v2 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + v1 (0) = 0; + v1 (N - 1) = 0; + v2 (0) = 0; + v2 (N - 1) = 0; + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1); + initialize_vector (v1); + v2 = ublas::prod (m1, v1); + std::cout << "prod (m1, v1) = " << v2 << std::endl; + v2 = ublas::prod (v1, m1); + std::cout << "prod (v1, m1) = " << v2 << std::endl; + } + } + void operator () () const { + { + V v1 (N), v2 (N); + M m1 (N, N); + test_with (v1, v2, m1); + + ublas::matrix_row<M> mr1 (m1, N - 1), mr2 (m1, N - 1); + test_with (mr1, mr2, m1); + + ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 0); + test_with (mc1, mc2, m1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, m1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, m1); +#endif + } + } + + void operator () (int) const { +#ifdef USE_ADAPTOR + { + V v1 (N), v2 (N); + M m1 (N, N); + ublas::symmetric_adaptor<M> tam1 (m1); + test_with (v1, v2, tam1); + + ublas::matrix_row<ublas::symmetric_adaptor<M> > mr1 (tam1, N - 1), mr2 (tam1, N - 1); + test_with (mr1, mr2, tam1); + + ublas::matrix_column<ublas::symmetric_adaptor<M> > mc1 (tam1, 0), mc2 (tam1, 0); + test_with (mc1, mc2, tam1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<ublas::symmetric_adaptor<M> > mvr1 (tam1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (tam1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, tam1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<ublas::symmetric_adaptor<M> > mvs1 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (tam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, tam1); +#endif + } +#endif + } +}; + +// Test matrix & vector +void test_matrix_vector () { + std::cout << "test_matrix_vector" << std::endl; + +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::bounded_array<mp_test_type, 3> >, + ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::bounded_array<double, 3> >, + ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::bounded_array<std::complex<mp_test_type>, 3> >, + ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::bounded_array<std::complex<double>, 3> >, + ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, ublas::unbounded_array<mp_test_type> >, + ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, ublas::unbounded_array<double> >, + ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, ublas::unbounded_array<std::complex<mp_test_type> > >, + ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, ublas::unbounded_array<std::complex<double> > >, + ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3> () (); + test_my_matrix_vector<ublas::vector<mp_test_type, std::vector<mp_test_type> >, + ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (); + test_my_matrix_vector<ublas::vector<double, std::vector<double> >, + ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3> () (0); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<mp_test_type>, std::vector<std::complex<mp_test_type> > >, + ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3> () (0); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (); + test_my_matrix_vector<ublas::vector<std::complex<double>, std::vector<std::complex<double> > >, + ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3> () (0); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test63.cpp b/libs/multiprecision/test/ublas_interop/test63.cpp new file mode 100644 index 0000000000..d36f09c1d6 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test63.cpp @@ -0,0 +1,223 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test6.hpp" + +// Test matrix expression templates +template<class M, int N> +struct test_my_matrix { + typedef typename M::value_type value_type; + + template<class MP> + void test_with (MP &m1, MP &m2, MP &m3) const { + { + value_type t; + + // Default Construct + default_construct<MP>::test (); + + // Copy and swap + initialize_matrix (m1); + initialize_matrix (m2); + m1 = m2; + std::cout << "m1 = m2 = " << m1 << std::endl; + m1.assign_temporary (m2); + std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl; + m1.swap (m2); + std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl; + + // Zero assignment + m1 = ublas::zero_matrix<> (m1.size1 (), m1.size2 ()); + std::cout << "m1.zero_matrix = " << m1 << std::endl; + m1 = m2; + + // Unary matrix operations resulting in a matrix + initialize_matrix (m1); + m2 = - m1; + std::cout << "- m1 = " << m2 << std::endl; + m2 = ublas::conj (m1); + std::cout << "conj (m1) = " << m2 << std::endl; + + // Binary matrix operations resulting in a matrix + initialize_matrix (m1); + initialize_matrix (m2); + m3 = m1 + m2; + std::cout << "m1 + m2 = " << m3 << std::endl; + m3 = m1 - m2; + std::cout << "m1 - m2 = " << m3 << std::endl; + + // Scaling a matrix + t = N; + initialize_matrix (m1); + m2 = value_type (1.) * m1; + std::cout << "1. * m1 = " << m2 << std::endl; + m2 = t * m1; + std::cout << "N * m1 = " << m2 << std::endl; + initialize_matrix (m1); + m2 = m1 * value_type (1.); + std::cout << "m1 * 1. = " << m2 << std::endl; + m2 = m1 * t; + std::cout << "m1 * N = " << m2 << std::endl; + + // Some assignments + initialize_matrix (m1); + initialize_matrix (m2); + m2 += m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 -= m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; + m2 = m2 + m1; + std::cout << "m2 = m2 + m1 = " << m2 << std::endl; + m2 = m2 - m1; + std::cout << "m2 = m1 - m1 = " << m2 << std::endl; + m1 *= value_type (1.); + std::cout << "m1 *= 1. = " << m1 << std::endl; + m1 *= t; + std::cout << "m1 *= N = " << m1 << std::endl; + + // Transpose + initialize_matrix (m1); + m2 = ublas::trans (m1); + std::cout << "trans (m1) = " << m2 << std::endl; + + // Hermitean + initialize_matrix (m1); + m2 = ublas::herm (m1); + std::cout << "herm (m1) = " << m2 << std::endl; + + // Matrix multiplication + initialize_matrix (m1); + initialize_matrix (m2); + m3 = ublas::prod (m1, m2); + std::cout << "prod (m1, m2) = " << m3 << std::endl; + } + } + void operator () () const { + { + M m1 (N, N), m2 (N, N), m3 (N, N); + test_with (m1, m2, m3); + +#ifdef USE_RANGE + ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif + } + +#ifdef USE_ADAPTOR + { + M m1 (N, N), m2 (N, N), m3 (N, N); + ublas::symmetric_adaptor<M> sam1 (m1), sam2 (m2), sam3 (m3); + test_with (sam1, sam2, sam3); + +#ifdef USE_RANGE + ublas::matrix_range<ublas::symmetric_adaptor<M> > mr1 (sam1, ublas::range (0, N), ublas::range (0, N)), + mr2 (sam2, ublas::range (0, N), ublas::range (0, N)), + mr3 (sam3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<ublas::symmetric_adaptor<M> > ms1 (sam1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (sam2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (sam3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif + } +#endif + } +}; + +// Test matrix +void test_matrix () { + std::cout << "test_matrix" << std::endl; + +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, bounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::bounded_array<mp_test_type, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, bounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<mp_test_type>, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, bounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::bounded_array<std::complex<double>, 3 * 3> >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "mp_test_type, unbounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, ublas::unbounded_array<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, unbounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::unbounded_array<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, ublas::unbounded_array<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "mp_test_type, std::vector" << std::endl; + test_my_matrix<ublas::symmetric_matrix<mp_test_type, ublas::lower, ublas::row_major, std::vector<mp_test_type> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "double, std::vector" << std::endl; + test_my_matrix<ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, std::vector<double> >, 3 > () (); +#endif + +#ifdef USE_STD_COMPLEX +#ifdef USE_FLOAT + std::cout << "std::complex<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::symmetric_matrix<std::complex<mp_test_type>, ublas::lower, ublas::row_major, std::vector<std::complex<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "std::complex<double>, std::vector" << std::endl; + test_my_matrix<ublas::symmetric_matrix<std::complex<double>, ublas::lower, ublas::row_major, std::vector<std::complex<double> > >, 3 > () (); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test7.cpp b/libs/multiprecision/test/ublas_interop/test7.cpp new file mode 100644 index 0000000000..f564031cef --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test7.cpp @@ -0,0 +1,31 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include <iostream> + +#include <boost/numeric/interval.hpp> +#include <boost/numeric/interval/io.hpp> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/io.hpp> + +#include "test7.hpp" + +// this testcase requires fix of task #2473 + +int main () { + test_vector (); + test_matrix_vector (); + test_matrix (); + return 0; +} diff --git a/libs/multiprecision/test/ublas_interop/test7.hpp b/libs/multiprecision/test/ublas_interop/test7.hpp new file mode 100644 index 0000000000..65325a2619 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test7.hpp @@ -0,0 +1,66 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#ifndef TEST7_H +#define TEST7_H + +#ifdef _MSC_VER +# pragma warning(disable:4800 4996) +#endif + +#include <boost/multiprecision/cpp_dec_float.hpp> + +#ifdef TEST_ET +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_on> mp_test_type; +#else +typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<50>, boost::multiprecision::et_off> mp_test_type; +#endif +//typedef double mp_test_type; + +#define USE_RANGE +#define USE_SLICE +#define USE_FLOAT +#define USE_UNBOUNDED_ARRAY +#define USE_BOUNDED_ARRAY +#define USE_STD_VECTOR +#define USE_BOUNDED_VECTOR USE_MATRIX +#define USE_UNBOUNDED_ARRAY +#define USE_MAP_ARRAY +#define USE_STD_MAP +#define USE_MAPPED_VECTOR +#define USE_COMPRESSED_VECTOR +#define USE_COORDINATE_VECTOR +#define USE_MAPPED_MATRIX +#define USE_COMPRESSED_MATRIX +#define USE_COORDINATE_MATRIX + +#include <iostream> + +#include <boost/numeric/interval.hpp> +#include <boost/numeric/interval/io.hpp> + +#include <boost/numeric/ublas/vector.hpp> +#include <boost/numeric/ublas/vector_proxy.hpp> +#include <boost/numeric/ublas/matrix.hpp> +#include <boost/numeric/ublas/matrix_proxy.hpp> +#include <boost/numeric/ublas/io.hpp> + +namespace ublas = boost::numeric::ublas; + +#include "common/init.hpp" + +void test_vector (); +void test_matrix_vector (); +void test_matrix (); + + +#endif diff --git a/libs/multiprecision/test/ublas_interop/test71.cpp b/libs/multiprecision/test/ublas_interop/test71.cpp new file mode 100644 index 0000000000..5fc6c2b0f4 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test71.cpp @@ -0,0 +1,174 @@ +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +// +// This file fails to compile - appears to be a known uBlas issue :-( +// + +#include "test7.hpp" + +// Test vector expression templates +template<class V, int N> +struct test_my_vector { + typedef typename V::value_type value_type; + typedef typename V::size_type size_type; + typedef typename ublas::type_traits<value_type>::real_type real_type; + + template<class VP> + void test_with (VP &v1, VP &v2, VP &v3) const { + { + value_type t; + size_type i; + real_type n; + + // Copy and swap + initialize_vector (v1); + initialize_vector (v2); + v1 = v2; + std::cout << "v1 = v2 = " << v1 << std::endl; + v1.assign_temporary (v2); + std::cout << "v1.assign_temporary (v2) = " << v1 << std::endl; + v1.swap (v2); + std::cout << "v1.swap (v2) = " << v1 << " " << v2 << std::endl; + + // Zero assignment + v1 = ublas::zero_vector<value_type> (v1.size ()); + std::cout << "v1.zero_vector = " << v1 << std::endl; + v1 = v2; + + // Unary vector operations resulting in a vector + initialize_vector (v1); + v2 = - v1; + std::cout << "- v1 = " << v2 << std::endl; + v2 = ublas::conj (v1); + std::cout << "conj (v1) = " << v2 << std::endl; + + // Binary vector operations resulting in a vector + initialize_vector (v1); + initialize_vector (v2); + v3 = v1 + v2; + std::cout << "v1 + v2 = " << v3 << std::endl; + + v3 = v1 - v2; + std::cout << "v1 - v2 = " << v3 << std::endl; + + // Scaling a vector + t = value_type (N); + initialize_vector (v1); + v2 = value_type (1.) * v1; + std::cout << "1. * v1 = " << v2 << std::endl; +// v2 = t * v1; + std::cout << "N * v1 = " << v2 << std::endl; + initialize_vector (v1); +// v2 = v1 * value_type (1.); + std::cout << "v1 * 1. = " << v2 << std::endl; +// v2 = v1 * t; + std::cout << "v1 * N = " << v2 << std::endl; + + // Some assignments + initialize_vector (v1); + initialize_vector (v2); + v2 += v1; + std::cout << "v2 += v1 = " << v2 << std::endl; + v2 -= v1; + std::cout << "v2 -= v1 = " << v2 << std::endl; + v2 = v2 + v1; + std::cout << "v2 = v2 + v1 = " << v2 << std::endl; + v2 = v2 - v1; + std::cout << "v2 = v2 - v1 = " << v2 << std::endl; + v1 *= value_type (1.); + std::cout << "v1 *= 1. = " << v1 << std::endl; + v1 *= t; + std::cout << "v1 *= N = " << v1 << std::endl; + + // Unary vector operations resulting in a scalar + initialize_vector (v1); + t = ublas::sum (v1); + std::cout << "sum (v1) = " << t << std::endl; + n = ublas::norm_1 (v1); + std::cout << "norm_1 (v1) = " << n << std::endl; + n = ublas::norm_2 (v1); + std::cout << "norm_2 (v1) = " << n << std::endl; + n = ublas::norm_inf (v1); + std::cout << "norm_inf (v1) = " << n << std::endl; + + i = ublas::index_norm_inf (v1); + std::cout << "index_norm_inf (v1) = " << i << std::endl; + + // Binary vector operations resulting in a scalar + initialize_vector (v1); + initialize_vector (v2); + t = ublas::inner_prod (v1, v2); + std::cout << "inner_prod (v1, v2) = " << t << std::endl; + } + } + void operator () () const { + { + V v1 (N), v2 (N), v3 (N); + test_with (v1, v2, v3); + +#ifdef USE_RANGE + ublas::vector_range<V> vr1 (v1, ublas::range (0, N)), + vr2 (v2, ublas::range (0, N)), + vr3 (v3, ublas::range (0, N)); + test_with (vr1, vr2, vr3); +#endif + +#ifdef USE_SLICE + ublas::vector_slice<V> vs1 (v1, ublas::slice (0, 1, N)), + vs2 (v2, ublas::slice (0, 1, N)), + vs3 (v3, ublas::slice (0, 1, N)); + test_with (vs1, vs2, vs3); +#endif + } + } +}; + +// Test vector +void test_vector () { + std::cout << "test_vector" << std::endl; + +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl; + test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl; + test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, 3 > () (); +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl; + test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl; + test_my_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, 3 > () (); +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl; + test_my_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, std::vector" << std::endl; + test_my_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, 3 > () (); +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test72.cpp b/libs/multiprecision/test/ublas_interop/test72.cpp new file mode 100644 index 0000000000..07b1d8a07b --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test72.cpp @@ -0,0 +1,165 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test7.hpp" + +// Test matrix & vector expression templates +template<class V, class M, int N> +struct test_my_matrix_vector { + typedef typename V::value_type value_type; + + template<class VP, class MP> + void test_with (VP &v1, VP &v2, MP &m1) const { + { + // Rows and columns + initialize_matrix (m1); + for (int i = 0; i < N; ++ i) { + v1 = ublas::row (m1, i); + std::cout << "row (m, " << i << ") = " << v1 << std::endl; + v1 = ublas::column (m1, i); + std::cout << "column (m, " << i << ") = " << v1 << std::endl; + } + + // Outer product + initialize_vector (v1); + initialize_vector (v2); + m1 = ublas::outer_prod (v1, v2); + std::cout << "outer_prod (v1, v2) = " << m1 << std::endl; + + // Matrix vector product + initialize_matrix (m1); + initialize_vector (v1); + v2 = ublas::prod (m1, v1); + std::cout << "prod (m1, v1) = " << v2 << std::endl; + v2 = ublas::prod (v1, m1); + std::cout << "prod (v1, m1) = " << v2 << std::endl; + } + } + void operator () () const { + { + V v1 (N), v2 (N); + M m1 (N, N); + test_with (v1, v2, m1); + + ublas::matrix_row<M> mr1 (m1, 0), mr2 (m1, 1); + test_with (mr1, mr2, m1); + + ublas::matrix_column<M> mc1 (m1, 0), mc2 (m1, 1); + test_with (mc1, mc2, m1); + +#ifdef USE_RANGE + ublas::matrix_vector_range<M> mvr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mvr2 (m1, ublas::range (0, N), ublas::range (0, N)); + test_with (mvr1, mvr2, m1); +#endif + +#ifdef USE_SLICE + ublas::matrix_vector_slice<M> mvs1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + mvs2 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (mvs1, mvs2, m1); +#endif + } + } +}; + +// Test matrix & vector +void test_matrix_vector () { + std::cout << "test_matrix_vector" << std::endl; + +#ifdef USE_MATRIX +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >, + ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3 * 3> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, + ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3> () (); +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, + ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, + ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3> () (); +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >, + ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<boost::numeric::interval<mp_test_type> > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, + ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3> () (); +#endif +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3> >, + ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3>, 3 + 1> >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::bounded_array<boost::numeric::interval<double>, 3> >, + ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<double>, 3>, 3 + 1> >, 3> () (); +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, + ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<mp_test_type> > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, ublas::unbounded_array<boost::numeric::interval<double> > >, + ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<double> > > >, 3> () (); +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<mp_test_type>, std::vector<boost::numeric::interval<mp_test_type> > >, + ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<mp_test_type> > > >, 3> () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, std::vector" << std::endl; + test_my_matrix_vector<ublas::vector<boost::numeric::interval<double>, std::vector<boost::numeric::interval<double> > >, + ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3> () (); +#endif +#endif +#endif +} diff --git a/libs/multiprecision/test/ublas_interop/test73.cpp b/libs/multiprecision/test/ublas_interop/test73.cpp new file mode 100644 index 0000000000..60b10bb764 --- /dev/null +++ b/libs/multiprecision/test/ublas_interop/test73.cpp @@ -0,0 +1,202 @@ +// +// Copyright (c) 2000-2002 +// Joerg Walter, Mathias Koch +// +// 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) +// +// The authors gratefully acknowledge the support of +// GeNeSys mbH & Co. KG in producing this work. +// + +#include "test7.hpp" + +// Test matrix expression templates +template<class M, int N> +struct test_my_matrix { + typedef typename M::value_type value_type; + + template<class MP> + void test_with (MP &m1, MP &m2, MP &m3) const { + { + value_type t; + + // Copy and swap + initialize_matrix (m1); + initialize_matrix (m2); + m1 = m2; + std::cout << "m1 = m2 = " << m1 << std::endl; + m1.assign_temporary (m2); + std::cout << "m1.assign_temporary (m2) = " << m1 << std::endl; + m1.swap (m2); + std::cout << "m1.swap (m2) = " << m1 << " " << m2 << std::endl; + + // Zero assignment + m1 = ublas::zero_matrix<value_type> (m1.size1 (), m1.size2 ()); + std::cout << "m1.zero_matrix = " << m1 << std::endl; + m1 = m2; + + // Unary matrix operations resulting in a matrix + initialize_matrix (m1); + m2 = - m1; + std::cout << "- m1 = " << m2 << std::endl; + m2 = ublas::conj (m1); + std::cout << "conj (m1) = " << m2 << std::endl; + + // Binary matrix operations resulting in a matrix + initialize_matrix (m1); + initialize_matrix (m2); + m3 = m1 + m2; + std::cout << "m1 + m2 = " << m3 << std::endl; + m3 = m1 - m2; + std::cout << "m1 - m2 = " << m3 << std::endl; + + // Scaling a matrix + t = N; + initialize_matrix (m1); + m2 = value_type (1.) * m1; + std::cout << "1. * m1 = " << m2 << std::endl; + m2 = t * m1; + std::cout << "N * m1 = " << m2 << std::endl; + initialize_matrix (m1); + m2 = m1 * value_type (1.); + std::cout << "m1 * 1. = " << m2 << std::endl; + m2 = m1 * t; + std::cout << "m1 * N = " << m2 << std::endl; + + // Some assignments + initialize_matrix (m1); + initialize_matrix (m2); + m2 += m1; + std::cout << "m2 += m1 = " << m2 << std::endl; + m2 -= m1; + std::cout << "m2 -= m1 = " << m2 << std::endl; + m2 = m2 + m1; + std::cout << "m2 = m2 + m1 = " << m2 << std::endl; + m2 = m2 - m1; + std::cout << "m2 = m1 - m1 = " << m2 << std::endl; + m1 *= value_type (1.); + std::cout << "m1 *= 1. = " << m1 << std::endl; + m1 *= t; + std::cout << "m1 *= N = " << m1 << std::endl; + + // Transpose + initialize_matrix (m1); + m2 = ublas::trans (m1); + std::cout << "trans (m1) = " << m2 << std::endl; + + // Hermitean + initialize_matrix (m1); + m2 = ublas::herm (m1); + std::cout << "herm (m1) = " << m2 << std::endl; + + // Matrix multiplication + initialize_matrix (m1); + initialize_matrix (m2); + m3 = ublas::prod (m1, m2); + std::cout << "prod (m1, m2) = " << m3 << std::endl; + } + } + void operator () () const { + { + M m1 (N, N), m2 (N, N), m3 (N, N); + test_with (m1, m2, m3); + +#ifdef USE_RANGE + ublas::matrix_range<M> mr1 (m1, ublas::range (0, N), ublas::range (0, N)), + mr2 (m2, ublas::range (0, N), ublas::range (0, N)), + mr3 (m3, ublas::range (0, N), ublas::range (0, N)); + test_with (mr1, mr2, mr3); +#endif + +#ifdef USE_SLICE + ublas::matrix_slice<M> ms1 (m1, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms2 (m2, ublas::slice (0, 1, N), ublas::slice (0, 1, N)), + ms3 (m3, ublas::slice (0, 1, N), ublas::slice (0, 1, N)); + test_with (ms1, ms2, ms3); +#endif + } + } +}; + +// Test matrix +void test_matrix () { + std::cout << "test_matrix" << std::endl; + +#ifdef USE_MATRIX +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3 * 3> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl; + test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<boost::numeric::interval<double>, 3 * 3> >, 3 > () (); +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<boost::numeric::interval<double> > >, 3 > () (); +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::matrix<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<boost::numeric::interval<mp_test_type> > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, std::vector" << std::endl; + test_my_matrix<ublas::matrix<boost::numeric::interval<double>, ublas::row_major, std::vector<boost::numeric::interval<double> > >, 3 > () (); +#endif +#endif +#endif + +#ifdef USE_VECTOR_OF_VECTOR +#ifdef USE_BOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, bounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<mp_test_type>, 3>, 3 + 1> >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, bounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::bounded_array<ublas::bounded_array<boost::numeric::interval<double>, 3>, 3 + 1> >, 3 > () (); +#endif +#endif + +#ifdef USE_UNBOUNDED_ARRAY +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, unbounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<mp_test_type> > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, unbounded_array" << std::endl; + test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, ublas::unbounded_array<ublas::unbounded_array<boost::numeric::interval<double> > > >, 3 > () (); +#endif +#endif + +#ifdef USE_STD_VECTOR +#ifdef USE_FLOAT + std::cout << "boost::numeric::interval<mp_test_type>, std::vector" << std::endl; + test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<mp_test_type>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<mp_test_type> > > >, 3 > () (); +#endif + +#ifdef USE_DOUBLE + std::cout << "boost::numeric::interval<double>, std::vector" << std::endl; + test_my_matrix<ublas::vector_of_vector<boost::numeric::interval<double>, ublas::row_major, std::vector<std::vector<boost::numeric::interval<double> > > >, 3 > () (); +#endif +#endif +#endif +} |