Medial Code Documentation
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 <desire.nuentsa_wakam@inria.fr>
5// Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
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
14namespace Eigen {
15namespace internal {
16
31template <int SegSizeAtCompileTime> struct LU_kernel_bmod
32{
33 template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
34 static EIGEN_DONT_INLINE void run(const Index segsize, BlockScalarVector& dense, ScalarVector& tempv, ScalarVector& lusup, Index& luptr, const Index lda,
35 const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros);
36};
37
38template <int SegSizeAtCompileTime>
39template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
40EIGEN_DONT_INLINE void LU_kernel_bmod<SegSizeAtCompileTime>::run(const Index segsize, BlockScalarVector& dense, ScalarVector& tempv, ScalarVector& lusup, Index& luptr, const Index lda,
41 const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros)
42{
43 typedef typename ScalarVector::Scalar Scalar;
44 // First, copy U[*,j] segment from dense(*) to tempv(*)
45 // The result of triangular solve is in tempv[*];
46 // The result of matric-vector update is in dense[*]
47 Index isub = lptr + no_zeros;
48 Index i;
49 Index irow;
50 for (i = 0; i < ((SegSizeAtCompileTime==Dynamic)?segsize:SegSizeAtCompileTime); i++)
51 {
52 irow = lsub(isub);
53 tempv(i) = dense(irow);
54 ++isub;
55 }
56 // Dense triangular solve -- start effective triangle
57 luptr += lda * no_zeros + no_zeros;
58 // Form Eigen matrix and vector
61
62 u = A.template triangularView<UnitLower>().solve(u);
63
64 // Dense matrix-vector product y <-- B*x
65 luptr += segsize;
66 const Index PacketSize = internal::packet_traits<Scalar>::size;
67 Index ldl = internal::first_multiple(nrow, PacketSize);
69 Index aligned_offset = internal::first_default_aligned(tempv.data()+segsize, PacketSize);
70 Index aligned_with_B_offset = (PacketSize-internal::first_default_aligned(B.data(), PacketSize))%PacketSize;
72
73 l.setZero();
74 internal::sparselu_gemm<Scalar>(l.rows(), l.cols(), B.cols(), B.data(), B.outerStride(), u.data(), u.outerStride(), l.data(), l.outerStride());
75
76 // Scatter tempv[] into SPA dense[] as a temporary storage
77 isub = lptr + no_zeros;
78 for (i = 0; i < ((SegSizeAtCompileTime==Dynamic)?segsize:SegSizeAtCompileTime); i++)
79 {
80 irow = lsub(isub++);
81 dense(irow) = tempv(i);
82 }
83
84 // Scatter l into SPA dense[]
85 for (i = 0; i < nrow; i++)
86 {
87 irow = lsub(isub++);
88 dense(irow) -= l(i);
89 }
90}
91
92template <> struct LU_kernel_bmod<1>
93{
94 template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
95 static EIGEN_DONT_INLINE void run(const Index /*segsize*/, BlockScalarVector& dense, ScalarVector& /*tempv*/, ScalarVector& lusup, Index& luptr,
96 const Index lda, const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros);
97};
98
99
100template <typename BlockScalarVector, typename ScalarVector, typename IndexVector>
101EIGEN_DONT_INLINE void LU_kernel_bmod<1>::run(const Index /*segsize*/, BlockScalarVector& dense, ScalarVector& /*tempv*/, ScalarVector& lusup, Index& luptr,
102 const Index lda, const Index nrow, IndexVector& lsub, const Index lptr, const Index no_zeros)
103{
104 typedef typename ScalarVector::Scalar Scalar;
105 typedef typename IndexVector::Scalar StorageIndex;
106 Scalar f = dense(lsub(lptr + no_zeros));
107 luptr += lda * no_zeros + no_zeros + 1;
108 const Scalar* a(lusup.data() + luptr);
109 const StorageIndex* irow(lsub.data()+lptr + no_zeros + 1);
110 Index i = 0;
111 for (; i+1 < nrow; i+=2)
112 {
113 Index i0 = *(irow++);
114 Index i1 = *(irow++);
115 Scalar a0 = *(a++);
116 Scalar a1 = *(a++);
117 Scalar d0 = dense.coeff(i0);
118 Scalar d1 = dense.coeff(i1);
119 d0 -= f*a0;
120 d1 -= f*a1;
121 dense.coeffRef(i0) = d0;
122 dense.coeffRef(i1) = d1;
123 }
124 if(i<nrow)
125 dense.coeffRef(*(irow++)) -= f * *(a++);
126}
127
128} // end namespace internal
129
130} // end namespace Eigen
131#endif // SPARSELU_KERNEL_BMOD_H
Pseudo expression representing a solving operation.
Definition Solve.h:63
Performs numeric block updates from a given supernode to a single column.
Definition SparseLU_kernel_bmod.h:32
Definition GenericPacketMath.h:90