Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
SparseLU_kernel_bmod.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2012 Désiré Nuentsa-Wakam <[email protected]>
5// Copyright (C) 2012 Gael Guennebaud <[email protected]>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef SPARSELU_KERNEL_BMOD_H
12#define SPARSELU_KERNEL_BMOD_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18namespace internal {
19
20template <int SegSizeAtCompileTime>
21struct LU_kernel_bmod {
35 template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
36 static EIGEN_DONT_INLINE void run(const Index segsize, BlockScalarVector& dense, ScalarVector& tempv,
37 ScalarVector& lusup, Index& luptr, const Index lda, const Index nrow,
38 IndexVector& lsub, const Index lptr, const Index no_zeros);
39};
40
41template <int SegSizeAtCompileTime>
42template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
43EIGEN_DONT_INLINE void LU_kernel_bmod<SegSizeAtCompileTime>::run(const Index segsize, BlockScalarVector& dense,
44 ScalarVector& tempv, ScalarVector& lusup, Index& luptr,
45 const Index lda, const Index nrow, IndexVector& lsub,
46 const Index lptr, const Index no_zeros) {
47 typedef typename ScalarVector::Scalar Scalar;
48 // First, copy U[*,j] segment from dense(*) to tempv(*)
49 // The result of triangular solve is in tempv[*];
50 // The result of matric-vector update is in dense[*]
51 Index isub = lptr + no_zeros;
52 Index i;
53 Index irow;
54 for (i = 0; i < ((SegSizeAtCompileTime == Dynamic) ? segsize : SegSizeAtCompileTime); i++) {
55 irow = lsub(isub);
56 tempv(i) = dense(irow);
57 ++isub;
58 }
59 // Dense triangular solve -- start effective triangle
60 luptr += lda * no_zeros + no_zeros;
61 // Form Eigen matrix and vector
62 Map<Matrix<Scalar, SegSizeAtCompileTime, SegSizeAtCompileTime, ColMajor>, 0, OuterStride<> > A(
63 &(lusup.data()[luptr]), segsize, segsize, OuterStride<>(lda));
64 Map<Matrix<Scalar, SegSizeAtCompileTime, 1> > u(tempv.data(), segsize);
65
66 u = A.template triangularView<UnitLower>().solve(u);
67
68 // Dense matrix-vector product y <-- B*x
69 luptr += segsize;
70 const Index PacketSize = internal::packet_traits<Scalar>::size;
71 Index ldl = internal::first_multiple(nrow, PacketSize);
72 Map<Matrix<Scalar, Dynamic, SegSizeAtCompileTime, ColMajor>, 0, OuterStride<> > B(&(lusup.data()[luptr]), nrow,
73 segsize, OuterStride<>(lda));
74 Index aligned_offset = internal::first_default_aligned(tempv.data() + segsize, PacketSize);
75 Index aligned_with_B_offset = (PacketSize - internal::first_default_aligned(B.data(), PacketSize)) % PacketSize;
76 Map<Matrix<Scalar, Dynamic, 1>, 0, OuterStride<> > l(tempv.data() + segsize + aligned_offset + aligned_with_B_offset,
77 nrow, OuterStride<>(ldl));
78
79 l.noalias() = B * u;
80
81 // Scatter tempv[] into SPA dense[] as a temporary storage
82 isub = lptr + no_zeros;
83 for (i = 0; i < ((SegSizeAtCompileTime == Dynamic) ? segsize : SegSizeAtCompileTime); i++) {
84 irow = lsub(isub++);
85 dense(irow) = tempv(i);
86 }
87
88 // Scatter l into SPA dense[]
89 for (i = 0; i < nrow; i++) {
90 irow = lsub(isub++);
91 dense(irow) -= l(i);
92 }
93}
94
95template <>
96struct LU_kernel_bmod<1> {
97 template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
98 static EIGEN_DONT_INLINE void run(const Index /*segsize*/, BlockScalarVector& dense, ScalarVector& /*tempv*/,
99 ScalarVector& lusup, Index& luptr, const Index lda, const Index nrow,
100 IndexVector& lsub, const Index lptr, const Index no_zeros);
101};
102
103template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
104EIGEN_DONT_INLINE void LU_kernel_bmod<1>::run(const Index /*segsize*/, BlockScalarVector& dense,
105 ScalarVector& /*tempv*/, ScalarVector& lusup, Index& luptr,
106 const Index lda, const Index nrow, IndexVector& lsub, const Index lptr,
107 const Index no_zeros) {
108 typedef typename ScalarVector::Scalar Scalar;
109 typedef typename IndexVector::Scalar StorageIndex;
110 Scalar f = dense(lsub(lptr + no_zeros));
111 luptr += lda * no_zeros + no_zeros + 1;
112 const Scalar* a(lusup.data() + luptr);
113 const StorageIndex* irow(lsub.data() + lptr + no_zeros + 1);
114 Index i = 0;
115 for (; i + 1 < nrow; i += 2) {
116 Index i0 = *(irow++);
117 Index i1 = *(irow++);
118 Scalar a0 = *(a++);
119 Scalar a1 = *(a++);
120 Scalar d0 = dense.coeff(i0);
121 Scalar d1 = dense.coeff(i1);
122 d0 -= f * a0;
123 d1 -= f * a1;
124 dense.coeffRef(i0) = d0;
125 dense.coeffRef(i1) = d1;
126 }
127 if (i < nrow) dense.coeffRef(*(irow++)) -= f * *(a++);
128}
129
130} // end namespace internal
131
132} // end namespace Eigen
133#endif // SPARSELU_KERNEL_BMOD_H
Namespace containing all symbols from the Eigen library.
Definition Core:137
const int Dynamic
Definition Constants.h:25