|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r49547 - sandbox/libs/numeric/bindings/blas/test
From: thomas.klimpel_at_[hidden]
Date: 2008-11-03 02:38:29
Author: klimpel
Date: 2008-11-03 02:38:28 EST (Mon, 03 Nov 2008)
New Revision: 49547
URL: http://svn.boost.org/trac/boost/changeset/49547
Log:
tests for bindings for std::vector, std::valarray and c_array as
column_major (n,1) matrix and
dense_matrix_stride1/stride2 functionality from Markus Rickert
Added:
sandbox/libs/numeric/bindings/blas/test/dense_matrix_stride.cpp (contents, props changed)
sandbox/libs/numeric/bindings/blas/test/vector2.cpp (contents, props changed)
Text files modified:
sandbox/libs/numeric/bindings/blas/test/Jamfile.v2 | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
Modified: sandbox/libs/numeric/bindings/blas/test/Jamfile.v2
==============================================================================
--- sandbox/libs/numeric/bindings/blas/test/Jamfile.v2 (original)
+++ sandbox/libs/numeric/bindings/blas/test/Jamfile.v2 2008-11-03 02:38:28 EST (Mon, 03 Nov 2008)
@@ -16,5 +16,7 @@
[ link blas2.cpp ]
[ run blas3.cpp ]
[ run ublas_slice.cpp ]
+ [ run vector2.cpp ]
+ [ run dense_matrix_stride.cpp ]
;
Added: sandbox/libs/numeric/bindings/blas/test/dense_matrix_stride.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/numeric/bindings/blas/test/dense_matrix_stride.cpp 2008-11-03 02:38:28 EST (Mon, 03 Nov 2008)
@@ -0,0 +1,123 @@
+//
+// Copyright Markus Rickert 2008
+//
+// 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/io.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/numeric/ublas/matrix_proxy.hpp>
+#include <boost/numeric/ublas/vector.hpp>
+#include <boost/numeric/ublas/vector_proxy.hpp>
+#include <boost/numeric/bindings/traits/c_array2.hpp>
+#include <boost/numeric/bindings/traits/dense_traits.hpp>
+#include <boost/numeric/bindings/traits/std_valarray2.hpp>
+#include <boost/numeric/bindings/traits/std_vector2.hpp>
+#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
+//#include <boost/numeric/bindings/traits/ublas_vector.hpp>
+#include <boost/numeric/bindings/traits/ublas_vector2.hpp>
+
+int
+main(int argc, char** argv)
+{
+ // matrix
+ boost::numeric::ublas::matrix<double> a(3, 4);
+ for (std::size_t i = 0; i < a.size1(); ++i) for (std::size_t j = 0; j < a.size2(); ++j) a(i, j) = i * a.size2() + j;
+ std::cout << "A=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(a) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(a) << std::endl;
+ std::cout << a << std::endl;
+
+ // matrix matrix_range
+ boost::numeric::ublas::matrix_range<
+ boost::numeric::ublas::matrix<double>
+ > a2 = boost::numeric::ublas::subrange(a, 1, 3, 0, 2);
+ std::cout << "A2=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(a2) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(a2) << std::endl;
+ std::cout << a2 << std::endl;
+
+ // matrix column_major
+ boost::numeric::ublas::matrix<double, boost::numeric::ublas::column_major> b(3, 4);
+ std::cout << "B=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(b) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(b) << std::endl;
+
+ // bounded_matrix
+ boost::numeric::ublas::bounded_matrix<double, 3, 4> c;
+ std::cout << "C=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(c) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(c) << std::endl;
+
+ // bounded_matrix matrix_range
+ boost::numeric::ublas::matrix_range<
+ boost::numeric::ublas::bounded_matrix<double, 3, 4>
+ > c2 = boost::numeric::ublas::subrange(c, 0, 1, 0, 2);
+ std::cout << "C2=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(c2) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(c2) << std::endl;
+
+ // bounded_matrix column_major
+ boost::numeric::ublas::bounded_matrix<double, 3, 4, boost::numeric::ublas::column_major> d;
+ std::cout << "D=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(d) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(d) << std::endl;
+
+ // vector
+ boost::numeric::ublas::vector<double> e(3);
+ std::cout << "e=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(e) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(e) << std::endl;
+
+ // vector vector_range
+ boost::numeric::ublas::vector_range<
+ boost::numeric::ublas::vector<double>
+ > f = boost::numeric::ublas::subrange(e, 0, 2);
+ std::cout << "f=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(f) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(f) << std::endl;
+
+ // bounded_vector
+ boost::numeric::ublas::bounded_vector<double, 3> h;
+ std::cout << "h=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(h) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(h) << std::endl;
+
+ // bounded_vector vector_range
+ boost::numeric::ublas::vector_range<
+ boost::numeric::ublas::bounded_vector<double, 3>
+ > i = boost::numeric::ublas::subrange(h, 0, 2);
+ std::cout << "i=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(i) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(i) << std::endl;
+
+ // std::vector
+ std::vector<double> k(3);
+ std::cout << "k=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(k) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(k) << std::endl;
+
+ // std::valarray
+ std::valarray<double> l(3);
+ std::cout << "l=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(l) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(l) << std::endl;
+
+ // array
+ double m[3];
+ std::cout << "m=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(m) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(m) << std::endl;
+
+ // matrix
+ boost::numeric::ublas::matrix<double> n(3, 1);
+ std::cout << "N=";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride1(n) << ",";
+ std::cout << boost::numeric::bindings::traits::dense_matrix_stride2(n) << std::endl;
+ std::cout << boost::numeric::bindings::traits::matrix_stride1(n) << ",";
+ std::cout << boost::numeric::bindings::traits::matrix_stride2(n) << std::endl;
+
+ return 0;
+}
Added: sandbox/libs/numeric/bindings/blas/test/vector2.cpp
==============================================================================
--- (empty file)
+++ sandbox/libs/numeric/bindings/blas/test/vector2.cpp 2008-11-03 02:38:28 EST (Mon, 03 Nov 2008)
@@ -0,0 +1,130 @@
+//
+// Copyright Markus Rickert 2008
+//
+// 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/io.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/numeric/ublas/matrix_proxy.hpp>
+#include <boost/numeric/ublas/vector.hpp>
+#include <boost/numeric/ublas/vector_proxy.hpp>
+#include <boost/numeric/bindings/blas/blas.hpp>
+#include <boost/numeric/bindings/traits/c_array.hpp>
+#include <boost/numeric/bindings/traits/c_array2.hpp>
+#include <boost/numeric/bindings/traits/dense_traits.hpp>
+#include <boost/numeric/bindings/traits/std_valarray.hpp>
+#include <boost/numeric/bindings/traits/std_valarray2.hpp>
+#include <boost/numeric/bindings/traits/std_vector.hpp>
+#include <boost/numeric/bindings/traits/std_vector2.hpp>
+#include <boost/numeric/bindings/traits/ublas_matrix.hpp>
+#include <boost/numeric/bindings/traits/ublas_vector.hpp>
+#include <boost/numeric/bindings/traits/ublas_vector2.hpp>
+
+int
+main(int argc, char** argv)
+{
+ {
+ // a * b' = C ; a' * b = d
+
+ boost::numeric::ublas::vector<double> a(3);
+ for (std::size_t i = 0; i < a.size(); ++i) a(i) = i;
+ std::cout << "a=" << a << std::endl;
+
+ boost::numeric::ublas::vector<double> b(3);
+ for (std::size_t i = 0; i < b.size(); ++i) b(i) = i;
+ std::cout << "b=" << b << std::endl;
+
+ boost::numeric::ublas::matrix<double, boost::numeric::ublas::column_major> c(3, 3);
+ boost::numeric::bindings::blas::gemm(
+ boost::numeric::bindings::traits::NO_TRANSPOSE,
+ boost::numeric::bindings::traits::TRANSPOSE,
+ 1.0, a, b, 0.0, c
+ );
+ std::cout << "c=" << c << std::endl;
+
+ boost::numeric::ublas::vector<double> d(1);
+ boost::numeric::bindings::blas::gemm(
+ boost::numeric::bindings::traits::TRANSPOSE,
+ boost::numeric::bindings::traits::NO_TRANSPOSE,
+ 1.0, a, b, 0.0, d
+ );
+ std::cout << "d=" << d << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ {
+ // a * b' = C ; a' * b = d
+
+ std::vector<double> a(3);
+ for (std::size_t i = 0; i < a.size(); ++i) a[i] = i;
+ std::cout << "a=[" << a.size() << "](";
+ for (std::size_t i = 0; i < a.size(); ++i) std::cout << (i > 0 ? "," : "") << a[i];
+ std::cout << ")" << std::endl;
+
+ std::valarray<double> b(3);
+ for (std::size_t i = 0; i < b.size(); ++i) b[i] = i;
+ std::cout << "b=[" << b.size() << "](";
+ for (std::size_t i = 0; i < b.size(); ++i) std::cout << (i > 0 ? "," : "") << b[i];
+ std::cout << ")" << std::endl;
+
+ boost::numeric::ublas::matrix<double, boost::numeric::ublas::column_major> c(3, 3);
+ boost::numeric::bindings::blas::gemm(
+ boost::numeric::bindings::traits::NO_TRANSPOSE,
+ boost::numeric::bindings::traits::TRANSPOSE,
+ 1.0, a, b, 0.0, c
+ );
+ std::cout << "c=" << c << std::endl;
+
+ std::vector<double> d(1);
+ boost::numeric::bindings::blas::gemm(
+ boost::numeric::bindings::traits::TRANSPOSE,
+ boost::numeric::bindings::traits::NO_TRANSPOSE,
+ 1.0, a, b, 0.0, d
+ );
+ std::cout << "d=[" << d.size() << "](";
+ for (std::size_t i = 0; i < d.size(); ++i) std::cout << (i > 0 ? "," : "") << d[i];
+ std::cout << ")" << std::endl;
+ }
+
+ std::cout << std::endl;
+
+ {
+ // a * b' = C ; a' * b = d
+
+ double a[3];
+ for (std::size_t i = 0; i < 3; ++i) a[i] = i;
+ std::cout << "a=[" << 3 << "](";
+ for (std::size_t i = 0; i < 3; ++i) std::cout << (i > 0 ? "," : "") << a[i];
+ std::cout << ")" << std::endl;
+
+ std::vector<double> b(3);
+ for (std::size_t i = 0; i < b.size(); ++i) b[i] = i;
+ std::cout << "b=[" << b.size() << "](";
+ for (std::size_t i = 0; i < b.size(); ++i) std::cout << (i > 0 ? "," : "") << b[i];
+ std::cout << ")" << std::endl;
+
+ boost::numeric::ublas::matrix<double, boost::numeric::ublas::column_major> c(3, 3);
+ boost::numeric::bindings::blas::gemm(
+ boost::numeric::bindings::traits::NO_TRANSPOSE,
+ boost::numeric::bindings::traits::TRANSPOSE,
+ 1.0, a, b, 0.0, c
+ );
+ std::cout << "c=" << c << std::endl;
+
+ std::valarray<double> d(1);
+ boost::numeric::bindings::blas::gemm(
+ boost::numeric::bindings::traits::TRANSPOSE,
+ boost::numeric::bindings::traits::NO_TRANSPOSE,
+ 1.0, a, b, 0.0, d
+ );
+ std::cout << "d=[" << d.size() << "](";
+ for (std::size_t i = 0; i < d.size(); ++i) std::cout << (i > 0 ? "," : "") << d[i];
+ std::cout << ")" << std::endl;
+ }
+
+ return 0;
+}
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