|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56602 - in trunk: boost/numeric/ublas boost/numeric/ublas/operation boost/numeric/ublas/traits libs/numeric/ublas/test
From: guwi17_at_[hidden]
Date: 2009-10-05 16:57:42
Author: guwi17
Date: 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
New Revision: 56602
URL: http://svn.boost.org/trac/boost/changeset/56602
Log:
see #3449: introduce new free functions to access matrix/vector properties (Incomplete)
* added patch from Marco Guazzone implementing all requested new functions
Added:
trunk/boost/numeric/ublas/operation/
trunk/boost/numeric/ublas/operation/begin.hpp (contents, props changed)
trunk/boost/numeric/ublas/operation/c_array.hpp (contents, props changed)
trunk/boost/numeric/ublas/operation/end.hpp (contents, props changed)
trunk/boost/numeric/ublas/operation/num_columns.hpp (contents, props changed)
trunk/boost/numeric/ublas/operation/num_rows.hpp (contents, props changed)
trunk/boost/numeric/ublas/operation/size.hpp (contents, props changed)
trunk/boost/numeric/ublas/operations.hpp (contents, props changed)
trunk/boost/numeric/ublas/tags.hpp (contents, props changed)
trunk/boost/numeric/ublas/traits/const_iterator_type.hpp (contents, props changed)
trunk/boost/numeric/ublas/traits/iterator_type.hpp (contents, props changed)
trunk/libs/numeric/ublas/test/begin_end.cpp (contents, props changed)
trunk/libs/numeric/ublas/test/num_columns.cpp (contents, props changed)
trunk/libs/numeric/ublas/test/num_rows.cpp (contents, props changed)
trunk/libs/numeric/ublas/test/size.cpp (contents, props changed)
trunk/libs/numeric/ublas/test/utils.hpp (contents, props changed)
Text files modified:
trunk/libs/numeric/ublas/test/Jamfile.v2 | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
Added: trunk/boost/numeric/ublas/operation/begin.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/operation/begin.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,318 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file begin.hpp
+ *
+ * \brief The \c begin operation.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+#ifndef BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP
+#define BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP
+
+
+#include <boost/numeric/ublas/expression_types.hpp>
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/traits/const_iterator_type.hpp>
+#include <boost/numeric/ublas/traits/iterator_type.hpp>
+
+
+namespace boost { namespace numeric { namespace ublas {
+
+ namespace detail {
+
+ /**
+ * \brief Auxiliary class for implementing the \c begin operation.
+ * \tparam CategoryT The expression category type (e.g., vector_tag).
+ * \tparam TagT The dimension type tag (e.g., tag::major).
+ * \tparam OrientationT The orientation category type (e.g., row_major_tag).
+ */
+ template <typename CategoryT, typename TagT=void, typename OrientationT=void>
+ struct begin_impl;
+
+
+ /// \brief Specialization of \c begin_impl for iterating vector expressions.
+ template <>
+ struct begin_impl<vector_tag,void,void>
+ {
+ /**
+ * \brief Return an iterator to the first element of the given vector
+ * expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return An iterator over the given vector expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator apply(ExprT& e)
+ {
+ return e.begin();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the first element of the given vector
+ * expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return A const iterator to the first element of the given vector
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator apply(ExprT const& e)
+ {
+ return e.begin();
+ }
+ };
+
+
+ /// \brief Specialization of \c begin_impl for iterating matrix expressions with
+ /// a row-major orientation over the major dimension.
+ template <>
+ struct begin_impl<matrix_tag,tag::major,row_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the first element of the given row-major
+ * matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator1 apply(ExprT& e)
+ {
+ return e.begin1();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the first element of the given
+ * row-major matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator1 apply(ExprT const& e)
+ {
+ return e.begin1();
+ }
+ };
+
+
+ /// \brief Specialization of \c begin_impl for iterating matrix expressions with
+ /// a column-major orientation over the major dimension.
+ template <>
+ struct begin_impl<matrix_tag,tag::major,column_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the first element of the given column-major
+ * matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator2 apply(ExprT& e)
+ {
+ return e.begin2();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the first element of the given
+ * column-major matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator2 apply(ExprT const& e)
+ {
+ return e.begin2();
+ }
+ };
+
+
+ /// \brief Specialization of \c begin_impl for iterating matrix expressions with
+ /// a row-major orientation over the minor dimension.
+ template <>
+ struct begin_impl<matrix_tag,tag::minor,row_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the first element of the given row-major
+ * matrix expression over the minor dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator2 apply(ExprT& e)
+ {
+ return e.begin2();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the first element of the given
+ * row-major matrix expression over the minor dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator2 apply(ExprT const& e)
+ {
+ return e.begin2();
+ }
+ };
+
+
+
+ /// \brief Specialization of \c begin_impl for iterating matrix expressions with
+ /// a column-major orientation over the minor dimension.
+ template <>
+ struct begin_impl<matrix_tag,tag::minor,column_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the first element of the given column-major
+ * matrix expression over the minor dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator1 apply(ExprT& e)
+ {
+ return e.begin1();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the first element of the given
+ * column-major matrix expression over the minor dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator1 apply(ExprT const& e)
+ {
+ return e.begin1();
+ }
+ };
+
+ } // Namespace detail
+
+
+ /**
+ * \brief An iterator to the first element of the given vector expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return An iterator to the first element of the given vector expression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename ExprT::iterator begin(vector_expression<ExprT>& e)
+ {
+ return detail::begin_impl<typename ExprT::type_category>::apply(e());
+ }
+
+
+ /**
+ * \brief A const iterator to the first element of the given vector expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return A const iterator to the first element of the given vector expression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename ExprT::const_iterator begin(vector_expression<ExprT> const& e)
+ {
+ return detail::begin_impl<typename ExprT::type_category>::apply(e());
+ }
+
+
+ /**
+ * \brief An iterator to the first element of the given matrix expression
+ * according to its orientation.
+ * \tparam DimTagT A dimension tag type (e.g., tag::major).
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator to the first element of the given matrix expression
+ * according to its orientation.
+ */
+ template <typename TagT, typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename iterator_type<ExprT,TagT>::type begin(matrix_expression<ExprT>& e)
+ {
+ return detail::begin_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
+ }
+
+
+ /**
+ * \brief A const iterator to the first element of the given matrix expression
+ * according to its orientation.
+ * \tparam TagT A dimension tag type (e.g., tag::major).
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator to the first element of the given matrix expression
+ * according to its orientation.
+ */
+ template <typename TagT, typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename const_iterator_type<ExprT,TagT>::type begin(matrix_expression<ExprT> const& e)
+ {
+ return detail::begin_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
+ }
+
+
+ /**
+ * \brief An iterator to the first element over the dual dimension of the given
+ * iterator.
+ * \tparam IteratorT A model of Iterator type.
+ * \param it An iterator.
+ * \return An iterator to the first element over the dual dimension of the given
+ * iterator.
+ */
+ template <typename IteratorT>
+ BOOST_UBLAS_INLINE
+ typename IteratorT::dual_iterator_type begin(IteratorT& it)
+ {
+ return it.begin();
+ }
+
+
+ /**
+ * \brief A const iterator to the first element over the dual dimension of the
+ * given iterator.
+ * \tparam IteratorT A model of Iterator type.
+ * \param it An iterator.
+ * \return A const iterator to the first element over the dual dimension of the
+ * given iterator.
+ */
+ template <typename IteratorT>
+ BOOST_UBLAS_INLINE
+ typename IteratorT::dual_iterator_type begin(IteratorT const& it)
+ {
+ return it.begin();
+ }
+
+}}} // Namespace boost::numeric::ublas
+
+
+#endif // BOOST_NUMERIC_UBLAS_OPERATION_BEGIN_HPP
Added: trunk/boost/numeric/ublas/operation/c_array.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/operation/c_array.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,41 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file c_array.hpp
+ *
+ * \brief provides specializations of matrix and vector operations for c arrays and c matrices.
+ *
+ * Copyright (c) 2009, Gunter Winkler
+ *
+ * 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)
+ *
+ * \author Gunter Winkler (guwi17 at gmx dot de)
+ */
+
+#ifndef BOOST_NUMERIC_UBLAS_OPERATION_C_ARRAY_HPP
+#define BOOST_NUMERIC_UBLAS_OPERATION_C_ARRAY_HPP
+
+#include <boost/numeric/ublas/traits/c_array.hpp>
+
+namespace boost { namespace numeric { namespace ublas {
+
+ namespace detail {
+
+
+
+ } // namespace boost::numeric::ublas::detail
+
+
+ template <typename T>
+ BOOST_UBLAS_INLINE
+ typename ExprT::const_iterator begin(vector_expression<ExprT> const& e)
+ {
+ return detail::begin_impl<typename ExprT::type_category>::apply(e());
+ }
+
+
+}}} // Namespace boost::numeric::ublas
+
+#endif
Added: trunk/boost/numeric/ublas/operation/end.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/operation/end.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,318 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file end.hpp
+ *
+ * \brief The \c end operation.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+
+#ifndef BOOST_NUMERIC_UBLAS_OPERATION_END_HPP
+#define BOOST_NUMERIC_UBLAS_OPERATION_END_HPP
+
+
+#include <boost/numeric/ublas/expression_types.hpp>
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/traits/const_iterator_type.hpp>
+#include <boost/numeric/ublas/traits/iterator_type.hpp>
+
+
+namespace boost { namespace numeric { namespace ublas {
+
+ namespace detail {
+
+ /**
+ * \brief Auxiliary class for implementing the \c end operation.
+ * \tparam CategoryT The expression category type (e.g., vector_tag).
+ * \tparam TagT The dimension type tag (e.g., tag::major).
+ * \tparam OrientationT The orientation category type (e.g., row_major_tag).
+ */
+ template <typename CategoryT, typename TagT=void, typename OrientationT=void>
+ struct end_impl;
+
+
+ /// \brief Specialization of \c end_impl for iterating vector expressions.
+ template <>
+ struct end_impl<vector_tag,void,void>
+ {
+ /**
+ * \brief Return an iterator to the last element of the given vector
+ * expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return An iterator over the given vector expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator apply(ExprT& e)
+ {
+ return e.end();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the last element of the given vector
+ * expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return A const iterator to the first element of the given vector
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator apply(ExprT const& e)
+ {
+ return e.end();
+ }
+ };
+
+
+ /// \brief Specialization of \c end_impl for iterating matrix expressions with a
+ /// row-major orientation over the major dimension.
+ template <>
+ struct end_impl<matrix_tag,tag::major,row_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the last element of the given row-major
+ * matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator1 apply(ExprT& e)
+ {
+ return e.end1();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the last element of the given row-major
+ * matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator1 apply(ExprT const& e)
+ {
+ return e.end1();
+ }
+ };
+
+
+ /// \brief Specialization of \c end_impl for iterating matrix expressions with a
+ /// column-major orientation over the major dimension.
+ template <>
+ struct end_impl<matrix_tag,tag::major,column_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the last element of the given column-major
+ * matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator2 apply(ExprT& e)
+ {
+ return e.end2();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the last element of the given
+ * column-major matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the major dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator2 apply(ExprT const& e)
+ {
+ return e.end2();
+ }
+ };
+
+
+ /// \brief Specialization of \c end_impl for iterating matrix expressions with a
+ /// row-major orientation over the minor dimension.
+ template <>
+ struct end_impl<matrix_tag,tag::minor,row_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the last element of the given row-major
+ * matrix expression over the minor dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator2 apply(ExprT& e)
+ {
+ return e.end2();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the last element of the given
+ * row-minor matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator2 apply(ExprT const& e)
+ {
+ return e.end2();
+ }
+ };
+
+
+ /// \brief Specialization of \c end_impl for iterating matrix expressions with a
+ /// column-major orientation over the minor dimension.
+ template <>
+ struct end_impl<matrix_tag,tag::minor,column_major_tag>
+ {
+ /**
+ * \brief Return an iterator to the last element of the given column-major
+ * matrix expression over the minor dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::iterator1 apply(ExprT& e)
+ {
+ return e.end1();
+ }
+
+
+ /**
+ * \brief Return a const iterator to the last element of the given
+ * column-minor matrix expression over the major dimension.
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator over the minor dimension of the given matrix
+ * expression.
+ */
+ template <typename ExprT>
+ static typename ExprT::const_iterator1 apply(ExprT const& e)
+ {
+ return e.end1();
+ }
+ };
+
+ } // Namespace detail
+
+
+ /**
+ * \brief An iterator to the last element of the given vector expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return An iterator to the last element of the given vector expression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename ExprT::iterator end(vector_expression<ExprT>& e)
+ {
+ return detail::end_impl<typename ExprT::type_category>::apply(e());
+ }
+
+
+ /**
+ * \brief A const iterator to the last element of the given vector expression.
+ * \tparam ExprT A model of VectorExpression type.
+ * \param e A vector expression.
+ * \return A const iterator to the last element of the given vector expression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename ExprT::const_iterator end(vector_expression<ExprT> const& e)
+ {
+ return detail::end_impl<typename ExprT::type_category>::apply(e());
+ }
+
+
+ /**
+ * \brief An iterator to the last element of the given matrix expression
+ * according to its orientation.
+ * \tparam DimTagT A dimension tag type (e.g., tag::major).
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return An iterator to the last element of the given matrix expression
+ * according to its orientation.
+ */
+ template <typename TagT, typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename iterator_type<ExprT,TagT>::type end(matrix_expression<ExprT>& e)
+ {
+ return detail::end_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
+ }
+
+
+ /**
+ * \brief A const iterator to the last element of the given matrix expression
+ * according to its orientation.
+ * \tparam TagT A dimension tag type (e.g., tag::major).
+ * \tparam ExprT A model of MatrixExpression type.
+ * \param e A matrix expression.
+ * \return A const iterator to the last element of the given matrix expression
+ * according to its orientation.
+ */
+ template <typename TagT, typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename const_iterator_type<ExprT,TagT>::type end(matrix_expression<ExprT> const& e)
+ {
+ return detail::end_impl<typename ExprT::type_category, TagT, typename ExprT::orientation_category>::apply(e());
+ }
+
+
+ /**
+ * \brief An iterator to the last element over the dual dimension of the given
+ * iterator.
+ * \tparam IteratorT A model of Iterator type.
+ * \param it An iterator.
+ * \return An iterator to the last element over the dual dimension of the given
+ * iterator.
+ */
+ template <typename IteratorT>
+ BOOST_UBLAS_INLINE
+ typename IteratorT::dual_iterator_type end(IteratorT& it)
+ {
+ return it.end();
+ }
+
+
+ /**
+ * \brief A const iterator to the last element over the dual dimension of the
+ * given iterator.
+ * \tparam IteratorT A model of Iterator type.
+ * \param it An iterator.
+ * \return A const iterator to the last element over the dual dimension of the
+ * given iterator.
+ */
+ template <typename IteratorT>
+ BOOST_UBLAS_INLINE
+ typename IteratorT::dual_iterator_type end(IteratorT const& it)
+ {
+ return it.end();
+ }
+
+}}} // Namespace boost::numeric::ublas
+
+
+#endif // BOOST_NUMERIC_UBLAS_OPERATION_END_HPP
Added: trunk/boost/numeric/ublas/operation/num_columns.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/operation/num_columns.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,43 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file num_columns.hpp
+ *
+ * \brief The \c num_columns operation.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+
+#ifndef BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP
+#define BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP
+
+
+#include <boost/numeric/ublas/detail/config.hpp>
+
+
+namespace boost { namespace numeric { namespace ublas {
+
+ /**
+ * \brief Return the number of columns.
+ * \tparam MatrixExprT A type which models the matrix expression concept.
+ * \param m A matrix expression.
+ * \return The number of columns.
+ */
+ template <typename MatrixExprT>
+ BOOST_UBLAS_INLINE
+ typename MatrixExprT::size_type num_columns(MatrixExprT const& m)
+ {
+ return m.size2();
+ }
+
+}}} // Namespace boost::numeric::ublas
+
+
+#endif // BOOST_NUMERIC_UBLAS_OPERATION_NUM_COLUMNS_HPP
Added: trunk/boost/numeric/ublas/operation/num_rows.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/operation/num_rows.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,42 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file num_rows.hpp
+ *
+ * \brief The \c num_rows operation.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+#ifndef BOOST_NUMERIC_UBLAS_OPERATION_NUM_ROWS_HPP
+#define BOOST_NUMERIC_UBLAS_OPERATION_NUM_ROWS_HPP
+
+
+#include <boost/numeric/ublas/detail/config.hpp>
+
+
+namespace boost { namespace numeric { namespace ublas {
+
+ /**
+ * \brief Return the number of rows.
+ * \tparam MatrixExprT A type which models the matrix expression concept.
+ * \param m A matrix expression.
+ * \return The number of rows.
+ */
+ template <typename MatrixExprT>
+ BOOST_UBLAS_INLINE
+ typename MatrixExprT::size_type num_rows(MatrixExprT const& m)
+ {
+ return m.size1();
+ }
+
+}}} // Namespace boost::numeric::ublas
+
+
+#endif // BOOST_NUMERIC_UBLAS_OPERATION_NUM_ROWS_HPP
Added: trunk/boost/numeric/ublas/operation/size.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/operation/size.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,273 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file size.hpp
+ *
+ * \brief The \c size operation.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+#ifndef BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
+#define BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
+
+
+#include <boost/numeric/ublas/detail/config.hpp>
+#include <boost/numeric/ublas/expression_types.hpp>
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/tags.hpp>
+#include <cstddef>
+
+
+namespace boost { namespace numeric { namespace ublas {
+
+ namespace detail {
+
+ /**
+ * \brief Auxiliary class for computing the size of the given dimension for
+ * a container of the given category..
+ * \tparam Dim The dimension number (starting from 1).
+ * \tparam CategoryT The category type (e.g., vector_tag).
+ */
+ template <size_t Dim, typename CategoryT>
+ struct size_by_dim_impl;
+
+
+ /// \brief Specialization of \c size_by_dim_impl for computing the size of a
+ /// vector
+ template <>
+ struct size_by_dim_impl<1, vector_tag>
+ {
+ /**
+ * \brief Compute the size of the given vector.
+ * \tparam ExprT A vector expression type.
+ * \pre ExprT must be a model of VectorExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size();
+ }
+ };
+
+
+ /// \brief Specialization of \c size_by_dim_impl for computing the number of
+ /// rows of a matrix
+ template <>
+ struct size_by_dim_impl<1, matrix_tag>
+ {
+ /**
+ * \brief Compute the number of rows of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size1();
+ }
+ };
+
+
+ /// \brief Specialization of \c size_by_dim_impl for computing the number of
+ /// columns of a matrix
+ template <>
+ struct size_by_dim_impl<2, matrix_tag>
+ {
+ /**
+ * \brief Compute the number of columns of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size2();
+ }
+ };
+
+
+ /**
+ * \brief Auxiliary class for computing the size of the given dimension for
+ * a container of the given category and with the given orientation..
+ * \tparam Dim The dimension number (starting from 1).
+ * \tparam CategoryT The category type (e.g., vector_tag).
+ * \tparam OrientationT The orientation category type (e.g., row_major_tag).
+ */
+ template <typename TagT, typename CategoryT, typename OrientationT>
+ struct size_by_tag_impl;
+
+
+ /// \brief Specialization of \c size_by_tag_impl for computing the size of the
+ /// major dimension of a row-major oriented matrix.
+ template <>
+ struct size_by_tag_impl<tag::major, matrix_tag, row_major_tag>
+ {
+ /**
+ * \brief Compute the number of rows of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size1();
+ }
+ };
+
+
+ /// \brief Specialization of \c size_by_tag_impl for computing the size of the
+ /// minor dimension of a row-major oriented matrix.
+ template <>
+ struct size_by_tag_impl<tag::minor, matrix_tag, row_major_tag>
+ {
+ /**
+ * \brief Compute the number of columns of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size2();
+ }
+ };
+
+
+ /// \brief Specialization of \c size_by_tag_impl for computing the size of the
+ /// leading dimension of a row-major oriented matrix.
+ template <>
+ struct size_by_tag_impl<tag::leading, matrix_tag, row_major_tag>
+ {
+ /**
+ * \brief Compute the number of columns of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size2();
+ }
+ };
+
+
+ /// \brief Specialization of \c size_by_tag_impl for computing the size of the
+ /// major dimension of a column-major oriented matrix.
+ template <>
+ struct size_by_tag_impl<tag::major, matrix_tag, column_major_tag>
+ {
+ /**
+ * \brief Compute the number of columns of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size2();
+ }
+ };
+
+
+ /// \brief Specialization of \c size_by_tag_impl for computing the size of the
+ /// minor dimension of a column-major oriented matrix.
+ template <>
+ struct size_by_tag_impl<tag::minor, matrix_tag, column_major_tag>
+ {
+ /**
+ * \brief Compute the number of rows of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size1();
+ }
+ };
+
+
+ /// \brief Specialization of \c size_by_tag_impl for computing the size of the
+ /// leading dimension of a column-major oriented matrix.
+ template <>
+ struct size_by_tag_impl<tag::leading, matrix_tag, column_major_tag>
+ {
+ /**
+ * \brief Compute the number of rows of the given matrix.
+ * \tparam ExprT A matrix expression type.
+ * \pre ExprT must be a model of MatrixExpression.
+ */
+ template <typename ExprT>
+ BOOST_UBLAS_INLINE
+ static typename ExprT::size_type apply(ExprT const& e)
+ {
+ return e.size1();
+ }
+ };
+
+ } // Namespace detail
+
+
+ /**
+ * \brief Return the number of columns.
+ * \tparam MatrixExprT A type which models the matrix expression concept.
+ * \param m A matrix expression.
+ * \return The number of columns.
+ */
+ template <typename VectorExprT>
+ BOOST_UBLAS_INLINE
+ typename VectorExprT::size_type size(VectorExprT const& v)
+ {
+ return v.size();
+ }
+
+
+ /**
+ * \brief Return the size of the given dimension for the given expression.
+ * \tparam Dim The dimension number (starting from 1).
+ * \tparam ExprT An expression type.
+ * \param e An expression.
+ * \return The number of columns.
+ * \return The size associated to the dimension \a Dim.
+ */
+ template <std::size_t Dim, typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename ExprT::size_type size(ExprT const& e)
+ {
+ return detail::size_by_dim_impl<Dim, typename ExprT::type_category>::apply(e);
+ }
+
+
+ /**
+ * \brief Return the size of the given dimension tag for the given expression.
+ * \tparam TagT The dimension tag type (e.g., tag::major).
+ * \tparam ExprT An expression type.
+ * \param e An expression.
+ * \return The size associated to the dimension tag \a TagT.
+ */
+ template <typename TagT, typename ExprT>
+ BOOST_UBLAS_INLINE
+ typename ExprT::size_type size(ExprT const& e)
+ {
+ return detail::size_by_tag_impl<TagT, typename ExprT::type_category, typename ExprT::orientation_category>::apply(e);
+ }
+
+}}} // Namespace boost::numeric::ublas
+
+
+#endif // BOOST_NUMERIC_UBLAS_OPERATION_SIZE_HPP
Added: trunk/boost/numeric/ublas/operations.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/operations.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,26 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file operations.hpp
+ *
+ * \brief This header includes several headers from the operation directory.
+ *
+ * Copyright (c) 2009, Gunter Winkler
+ *
+ * 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)
+ *
+ * \author Gunter Winkler (guwi17 at gmx dot de)
+ */
+
+#ifndef BOOST_NUMERIC_UBLAS_OPERATIONS_HPP
+#define BOOST_NUMERIC_UBLAS_OPERATIONS_HPP
+
+#include <boost/numeric/ublas/operation/begin.hpp>
+#include <boost/numeric/ublas/operation/end.hpp>
+#include <boost/numeric/ublas/operation/num_columns.hpp>
+#include <boost/numeric/ublas/operation/num_rows.hpp>
+#include <boost/numeric/ublas/operation/size.hpp>
+
+#endif
Added: trunk/boost/numeric/ublas/tags.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/tags.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,37 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file tags.hpp
+ *
+ * \brief Tags.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+#ifndef BOOST_NUMERIC_UBLAS_TAG_HPP
+#define BOOST_NUMERIC_UBLAS_TAG_HPP
+
+
+namespace boost { namespace numeric { namespace ublas { namespace tag {
+
+/// \brief Tag for the major dimension.
+struct major {};
+
+
+/// \brief Tag for the minor dimension.
+struct minor {};
+
+
+/// \brief Tag for the leading dimension.
+struct leading {};
+
+}}}} // Namespace boost::numeric::ublas::tag
+
+
+#endif // BOOST_NUMERIC_UBLAS_TAG_HPP
Added: trunk/boost/numeric/ublas/traits/const_iterator_type.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/traits/const_iterator_type.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,127 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file const_iterator_type.hpp
+ *
+ * \brief Const iterator to a given container type.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+
+#ifndef BOOST_NUMERIC_UBLAS_TRAITS_CONST_ITERATOR_TYPE_HPP
+#define BOOST_NUMERIC_UBLAS_TRAITS_CONST_ITERATOR_TYPE_HPP
+
+
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/tags.hpp>
+#include <boost/numeric/ublas/traits.hpp>
+
+
+namespace boost { namespace numeric { namespace ublas {
+
+ namespace detail {
+
+ /**
+ * \brief Auxiliary class for retrieving the const iterator to the given
+ * matrix expression according its orientation and to the given dimension tag.
+ * \tparam MatrixT A model of MatrixExpression.
+ * \tparam TagT A dimension tag type (e.g., tag::major).
+ * \tparam OrientationT An orientation category type (e.g., row_major_tag).
+ */
+ template <typename MatrixT, typename TagT, typename OrientationT>
+ struct const_iterator_type_impl;
+
+
+ /// \brief Specialization of \c const_iterator_type_impl for row-major oriented
+ /// matrices and over the major dimension.
+ template <typename MatrixT>
+ struct const_iterator_type_impl<MatrixT,tag::major,row_major_tag>
+ {
+ typedef typename matrix_view_traits<MatrixT>::const_iterator1 type;
+ };
+
+
+ /// \brief Specialization of \c const_iterator_type_impl for column-major
+ /// oriented matrices and over the major dimension.
+ template <typename MatrixT>
+ struct const_iterator_type_impl<MatrixT,tag::major,column_major_tag>
+ {
+ typedef typename matrix_view_traits<MatrixT>::const_iterator2 type;
+ };
+
+
+ /// \brief Specialization of \c const_iterator_type_impl for row-major oriented
+ /// matrices and over the minor dimension.
+ template <typename MatrixT>
+ struct const_iterator_type_impl<MatrixT,tag::minor,row_major_tag>
+ {
+ typedef typename matrix_view_traits<MatrixT>::const_iterator2 type;
+ };
+
+
+ /// \brief Specialization of \c const_iterator_type_impl for column-major
+ /// oriented matrices and over the minor dimension.
+ template <typename MatrixT>
+ struct const_iterator_type_impl<MatrixT,tag::minor,column_major_tag>
+ {
+ typedef typename matrix_view_traits<MatrixT>::const_iterator1 type;
+ };
+
+ } // Namespace detail
+
+
+ /**
+ * \brief A const iterator for the given container type over the given
+ * dimension.
+ * \tparam ContainerT A container expression type.
+ * \tparam TagT A dimension tag type (e.g., tag::major).
+ */
+ template <typename ContainerT, typename TagT=void>
+ struct const_iterator_type;
+
+
+ /**
+ * \brief Specialization of \c const_iterator_type for vector expressions.
+ * \tparam VectorT A model of VectorExpression type.
+ */
+ template <typename VectorT>
+ struct const_iterator_type<VectorT, void>
+ {
+ typedef typename vector_view_traits<VectorT>::const_iterator type;
+ };
+
+
+ /**
+ * \brief Specialization of \c const_iterator_type for matrix expressions and
+ * over the major dimension.
+ * \tparam MatrixT A model of MatrixExpression type.
+ */
+ template <typename MatrixT>
+ struct const_iterator_type<MatrixT,tag::major>
+ {
+ typedef typename detail::const_iterator_type_impl<MatrixT,tag::minor,typename matrix_view_traits<MatrixT>::orientation_category>::type type;
+ };
+
+
+ /**
+ * \brief Specialization of \c const_iterator_type for matrix expressions and
+ * over the minor dimension.
+ * \tparam MatrixT A model of MatrixExpression type.
+ */
+ template <typename MatrixT>
+ struct const_iterator_type<MatrixT,tag::minor>
+ {
+ typedef typename detail::const_iterator_type_impl<MatrixT,tag::minor,typename matrix_view_traits<MatrixT>::orientation_category>::type type;
+ };
+
+}}} // Namespace boost::numeric::ublas
+
+
+#endif // BOOST_NUMERIC_UBLAS_TRAITS_CONST_ITERATOR_TYPE_HPP
Added: trunk/boost/numeric/ublas/traits/iterator_type.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/numeric/ublas/traits/iterator_type.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,126 @@
+/**
+ * -*- c++ -*-
+ *
+ * \file iterator_type.hpp
+ *
+ * \brief Iterator to a given container type.
+ *
+ * Copyright (c) 2009, Marco Guazzone
+ *
+ * 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)
+ *
+ * \author Marco Guazzone, marco.guazzone_at_[hidden]
+ */
+
+
+#ifndef BOOST_NUMERIC_UBLAS_TRAITS_ITERATOR_TYPE_HPP
+#define BOOST_NUMERIC_UBLAS_TRAITS_ITERATOR_TYPE_HPP
+
+
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/traits.hpp>
+#include <boost/numeric/ublas/tags.hpp>
+
+
+namespace boost { namespace numeric { namespace ublas {
+
+ namespace detail {
+
+ /**
+ * \brief Auxiliary class for retrieving the iterator to the given
+ * matrix expression according its orientation and to the given dimension tag.
+ * \tparam MatrixT A model of MatrixExpression.
+ * \tparam TagT A dimension tag type (e.g., tag::major).
+ * \tparam OrientationT An orientation category type (e.g., row_major_tag).
+ */
+ template <typename MatrixT, typename TagT, typename OrientationT>
+ struct iterator_type_impl;
+
+
+ /// \brief Specialization of \c iterator_type_impl for row-major oriented
+ /// matrices and over the major dimension.
+ template <typename MatrixT>
+ struct iterator_type_impl<MatrixT,tag::major,row_major_tag>
+ {
+ typedef typename matrix_traits<MatrixT>::iterator1 type;
+ };
+
+
+ /// \brief Specialization of \c iterator_type_impl for column-major oriented
+ /// matrices and over the major dimension.
+ template <typename MatrixT>
+ struct iterator_type_impl<MatrixT,tag::major,column_major_tag>
+ {
+ typedef typename matrix_traits<MatrixT>::iterator2 type;
+ };
+
+
+ /// \brief Specialization of \c iterator_type_impl for row-major oriented
+ /// matrices and over the minor dimension.
+ template <typename MatrixT>
+ struct iterator_type_impl<MatrixT,tag::minor,row_major_tag>
+ {
+ typedef typename matrix_traits<MatrixT>::iterator2 type;
+ };
+
+
+ /// \brief Specialization of \c iterator_type_impl for column-major oriented
+ /// matrices and over the minor dimension.
+ template <typename MatrixT>
+ struct iterator_type_impl<MatrixT,tag::minor,column_major_tag>
+ {
+ typedef typename matrix_traits<MatrixT>::iterator1 type;
+ };
+
+ } // Namespace detail
+
+
+ /**
+ * \brief A iterator for the given container type over the given dimension.
+ * \tparam ContainerT A container expression type.
+ * \tparam TagT A dimension tag type (e.g., tag::major).
+ */
+ template <typename ContainerT, typename TagT=void>
+ struct iterator_type;
+
+
+ /**
+ * \brief Specialization of \c iterator_type for vector expressions.
+ * \tparam VectorT A model of VectorExpression type.
+ */
+ template <typename VectorT>
+ struct iterator_type<VectorT, void>
+ {
+ typedef typename vector_traits<VectorT>::iterator type;
+ };
+
+
+ /**
+ * \brief Specialization of \c iterator_type for matrix expressions and
+ * over the major dimension.
+ * \tparam MatrixT A model of MatrixExpression type.
+ */
+ template <typename MatrixT>
+ struct iterator_type<MatrixT,tag::major>
+ {
+ typedef typename detail::iterator_type_impl<MatrixT,tag::major,typename matrix_traits<MatrixT>::orientation_category>::type type;
+ };
+
+
+ /**
+ * \brief Specialization of \c iterator_type for matrix expressions and
+ * over the minor dimension.
+ * \tparam MatrixT A model of MatrixExpression type.
+ */
+ template <typename MatrixT>
+ struct iterator_type<MatrixT,tag::minor>
+ {
+ typedef typename detail::iterator_type_impl<MatrixT,tag::minor,typename matrix_traits<MatrixT>::orientation_category>::type type;
+ };
+
+}}} // Namespace boost::numeric::ublas
+
+
+#endif // BOOST_NUMERIC_UBLAS_TRAITS_ITERATOR_TYPE_HPP
Modified: trunk/libs/numeric/ublas/test/Jamfile.v2
==============================================================================
--- trunk/libs/numeric/ublas/test/Jamfile.v2 (original)
+++ trunk/libs/numeric/ublas/test/Jamfile.v2 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -103,8 +103,10 @@
[ compile concepts.cpp
: # requirements
<define>EXTERNAL
+# <define>INTERAL
+# <define>SKIP_BAD
<toolset>intel-linux:<cxxflags>"-Xc"
- <toolset>darwin:<cxxflags>"-fabi-version=0"
+ <toolset>darwin:<cxxflags>"-fabi-version=0"
]
[ run test_lu.cpp
]
@@ -118,4 +120,12 @@
]
[ run sparse_view_test.cpp
]
+ [ run begin_end.cpp
+ ]
+ [ run num_columns.cpp
+ ]
+ [ run num_rows.cpp
+ ]
+ [ run size.cpp
+ ]
;
Added: trunk/libs/numeric/ublas/test/begin_end.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/begin_end.cpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,174 @@
+/** -*- c++ -*- \file begin_end.hpp \brief Test the \c begin and \c end operations. */
+
+#include <cmath>
+#include <boost/numeric/ublas/traits/const_iterator_type.hpp>
+#include <boost/numeric/ublas/traits/iterator_type.hpp>
+#include <boost/numeric/ublas/traits/c_array.hpp>
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/numeric/ublas/matrix_expression.hpp>
+#include <boost/numeric/ublas/operation/begin.hpp>
+#include <boost/numeric/ublas/operation/end.hpp>
+#include <boost/numeric/ublas/tags.hpp>
+#include <boost/numeric/ublas/vector.hpp>
+#include <boost/numeric/ublas/vector_expression.hpp>
+#include <iostream>
+#include "libs/numeric/ublas/test/utils.hpp"
+
+
+static const double TOL(1.0e-5); ///< Used for comparing two real numbers.
+
+
+BOOST_UBLAS_TEST_DEF( test_vector_iteration )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Vector Iteration" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::vector<value_type> vector_type;
+
+ vector_type v(5);
+
+ v(0) = 0.555950;
+ v(1) = 0.108929;
+ v(2) = 0.948014;
+ v(3) = 0.023787;
+ v(4) = 1.023787;
+
+
+ vector_type::size_type ix = 0;
+ for (
+ boost::numeric::ublas::iterator_type<vector_type>::type it = boost::numeric::ublas::begin<vector_type>(v);
+ it != boost::numeric::ublas::end<vector_type>(v);
+ ++it
+ ) {
+ BOOST_UBLAS_DEBUG_TRACE( "*it = " << *it << " ==> " << v(ix) );
+ BOOST_UBLAS_TEST_CHECK( std::fabs(*it - v(ix)) <= TOL );
+ ++ix;
+ }
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_vector_const_iteration )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Vector Const Iteration" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::vector<value_type> vector_type;
+
+ vector_type v(5);
+
+ v(0) = 0.555950;
+ v(1) = 0.108929;
+ v(2) = 0.948014;
+ v(3) = 0.023787;
+ v(4) = 1.023787;
+
+
+ vector_type::size_type ix = 0;
+ for (
+ boost::numeric::ublas::const_iterator_type<vector_type>::type it = boost::numeric::ublas::begin<vector_type>(v);
+ it != boost::numeric::ublas::end<vector_type>(v);
+ ++it
+ ) {
+ BOOST_UBLAS_DEBUG_TRACE( "*it = " << *it << " ==> " << v(ix) );
+ BOOST_UBLAS_TEST_CHECK( std::fabs(*it - v(ix)) <= TOL );
+ ++ix;
+ }
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_row_major_matrix_iteration )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Row-major Matrix Iteration" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::row_major> matrix_type;
+ typedef boost::numeric::ublas::iterator_type<matrix_type, boost::numeric::ublas::tag::major>::type outer_iterator_type;
+ typedef boost::numeric::ublas::iterator_type<matrix_type, boost::numeric::ublas::tag::minor>::type inner_iterator_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ matrix_type::size_type row(0);
+ for (
+ outer_iterator_type outer_it = boost::numeric::ublas::begin<boost::numeric::ublas::tag::major>(A);
+ outer_it != boost::numeric::ublas::end<boost::numeric::ublas::tag::major>(A);
+ ++outer_it
+ ) {
+ matrix_type::size_type col(0);
+
+ for (
+ inner_iterator_type inner_it = boost::numeric::ublas::begin(outer_it);
+ inner_it != boost::numeric::ublas::end(outer_it);
+ ++inner_it
+ ) {
+ BOOST_UBLAS_DEBUG_TRACE( "*it = " << *inner_it << " ==> " << A(row,col) );
+ BOOST_UBLAS_TEST_CHECK( std::fabs(*inner_it - A(row,col)) <= TOL );
+
+ ++col;
+ }
+
+ ++row;
+ }
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_col_major_matrix_iteration )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Column-major Matrix Iteration" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::column_major> matrix_type;
+ typedef boost::numeric::ublas::iterator_type<matrix_type, boost::numeric::ublas::tag::major>::type outer_iterator_type;
+ typedef boost::numeric::ublas::iterator_type<matrix_type, boost::numeric::ublas::tag::minor>::type inner_iterator_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ matrix_type::size_type col(0);
+ for (
+ outer_iterator_type outer_it = boost::numeric::ublas::begin<boost::numeric::ublas::tag::major>(A);
+ outer_it != boost::numeric::ublas::end<boost::numeric::ublas::tag::major>(A);
+ ++outer_it
+ ) {
+ matrix_type::size_type row(0);
+
+ for (
+ inner_iterator_type inner_it = boost::numeric::ublas::begin(outer_it);
+ inner_it != boost::numeric::ublas::end(outer_it);
+ ++inner_it
+ ) {
+ BOOST_UBLAS_DEBUG_TRACE( "*it = " << *inner_it << " ==> " << A(row,col) );
+ BOOST_UBLAS_TEST_CHECK( std::fabs(*inner_it - A(row,col)) <= TOL );
+
+ ++row;
+ }
+
+ ++col;
+ }
+}
+
+
+int main()
+{
+ BOOST_UBLAS_TEST_BEGIN();
+
+ BOOST_UBLAS_TEST_DO( test_vector_iteration );
+ BOOST_UBLAS_TEST_DO( test_vector_const_iteration );
+ BOOST_UBLAS_TEST_DO( test_row_major_matrix_iteration );
+ BOOST_UBLAS_TEST_DO( test_col_major_matrix_iteration );
+
+ BOOST_UBLAS_TEST_END();
+}
Added: trunk/libs/numeric/ublas/test/num_columns.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/num_columns.cpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,106 @@
+/** -*- c++ -*- \file num_columns.cpp \breif Test for the \c num_columns operation. */
+
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/numeric/ublas/matrix_expression.hpp>
+#include <boost/numeric/ublas/operation/num_columns.hpp>
+#include <iostream>
+#include "libs/numeric/ublas/test/utils.hpp"
+
+
+BOOST_UBLAS_TEST_DEF( test_row_major_matrix_container )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Row-major Matrix Container" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::row_major> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_columns(A) = " << boost::numeric::ublas::num_columns(A) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_columns(A) == A.size2() );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_col_major_matrix_container )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Column-major Matrix Container" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::column_major> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_columns(A) = " << boost::numeric::ublas::num_columns(A) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_columns(A) == A.size2() );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_matrix_expression )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Expression" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_columns(A') = " << boost::numeric::ublas::num_columns(boost::numeric::ublas::trans(A)) << " ==> " << boost::numeric::ublas::trans(A).size2() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_columns(boost::numeric::ublas::trans(A)) == boost::numeric::ublas::trans(A).size2() );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_matrix_reference )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Reference" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type> matrix_type;
+ typedef boost::numeric::ublas::matrix_reference<matrix_type> matrix_reference_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_columns(reference(A)) = " << boost::numeric::ublas::num_columns(matrix_reference_type(A)) << " ==> " << matrix_reference_type(A).size2() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_columns(matrix_reference_type(A)) == matrix_reference_type(A).size2() );
+}
+
+
+int main()
+{
+ BOOST_UBLAS_TEST_BEGIN();
+
+ BOOST_UBLAS_TEST_DO( test_row_major_matrix_container );
+ BOOST_UBLAS_TEST_DO( test_col_major_matrix_container );
+ BOOST_UBLAS_TEST_DO( test_matrix_expression );
+ BOOST_UBLAS_TEST_DO( test_matrix_reference );
+
+ BOOST_UBLAS_TEST_END();
+}
Added: trunk/libs/numeric/ublas/test/num_rows.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/num_rows.cpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,106 @@
+/** -*- c++ -*- \file num_rows.hpp \file Test the \c num_rows operation. */
+
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/numeric/ublas/matrix_expression.hpp>
+#include <boost/numeric/ublas/operation/num_rows.hpp>
+#include <iostream>
+#include "libs/numeric/ublas/test/utils.hpp"
+
+
+BOOST_UBLAS_TEST_DEF( test_row_major_matrix_container )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Row-major Matrix Container" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::row_major> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_rows(A) = " << boost::numeric::ublas::num_rows(A) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(A) == A.size1() );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_col_major_matrix_container )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Column-major Matrix Container" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::column_major> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_rows(A) = " << boost::numeric::ublas::num_rows(A) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(A) == A.size1() );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_matrix_expression )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Expression" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_rows(A') = " << boost::numeric::ublas::num_rows(boost::numeric::ublas::trans(A)) << " ==> " << boost::numeric::ublas::trans(A).size1() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(boost::numeric::ublas::trans(A)) == boost::numeric::ublas::trans(A).size1() );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_matrix_reference )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Reference" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type> matrix_type;
+ typedef boost::numeric::ublas::matrix_reference<matrix_type> matrix_reference_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ BOOST_UBLAS_DEBUG_TRACE( "num_rows(reference(A)) = " << boost::numeric::ublas::num_rows(matrix_reference_type(A)) << " ==> " << matrix_reference_type(A).size1() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::num_rows(matrix_reference_type(A)) == matrix_reference_type(A).size1() );
+}
+
+
+int main()
+{
+ BOOST_UBLAS_TEST_BEGIN();
+
+ BOOST_UBLAS_TEST_DO( test_row_major_matrix_container );
+ BOOST_UBLAS_TEST_DO( test_col_major_matrix_container );
+ BOOST_UBLAS_TEST_DO( test_matrix_expression );
+ BOOST_UBLAS_TEST_DO( test_matrix_reference );
+
+ BOOST_UBLAS_TEST_END();
+}
Added: trunk/libs/numeric/ublas/test/size.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/size.cpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,271 @@
+/** -*- c++ -*- \file size.hpp \brief Test the \c size operation. */
+
+#include <boost/numeric/ublas/fwd.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+#include <boost/numeric/ublas/matrix_expression.hpp>
+#include <boost/numeric/ublas/operation/size.hpp>
+#include <boost/numeric/ublas/tags.hpp>
+#include <boost/numeric/ublas/vector.hpp>
+#include <boost/numeric/ublas/vector_expression.hpp>
+#include <iostream>
+#include "libs/numeric/ublas/test/utils.hpp"
+
+
+BOOST_UBLAS_TEST_DEF( test_vector_container )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Vector Container" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::vector<value_type> vector_type;
+
+ vector_type v(5);
+
+ v(0) = 0.555950;
+ v(1) = 0.108929;
+ v(2) = 0.948014;
+ v(3) = 0.023787;
+ v(4) = 1.023787;
+
+
+ // size(v)
+ BOOST_UBLAS_DEBUG_TRACE( "size(v) = " << boost::numeric::ublas::size(v) << " ==> " << v.size() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::size(v) == v.size() );
+
+ // size<1>(v)
+ BOOST_UBLAS_DEBUG_TRACE( "size<1>(v) = " << (boost::numeric::ublas::size<1>(v)) << " ==> " << v.size() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<1>(v) == v.size()) );
+
+ // [NOT_COMPILE]: this should *correctly* cause a compilation error
+ // size<2>(v)
+ //BOOST_UBLAS_DEBUG_TRACE( "size<2>(v) = " << (boost::numeric::ublas::size<vector_type,2>(v)) << " ==> " << v.size() );
+ //BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<2>(v) == v.size()) );
+ // [/NOT_COMPILE]
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_vector_expression )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Vector Expression" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::vector<value_type> vector_type;
+
+ vector_type v(5);
+
+ v(0) = 0.555950;
+ v(1) = 0.108929;
+ v(2) = 0.948014;
+ v(3) = 0.023787;
+ v(4) = 1.023787;
+
+
+ // size(-v)
+ BOOST_UBLAS_DEBUG_TRACE( "size(-v) = " << boost::numeric::ublas::size(-v) << " ==> " << (-v).size() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::size(-v) == (-v).size() );
+
+ // size<1>(-v)
+ BOOST_UBLAS_DEBUG_TRACE( "size<1>(-v) = " << (boost::numeric::ublas::size<1>(-v)) << " ==> " << (-v).size() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<1>(-v) == (-v).size()) );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_vector_reference )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Vector Reference" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::vector<value_type> vector_type;
+ typedef boost::numeric::ublas::vector_reference<vector_type> vector_reference_type;
+
+ vector_type v(5);
+
+ v(0) = 0.555950;
+ v(1) = 0.108929;
+ v(2) = 0.948014;
+ v(3) = 0.023787;
+ v(4) = 1.023787;
+
+
+ // size(reference(v)
+ BOOST_UBLAS_DEBUG_TRACE( "size(reference(v)) = " << boost::numeric::ublas::size(vector_reference_type(v)) << " ==> " << vector_reference_type(v).size() );
+ BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::size(vector_reference_type(v)) == vector_reference_type(v).size() );
+
+ // size<1>(reference(v))
+ BOOST_UBLAS_DEBUG_TRACE( "size<1>(reference(v)) = " << (boost::numeric::ublas::size<1>(vector_reference_type(v))) << " ==> " << vector_reference_type(v).size() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<1>(vector_reference_type(v)) == vector_reference_type(v).size()) );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_row_major_matrix_container )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Row-major Matrix Container" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::row_major> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ // [NOT_COMPILE]
+ // size(A)
+ //BOOST_UBLAS_DEBUG_TRACE( "size(A) = " << boost::numeric::ublas::size(A) << " ==> " << A.size1() );
+ //BOOST_UBLAS_TEST_CHECK( boost::numeric::ublas::size(A) == A.size1() );
+ // [/NOT_COMPILE]
+
+ // size<1>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<1>(A) = " << (boost::numeric::ublas::size<1>(A)) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<1>(A) == A.size1()) );
+
+ // size<2>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<2>(A) = " << (boost::numeric::ublas::size<2>(A)) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<2>(A) == A.size2()) );
+
+ // size<major>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<major>(A) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(A)) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(A) == A.size1()) );
+
+ // size<minor>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<minor>(A) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(A)) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(A) == A.size2()) );
+
+ // size<leading>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<leading>(A) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(A)) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(A) == A.size2()) );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_col_major_matrix_container )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Column-major Matrix Container" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type, boost::numeric::ublas::column_major> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ // size<1>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<1>(A) = " << (boost::numeric::ublas::size<1>(A)) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<1>(A) == A.size1()) );
+
+ // size<2>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<2>(A) = " << (boost::numeric::ublas::size<2>(A)) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<2>(A) == A.size2()) );
+
+ // size<major>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<major>(A) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(A)) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(A) == A.size2()) );
+
+ // size<minor>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<minor>(A) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(A)) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(A) == A.size1()) );
+
+ // size<leading>(A)
+ BOOST_UBLAS_DEBUG_TRACE( "size<leading>(A) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(A)) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(A) == A.size1()) );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_matrix_expression )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Expression" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type> matrix_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ // size<1>(A')
+ BOOST_UBLAS_DEBUG_TRACE( "size<1>(A') = " << (boost::numeric::ublas::size<1>(boost::numeric::ublas::trans(A))) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<1>(boost::numeric::ublas::trans(A)) == A.size2()) );
+
+ // size<2>(A')
+ BOOST_UBLAS_DEBUG_TRACE( "size<2>(A') = " << (boost::numeric::ublas::size<2>(boost::numeric::ublas::trans(A))) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<2>(boost::numeric::ublas::trans(A)) == A.size1()) );
+
+ // size<major>(A') [A is row-major => A' column-major, and viceversa]
+ BOOST_UBLAS_DEBUG_TRACE( "size<major>(A') = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(boost::numeric::ublas::trans(A))) << " ==> " << A.size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(boost::numeric::ublas::trans(A)) == A.size1()) );
+
+ // size<minor>(A') [A is row-major => A' column-major, and viceversa]
+ BOOST_UBLAS_DEBUG_TRACE( "size<minor>(A') = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(boost::numeric::ublas::trans(A))) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(boost::numeric::ublas::trans(A)) == A.size2()) );
+
+ // size<leading>(A') [A row-major => A' column-major, and viceversa]
+ BOOST_UBLAS_DEBUG_TRACE( "size<leading>(A') = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(boost::numeric::ublas::trans(A))) << " ==> " << A.size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(boost::numeric::ublas::trans(A)) == A.size2()) );
+}
+
+
+BOOST_UBLAS_TEST_DEF( test_matrix_reference )
+{
+ BOOST_UBLAS_DEBUG_TRACE( "TEST Matrix Reference" );
+
+ typedef double value_type;
+ typedef boost::numeric::ublas::matrix<value_type> matrix_type;
+ typedef boost::numeric::ublas::matrix_reference<matrix_type> matrix_reference_type;
+
+ matrix_type A(5,4);
+
+ A(0,0) = 0.555950; A(0,1) = 0.274690; A(0,2) = 0.540605; A(0,3) = 0.798938;
+ A(1,0) = 0.108929; A(1,1) = 0.830123; A(1,2) = 0.891726; A(1,3) = 0.895283;
+ A(2,0) = 0.948014; A(2,1) = 0.973234; A(2,2) = 0.216504; A(2,3) = 0.883152;
+ A(3,0) = 0.023787; A(3,1) = 0.675382; A(3,2) = 0.231751; A(3,3) = 0.450332;
+ A(4,0) = 1.023787; A(4,1) = 1.675382; A(4,2) = 1.231751; A(4,3) = 1.450332;
+
+
+ // size<1>(reference(A))
+ BOOST_UBLAS_DEBUG_TRACE( "size<1>(reference(A)) = " << (boost::numeric::ublas::size<1>(matrix_reference_type(A))) << " ==> " << matrix_reference_type(A).size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<1>(matrix_reference_type(A)) == matrix_reference_type(A).size1()) );
+
+ // size<2>(reference(A))
+ BOOST_UBLAS_DEBUG_TRACE( "size<2>(reference(A)) = " << (boost::numeric::ublas::size<2>(matrix_reference_type(A))) << " ==> " << matrix_reference_type(A).size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<2>(matrix_reference_type(A)) == matrix_reference_type(A).size2()) );
+
+ // size<major>(reference(A))
+ BOOST_UBLAS_DEBUG_TRACE( "size<major>(reference(A) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(matrix_reference_type(A))) << " ==> " << matrix_reference_type(A).size1() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::major>(matrix_reference_type(A)) == matrix_reference_type(A).size1()) );
+
+ // size<minor>(reference(A))
+ BOOST_UBLAS_DEBUG_TRACE( "size<minor>(reference(A)) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(matrix_reference_type(A))) << " ==> " << matrix_reference_type(A).size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::minor>(matrix_reference_type(A)) == matrix_reference_type(A).size2()) );
+
+ // size<leading>(reference(A))
+ BOOST_UBLAS_DEBUG_TRACE( "size<leading>(reference(A)) = " << (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(matrix_reference_type(A))) << " ==> " << matrix_reference_type(A).size2() );
+ BOOST_UBLAS_TEST_CHECK( (boost::numeric::ublas::size<boost::numeric::ublas::tag::leading>(matrix_reference_type(A)) == matrix_reference_type(A).size2()) );
+}
+
+
+int main()
+{
+ BOOST_UBLAS_TEST_BEGIN();
+
+ BOOST_UBLAS_TEST_DO( test_vector_container );
+ BOOST_UBLAS_TEST_DO( test_vector_expression );
+ BOOST_UBLAS_TEST_DO( test_vector_reference );
+ BOOST_UBLAS_TEST_DO( test_row_major_matrix_container );
+ BOOST_UBLAS_TEST_DO( test_col_major_matrix_container );
+ BOOST_UBLAS_TEST_DO( test_matrix_expression );
+ BOOST_UBLAS_TEST_DO( test_matrix_reference );
+
+ BOOST_UBLAS_TEST_END();
+}
Added: trunk/libs/numeric/ublas/test/utils.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/numeric/ublas/test/utils.hpp 2009-10-05 16:57:40 EDT (Mon, 05 Oct 2009)
@@ -0,0 +1,33 @@
+/** -*- c++ -*- \file utils.hpp \brief Test utilities. */
+
+#ifndef TEST_UTILS_HPP
+#define TEST_UTILS_HPP
+
+
+#include <iostream>
+
+
+#define EXPAND_(x) x
+
+#define STRINGIFY_(x) #x
+
+#define JOIN_(x,y) x ## y
+
+#ifndef NDEBUG
+# define BOOST_UBLAS_DEBUG_TRACE(x) std::cerr << "[Debug>> " << EXPAND_(x) << std::endl
+#else
+# define BOOST_UBLAS_DEBUG_TRACE(x) /**/
+#endif // NDEBUG
+
+#define BOOST_UBLAS_TEST_BEGIN() unsigned int test_fails_(0)
+
+#define BOOST_UBLAS_TEST_DEF(x) void EXPAND_(x)(unsigned int& test_fails_)
+
+#define BOOST_UBLAS_TEST_DO(x) EXPAND_(x)(test_fails_)
+
+#define BOOST_UBLAS_TEST_END() if (test_fails_ > 0) { std::cerr << "Number of failed tests: " << test_fails_ << std::endl; } else { std::cerr << "No failed test" << std::endl; }
+
+#define BOOST_UBLAS_TEST_CHECK(x) if (!(x)) { std::cerr << "Failed assertion: " << STRINGIFY_(x) << std::endl; ++test_fails_; }
+
+
+#endif // TEST_UTILS_HPP
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