Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49546 - in sandbox/boost/numeric/bindings/traits: . detail
From: thomas.klimpel_at_[hidden]
Date: 2008-11-03 02:37:07


Author: klimpel
Date: 2008-11-03 02:37:05 EST (Mon, 03 Nov 2008)
New Revision: 49546
URL: http://svn.boost.org/trac/boost/changeset/49546

Log:
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/boost/numeric/bindings/traits/c_array2.hpp (contents, props changed)
   sandbox/boost/numeric/bindings/traits/dense_traits.hpp (contents, props changed)
   sandbox/boost/numeric/bindings/traits/detail/dense_ordering.hpp (contents, props changed)
   sandbox/boost/numeric/bindings/traits/std_valarray2.hpp (contents, props changed)
   sandbox/boost/numeric/bindings/traits/std_vector2.hpp (contents, props changed)

Added: sandbox/boost/numeric/bindings/traits/c_array2.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/numeric/bindings/traits/c_array2.hpp 2008-11-03 02:37:05 EST (Mon, 03 Nov 2008)
@@ -0,0 +1,66 @@
+/*
+ *
+ * Copyright (c) 2002, 2003 Kresimir Fresl, Toon Knapen and Karl Meerbergen
+ * Copyright (c) 2008 Markus Rickert
+ *
+ * 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)
+ *
+ * KF acknowledges the support of the Faculty of Civil Engineering,
+ * University of Zagreb, Croatia.
+ *
+ */
+
+#ifndef BOOST_NUMERIC_BINDINGS_TRAITS_C_ARRAY2_H
+#define BOOST_NUMERIC_BINDINGS_TRAITS_C_ARRAY2_H
+
+#include <boost/numeric/bindings/traits/config.hpp>
+
+#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#include <boost/numeric/bindings/traits/c_array.hpp>
+#include <boost/numeric/bindings/traits/matrix_traits.hpp>
+
+namespace boost { namespace numeric { namespace bindings { namespace traits {
+
+ // built-in array as matrix (nx1)
+ template <typename T, std::size_t N, typename V>
+ struct matrix_detail_traits<T[N], V>
+ {
+#ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
+ BOOST_STATIC_ASSERT(
+ (boost::is_same<
+ T[N],
+ typename boost::remove_const<V>::type
+ >::value) );
+#endif
+
+ typedef T identifier_type [N];
+ typedef V matrix_type;
+ typedef general_t matrix_structure;
+ typedef column_major_t ordering_type;
+
+ typedef T value_type;
+ typedef typename default_vector_traits< V, T >::pointer pointer;
+
+ static pointer storage (matrix_type& v) {
+ return vector_traits<matrix_type>::storage (v);
+ }
+ static std::ptrdiff_t num_rows (matrix_type& v) { return N; }
+ static std::ptrdiff_t num_columns (matrix_type&) { return 1; }
+ static std::ptrdiff_t storage_size (matrix_type& v) { return N; }
+// static std::ptrdiff_t stride1 (matrix_type& v) { return vector_traits<V>::stride (v); }
+// static std::ptrdiff_t stride2 (matrix_type&) { return 1; }
+ static std::ptrdiff_t leading_dimension (matrix_type& v) { return N; }
+ };
+
+}}}}
+
+#else // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#error with your compiler plain C array cannot be used in bindings
+
+#endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#endif // BOOST_NUMERIC_BINDINGS_TRAITS_C_ARRAY2_H

