comparison libinterp/dldfcn/chol.cc @ 20497:5ce959c55cc0

Propagate 'lower' in chol(a, 'lower') to underlying library function. * chol.cc (chol): Send 'L' parameter correctly when chol is called with 'lower'. * floatCHOL.cc (init): Propagate 'lower' to underlying library function. * floatCHOL.h: Modify the prototype of methods. * fMatrix.cc (inverse): Invoke chol with additional parameter. * dbleCHOL.cc (init): Propagate 'lower' to underlying library function. * dbleCHOL.h: Modify the prototype of methods. * dMatrix.cc (inverse): Invoke chol with additional parameter. * CmplxCHOL.cc (init): Propagate 'lower' to underlying library function. * CmplxCHOL.h: Modify the prototype of methods. * CMatrix.cc (inverse): Invoke chol with additional parameter.
author PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
date Sun, 24 Aug 2014 19:35:06 +0530
parents 075a5e2e1ba5
children 0650b8431037
comparison
equal deleted inserted replaced
20496:0fe7133da8ce 20497:5ce959c55cc0
41 #include "defun-dld.h" 41 #include "defun-dld.h"
42 #include "error.h" 42 #include "error.h"
43 #include "gripes.h" 43 #include "gripes.h"
44 #include "oct-obj.h" 44 #include "oct-obj.h"
45 #include "utils.h" 45 #include "utils.h"
46
47 template <class CHOLT>
48 static octave_value
49 get_chol (const CHOLT& fact)
50 {
51 return octave_value (fact.chol_matrix());
52 }
46 53
47 template <class CHOLT> 54 template <class CHOLT>
48 static octave_value 55 static octave_value
49 get_chol_r (const CHOLT& fact) 56 get_chol_r (const CHOLT& fact)
50 { 57 {
160 if (! error_state) 167 if (! error_state)
161 { 168 {
162 if (tmp.compare ("vector") == 0) 169 if (tmp.compare ("vector") == 0)
163 vecout = true; 170 vecout = true;
164 else if (tmp.compare ("lower") == 0) 171 else if (tmp.compare ("lower") == 0)
165 // FIXME: currently the option "lower" is handled by transposing
166 // the matrix, factorizing it with the lapack function
167 // DPOTRF ('U', ...) and finally transposing the factor. It would
168 // be more efficient to use DPOTRF ('L', ...) in this case.
169 LLt = true; 172 LLt = true;
170 else if (tmp.compare ("upper") == 0) 173 else if (tmp.compare ("upper") == 0)
171 LLt = false; 174 LLt = false;
172 else 175 else
173 error ("chol: unexpected second or third input"); 176 error ("chol: unexpected second or third input");
264 if (! error_state) 267 if (! error_state)
265 { 268 {
266 octave_idx_type info; 269 octave_idx_type info;
267 270
268 FloatCHOL fact; 271 FloatCHOL fact;
269 if (LLt) 272 fact = FloatCHOL (m, info, LLt != true);
270 fact = FloatCHOL (m.transpose (), info);
271 else
272 fact = FloatCHOL (m, info);
273 273
274 if (nargout == 2 || info == 0) 274 if (nargout == 2 || info == 0)
275 { 275 {
276 retval(1) = info; 276 retval(1) = info;
277 if (LLt) 277 retval(0) = get_chol (fact);
278 retval(0) = get_chol_l (fact);
279 else
280 retval(0) = get_chol_r (fact);
281 } 278 }
282 else 279 else
283 error ("chol: input matrix must be positive definite"); 280 error ("chol: input matrix must be positive definite");
284 } 281 }
285 } 282 }
321 if (! error_state) 318 if (! error_state)
322 { 319 {
323 octave_idx_type info; 320 octave_idx_type info;
324 321
325 CHOL fact; 322 CHOL fact;
326 if (LLt) 323 fact = CHOL (m, info, LLt != true);
327 fact = CHOL (m.transpose (), info);
328 else
329 fact = CHOL (m, info);
330 324
331 if (nargout == 2 || info == 0) 325 if (nargout == 2 || info == 0)
332 { 326 {
333 retval(1) = info; 327 retval(1) = info;
334 if (LLt) 328 retval(0) = get_chol (fact);
335 retval(0) = get_chol_l (fact);
336 else
337 retval(0) = get_chol_r (fact);
338 } 329 }
339 else 330 else
340 error ("chol: input matrix must be positive definite"); 331 error ("chol: input matrix must be positive definite");
341 } 332 }
342 } 333 }
347 if (! error_state) 338 if (! error_state)
348 { 339 {
349 octave_idx_type info; 340 octave_idx_type info;
350 341
351 ComplexCHOL fact; 342 ComplexCHOL fact;
352 if (LLt) 343 fact = ComplexCHOL (m, info, LLt != true);
353 fact = ComplexCHOL (m.transpose (), info);
354 else
355 fact = ComplexCHOL (m, info);
356 344
357 if (nargout == 2 || info == 0) 345 if (nargout == 2 || info == 0)
358 { 346 {
359 retval(1) = info; 347 retval(1) = info;
360 if (LLt) 348 retval(0) = get_chol (fact);
361 retval(0) = get_chol_l (fact);
362 else
363 retval(0) = get_chol_r (fact);
364 } 349 }
365 else 350 else
366 error ("chol: input matrix must be positive definite"); 351 error ("chol: input matrix must be positive definite");
367 } 352 }
368 } 353 }