Mercurial > octave-antonio
comparison scripts/sparse/eigs.m @ 17846:42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
* scripts/sparse/eigs.m: Return k eigenvalues closest to sigma when sigma is
numeric. Replace double quotes with single quotes in error messages to avoid
having to escape double quote characters so frequently.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 04 Nov 2013 10:38:32 -0800 |
parents | 0f912af348e0 |
children | 1782f5294fdc |
comparison
equal
deleted
inserted
replaced
17845:0f912af348e0 | 17846:42453dcfa95e |
---|---|
280 | 280 |
281 case "la" | 281 case "la" |
282 if (real_valued && symmetric) | 282 if (real_valued && symmetric) |
283 [~, idx] = sort (real (d), "descend"); | 283 [~, idx] = sort (real (d), "descend"); |
284 else | 284 else |
285 error ("sigma = \"la\" requires real symmetric problem"); | 285 error ('sigma = "la" requires real symmetric problem'); |
286 endif | 286 endif |
287 | 287 |
288 case "sa" | 288 case "sa" |
289 if (real_valued && symmetric) | 289 if (real_valued && symmetric) |
290 [~, idx] = sort (real (d), "ascend"); | 290 [~, idx] = sort (real (d), "ascend"); |
291 else | 291 else |
292 error ("sigma = \"sa\" requires real symmetric problem"); | 292 error ('sigma = "sa" requires real symmetric problem'); |
293 endif | 293 endif |
294 | 294 |
295 case "be" | 295 case "be" |
296 if (real_valued && symmetric) | 296 if (real_valued && symmetric) |
297 [~, idx] = sort (real (d), "ascend"); | 297 [~, idx] = sort (real (d), "ascend"); |
298 else | 298 else |
299 error ("sigma = \"be\" requires real symmetric problem"); | 299 error ('sigma = "be" requires real symmetric problem'); |
300 endif | 300 endif |
301 | 301 |
302 case "lr" | 302 case "lr" |
303 if (! (real_valued || symmetric)) | 303 if (! (real_valued || symmetric)) |
304 [~, idx] = sort (real (d), "descend"); | 304 [~, idx] = sort (real (d), "descend"); |
305 else | 305 else |
306 error ("sigma = \"lr\" requires complex or unsymmetric problem"); | 306 error ('sigma = "lr" requires complex or unsymmetric problem'); |
307 endif | 307 endif |
308 | 308 |
309 case "sr" | 309 case "sr" |
310 if (! (real_valued || symmetric)) | 310 if (! (real_valued || symmetric)) |
311 [~, idx] = sort (real (d), "ascend"); | 311 [~, idx] = sort (real (d), "ascend"); |
312 else | 312 else |
313 error ("sigma = \"sr\" requires complex or unsymmetric problem"); | 313 error ('sigma = "sr" requires complex or unsymmetric problem'); |
314 endif | 314 endif |
315 | 315 |
316 case "li" | 316 case "li" |
317 if (! (real_valued || symmetric)) | 317 if (! (real_valued || symmetric)) |
318 [~, idx] = sort (imag (d), "descend"); | 318 [~, idx] = sort (imag (d), "descend"); |
319 else | 319 else |
320 error ("sigma = \"li\" requires complex or unsymmetric problem"); | 320 error ('sigma = "li" requires complex or unsymmetric problem'); |
321 endif | 321 endif |
322 | 322 |
323 case "si" | 323 case "si" |
324 if (! (real_valued || symmetric)) | 324 if (! (real_valued || symmetric)) |
325 [~, idx] = sort (imag (d), "ascend"); | 325 [~, idx] = sort (imag (d), "ascend"); |
326 else | 326 else |
327 error ("sigma = \"si\" requires complex or unsymmetric problem"); | 327 error ('sigma = "si" requires complex or unsymmetric problem'); |
328 endif | 328 endif |
329 | 329 |
330 otherwise | 330 otherwise |
331 error ("unrecognized value for sigma: %s", sigma); | 331 error ("unrecognized value for sigma: %s", sigma); |
332 endswitch | 332 endswitch |
333 else | |
334 ## numeric sigma, find k closest values | |
335 [~, idx] = sort (abs (d - sigma)); | |
333 endif | 336 endif |
334 | 337 |
335 d = d(idx); | 338 d = d(idx); |
336 | 339 |
337 n = numel (d); | 340 n = numel (d); |
338 | 341 |
339 k = min (k, n); | 342 k = min (k, n); |
340 | 343 |
341 if (strcmp (sigma, 'be')) | 344 if (strcmp (sigma, "be")) |
342 tmp = k / 2; | 345 tmp = k / 2; |
343 n1 = floor (tmp); | 346 n1 = floor (tmp); |
344 n2 = n - ceil (tmp) + 1; | 347 n2 = n - ceil (tmp) + 1; |
345 selection = [1:floor(k/2), n2:n]; | 348 selection = [1:floor(k/2), n2:n]; |
346 else | 349 else |