Added: sandbox/boost/numeric/bindings/traits/dense_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/numeric/bindings/traits/dense_traits.hpp 2008-11-03 02:37:05 EST (Mon, 03 Nov 2008)
@@ -0,0 +1,42 @@
+//
+// 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)
+//
+
+#ifndef BOOST_NUMERIC_BINDINGS_TRAITS_DENSE_TRAITS_H
+#define BOOST_NUMERIC_BINDINGS_TRAITS_DENSE_TRAITS_H
+
+#include <boost/numeric/bindings/traits/config.hpp>
+
+#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#include <boost/numeric/bindings/traits/traits.hpp>
+#include <boost/numeric/bindings/traits/detail/dense_ordering.hpp>
+
+namespace boost { namespace numeric { namespace bindings { namespace traits {
+
+ template <typename M>
+ inline
+ std::ptrdiff_t
+ dense_matrix_stride1 (M& m) {
+ return detail::dense_ordering< typename matrix_traits<M>::ordering_type >::stride1 (m);
+ }
+ template <typename M>
+ inline
+ std::ptrdiff_t
+ dense_matrix_stride2 (M& m) {
+ return detail::dense_ordering< typename matrix_traits<M>::ordering_type >::stride2 (m);
+ }
+
+}}}}
+
+#else // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#error with your compiler dense matrices cannot be used in bindings
+
+#endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#endif // BOOST_NUMERIC_BINDINGS_TRAITS_DENSE_TRAITS_H

Added: sandbox/boost/numeric/bindings/traits/detail/dense_ordering.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/numeric/bindings/traits/detail/dense_ordering.hpp 2008-11-03 02:37:05 EST (Mon, 03 Nov 2008)
@@ -0,0 +1,55 @@
+//
+// 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)
+//
+
+#ifndef BOOST_NUMERIC_BINDINGS_TRAITS_DETAIL_DENSE_ORDERING_H
+#define BOOST_NUMERIC_BINDINGS_TRAITS_DETAIL_DENSE_ORDERING_H
+
+#include <boost/numeric/ublas/fwd.hpp>
+
+namespace boost { namespace numeric { namespace bindings { namespace traits {
+
+ namespace detail {
+
+ template <typename StOrdTag>
+ struct dense_ordering {};
+
+ template<>
+ struct dense_ordering<row_major_t> {
+ typedef row_major_t type;
+
+ template <typename M>
+ static std::ptrdiff_t stride1( M const& m ) {
+ return leading_dimension (m) ;
+ }
+
+ template <typename M>
+ static std::ptrdiff_t stride2( M const& m ) {
+ return 1 ;
+ }
+ };
+
+ template<>
+ struct dense_ordering<column_major_t> {
+ typedef column_major_t type;
+
+ template <typename M>
+ static std::ptrdiff_t stride1( M const& m ) {
+ return 1 ;
+ }
+
+ template <typename M>
+ static std::ptrdiff_t stride2( M const& m ) {
+ return leading_dimension (m) ;
+ }
+ };
+
+ }
+
+}}}}
+
+#endif // BOOST_NUMERIC_BINDINGS_TRAITS_DETAIL_DENSE_ORDERING_H

