comparison libinterp/dldfcn/chol.cc @ 22217:3ac380d46d54

chol: make option passed as string case insensitive. * libinterp/dldfcn/chol.cc: make comparison of strings for options case insensitive. Add tests. Add missing include for <string> which is used elsewhere in the file.
author Carnë Draug <carandraug@octave.org>
date Sun, 07 Aug 2016 19:39:40 +0100
parents 278fc29b69ca
children 22c2bd440544
comparison
equal deleted inserted replaced
22216:f99c0b8cb67b 22217:3ac380d46d54
24 24
25 #if defined (HAVE_CONFIG_H) 25 #if defined (HAVE_CONFIG_H)
26 # include "config.h" 26 # include "config.h"
27 #endif 27 #endif
28 28
29 #include <string>
30
29 #include "chol.h" 31 #include "chol.h"
30 #include "sparse-chol.h" 32 #include "sparse-chol.h"
31 #include "oct-spparms.h" 33 #include "oct-spparms.h"
32 #include "sparse-util.h" 34 #include "sparse-util.h"
33 35
36 #include "caseless-str.h"
34 #include "ov-re-sparse.h" 37 #include "ov-re-sparse.h"
35 #include "ov-cx-sparse.h" 38 #include "ov-cx-sparse.h"
36 #include "defun-dld.h" 39 #include "defun-dld.h"
37 #include "error.h" 40 #include "error.h"
38 #include "errwarn.h" 41 #include "errwarn.h"
158 bool vecout = false; 161 bool vecout = false;
159 162
160 int n = 1; 163 int n = 1;
161 while (n < nargin) 164 while (n < nargin)
162 { 165 {
163 std::string tmp = args(n++).xstring_value ("chol: optional arguments must be strings"); 166 caseless_str tmp = args(n++).xstring_value ("chol: optional arguments must be strings");
164 167
165 if (tmp == "vector") 168 if (tmp.compare ("vector"))
166 vecout = true; 169 vecout = true;
167 else if (tmp == "lower") 170 else if (tmp.compare ("lower"))
168 LLt = true; 171 LLt = true;
169 else if (tmp == "upper") 172 else if (tmp.compare ("upper"))
170 LLt = false; 173 LLt = false;
171 else 174 else
172 error ("chol: optional argument must be one of \"vector\", \"lower\", or \"upper\""); 175 error ("chol: optional argument must be one of \"vector\", \"lower\", or \"upper\"");
173 } 176 }
174 177
311 } 314 }
312 315
313 /* 316 /*
314 %!assert (chol ([2, 1; 1, 1]), [sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)], sqrt (eps)) 317 %!assert (chol ([2, 1; 1, 1]), [sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)], sqrt (eps))
315 %!assert (chol (single ([2, 1; 1, 1])), single ([sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)]), sqrt (eps ("single"))) 318 %!assert (chol (single ([2, 1; 1, 1])), single ([sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)]), sqrt (eps ("single")))
319
320 %!assert (chol ([2, 1; 1, 1], "upper"), [sqrt(2), 1/sqrt(2); 0, 1/sqrt(2)],
321 %! sqrt (eps))
322 %!assert (chol ([2, 1; 1, 1], "lower"), [sqrt(2), 0; 1/sqrt(2), 1/sqrt(2)],
323 %! sqrt (eps))
324
325 %!assert (chol ([2, 1; 1, 1], "lower"), chol ([2, 1; 1, 1], "LoweR"))
326 %!assert (chol ([2, 1; 1, 1], "upper"), chol ([2, 1; 1, 1], "Upper"))
327 %!assert (chol ([2, 1; 1, 1], "vector"), chol ([2, 1; 1, 1], "VECTOR"))
328
316 %!testif HAVE_CHOLMOD 329 %!testif HAVE_CHOLMOD
317 %! ## Bug #42587 330 %! ## Bug #42587
318 %! A = sparse ([1 0 8;0 1 8;8 8 1]); 331 %! A = sparse ([1 0 8;0 1 8;8 8 1]);
319 %! [Q, p] = chol (A); 332 %! [Q, p] = chol (A);
320 %! assert (p != 0); 333 %! assert (p != 0);