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_TRIANGULAR_SOLVER_MATRIX_H
00026 #define EIGEN_TRIANGULAR_SOLVER_MATRIX_H
00027
00028 namespace internal {
00029
00030
00031 template <typename Scalar, typename Index, int Side, int Mode, bool Conjugate, int TriStorageOrder>
00032 struct triangular_solve_matrix<Scalar,Index,Side,Mode,Conjugate,TriStorageOrder,RowMajor>
00033 {
00034 static EIGEN_DONT_INLINE void run(
00035 Index size, Index cols,
00036 const Scalar* tri, Index triStride,
00037 Scalar* _other, Index otherStride)
00038 {
00039 triangular_solve_matrix<
00040 Scalar, Index, Side==OnTheLeft?OnTheRight:OnTheLeft,
00041 (Mode&UnitDiag) | ((Mode&Upper) ? Lower : Upper),
00042 NumTraits<Scalar>::IsComplex && Conjugate,
00043 TriStorageOrder==RowMajor ? ColMajor : RowMajor, ColMajor>
00044 ::run(size, cols, tri, triStride, _other, otherStride);
00045 }
00046 };
00047
00048
00049
00050 template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder>
00051 struct triangular_solve_matrix<Scalar,Index,OnTheLeft,Mode,Conjugate,TriStorageOrder,ColMajor>
00052 {
00053 static EIGEN_DONT_INLINE void run(
00054 Index size, Index otherSize,
00055 const Scalar* _tri, Index triStride,
00056 Scalar* _other, Index otherStride)
00057 {
00058 Index cols = otherSize;
00059 const_blas_data_mapper<Scalar, Index, TriStorageOrder> tri(_tri,triStride);
00060 blas_data_mapper<Scalar, Index, ColMajor> other(_other,otherStride);
00061
00062 typedef gebp_traits<Scalar,Scalar> Traits;
00063 enum {
00064 SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
00065 IsLower = (Mode&Lower) == Lower
00066 };
00067
00068 Index kc = size;
00069 Index mc = size;
00070 Index nc = cols;
00071 computeProductBlockingSizes<Scalar,Scalar,4>(kc, mc, nc);
00072
00073 Scalar* blockA = ei_aligned_stack_new(Scalar, kc*mc);
00074 std::size_t sizeW = kc*Traits::WorkSpaceFactor;
00075 std::size_t sizeB = sizeW + kc*cols;
00076 Scalar* allocatedBlockB = ei_aligned_stack_new(Scalar, sizeB);
00077 Scalar* blockB = allocatedBlockB + sizeW;
00078
00079 conj_if<Conjugate> conj;
00080 gebp_kernel<Scalar, Scalar, Index, Traits::mr, Traits::nr, Conjugate, false> gebp_kernel;
00081 gemm_pack_lhs<Scalar, Index, Traits::mr, Traits::LhsProgress, TriStorageOrder> pack_lhs;
00082 gemm_pack_rhs<Scalar, Index, Traits::nr, ColMajor, false, true> pack_rhs;
00083
00084 for(Index k2=IsLower ? 0 : size;
00085 IsLower ? k2<size : k2>0;
00086 IsLower ? k2+=kc : k2-=kc)
00087 {
00088 const Index actual_kc = std::min(IsLower ? size-k2 : k2, kc);
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 {
00104
00105 for (Index k1=0; k1<actual_kc; k1+=SmallPanelWidth)
00106 {
00107 Index actualPanelWidth = std::min<Index>(actual_kc-k1, SmallPanelWidth);
00108
00109 for (Index k=0; k<actualPanelWidth; ++k)
00110 {
00111
00112 Index i = IsLower ? k2+k1+k : k2-k1-k-1;
00113 Index s = IsLower ? k2+k1 : i+1;
00114 Index rs = actualPanelWidth - k - 1;
00115
00116 Scalar a = (Mode & UnitDiag) ? Scalar(1) : Scalar(1)/conj(tri(i,i));
00117 for (Index j=0; j<cols; ++j)
00118 {
00119 if (TriStorageOrder==RowMajor)
00120 {
00121 Scalar b = 0;
00122 const Scalar* l = &tri(i,s);
00123 Scalar* r = &other(s,j);
00124 for (Index i3=0; i3<k; ++i3)
00125 b += conj(l[i3]) * r[i3];
00126
00127 other(i,j) = (other(i,j) - b)*a;
00128 }
00129 else
00130 {
00131 Index s = IsLower ? i+1 : i-rs;
00132 Scalar b = (other(i,j) *= a);
00133 Scalar* r = &other(s,j);
00134 const Scalar* l = &tri(s,i);
00135 for (Index i3=0;i3<rs;++i3)
00136 r[i3] -= b * conj(l[i3]);
00137 }
00138 }
00139 }
00140
00141 Index lengthTarget = actual_kc-k1-actualPanelWidth;
00142 Index startBlock = IsLower ? k2+k1 : k2-k1-actualPanelWidth;
00143 Index blockBOffset = IsLower ? k1 : lengthTarget;
00144
00145
00146 pack_rhs(blockB, _other+startBlock, otherStride, actualPanelWidth, cols, actual_kc, blockBOffset);
00147
00148
00149 if (lengthTarget>0)
00150 {
00151 Index startTarget = IsLower ? k2+k1+actualPanelWidth : k2-actual_kc;
00152
00153 pack_lhs(blockA, &tri(startTarget,startBlock), triStride, actualPanelWidth, lengthTarget);
00154
00155 gebp_kernel(_other+startTarget, otherStride, blockA, blockB, lengthTarget, actualPanelWidth, cols, Scalar(-1),
00156 actualPanelWidth, actual_kc, 0, blockBOffset);
00157 }
00158 }
00159 }
00160
00161
00162 {
00163 Index start = IsLower ? k2+kc : 0;
00164 Index end = IsLower ? size : k2-kc;
00165 for(Index i2=start; i2<end; i2+=mc)
00166 {
00167 const Index actual_mc = std::min(mc,end-i2);
00168 if (actual_mc>0)
00169 {
00170 pack_lhs(blockA, &tri(i2, IsLower ? k2 : k2-kc), triStride, actual_kc, actual_mc);
00171
00172 gebp_kernel(_other+i2, otherStride, blockA, blockB, actual_mc, actual_kc, cols, Scalar(-1));
00173 }
00174 }
00175 }
00176 }
00177
00178 ei_aligned_stack_delete(Scalar, blockA, kc*mc);
00179 ei_aligned_stack_delete(Scalar, allocatedBlockB, sizeB);
00180 }
00181 };
00182
00183
00184
00185 template <typename Scalar, typename Index, int Mode, bool Conjugate, int TriStorageOrder>
00186 struct triangular_solve_matrix<Scalar,Index,OnTheRight,Mode,Conjugate,TriStorageOrder,ColMajor>
00187 {
00188 static EIGEN_DONT_INLINE void run(
00189 Index size, Index otherSize,
00190 const Scalar* _tri, Index triStride,
00191 Scalar* _other, Index otherStride)
00192 {
00193 Index rows = otherSize;
00194 const_blas_data_mapper<Scalar, Index, TriStorageOrder> rhs(_tri,triStride);
00195 blas_data_mapper<Scalar, Index, ColMajor> lhs(_other,otherStride);
00196
00197 typedef gebp_traits<Scalar,Scalar> Traits;
00198 enum {
00199 RhsStorageOrder = TriStorageOrder,
00200 SmallPanelWidth = EIGEN_PLAIN_ENUM_MAX(Traits::mr,Traits::nr),
00201 IsLower = (Mode&Lower) == Lower
00202 };
00203
00204
00205
00206
00207 Index kc = size;
00208 Index mc = size;
00209 Index nc = rows;
00210 computeProductBlockingSizes<Scalar,Scalar,4>(kc, mc, nc);
00211
00212 Scalar* blockA = ei_aligned_stack_new(Scalar, kc*mc);
00213 std::size_t sizeW = kc*Traits::WorkSpaceFactor;
00214 std::size_t sizeB = sizeW + kc*size;
00215 Scalar* allocatedBlockB = ei_aligned_stack_new(Scalar, sizeB);
00216 Scalar* blockB = allocatedBlockB + sizeW;
00217
00218 conj_if<Conjugate> conj;
00219 gebp_kernel<Scalar,Scalar, Index, Traits::mr, Traits::nr, false, Conjugate> gebp_kernel;
00220 gemm_pack_rhs<Scalar, Index, Traits::nr,RhsStorageOrder> pack_rhs;
00221 gemm_pack_rhs<Scalar, Index, Traits::nr,RhsStorageOrder,false,true> pack_rhs_panel;
00222 gemm_pack_lhs<Scalar, Index, Traits::mr, Traits::LhsProgress, ColMajor, false, true> pack_lhs_panel;
00223
00224 for(Index k2=IsLower ? size : 0;
00225 IsLower ? k2>0 : k2<size;
00226 IsLower ? k2-=kc : k2+=kc)
00227 {
00228 const Index actual_kc = std::min(IsLower ? k2 : size-k2, kc);
00229 Index actual_k2 = IsLower ? k2-actual_kc : k2 ;
00230
00231 Index startPanel = IsLower ? 0 : k2+actual_kc;
00232 Index rs = IsLower ? actual_k2 : size - actual_k2 - actual_kc;
00233 Scalar* geb = blockB+actual_kc*actual_kc;
00234
00235 if (rs>0) pack_rhs(geb, &rhs(actual_k2,startPanel), triStride, actual_kc, rs);
00236
00237
00238
00239 {
00240 for (Index j2=0; j2<actual_kc; j2+=SmallPanelWidth)
00241 {
00242 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
00243 Index actual_j2 = actual_k2 + j2;
00244 Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
00245 Index panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2;
00246
00247 if (panelLength>0)
00248 pack_rhs_panel(blockB+j2*actual_kc,
00249 &rhs(actual_k2+panelOffset, actual_j2), triStride,
00250 panelLength, actualPanelWidth,
00251 actual_kc, panelOffset);
00252 }
00253 }
00254
00255 for(Index i2=0; i2<rows; i2+=mc)
00256 {
00257 const Index actual_mc = std::min(mc,rows-i2);
00258
00259
00260 {
00261
00262 for (Index j2 = IsLower
00263 ? (actual_kc - ((actual_kc%SmallPanelWidth) ? Index(actual_kc%SmallPanelWidth)
00264 : Index(SmallPanelWidth)))
00265 : 0;
00266 IsLower ? j2>=0 : j2<actual_kc;
00267 IsLower ? j2-=SmallPanelWidth : j2+=SmallPanelWidth)
00268 {
00269 Index actualPanelWidth = std::min<Index>(actual_kc-j2, SmallPanelWidth);
00270 Index absolute_j2 = actual_k2 + j2;
00271 Index panelOffset = IsLower ? j2+actualPanelWidth : 0;
00272 Index panelLength = IsLower ? actual_kc - j2 - actualPanelWidth : j2;
00273
00274
00275 if(panelLength>0)
00276 {
00277 gebp_kernel(&lhs(i2,absolute_j2), otherStride,
00278 blockA, blockB+j2*actual_kc,
00279 actual_mc, panelLength, actualPanelWidth,
00280 Scalar(-1),
00281 actual_kc, actual_kc,
00282 panelOffset, panelOffset,
00283 allocatedBlockB);
00284 }
00285
00286
00287 for (Index k=0; k<actualPanelWidth; ++k)
00288 {
00289 Index j = IsLower ? absolute_j2+actualPanelWidth-k-1 : absolute_j2+k;
00290
00291 Scalar* r = &lhs(i2,j);
00292 for (Index k3=0; k3<k; ++k3)
00293 {
00294 Scalar b = conj(rhs(IsLower ? j+1+k3 : absolute_j2+k3,j));
00295 Scalar* a = &lhs(i2,IsLower ? j+1+k3 : absolute_j2+k3);
00296 for (Index i=0; i<actual_mc; ++i)
00297 r[i] -= a[i] * b;
00298 }
00299 Scalar b = (Mode & UnitDiag) ? Scalar(1) : Scalar(1)/conj(rhs(j,j));
00300 for (Index i=0; i<actual_mc; ++i)
00301 r[i] *= b;
00302 }
00303
00304
00305 pack_lhs_panel(blockA, _other+absolute_j2*otherStride+i2, otherStride,
00306 actualPanelWidth, actual_mc,
00307 actual_kc, j2);
00308 }
00309 }
00310
00311 if (rs>0)
00312 gebp_kernel(_other+i2+startPanel*otherStride, otherStride, blockA, geb,
00313 actual_mc, actual_kc, rs, Scalar(-1),
00314 -1, -1, 0, 0, allocatedBlockB);
00315 }
00316 }
00317
00318 ei_aligned_stack_delete(Scalar, blockA, kc*mc);
00319 ei_aligned_stack_delete(Scalar, allocatedBlockB, sizeB);
00320 }
00321 };
00322
00323 }
00324
00325 #endif // EIGEN_TRIANGULAR_SOLVER_MATRIX_H