2
0
mirror of https://github.com/boostorg/ublas.git synced 2026-02-21 15:32:12 +00:00

fix #3539: merged [61135], [61136], [61137] into release

boost/numeric/ublas/traits.hpp: fixed complex_traits

libs/numeric/ublas/test/Jamfile.v2: added testcase

libs/numeric/ublas/test/test_complex_norms.cpp: new testcase

libs/numeric/ublas/doc/release_notes.htm: updated release notes



[SVN r61206]
This commit is contained in:
Gunter Winkler
2010-04-11 20:11:14 +00:00
parent 45f0ee6cca
commit 9bcf20f455
4 changed files with 101 additions and 4 deletions

View File

@@ -25,6 +25,15 @@
<ul>
<li><a href="https://svn.boost.org/trac/boost/ticket/3968">[3968]</a> fixed coordinate_matrix sort problem on MSVC10
</li>
<li><a href="https://svn.boost.org/trac/boost/ticket/3539">[3539]</a>
changed computation of <code>norm_inf</code> for complex types to match
mathematical definition. <br />
<b>Note:</b> This might cause a performance drop
because now <code>std::abs(z)</code> is called for each vector element.
The old implementation used <code>std::max(std::abs(real(z)),std::abs(imag(z))</code>.
Further <code>norm_inf</code> and <code>norm_1</code> will now return
the same values for complex vector.
</li>
<li><a href="https://svn.boost.org/trac/boost/ticket/3501">[3501]</a> Moved free functions in <code>concepts.hpp</code> into anonymous namespace.
</li>
</ul>

View File

@@ -220,8 +220,10 @@ namespace boost { namespace numeric { namespace ublas {
static
BOOST_UBLAS_INLINE
real_type norm_1 (const_reference t) {
return type_traits<real_type>::type_abs (self_type::real (t)) +
type_traits<real_type>::type_abs (self_type::imag (t));
return self_type::type_abs (t);
// original computation has been replaced because a complex number should behave like a scalar type
// return type_traits<real_type>::type_abs (self_type::real (t)) +
// type_traits<real_type>::type_abs (self_type::imag (t));
}
static
BOOST_UBLAS_INLINE
@@ -231,8 +233,10 @@ namespace boost { namespace numeric { namespace ublas {
static
BOOST_UBLAS_INLINE
real_type norm_inf (const_reference t) {
return (std::max) (type_traits<real_type>::type_abs (self_type::real (t)),
type_traits<real_type>::type_abs (self_type::imag (t)));
return self_type::type_abs (t);
// original computation has been replaced because a complex number should behave like a scalar type
// return (std::max) (type_traits<real_type>::type_abs (self_type::real (t)),
// type_traits<real_type>::type_abs (self_type::imag (t)));
}
static

View File

@@ -128,4 +128,6 @@ test-suite numeric/uBLAS
]
[ run test_coordinate_matrix_sort.cpp
]
[ run test_complex_norms.cpp
]
;

View File

@@ -0,0 +1,82 @@
// Copyright 2010 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)
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <complex>
#include "libs/numeric/ublas/test/utils.hpp"
using namespace boost::numeric::ublas;
static const double TOL(1.0e-5); ///< Used for comparing two real numbers.
BOOST_UBLAS_TEST_DEF ( test_double_complex_norm_inf ) {
typedef std::complex<double> dComplex;
vector<dComplex> v(4);
for (unsigned int i = 0; i < v.size(); ++i)
v[i] = dComplex(i, i + 1);
const double expected = abs(v[3]);
BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_inf(v) );
BOOST_UBLAS_TEST_CHECK(std::abs(norm_inf(v) - expected) < TOL);
v *= 3.;
BOOST_UBLAS_TEST_CHECK(std::abs(norm_inf(v) - (3.0*expected)) < TOL);
}
BOOST_UBLAS_TEST_DEF ( test_double_complex_norm_2 ) {
typedef std::complex<double> dComplex;
vector<dComplex> v(4);
for (unsigned int i = 0; i < v.size(); ++i)
v[i] = dComplex(i, i + 1);
const double expected = sqrt(44.0);
BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) );
BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL);
v *= 3.;
BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - (3.0*expected)) < TOL);
}
BOOST_UBLAS_TEST_DEF ( test_float_complex_norm_inf ) {
typedef std::complex<float> dComplex;
vector<dComplex> v(4);
for (unsigned int i = 0; i < v.size(); ++i)
v[i] = dComplex(i, i + 1);
const float expected = abs(v[3]);
BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_inf(v) );
BOOST_UBLAS_TEST_CHECK(std::abs(norm_inf(v) - expected) < TOL);
v *= 3.;
BOOST_UBLAS_TEST_CHECK(std::abs(norm_inf(v) - (3.0*expected)) < TOL);
}
BOOST_UBLAS_TEST_DEF ( test_float_complex_norm_2 ) {
typedef std::complex<float> dComplex;
vector<dComplex> v(4);
for (unsigned int i = 0; i < v.size(); ++i)
v[i] = dComplex(i, i + 1);
const float expected = sqrt(44.0);
BOOST_UBLAS_DEBUG_TRACE( "norm is " << norm_2(v) );
BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - expected) < TOL);
v *= 3.;
BOOST_UBLAS_TEST_CHECK(std::abs(norm_2(v) - (3.0*expected)) < TOL);
}
int main() {
BOOST_UBLAS_TEST_BEGIN();
BOOST_UBLAS_TEST_DO( test_double_complex_norm_inf );
BOOST_UBLAS_TEST_DO( test_float_complex_norm_inf );
BOOST_UBLAS_TEST_DO( test_double_complex_norm_2 );
BOOST_UBLAS_TEST_DO( test_float_complex_norm_2 );
BOOST_UBLAS_TEST_END();
}