00001 /* 00002 * 00003 * Copyright (c) 2002, 2003 Kresimir Fresl, Toon Knapen and Karl Meerbergen 00004 * 00005 * Distributed under the Boost Software License, Version 1.0. 00006 * (See accompanying file LICENSE_1_0.txt or copy at 00007 * http://www.boost.org/LICENSE_1_0.txt) 00008 * 00009 * KF acknowledges the support of the Faculty of Civil Engineering, 00010 * University of Zagreb, Croatia. 00011 * 00012 */ 00013 00014 #ifndef BOOST_NUMERIC_BINDINGS_TRAITS_MATRIX_TRAITS_HPP 00015 #define BOOST_NUMERIC_BINDINGS_TRAITS_MATRIX_TRAITS_HPP 00016 00017 #include <boost/numeric/bindings/traits/config.hpp> 00018 00019 #ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS 00020 00021 #include <boost/numeric/bindings/traits/detail/generate_const.hpp> 00022 #include <boost/type_traits/remove_const.hpp> 00023 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK 00024 # include <boost/type_traits/is_same.hpp> 00025 # include <boost/static_assert.hpp> 00026 #endif 00027 00028 namespace boost { namespace numeric { namespace bindings { namespace traits { 00029 00032 00033 00040 template <typename MIdentifier, typename MType> 00041 struct matrix_detail_traits { 00042 typedef MIdentifier identifier_type; 00043 typedef MType matrix_type; 00044 }; 00045 00047 template <typename M> 00048 struct matrix_traits : matrix_detail_traits< typename boost::remove_const<M>::type, M> { 00049 // typedefs: 00050 // matrix_structure 00051 // ordering_type 00052 // value_type 00053 // pointer 00054 // symmetric/hermitian typedefs: 00055 // uplo_type 00056 // static functions: 00057 // pointer storage() 00058 // int size1() 00059 // int size2() 00060 // int lower_bandwidth() // only banded matrix types 00061 // int upper_bandwidth() // only banded matrix types 00062 // int storage_size() // not all matrix types 00063 // int leading_dimension() // not all matrix types 00064 }; 00065 00066 // matrix structure tags: 00067 struct general_t {}; 00068 struct symmetric_t {}; 00069 struct symmetric_packed_t {}; 00070 struct hermitian_t {}; 00071 struct hermitian_packed_t {}; 00072 struct banded_t {}; 00073 // TO DO: add triangular, etc. 00074 struct unknown_structure_t {}; 00075 00076 // storage ordering tags: 00077 struct row_major_t {}; 00078 struct column_major_t {}; 00079 00080 // upper/lower triangular part tags: 00081 struct upper_t {}; 00082 struct lower_t {}; 00083 00084 00086 // 00087 // free accessor functions 00088 // 00090 00091 template <typename M> 00092 inline 00093 typename matrix_traits<M>::pointer matrix_storage (M& m) { 00094 return matrix_traits<M>::storage (m); 00095 } 00096 00097 template <typename M> 00098 inline 00099 int matrix_size1 (M& m) { return matrix_traits<M>::size1 (m); } 00100 00101 template <typename M> 00102 inline 00103 int matrix_size2 (M& m) { return matrix_traits<M>::size2 (m); } 00104 00105 template <typename M> 00106 inline 00107 int matrix_storage_size (M& m) { return matrix_traits<M>::storage_size (m); } 00108 00109 template <typename M> 00110 inline 00111 int matrix_stride1 (M& m) { return matrix_traits<M>::stride1 (m); } 00112 00113 template <typename M> 00114 inline 00115 int matrix_stride2 (M& m) { return matrix_traits<M>::stride2 (m); } 00116 00117 template <typename M> 00118 inline 00119 int matrix_upper_bandwidth (M& m) { return matrix_traits<M>::upper_bandwidth (m); } 00120 00121 template <typename M> 00122 inline 00123 int matrix_lower_bandwidth (M& m) { return matrix_traits<M>::lower_bandwidth (m); } 00124 00125 template <typename M> 00126 inline 00127 int leading_dimension (M& m) { 00128 return matrix_traits<M>::leading_dimension (m); 00129 } 00130 00131 namespace detail { 00132 00133 inline char matrix_uplo_tag (upper_t const&) { return 'U'; } 00134 inline char matrix_uplo_tag (lower_t const&) { return 'L'; } 00135 00136 } 00137 00138 template <typename SymmM> 00139 inline 00140 char matrix_uplo_tag (SymmM&) { 00141 typedef typename matrix_traits<SymmM>::uplo_type uplo_t; 00142 return detail::matrix_uplo_tag (uplo_t()); 00143 } 00144 00145 }}}} 00146 00147 #else // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS 00148 00149 #include <boost/numeric/bindings/traits/matrix_raw.hpp> 00150 00151 #endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS 00152 00153 #endif // BOOST_NUMERIC_BINDINGS_TRAITS_MATRIX_TRAITS_HPP