xref: /aosp_15_r20/external/eigen/blas/GeneralRank1Update.h (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li // This file is part of Eigen, a lightweight C++ template library
2*bf2c3715SXin Li // for linear algebra.
3*bf2c3715SXin Li //
4*bf2c3715SXin Li // Copyright (C) 2012 Chen-Pang He <[email protected]>
5*bf2c3715SXin Li //
6*bf2c3715SXin Li // This Source Code Form is subject to the terms of the Mozilla
7*bf2c3715SXin Li // Public License v. 2.0. If a copy of the MPL was not distributed
8*bf2c3715SXin Li // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9*bf2c3715SXin Li 
10*bf2c3715SXin Li #ifndef EIGEN_GENERAL_RANK1UPDATE_H
11*bf2c3715SXin Li #define EIGEN_GENERAL_RANK1UPDATE_H
12*bf2c3715SXin Li 
13*bf2c3715SXin Li namespace internal {
14*bf2c3715SXin Li 
15*bf2c3715SXin Li /* Optimized matrix += alpha * uv' */
16*bf2c3715SXin Li template<typename Scalar, typename Index, int StorageOrder, bool ConjLhs, bool ConjRhs>
17*bf2c3715SXin Li struct general_rank1_update;
18*bf2c3715SXin Li 
19*bf2c3715SXin Li template<typename Scalar, typename Index, bool ConjLhs, bool ConjRhs>
20*bf2c3715SXin Li struct general_rank1_update<Scalar,Index,ColMajor,ConjLhs,ConjRhs>
21*bf2c3715SXin Li {
22*bf2c3715SXin Li   static void run(Index rows, Index cols, Scalar* mat, Index stride, const Scalar* u, const Scalar* v, Scalar alpha)
23*bf2c3715SXin Li   {
24*bf2c3715SXin Li     typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap;
25*bf2c3715SXin Li     typedef typename conj_expr_if<ConjLhs,OtherMap>::type ConjRhsType;
26*bf2c3715SXin Li     conj_if<ConjRhs> cj;
27*bf2c3715SXin Li 
28*bf2c3715SXin Li     for (Index i=0; i<cols; ++i)
29*bf2c3715SXin Li       Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i,rows) += alpha * cj(v[i]) * ConjRhsType(OtherMap(u,rows));
30*bf2c3715SXin Li   }
31*bf2c3715SXin Li };
32*bf2c3715SXin Li 
33*bf2c3715SXin Li template<typename Scalar, typename Index, bool ConjLhs, bool ConjRhs>
34*bf2c3715SXin Li struct general_rank1_update<Scalar,Index,RowMajor,ConjLhs,ConjRhs>
35*bf2c3715SXin Li {
36*bf2c3715SXin Li   static void run(Index rows, Index cols, Scalar* mat, Index stride, const Scalar* u, const Scalar* v, Scalar alpha)
37*bf2c3715SXin Li   {
38*bf2c3715SXin Li     general_rank1_update<Scalar,Index,ColMajor,ConjRhs,ConjRhs>::run(rows,cols,mat,stride,u,v,alpha);
39*bf2c3715SXin Li   }
40*bf2c3715SXin Li };
41*bf2c3715SXin Li 
42*bf2c3715SXin Li } // end namespace internal
43*bf2c3715SXin Li 
44*bf2c3715SXin Li #endif // EIGEN_GENERAL_RANK1UPDATE_H
45