00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 namespace TooN {
00034
00035
00055 template<int Size=Dynamic, typename Precision=DefaultPrecision, typename Base=Internal::VBase>
00056 struct DiagonalMatrix {
00057 public:
00060
00061 inline DiagonalMatrix() {}
00062 inline DiagonalMatrix(int size_in) : my_vector(size_in) {}
00063 inline DiagonalMatrix(Precision* data) : my_vector(data) {}
00064 inline DiagonalMatrix(Precision* data, int size_in) : my_vector(data,size_in) {}
00065 inline DiagonalMatrix(Precision* data_in, int size_in, int stride_in, Internal::Slicing)
00066 : my_vector(data_in, size_in, stride_in, Internal::Slicing() ) {}
00067
00068
00069
00071 template <class Op>
00072 inline DiagonalMatrix(const Operator<Op>& op)
00073 : my_vector (op)
00074 {
00075 op.eval(my_vector);
00076 }
00077
00078
00079 template<int Size2, typename Precision2, typename Base2>
00080 inline DiagonalMatrix(const Vector<Size2,Precision2,Base2>& from)
00081 : my_vector(from.size())
00082 {
00083 my_vector=from;
00084 }
00086
00087
00088
00090 Precision& operator[](int i){return my_vector[i];}
00092 const Precision& operator[](int i) const {return my_vector[i];}
00093
00095 typename Vector<Size, Precision, Base>::as_slice_type diagonal_slice() {
00096 return my_vector.as_slice();
00097 }
00098
00100 const typename Vector<Size, Precision, Base>::as_slice_type diagonal_slice() const {
00101 return my_vector.as_slice();
00102 }
00103
00105 Vector<Size,Precision,Base> my_vector;
00106 };
00107
00108
00109 template<int S1, typename P1, typename B1, int S2, typename P2, typename B2>
00110 inline Vector<Internal::Sizer<S1,S2>::size, typename Internal::MultiplyType<P1,P2>::type>
00111 operator*(const DiagonalMatrix<S1,P1,B1>& d, const Vector<S2,P2,B2>& v){
00112 return diagmult(d.my_vector,v);
00113 }
00114
00115 template<int S1, typename P1, typename B1, int S2, typename P2, typename B2>
00116 inline Vector<Internal::Sizer<S1,S2>::size, typename Internal::MultiplyType<P1,P2>::type>
00117 operator*( const Vector<S1,P1,B1>& v, const DiagonalMatrix<S2,P2,B2>& d){
00118 return diagmult(v,d.my_vector);
00119 }
00120
00121
00122 template<int S1, typename P1, typename B1, int S2, typename P2, typename B2>
00123 inline DiagonalMatrix<Internal::Sizer<S1,S2>::size, typename Internal::MultiplyType<P1,P2>::type>
00124 operator*( const DiagonalMatrix<S1,P1,B1>& d1, const DiagonalMatrix<S2,P2,B2>& d2){
00125 SizeMismatch<S1,S2>::test(d1.my_vector.size(),d2.my_vector.size());
00126 return Operator<Internal::VPairwise<Internal::Multiply,S1,P1,B1,S2,P2,B2> >(d1.my_vector,d2.my_vector);
00127 }
00128
00129 template<int R, int C, int Size, typename P1, typename P2, typename B1, typename B2>
00130 Matrix<R, C, typename Internal::MultiplyType<P1,P2>::type>
00131 operator* (const Matrix<R, C, P1, B1>& m, const DiagonalMatrix<Size, P2, B2>& d){
00132 return diagmult(m,d.my_vector);
00133 }
00134
00135 template<int R, int C, typename P1, typename B1, int Size, typename P2, typename B2>
00136 Matrix<R, C, typename Internal::MultiplyType<P1,P2>::type>
00137 operator* (const DiagonalMatrix<Size,P1,B1>& d, const Matrix<R,C,P2,B2>& m)
00138 {
00139 return diagmult(d.my_vector, m);
00140 }
00141
00142 }