|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61135 - trunk/libs/numeric/ublas/test
From: guwi17_at_[hidden]
Date: 2010-04-07 15:15:08
Author: guwi17
Date: 2010-04-07 15:15:07 EDT (Wed, 07 Apr 2010)
New Revision: 61135
URL: http://svn.boost.org/trac/boost/changeset/61135
Log:
see #3539: a testcase was provided to recreate the problem
test/Jamfile.v2: added new target
test/test_complex_norms.cpp: added new testcase for complex vector norms
Added:
trunk/libs/numeric/ublas/test/test_complex_norms.cpp (contents, props changed)
Text files modified:
trunk/libs/numeric/ublas/test/Jamfile.v2 | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
Modified: trunk/libs/numeric/ublas/test/Jamfile.v2
==============================================================================
--- trunk/libs/numeric/ublas/test/Jamfile.v2 (original)
+++ trunk/libs/numeric/ublas/test/Jamfile.v2 2010-04-07 15:15:07 EDT (Wed, 07 Apr 2010)
@@ -130,4 +130,6 @@
]
[ run test_coordinate_matrix_sort.cpp
]
+ [ run test_complex_norms.cpp
+ ]
;
Added: trunk/libs/numeric/ublas/test/test_complex_norms.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/test_complex_norms.cpp 2010-04-07 15:15:07 EDT (Wed, 07 Apr 2010)
@@ -0,0 +1,82 @@
+// Copyright 2010 Gunter Winkler <guwi17_at_[hidden]>
+// 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();
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk