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 #ifndef EIGEN_SELFADJOINT_PRODUCT_H
00026 #define EIGEN_SELFADJOINT_PRODUCT_H
00027
00028
00029
00030
00031
00032
00033
00034 template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjLhs, bool ConjRhs>
00035 struct selfadjoint_rank1_update;
00036
00037 template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
00038 struct selfadjoint_rank1_update<Scalar,Index,ColMajor,UpLo,ConjLhs,ConjRhs>
00039 {
00040 static void run(Index size, Scalar* mat, Index stride, const Scalar* vec, Scalar alpha)
00041 {
00042 internal::conj_if<ConjRhs> cj;
00043 typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap;
00044 typedef typename internal::conditional<ConjLhs,typename OtherMap::ConjugateReturnType,const OtherMap&>::type ConjRhsType;
00045 for (Index i=0; i<size; ++i)
00046 {
00047 Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i+(UpLo==Lower ? i : 0), (UpLo==Lower ? size-i : (i+1)))
00048 += (alpha * cj(vec[i])) * ConjRhsType(OtherMap(vec+(UpLo==Lower ? i : 0),UpLo==Lower ? size-i : (i+1)));
00049 }
00050 }
00051 };
00052
00053 template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
00054 struct selfadjoint_rank1_update<Scalar,Index,RowMajor,UpLo,ConjLhs,ConjRhs>
00055 {
00056 static void run(Index size, Scalar* mat, Index stride, const Scalar* vec, Scalar alpha)
00057 {
00058 selfadjoint_rank1_update<Scalar,Index,ColMajor,UpLo==Lower?Upper:Lower,ConjRhs,ConjLhs>::run(size,mat,stride,vec,alpha);
00059 }
00060 };
00061
00062 template<typename MatrixType, typename OtherType, int UpLo, bool OtherIsVector = OtherType::IsVectorAtCompileTime>
00063 struct selfadjoint_product_selector;
00064
00065 template<typename MatrixType, typename OtherType, int UpLo>
00066 struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,true>
00067 {
00068 static void run(MatrixType& mat, const OtherType& other, typename MatrixType::Scalar alpha)
00069 {
00070 typedef typename MatrixType::Scalar Scalar;
00071 typedef typename MatrixType::Index Index;
00072 typedef internal::blas_traits<OtherType> OtherBlasTraits;
00073 typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType;
00074 typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType;
00075 const ActualOtherType actualOther = OtherBlasTraits::extract(other.derived());
00076
00077 Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived());
00078
00079 enum {
00080 StorageOrder = (internal::traits<MatrixType>::Flags&RowMajorBit) ? RowMajor : ColMajor,
00081 UseOtherDirectly = _ActualOtherType::InnerStrideAtCompileTime==1
00082 };
00083 internal::gemv_static_vector_if<Scalar,OtherType::SizeAtCompileTime,OtherType::MaxSizeAtCompileTime,!UseOtherDirectly> static_other;
00084
00085 ei_declare_aligned_stack_constructed_variable(Scalar, actualOtherPtr, other.size(),
00086 (UseOtherDirectly ? const_cast<Scalar*>(actualOther.data()) : static_other.data()));
00087
00088 if(!UseOtherDirectly)
00089 Map<typename _ActualOtherType::PlainObject>(actualOtherPtr, actualOther.size()) = actualOther;
00090
00091 selfadjoint_rank1_update<Scalar,Index,StorageOrder,UpLo,
00092 OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
00093 (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex>
00094 ::run(other.size(), mat.data(), mat.outerStride(), actualOtherPtr, actualAlpha);
00095 }
00096 };
00097
00098 template<typename MatrixType, typename OtherType, int UpLo>
00099 struct selfadjoint_product_selector<MatrixType,OtherType,UpLo,false>
00100 {
00101 static void run(MatrixType& mat, const OtherType& other, typename MatrixType::Scalar alpha)
00102 {
00103 typedef typename MatrixType::Scalar Scalar;
00104 typedef typename MatrixType::Index Index;
00105 typedef internal::blas_traits<OtherType> OtherBlasTraits;
00106 typedef typename OtherBlasTraits::DirectLinearAccessType ActualOtherType;
00107 typedef typename internal::remove_all<ActualOtherType>::type _ActualOtherType;
00108 const ActualOtherType actualOther = OtherBlasTraits::extract(other.derived());
00109
00110 Scalar actualAlpha = alpha * OtherBlasTraits::extractScalarFactor(other.derived());
00111
00112 enum { IsRowMajor = (internal::traits<MatrixType>::Flags&RowMajorBit) ? 1 : 0 };
00113
00114 internal::general_matrix_matrix_triangular_product<Index,
00115 Scalar, _ActualOtherType::Flags&RowMajorBit ? RowMajor : ColMajor, OtherBlasTraits::NeedToConjugate && NumTraits<Scalar>::IsComplex,
00116 Scalar, _ActualOtherType::Flags&RowMajorBit ? ColMajor : RowMajor, (!OtherBlasTraits::NeedToConjugate) && NumTraits<Scalar>::IsComplex,
00117 MatrixType::Flags&RowMajorBit ? RowMajor : ColMajor, UpLo>
00118 ::run(mat.cols(), actualOther.cols(),
00119 &actualOther.coeffRef(0,0), actualOther.outerStride(), &actualOther.coeffRef(0,0), actualOther.outerStride(),
00120 mat.data(), mat.outerStride(), actualAlpha);
00121 }
00122 };
00123
00124
00125
00126 template<typename MatrixType, unsigned int UpLo>
00127 template<typename DerivedU>
00128 SelfAdjointView<MatrixType,UpLo>& SelfAdjointView<MatrixType,UpLo>
00129 ::rankUpdate(const MatrixBase<DerivedU>& u, Scalar alpha)
00130 {
00131 selfadjoint_product_selector<MatrixType,DerivedU,UpLo>::run(_expression().const_cast_derived(), u.derived(), alpha);
00132
00133 return *this;
00134 }
00135
00136 #endif // EIGEN_SELFADJOINT_PRODUCT_H