12#ifndef SPARSELU_KERNEL_BMOD_H
13#define SPARSELU_KERNEL_BMOD_H
16#include "./InternalHeaderCheck.h"
21template <
int SegSizeAtCompileTime>
22struct LU_kernel_bmod {
36 template <
typename BlockScalarVector,
typename ScalarVector,
typename IndexVector>
37 static EIGEN_DONT_INLINE
void run(
const Index segsize, BlockScalarVector& dense, ScalarVector& tempv,
38 ScalarVector& lusup, Index& luptr,
const Index lda,
const Index nrow,
39 IndexVector& lsub,
const Index lptr,
const Index no_zeros);
42template <
int SegSizeAtCompileTime>
43template <
typename BlockScalarVector,
typename ScalarVector,
typename IndexVector>
44EIGEN_DONT_INLINE
void LU_kernel_bmod<SegSizeAtCompileTime>::run(
const Index segsize, BlockScalarVector& dense,
45 ScalarVector& tempv, ScalarVector& lusup, Index& luptr,
46 const Index lda,
const Index nrow, IndexVector& lsub,
47 const Index lptr,
const Index no_zeros) {
48 using Scalar =
typename ScalarVector::Scalar;
52 Index isub = lptr + no_zeros;
55 for (i = 0; i < ((SegSizeAtCompileTime == Dynamic) ? segsize : SegSizeAtCompileTime); i++) {
57 tempv(i) = dense(irow);
61 luptr += lda * no_zeros + no_zeros;
63 Map<Matrix<Scalar, SegSizeAtCompileTime, SegSizeAtCompileTime, ColMajor>, 0, OuterStride<> > A(
64 &(lusup.data()[luptr]), segsize, segsize, OuterStride<>(lda));
65 Map<Matrix<Scalar, SegSizeAtCompileTime, 1> > u(tempv.data(), segsize);
67 u = A.template triangularView<UnitLower>().solve(u);
71 const Index PacketSize = internal::packet_traits<Scalar>::size;
72 Index ldl = internal::first_multiple(nrow, PacketSize);
73 Map<Matrix<Scalar, Dynamic, SegSizeAtCompileTime, ColMajor>, 0, OuterStride<> > B(&(lusup.data()[luptr]), nrow,
74 segsize, OuterStride<>(lda));
75 Index aligned_offset = internal::first_default_aligned(tempv.data() + segsize, PacketSize);
76 Index aligned_with_B_offset = (PacketSize - internal::first_default_aligned(B.data(), PacketSize)) % PacketSize;
77 Map<Matrix<Scalar, Dynamic, 1>, 0, OuterStride<> > l(tempv.data() + segsize + aligned_offset + aligned_with_B_offset,
78 nrow, OuterStride<>(ldl));
83 isub = lptr + no_zeros;
84 for (i = 0; i < ((SegSizeAtCompileTime == Dynamic) ? segsize : SegSizeAtCompileTime); i++) {
86 dense(irow) = tempv(i);
90 for (i = sparse_scatter_sub_packets(dense.data(), lsub.data() + isub, l); i < nrow; i++) {
91 irow = lsub(isub + i);
97struct LU_kernel_bmod<1> {
98 template <
typename BlockScalarVector,
typename ScalarVector,
typename IndexVector>
99 static EIGEN_DONT_INLINE
void run(
const Index , BlockScalarVector& dense, ScalarVector& ,
100 ScalarVector& lusup, Index& luptr,
const Index lda,
const Index nrow,
101 IndexVector& lsub,
const Index lptr,
const Index no_zeros);
104template <
typename BlockScalarVector,
typename ScalarVector,
typename IndexVector>
105EIGEN_DONT_INLINE
void LU_kernel_bmod<1>::run(
const Index , BlockScalarVector& dense,
106 ScalarVector& , ScalarVector& lusup, Index& luptr,
107 const Index lda,
const Index nrow, IndexVector& lsub,
const Index lptr,
108 const Index no_zeros) {
109 using Scalar =
typename ScalarVector::Scalar;
110 using StorageIndex =
typename IndexVector::Scalar;
111 Scalar f = dense(lsub(lptr + no_zeros));
112 luptr += lda * no_zeros + no_zeros + 1;
113 const Scalar* a(lusup.data() + luptr);
114 const StorageIndex* irow(lsub.data() + lptr + no_zeros + 1);
116 for (; i + 1 < nrow; i += 2) {
117 Index i0 = *(irow++);
118 Index i1 = *(irow++);
121 Scalar d0 = dense.coeff(i0);
122 Scalar d1 = dense.coeff(i1);
125 dense.coeffRef(i0) = d0;
126 dense.coeffRef(i1) = d1;
128 if (i < nrow) dense.coeffRef(*(irow++)) -= f * *(a++);