00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef MTL_TRANS_INCLUDE
00013 #define MTL_TRANS_INCLUDE
00014
00015 #include <boost/numeric/mtl/mtl_fwd.hpp>
00016 #include <boost/numeric/mtl/utility/tag.hpp>
00017 #include <boost/numeric/mtl/utility/category.hpp>
00018 #include <boost/numeric/mtl/matrix/transposed_view.hpp>
00019 #include <boost/numeric/mtl/vector/parameter.hpp>
00020
00021 namespace mtl {
00022
00023 namespace matrix {
00024
00025 namespace sfunctor {
00026
00027
00028 template <typename Value, typename AlgebraicCategory>
00029 struct trans {};
00030
00031 template <typename Matrix>
00032 struct trans<Matrix, tag::matrix>
00033 {
00034 typedef transposed_view<Matrix> result_type;
00035
00036 static inline result_type apply(Matrix& matrix)
00037 {
00038 return result_type(matrix);
00039 }
00040 };
00041
00042
00043 template <typename Value, typename AlgebraicCategory>
00044 struct const_trans {};
00045
00046 template <typename Matrix>
00047 struct const_trans<Matrix, tag::matrix>
00048 {
00049 typedef const transposed_view<const Matrix> result_type;
00050
00051 static inline result_type apply(const Matrix& matrix)
00052 {
00053 return result_type(matrix);
00054 }
00055 };
00056
00057 }
00058
00059
00060 template <typename Value>
00061 typename sfunctor::const_trans<Value, typename mtl::traits::algebraic_category<Value>::type>::result_type
00062 inline trans(const Value& v)
00063 {
00064 return sfunctor::const_trans<const Value, typename mtl::traits::algebraic_category<Value>::type>::apply(v);
00065 }
00066
00067 template <typename Value>
00068 typename sfunctor::trans<Value, typename mtl::traits::algebraic_category<Value>::type>::result_type
00069 inline trans(Value& v)
00070 {
00071 return sfunctor::trans<Value, typename mtl::traits::algebraic_category<Value>::type>::apply(v);
00072 }
00073
00074 }
00075
00076
00077 namespace vector {
00078
00079 template <typename Vector>
00080 struct transposed_vector {};
00081
00082 template <typename Parameters>
00083 struct transposed_parameters
00084 {
00085 typedef typename matrix::transposed_orientation<typename Parameters::orientation>::type orientation;
00086 typedef parameters<orientation, typename Parameters::dimension, false, false> type;
00087 };
00088
00089 template <typename Value, typename Parameters>
00090 struct transposed_vector<dense_vector<Value, Parameters> >
00091 {
00092 typedef dense_vector<Value, typename transposed_parameters<Parameters>::type> type;
00093 };
00094
00095 template <typename Value, typename Parameters>
00096 struct transposed_vector<strided_vector_ref<Value, Parameters> >
00097 {
00098 typedef strided_vector_ref<Value, typename transposed_parameters<Parameters>::type> type;
00099 };
00100
00102 template <typename Vector>
00103 typename transposed_vector<Vector>::type const
00104 inline trans(const Vector& v)
00105 {
00106 typedef typename transposed_vector<Vector>::type type;
00107 return type(size(v), &const_cast<Vector&>(v)[0]);
00108 }
00109
00110 template <typename Vector>
00111 typename transposed_vector<Vector>::type
00112 inline trans(Vector& v)
00113 {
00114 typedef typename transposed_vector<Vector>::type type;
00115 return type(size(v), &v[0]);
00116 }
00117 }
00118
00119 }
00120
00121
00122 #endif // MTL_TRANS_INCLUDE