MCPcopy Create free account
hub / github.com/davisking/dlib / inv_upper_triangular

Function inv_upper_triangular

dlib/matrix/matrix_la.h:1147–1183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1145
1146 template <typename EXP>
1147 const typename matrix_exp<EXP>::matrix_type inv_upper_triangular (
1148 const matrix_exp<EXP>& A
1149 )
1150 {
1151 DLIB_ASSERT(A.nr() == A.nc(),
1152 "\tconst matrix inv_upper_triangular(const matrix_exp& A)"
1153 << "\n\tA must be a square matrix"
1154 << "\n\tA.nr(): " << A.nr()
1155 << "\n\tA.nc(): " << A.nc()
1156 );
1157
1158 typedef typename matrix_exp<EXP>::matrix_type matrix_type;
1159
1160 matrix_type m(A);
1161
1162 for(long c = 0; c < m.nc(); ++c)
1163 {
1164 if( m(c,c) == 0 )
1165 {
1166 // there isn't an inverse so just give up
1167 return m;
1168 }
1169
1170 // compute m(c,c)
1171 m(c,c) = 1/m(c,c);
1172
1173 // compute the values in column c that are above m(c,c)
1174 for(long r = 0; r < c; ++r)
1175 {
1176 const long n = c-r;
1177 m(r,c) = -m(c,c)*subm(m,r,r,1,n)*subm(m,r,c,n,1);
1178 }
1179 }
1180
1181 return m;
1182
1183 }
1184
1185// ----------------------------------------------------------------------------------------
1186

Callers 1

matrix_test2Function · 0.85

Calls 3

submFunction · 0.85
nrMethod · 0.45
ncMethod · 0.45

Tested by 1

matrix_test2Function · 0.68