Added: sandbox/boost/numeric/bindings/traits/std_valarray2.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/numeric/bindings/traits/std_valarray2.hpp 2008-11-03 02:37:05 EST (Mon, 03 Nov 2008)
@@ -0,0 +1,70 @@
+/*
+ *
+ * Copyright (c) 2002, 2003 Kresimir Fresl, Toon Knapen and Karl Meerbergen
+ * Copyright (c) 2008 Markus Rickert
+ *
+ * Permission to copy, modify, use and distribute this software
+ * for any non-commercial or commercial purpose is granted provided
+ * that this license appear on all copies of the software source code.
+ *
+ * Authors assume no responsibility whatsoever for its use and makes
+ * no guarantees about its quality, correctness or reliability.
+ *
+ * KF acknowledges the support of the Faculty of Civil Engineering,
+ * University of Zagreb, Croatia.
+ *
+ */
+
+#ifndef BOOST_NUMERIC_BINDINGS_TRAITS_STD_VALARRAY2_H
+#define BOOST_NUMERIC_BINDINGS_TRAITS_STD_VALARRAY2_H
+
+#include <boost/numeric/bindings/traits/config.hpp>
+
+#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#include <boost/numeric/bindings/traits/matrix_traits.hpp>
+#include <valarray>
+
+
+namespace boost { namespace numeric { namespace bindings { namespace traits {
+
+ // std::valarray<> treated as matrix (nx1)
+ template <typename T, typename V>
+ struct matrix_detail_traits<std::valarray<T>, V>
+ {
+#ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
+ BOOST_STATIC_ASSERT(
+ (boost::is_same<
+ std::valarray<T>,
+ typename boost::remove_const<V>::type
+ >::value) );
+#endif
+
+ typedef std::valarray<T> identifier_type;
+ typedef V matrix_type;
+ typedef general_t matrix_structure;
+ typedef column_major_t ordering_type;
+
+ typedef T value_type;
+ typedef typename default_vector_traits< V, T >::pointer pointer;
+
+ static pointer storage (matrix_type& v) {
+ return vector_traits<matrix_type>::storage (v);
+ }
+ static std::ptrdiff_t num_rows (matrix_type& v) { return v.size(); }
+ static std::ptrdiff_t num_columns (matrix_type&) { return 1; }
+ static std::ptrdiff_t storage_size (matrix_type& v) { return v.size(); }
+// static std::ptrdiff_t stride1 (matrix_type& v) { return vector_traits<V>::stride (v); }
+// static std::ptrdiff_t stride2 (matrix_type&) { return 1; }
+ static std::ptrdiff_t leading_dimension (matrix_type& v) { return v.size(); }
+ };
+
+}}}}
+
+#else // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#error with your compiler std::valarray<> cannot be used in bindings
+
+#endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#endif // BOOST_NUMERIC_BINDINGS_TRAITS_STD_VALARRAY2_H

Added: sandbox/boost/numeric/bindings/traits/std_vector2.hpp
==============================================================================
--- (empty file)
+++ sandbox/boost/numeric/bindings/traits/std_vector2.hpp 2008-11-03 02:37:05 EST (Mon, 03 Nov 2008)
@@ -0,0 +1,61 @@
+/*
+ *
+ * Copyright (c) 2002, 2003 Kresimir Fresl, Toon Knapen and Karl Meerbergen
+ *
+ * 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)
+ *
+ * KF acknowledges the support of the Faculty of Civil Engineering,
+ * University of Zagreb, Croatia.
+ *
+ */
+
+#ifndef BOOST_NUMERIC_BINDINGS_TRAITS_STD_VECTOR2_H
+#define BOOST_NUMERIC_BINDINGS_TRAITS_STD_VECTOR2_H
+
+#include <boost/numeric/bindings/traits/matrix_traits.hpp>
+
+#ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#include <vector>
+
+
+namespace boost { namespace numeric { namespace bindings { namespace traits {
+
+ // std::vector<> treated as matrix (nx1)
+ template <typename T, typename Alloc, typename V>
+ struct matrix_detail_traits<std::vector<T, Alloc>, V>
+ {
+#ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
+ BOOST_STATIC_ASSERT(
+ (boost::is_same<
+ std::vector<T, Alloc>,
+ typename boost::remove_const<V>::type
+ >::value) );
+#endif
+
+ typedef std::vector<T, Alloc> identifier_type;
+ typedef V matrix_type;
+ typedef general_t matrix_structure;
+ typedef column_major_t ordering_type;
+
+ typedef T value_type;
+ typedef typename default_vector_traits< V, T >::pointer pointer;
+
+ static pointer storage (matrix_type& v) {
+ return vector_traits<matrix_type>::storage (v);
+ }
+ static std::ptrdiff_t num_rows (matrix_type& v) { return v.size(); }
+ static std::ptrdiff_t num_columns (matrix_type&) { return 1; }
+ static std::ptrdiff_t storage_size (matrix_type& v) { return v.size(); }
+// static std::ptrdiff_t stride1 (matrix_type& v) { return vector_traits<V>::stride (v); }
+// static std::ptrdiff_t stride2 (matrix_type&) { return 1; }
+ static std::ptrdiff_t leading_dimension (matrix_type& v) { return v.size(); }
+ };
+
+}}}}
+
+#endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
+
+#endif // BOOST_NUMERIC_BINDINGS_TRAITS_STD_VECTOR2_H


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