comparison liboctave/CSparse.cc @ 15018:3d8ace26c5b4

maint: Use Octave coding conventions for cuddled parentheses in liboctave/. * Array-util.cc, Array.cc, Array.h, CMatrix.cc, CNDArray.cc, CSparse.cc, CmplxQR.cc, CollocWt.cc, DASPK.cc, DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, MSparse.cc, MatrixType.cc, Sparse-op-defs.h, Sparse-perm-op-defs.h, Sparse.cc, Sparse.h, SparseCmplxCHOL.cc, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseQR.cc, SparsedbleCHOL.cc, SparsedbleLU.cc, boolSparse.cc, cmd-hist.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dSparse.cc, data-conv.cc, dbleQR.cc, dbleSVD.cc, dim-vector.cc, eigs-base.cc, f2c-main.c, fCMatrix.cc, fCNDArray.cc, fCmplxQR.cc, fEIG.cc, fMatrix.cc, fNDArray.cc, floatQR.cc, floatSVD.cc, idx-vector.cc, kpse.cc, lo-specfun.cc, mx-inlines.cc, mx-op-defs.h, oct-alloc.cc, oct-binmap.h, oct-fftw.cc, oct-group.h, oct-inttypes.cc, oct-inttypes.h, oct-locbuf.cc, oct-md5.cc, oct-rand.cc, oct-sort.cc, oct-syscalls.cc, randgamma.c, randmtzig.c, randpoisson.c, sparse-base-chol.cc, sparse-base-lu.cc, sparse-dmsolve.cc, str-vec.cc, str-vec.h, tempnam.c, tempname.c: Use Octave coding conventions for cuddled parentheses in liboctave/.
author Rik <rik@octave.org>
date Thu, 26 Jul 2012 08:13:22 -0700
parents 460a3c6d8bf1
children 4bbd3bbb8912
comparison
equal deleted inserted replaced
15017:dd4ad69e4ab9 15018:3d8ace26c5b4
170 ridx (j) = i; 170 ridx (j) = i;
171 j++; 171 j++;
172 } 172 }
173 } 173 }
174 for (octave_idx_type i = l; i <= a.cols (); i++) 174 for (octave_idx_type i = l; i <= a.cols (); i++)
175 cidx(i) = j; 175 cidx (i) = j;
176 } 176 }
177 bool 177 bool
178 SparseComplexMatrix::operator == (const SparseComplexMatrix& a) const 178 SparseComplexMatrix::operator == (const SparseComplexMatrix& a) const
179 { 179 {
180 octave_idx_type nr = rows (); 180 octave_idx_type nr = rows ();
186 186
187 if (nr != nr_a || nc != nc_a || nz != nz_a) 187 if (nr != nr_a || nc != nc_a || nz != nz_a)
188 return false; 188 return false;
189 189
190 for (octave_idx_type i = 0; i < nc + 1; i++) 190 for (octave_idx_type i = 0; i < nc + 1; i++)
191 if (cidx(i) != a.cidx(i)) 191 if (cidx (i) != a.cidx (i))
192 return false; 192 return false;
193 193
194 for (octave_idx_type i = 0; i < nz; i++) 194 for (octave_idx_type i = 0; i < nz; i++)
195 if (data(i) != a.data(i) || ridx(i) != a.ridx(i)) 195 if (data (i) != a.data (i) || ridx (i) != a.ridx (i))
196 return false; 196 return false;
197 197
198 return true; 198 return true;
199 } 199 }
200 200
212 212
213 if (nr == nc && nr > 0) 213 if (nr == nc && nr > 0)
214 { 214 {
215 for (octave_idx_type j = 0; j < nc; j++) 215 for (octave_idx_type j = 0; j < nc; j++)
216 { 216 {
217 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 217 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
218 { 218 {
219 octave_idx_type ri = ridx(i); 219 octave_idx_type ri = ridx (i);
220 220
221 if (ri != j) 221 if (ri != j)
222 { 222 {
223 bool found = false; 223 bool found = false;
224 224
225 for (octave_idx_type k = cidx(ri); k < cidx(ri+1); k++) 225 for (octave_idx_type k = cidx (ri); k < cidx (ri+1); k++)
226 { 226 {
227 if (ridx(k) == j) 227 if (ridx (k) == j)
228 { 228 {
229 if (data(i) == conj(data(k))) 229 if (data (i) == conj (data (k)))
230 found = true; 230 found = true;
231 break; 231 break;
232 } 232 }
233 } 233 }
234 234
275 for (octave_idx_type j = 0; j < nc; j++) 275 for (octave_idx_type j = 0; j < nc; j++)
276 { 276 {
277 Complex tmp_max; 277 Complex tmp_max;
278 double abs_max = octave_NaN; 278 double abs_max = octave_NaN;
279 octave_idx_type idx_j = 0; 279 octave_idx_type idx_j = 0;
280 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 280 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
281 { 281 {
282 if (ridx(i) != idx_j) 282 if (ridx (i) != idx_j)
283 break; 283 break;
284 else 284 else
285 idx_j++; 285 idx_j++;
286 } 286 }
287 287
289 { 289 {
290 tmp_max = 0.; 290 tmp_max = 0.;
291 abs_max = 0.; 291 abs_max = 0.;
292 } 292 }
293 293
294 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 294 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
295 { 295 {
296 Complex tmp = data (i); 296 Complex tmp = data (i);
297 297
298 if (xisnan (tmp)) 298 if (xisnan (tmp))
299 continue; 299 continue;
330 } 330 }
331 else 331 else
332 { 332 {
333 idx_arg.resize (dim_vector (nr, 1), 0); 333 idx_arg.resize (dim_vector (nr, 1), 0);
334 334
335 for (octave_idx_type i = cidx(0); i < cidx(1); i++) 335 for (octave_idx_type i = cidx (0); i < cidx (1); i++)
336 idx_arg.elem(ridx(i)) = -1; 336 idx_arg.elem (ridx (i)) = -1;
337 337
338 for (octave_idx_type j = 0; j < nc; j++) 338 for (octave_idx_type j = 0; j < nc; j++)
339 for (octave_idx_type i = 0; i < nr; i++) 339 for (octave_idx_type i = 0; i < nr; i++)
340 { 340 {
341 if (idx_arg.elem(i) != -1) 341 if (idx_arg.elem (i) != -1)
342 continue; 342 continue;
343 bool found = false; 343 bool found = false;
344 for (octave_idx_type k = cidx(j); k < cidx(j+1); k++) 344 for (octave_idx_type k = cidx (j); k < cidx (j+1); k++)
345 if (ridx(k) == i) 345 if (ridx (k) == i)
346 { 346 {
347 found = true; 347 found = true;
348 break; 348 break;
349 } 349 }
350 350
351 if (!found) 351 if (!found)
352 idx_arg.elem(i) = j; 352 idx_arg.elem (i) = j;
353 353
354 } 354 }
355 355
356 for (octave_idx_type j = 0; j < nc; j++) 356 for (octave_idx_type j = 0; j < nc; j++)
357 { 357 {
358 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 358 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
359 { 359 {
360 octave_idx_type ir = ridx (i); 360 octave_idx_type ir = ridx (i);
361 octave_idx_type ix = idx_arg.elem (ir); 361 octave_idx_type ix = idx_arg.elem (ir);
362 Complex tmp = data (i); 362 Complex tmp = data (i);
363 363
364 if (xisnan (tmp)) 364 if (xisnan (tmp))
365 continue; 365 continue;
366 else if (ix == -1 || std::abs(tmp) > std::abs(elem (ir, ix))) 366 else if (ix == -1 || std::abs (tmp) > std::abs (elem (ir, ix)))
367 idx_arg.elem (ir) = j; 367 idx_arg.elem (ir) = j;
368 } 368 }
369 } 369 }
370 370
371 octave_idx_type nel = 0; 371 octave_idx_type nel = 0;
372 for (octave_idx_type j = 0; j < nr; j++) 372 for (octave_idx_type j = 0; j < nr; j++)
373 if (idx_arg.elem(j) == -1 || elem (j, idx_arg.elem (j)) != 0.) 373 if (idx_arg.elem (j) == -1 || elem (j, idx_arg.elem (j)) != 0.)
374 nel++; 374 nel++;
375 375
376 result = SparseComplexMatrix (nr, 1, nel); 376 result = SparseComplexMatrix (nr, 1, nel);
377 377
378 octave_idx_type ii = 0; 378 octave_idx_type ii = 0;
430 for (octave_idx_type j = 0; j < nc; j++) 430 for (octave_idx_type j = 0; j < nc; j++)
431 { 431 {
432 Complex tmp_min; 432 Complex tmp_min;
433 double abs_min = octave_NaN; 433 double abs_min = octave_NaN;
434 octave_idx_type idx_j = 0; 434 octave_idx_type idx_j = 0;
435 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 435 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
436 { 436 {
437 if (ridx(i) != idx_j) 437 if (ridx (i) != idx_j)
438 break; 438 break;
439 else 439 else
440 idx_j++; 440 idx_j++;
441 } 441 }
442 442
444 { 444 {
445 tmp_min = 0.; 445 tmp_min = 0.;
446 abs_min = 0.; 446 abs_min = 0.;
447 } 447 }
448 448
449 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 449 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
450 { 450 {
451 Complex tmp = data (i); 451 Complex tmp = data (i);
452 452
453 if (xisnan (tmp)) 453 if (xisnan (tmp))
454 continue; 454 continue;
485 } 485 }
486 else 486 else
487 { 487 {
488 idx_arg.resize (dim_vector (nr, 1), 0); 488 idx_arg.resize (dim_vector (nr, 1), 0);
489 489
490 for (octave_idx_type i = cidx(0); i < cidx(1); i++) 490 for (octave_idx_type i = cidx (0); i < cidx (1); i++)
491 idx_arg.elem(ridx(i)) = -1; 491 idx_arg.elem (ridx (i)) = -1;
492 492
493 for (octave_idx_type j = 0; j < nc; j++) 493 for (octave_idx_type j = 0; j < nc; j++)
494 for (octave_idx_type i = 0; i < nr; i++) 494 for (octave_idx_type i = 0; i < nr; i++)
495 { 495 {
496 if (idx_arg.elem(i) != -1) 496 if (idx_arg.elem (i) != -1)
497 continue; 497 continue;
498 bool found = false; 498 bool found = false;
499 for (octave_idx_type k = cidx(j); k < cidx(j+1); k++) 499 for (octave_idx_type k = cidx (j); k < cidx (j+1); k++)
500 if (ridx(k) == i) 500 if (ridx (k) == i)
501 { 501 {
502 found = true; 502 found = true;
503 break; 503 break;
504 } 504 }
505 505
506 if (!found) 506 if (!found)
507 idx_arg.elem(i) = j; 507 idx_arg.elem (i) = j;
508 508
509 } 509 }
510 510
511 for (octave_idx_type j = 0; j < nc; j++) 511 for (octave_idx_type j = 0; j < nc; j++)
512 { 512 {
513 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 513 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
514 { 514 {
515 octave_idx_type ir = ridx (i); 515 octave_idx_type ir = ridx (i);
516 octave_idx_type ix = idx_arg.elem (ir); 516 octave_idx_type ix = idx_arg.elem (ir);
517 Complex tmp = data (i); 517 Complex tmp = data (i);
518 518
519 if (xisnan (tmp)) 519 if (xisnan (tmp))
520 continue; 520 continue;
521 else if (ix == -1 || std::abs(tmp) < std::abs(elem (ir, ix))) 521 else if (ix == -1 || std::abs (tmp) < std::abs (elem (ir, ix)))
522 idx_arg.elem (ir) = j; 522 idx_arg.elem (ir) = j;
523 } 523 }
524 } 524 }
525 525
526 octave_idx_type nel = 0; 526 octave_idx_type nel = 0;
527 for (octave_idx_type j = 0; j < nr; j++) 527 for (octave_idx_type j = 0; j < nr; j++)
528 if (idx_arg.elem(j) == -1 || elem (j, idx_arg.elem (j)) != 0.) 528 if (idx_arg.elem (j) == -1 || elem (j, idx_arg.elem (j)) != 0.)
529 nel++; 529 nel++;
530 530
531 result = SparseComplexMatrix (nr, 1, nel); 531 result = SparseComplexMatrix (nr, 1, nel);
532 532
533 octave_idx_type ii = 0; 533 octave_idx_type ii = 0;
661 nz += tmp; 661 nz += tmp;
662 } 662 }
663 // retval.xcidx[1:nr] holds row entry *start* offsets for rows 0:(nr-1) 663 // retval.xcidx[1:nr] holds row entry *start* offsets for rows 0:(nr-1)
664 664
665 for (octave_idx_type j = 0; j < nc; j++) 665 for (octave_idx_type j = 0; j < nc; j++)
666 for (octave_idx_type k = cidx(j); k < cidx(j+1); k++) 666 for (octave_idx_type k = cidx (j); k < cidx (j+1); k++)
667 { 667 {
668 octave_idx_type q = retval.xcidx (ridx (k) + 1)++; 668 octave_idx_type q = retval.xcidx (ridx (k) + 1)++;
669 retval.xridx (q) = j; 669 retval.xridx (q) = j;
670 retval.xdata (q) = conj (data (k)); 670 retval.xdata (q) = conj (data (k));
671 } 671 }
753 if (calccond) 753 if (calccond)
754 { 754 {
755 double dmax = 0., dmin = octave_Inf; 755 double dmax = 0., dmin = octave_Inf;
756 for (octave_idx_type i = 0; i < nr; i++) 756 for (octave_idx_type i = 0; i < nr; i++)
757 { 757 {
758 double tmp = std::abs(v[i]); 758 double tmp = std::abs (v[i]);
759 if (tmp > dmax) 759 if (tmp > dmax)
760 dmax = tmp; 760 dmax = tmp;
761 if (tmp < dmin) 761 if (tmp < dmin)
762 dmin = tmp; 762 dmin = tmp;
763 } 763 }
803 { 803 {
804 // Calculate the 1-norm of matrix for rcond calculation 804 // Calculate the 1-norm of matrix for rcond calculation
805 for (octave_idx_type j = 0; j < nr; j++) 805 for (octave_idx_type j = 0; j < nr; j++)
806 { 806 {
807 double atmp = 0.; 807 double atmp = 0.;
808 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 808 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
809 atmp += std::abs(data(i)); 809 atmp += std::abs (data (i));
810 if (atmp > anorm) 810 if (atmp > anorm)
811 anorm = atmp; 811 anorm = atmp;
812 } 812 }
813 } 813 }
814 814
829 { 829 {
830 nz2 *= 2; 830 nz2 *= 2;
831 retval.change_capacity (nz2); 831 retval.change_capacity (nz2);
832 } 832 }
833 833
834 retval.xcidx(i) = cx; 834 retval.xcidx (i) = cx;
835 retval.xridx(cx) = i; 835 retval.xridx (cx) = i;
836 retval.xdata(cx) = 1.0; 836 retval.xdata (cx) = 1.0;
837 cx++; 837 cx++;
838 838
839 // iterate accross columns of input matrix 839 // iterate accross columns of input matrix
840 for (octave_idx_type j = i+1; j < nr; j++) 840 for (octave_idx_type j = i+1; j < nr; j++)
841 { 841 {
842 Complex v = 0.; 842 Complex v = 0.;
843 // iterate to calculate sum 843 // iterate to calculate sum
844 octave_idx_type colXp = retval.xcidx(i); 844 octave_idx_type colXp = retval.xcidx (i);
845 octave_idx_type colUp = cidx(j); 845 octave_idx_type colUp = cidx (j);
846 octave_idx_type rpX, rpU; 846 octave_idx_type rpX, rpU;
847 847
848 if (cidx(j) == cidx(j+1)) 848 if (cidx (j) == cidx (j+1))
849 { 849 {
850 (*current_liboctave_error_handler) 850 (*current_liboctave_error_handler)
851 ("division by zero"); 851 ("division by zero");
852 goto inverse_singular; 852 goto inverse_singular;
853 } 853 }
854 854
855 do 855 do
856 { 856 {
857 octave_quit (); 857 octave_quit ();
858 rpX = retval.xridx(colXp); 858 rpX = retval.xridx (colXp);
859 rpU = ridx(colUp); 859 rpU = ridx (colUp);
860 860
861 if (rpX < rpU) 861 if (rpX < rpU)
862 colXp++; 862 colXp++;
863 else if (rpX > rpU) 863 else if (rpX > rpU)
864 colUp++; 864 colUp++;
865 else 865 else
866 { 866 {
867 v -= retval.xdata(colXp) * data(colUp); 867 v -= retval.xdata (colXp) * data (colUp);
868 colXp++; 868 colXp++;
869 colUp++; 869 colUp++;
870 } 870 }
871 } while ((rpX<j) && (rpU<j) && 871 } while ((rpX<j) && (rpU<j) &&
872 (colXp<cx) && (colUp<nz)); 872 (colXp<cx) && (colUp<nz));
873 873
874 874
875 // get A(m,m) 875 // get A(m,m)
876 if (typ == MatrixType::Upper) 876 if (typ == MatrixType::Upper)
877 colUp = cidx(j+1) - 1; 877 colUp = cidx (j+1) - 1;
878 else 878 else
879 colUp = cidx(j); 879 colUp = cidx (j);
880 Complex pivot = data(colUp); 880 Complex pivot = data (colUp);
881 if (pivot == 0. || ridx(colUp) != j) 881 if (pivot == 0. || ridx (colUp) != j)
882 { 882 {
883 (*current_liboctave_error_handler) 883 (*current_liboctave_error_handler)
884 ("division by zero"); 884 ("division by zero");
885 goto inverse_singular; 885 goto inverse_singular;
886 } 886 }
891 { 891 {
892 nz2 *= 2; 892 nz2 *= 2;
893 retval.change_capacity (nz2); 893 retval.change_capacity (nz2);
894 } 894 }
895 895
896 retval.xridx(cx) = j; 896 retval.xridx (cx) = j;
897 retval.xdata(cx) = v / pivot; 897 retval.xdata (cx) = v / pivot;
898 cx++; 898 cx++;
899 } 899 }
900 } 900 }
901 901
902 // get A(m,m) 902 // get A(m,m)
903 octave_idx_type colUp; 903 octave_idx_type colUp;
904 if (typ == MatrixType::Upper) 904 if (typ == MatrixType::Upper)
905 colUp = cidx(i+1) - 1; 905 colUp = cidx (i+1) - 1;
906 else 906 else
907 colUp = cidx(i); 907 colUp = cidx (i);
908 Complex pivot = data(colUp); 908 Complex pivot = data (colUp);
909 if (pivot == 0. || ridx(colUp) != i) 909 if (pivot == 0. || ridx (colUp) != i)
910 { 910 {
911 (*current_liboctave_error_handler) ("division by zero"); 911 (*current_liboctave_error_handler) ("division by zero");
912 goto inverse_singular; 912 goto inverse_singular;
913 } 913 }
914 914
915 if (pivot != 1.0) 915 if (pivot != 1.0)
916 for (octave_idx_type j = cx_colstart; j < cx; j++) 916 for (octave_idx_type j = cx_colstart; j < cx; j++)
917 retval.xdata(j) /= pivot; 917 retval.xdata (j) /= pivot;
918 } 918 }
919 retval.xcidx(nr) = cx; 919 retval.xcidx (nr) = cx;
920 retval.maybe_compress (); 920 retval.maybe_compress ();
921 } 921 }
922 else 922 else
923 { 923 {
924 octave_idx_type nz = nnz (); 924 octave_idx_type nz = nnz ();
958 for (octave_idx_type j = iidx+1; j < nr; j++) 958 for (octave_idx_type j = iidx+1; j < nr; j++)
959 { 959 {
960 Complex v = 0.; 960 Complex v = 0.;
961 octave_idx_type jidx = perm[j]; 961 octave_idx_type jidx = perm[j];
962 // iterate to calculate sum 962 // iterate to calculate sum
963 for (octave_idx_type k = cidx(jidx); 963 for (octave_idx_type k = cidx (jidx);
964 k < cidx(jidx+1); k++) 964 k < cidx (jidx+1); k++)
965 { 965 {
966 octave_quit (); 966 octave_quit ();
967 v -= work[ridx(k)] * data(k); 967 v -= work[ridx (k)] * data (k);
968 } 968 }
969 969
970 // get A(m,m) 970 // get A(m,m)
971 Complex pivot; 971 Complex pivot;
972 if (typ == MatrixType::Permuted_Upper) 972 if (typ == MatrixType::Permuted_Upper)
973 pivot = data(cidx(jidx+1) - 1); 973 pivot = data (cidx (jidx+1) - 1);
974 else 974 else
975 pivot = data(cidx(jidx)); 975 pivot = data (cidx (jidx));
976 if (pivot == 0.) 976 if (pivot == 0.)
977 { 977 {
978 (*current_liboctave_error_handler) 978 (*current_liboctave_error_handler)
979 ("division by zero"); 979 ("division by zero");
980 goto inverse_singular; 980 goto inverse_singular;
984 } 984 }
985 985
986 // get A(m,m) 986 // get A(m,m)
987 octave_idx_type colUp; 987 octave_idx_type colUp;
988 if (typ == MatrixType::Permuted_Upper) 988 if (typ == MatrixType::Permuted_Upper)
989 colUp = cidx(perm[iidx]+1) - 1; 989 colUp = cidx (perm[iidx]+1) - 1;
990 else 990 else
991 colUp = cidx(perm[iidx]); 991 colUp = cidx (perm[iidx]);
992 992
993 Complex pivot = data(colUp); 993 Complex pivot = data (colUp);
994 if (pivot == 0.) 994 if (pivot == 0.)
995 { 995 {
996 (*current_liboctave_error_handler) 996 (*current_liboctave_error_handler)
997 ("division by zero"); 997 ("division by zero");
998 goto inverse_singular; 998 goto inverse_singular;
1011 { 1011 {
1012 nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2); 1012 nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2);
1013 retval.change_capacity (nz2); 1013 retval.change_capacity (nz2);
1014 } 1014 }
1015 1015
1016 retval.xcidx(i) = cx; 1016 retval.xcidx (i) = cx;
1017 for (octave_idx_type j = iidx; j < nr; j++) 1017 for (octave_idx_type j = iidx; j < nr; j++)
1018 if (work[j] != 0.) 1018 if (work[j] != 0.)
1019 { 1019 {
1020 retval.xridx(cx) = j; 1020 retval.xridx (cx) = j;
1021 retval.xdata(cx++) = work[j]; 1021 retval.xdata (cx++) = work[j];
1022 } 1022 }
1023 } 1023 }
1024 1024
1025 retval.xcidx(nr) = cx; 1025 retval.xcidx (nr) = cx;
1026 retval.maybe_compress (); 1026 retval.maybe_compress ();
1027 } 1027 }
1028 1028
1029 if (calccond) 1029 if (calccond)
1030 { 1030 {
1031 // Calculate the 1-norm of inverse matrix for rcond calculation 1031 // Calculate the 1-norm of inverse matrix for rcond calculation
1032 for (octave_idx_type j = 0; j < nr; j++) 1032 for (octave_idx_type j = 0; j < nr; j++)
1033 { 1033 {
1034 double atmp = 0.; 1034 double atmp = 0.;
1035 for (octave_idx_type i = retval.cidx(j); 1035 for (octave_idx_type i = retval.cidx (j);
1036 i < retval.cidx(j+1); i++) 1036 i < retval.cidx (j+1); i++)
1037 atmp += std::abs(retval.data(i)); 1037 atmp += std::abs (retval.data (i));
1038 if (atmp > ainvnorm) 1038 if (atmp > ainvnorm)
1039 ainvnorm = atmp; 1039 ainvnorm = atmp;
1040 } 1040 }
1041 1041
1042 rcond = 1. / ainvnorm / anorm; 1042 rcond = 1. / ainvnorm / anorm;
1081 if (info == 0) 1081 if (info == 0)
1082 { 1082 {
1083 double rcond2; 1083 double rcond2;
1084 SparseMatrix Q = fact.Q (); 1084 SparseMatrix Q = fact.Q ();
1085 SparseComplexMatrix InvL = fact.L ().transpose (). 1085 SparseComplexMatrix InvL = fact.L ().transpose ().
1086 tinverse(tmp_typ, info, rcond2, true, false); 1086 tinverse (tmp_typ, info, rcond2, true, false);
1087 ret = Q * InvL.hermitian () * InvL * Q.transpose (); 1087 ret = Q * InvL.hermitian () * InvL * Q.transpose ();
1088 } 1088 }
1089 else 1089 else
1090 { 1090 {
1091 // Matrix is either singular or not positive definite 1091 // Matrix is either singular or not positive definite
1104 MatrixType tmp_typ (MatrixType::Upper); 1104 MatrixType tmp_typ (MatrixType::Upper);
1105 SparseComplexLU fact (*this, Qinit, Matrix (), false, false); 1105 SparseComplexLU fact (*this, Qinit, Matrix (), false, false);
1106 rcond = fact.rcond (); 1106 rcond = fact.rcond ();
1107 double rcond2; 1107 double rcond2;
1108 SparseComplexMatrix InvL = fact.L ().transpose (). 1108 SparseComplexMatrix InvL = fact.L ().transpose ().
1109 tinverse(tmp_typ, info, rcond2, true, false); 1109 tinverse (tmp_typ, info, rcond2, true, false);
1110 SparseComplexMatrix InvU = fact.U (). 1110 SparseComplexMatrix InvU = fact.U ().
1111 tinverse(tmp_typ, info, rcond2, true, false).transpose (); 1111 tinverse (tmp_typ, info, rcond2, true, false).transpose ();
1112 ret = fact.Pc ().transpose () * InvU * InvL * fact.Pr (); 1112 ret = fact.Pc ().transpose () * InvU * InvL * fact.Pr ();
1113 } 1113 }
1114 } 1114 }
1115 1115
1116 return ret; 1116 return ret;
1277 mattype.info (); 1277 mattype.info ();
1278 1278
1279 if (typ == MatrixType::Diagonal || 1279 if (typ == MatrixType::Diagonal ||
1280 typ == MatrixType::Permuted_Diagonal) 1280 typ == MatrixType::Permuted_Diagonal)
1281 { 1281 {
1282 retval.resize (nc, b.cols (), Complex(0.,0.)); 1282 retval.resize (nc, b.cols (), Complex (0.,0.));
1283 if (typ == MatrixType::Diagonal) 1283 if (typ == MatrixType::Diagonal)
1284 for (octave_idx_type j = 0; j < b.cols (); j++) 1284 for (octave_idx_type j = 0; j < b.cols (); j++)
1285 for (octave_idx_type i = 0; i < nm; i++) 1285 for (octave_idx_type i = 0; i < nm; i++)
1286 retval(i,j) = b(i,j) / data (i); 1286 retval(i,j) = b(i,j) / data (i);
1287 else 1287 else
1288 for (octave_idx_type j = 0; j < b.cols (); j++) 1288 for (octave_idx_type j = 0; j < b.cols (); j++)
1289 for (octave_idx_type k = 0; k < nc; k++) 1289 for (octave_idx_type k = 0; k < nc; k++)
1290 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 1290 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
1291 retval(k,j) = b(ridx(i),j) / data (i); 1291 retval(k,j) = b(ridx (i),j) / data (i);
1292 1292
1293 if (calc_cond) 1293 if (calc_cond)
1294 { 1294 {
1295 double dmax = 0., dmin = octave_Inf; 1295 double dmax = 0., dmin = octave_Inf;
1296 for (octave_idx_type i = 0; i < nm; i++) 1296 for (octave_idx_type i = 0; i < nm; i++)
1297 { 1297 {
1298 double tmp = std::abs(data(i)); 1298 double tmp = std::abs (data (i));
1299 if (tmp > dmax) 1299 if (tmp > dmax)
1300 dmax = tmp; 1300 dmax = tmp;
1301 if (tmp < dmin) 1301 if (tmp < dmin)
1302 dmin = tmp; 1302 dmin = tmp;
1303 } 1303 }
1342 { 1342 {
1343 octave_idx_type b_nc = b.cols (); 1343 octave_idx_type b_nc = b.cols ();
1344 octave_idx_type b_nz = b.nnz (); 1344 octave_idx_type b_nz = b.nnz ();
1345 retval = SparseComplexMatrix (nc, b_nc, b_nz); 1345 retval = SparseComplexMatrix (nc, b_nc, b_nz);
1346 1346
1347 retval.xcidx(0) = 0; 1347 retval.xcidx (0) = 0;
1348 octave_idx_type ii = 0; 1348 octave_idx_type ii = 0;
1349 if (typ == MatrixType::Diagonal) 1349 if (typ == MatrixType::Diagonal)
1350 for (octave_idx_type j = 0; j < b.cols (); j++) 1350 for (octave_idx_type j = 0; j < b.cols (); j++)
1351 { 1351 {
1352 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 1352 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
1353 { 1353 {
1354 if (b.ridx(i) >= nm) 1354 if (b.ridx (i) >= nm)
1355 break; 1355 break;
1356 retval.xridx (ii) = b.ridx(i); 1356 retval.xridx (ii) = b.ridx (i);
1357 retval.xdata (ii++) = b.data(i) / data (b.ridx (i)); 1357 retval.xdata (ii++) = b.data (i) / data (b.ridx (i));
1358 } 1358 }
1359 retval.xcidx(j+1) = ii; 1359 retval.xcidx (j+1) = ii;
1360 } 1360 }
1361 else 1361 else
1362 for (octave_idx_type j = 0; j < b.cols (); j++) 1362 for (octave_idx_type j = 0; j < b.cols (); j++)
1363 { 1363 {
1364 for (octave_idx_type l = 0; l < nc; l++) 1364 for (octave_idx_type l = 0; l < nc; l++)
1365 for (octave_idx_type i = cidx(l); i < cidx(l+1); i++) 1365 for (octave_idx_type i = cidx (l); i < cidx (l+1); i++)
1366 { 1366 {
1367 bool found = false; 1367 bool found = false;
1368 octave_idx_type k; 1368 octave_idx_type k;
1369 for (k = b.cidx(j); k < b.cidx(j+1); k++) 1369 for (k = b.cidx (j); k < b.cidx (j+1); k++)
1370 if (ridx(i) == b.ridx(k)) 1370 if (ridx (i) == b.ridx (k))
1371 { 1371 {
1372 found = true; 1372 found = true;
1373 break; 1373 break;
1374 } 1374 }
1375 if (found) 1375 if (found)
1376 { 1376 {
1377 retval.xridx (ii) = l; 1377 retval.xridx (ii) = l;
1378 retval.xdata (ii++) = b.data(k) / data (i); 1378 retval.xdata (ii++) = b.data (k) / data (i);
1379 } 1379 }
1380 } 1380 }
1381 retval.xcidx(j+1) = ii; 1381 retval.xcidx (j+1) = ii;
1382 } 1382 }
1383 1383
1384 if (calc_cond) 1384 if (calc_cond)
1385 { 1385 {
1386 double dmax = 0., dmin = octave_Inf; 1386 double dmax = 0., dmin = octave_Inf;
1387 for (octave_idx_type i = 0; i < nm; i++) 1387 for (octave_idx_type i = 0; i < nm; i++)
1388 { 1388 {
1389 double tmp = std::abs(data(i)); 1389 double tmp = std::abs (data (i));
1390 if (tmp > dmax) 1390 if (tmp > dmax)
1391 dmax = tmp; 1391 dmax = tmp;
1392 if (tmp < dmin) 1392 if (tmp < dmin)
1393 dmin = tmp; 1393 dmin = tmp;
1394 } 1394 }
1429 mattype.info (); 1429 mattype.info ();
1430 1430
1431 if (typ == MatrixType::Diagonal || 1431 if (typ == MatrixType::Diagonal ||
1432 typ == MatrixType::Permuted_Diagonal) 1432 typ == MatrixType::Permuted_Diagonal)
1433 { 1433 {
1434 retval.resize (nc, b.cols (), Complex(0.,0.)); 1434 retval.resize (nc, b.cols (), Complex (0.,0.));
1435 if (typ == MatrixType::Diagonal) 1435 if (typ == MatrixType::Diagonal)
1436 for (octave_idx_type j = 0; j < b.cols (); j++) 1436 for (octave_idx_type j = 0; j < b.cols (); j++)
1437 for (octave_idx_type i = 0; i < nm; i++) 1437 for (octave_idx_type i = 0; i < nm; i++)
1438 retval(i,j) = b(i,j) / data (i); 1438 retval(i,j) = b(i,j) / data (i);
1439 else 1439 else
1440 for (octave_idx_type j = 0; j < b.cols (); j++) 1440 for (octave_idx_type j = 0; j < b.cols (); j++)
1441 for (octave_idx_type k = 0; k < nc; k++) 1441 for (octave_idx_type k = 0; k < nc; k++)
1442 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 1442 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
1443 retval(k,j) = b(ridx(i),j) / data (i); 1443 retval(k,j) = b(ridx (i),j) / data (i);
1444 1444
1445 if (calc_cond) 1445 if (calc_cond)
1446 { 1446 {
1447 double dmax = 0., dmin = octave_Inf; 1447 double dmax = 0., dmin = octave_Inf;
1448 for (octave_idx_type i = 0; i < nr; i++) 1448 for (octave_idx_type i = 0; i < nr; i++)
1449 { 1449 {
1450 double tmp = std::abs(data(i)); 1450 double tmp = std::abs (data (i));
1451 if (tmp > dmax) 1451 if (tmp > dmax)
1452 dmax = tmp; 1452 dmax = tmp;
1453 if (tmp < dmin) 1453 if (tmp < dmin)
1454 dmin = tmp; 1454 dmin = tmp;
1455 } 1455 }
1494 { 1494 {
1495 octave_idx_type b_nc = b.cols (); 1495 octave_idx_type b_nc = b.cols ();
1496 octave_idx_type b_nz = b.nnz (); 1496 octave_idx_type b_nz = b.nnz ();
1497 retval = SparseComplexMatrix (nc, b_nc, b_nz); 1497 retval = SparseComplexMatrix (nc, b_nc, b_nz);
1498 1498
1499 retval.xcidx(0) = 0; 1499 retval.xcidx (0) = 0;
1500 octave_idx_type ii = 0; 1500 octave_idx_type ii = 0;
1501 if (typ == MatrixType::Diagonal) 1501 if (typ == MatrixType::Diagonal)
1502 for (octave_idx_type j = 0; j < b.cols (); j++) 1502 for (octave_idx_type j = 0; j < b.cols (); j++)
1503 { 1503 {
1504 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 1504 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
1505 { 1505 {
1506 if (b.ridx(i) >= nm) 1506 if (b.ridx (i) >= nm)
1507 break; 1507 break;
1508 retval.xridx (ii) = b.ridx(i); 1508 retval.xridx (ii) = b.ridx (i);
1509 retval.xdata (ii++) = b.data(i) / data (b.ridx (i)); 1509 retval.xdata (ii++) = b.data (i) / data (b.ridx (i));
1510 } 1510 }
1511 retval.xcidx(j+1) = ii; 1511 retval.xcidx (j+1) = ii;
1512 } 1512 }
1513 else 1513 else
1514 for (octave_idx_type j = 0; j < b.cols (); j++) 1514 for (octave_idx_type j = 0; j < b.cols (); j++)
1515 { 1515 {
1516 for (octave_idx_type l = 0; l < nc; l++) 1516 for (octave_idx_type l = 0; l < nc; l++)
1517 for (octave_idx_type i = cidx(l); i < cidx(l+1); i++) 1517 for (octave_idx_type i = cidx (l); i < cidx (l+1); i++)
1518 { 1518 {
1519 bool found = false; 1519 bool found = false;
1520 octave_idx_type k; 1520 octave_idx_type k;
1521 for (k = b.cidx(j); k < b.cidx(j+1); k++) 1521 for (k = b.cidx (j); k < b.cidx (j+1); k++)
1522 if (ridx(i) == b.ridx(k)) 1522 if (ridx (i) == b.ridx (k))
1523 { 1523 {
1524 found = true; 1524 found = true;
1525 break; 1525 break;
1526 } 1526 }
1527 if (found) 1527 if (found)
1528 { 1528 {
1529 retval.xridx (ii) = l; 1529 retval.xridx (ii) = l;
1530 retval.xdata (ii++) = b.data(k) / data (i); 1530 retval.xdata (ii++) = b.data (k) / data (i);
1531 } 1531 }
1532 } 1532 }
1533 retval.xcidx(j+1) = ii; 1533 retval.xcidx (j+1) = ii;
1534 } 1534 }
1535 1535
1536 if (calc_cond) 1536 if (calc_cond)
1537 { 1537 {
1538 double dmax = 0., dmin = octave_Inf; 1538 double dmax = 0., dmin = octave_Inf;
1539 for (octave_idx_type i = 0; i < nm; i++) 1539 for (octave_idx_type i = 0; i < nm; i++)
1540 { 1540 {
1541 double tmp = std::abs(data(i)); 1541 double tmp = std::abs (data (i));
1542 if (tmp > dmax) 1542 if (tmp > dmax)
1543 dmax = tmp; 1543 dmax = tmp;
1544 if (tmp < dmin) 1544 if (tmp < dmin)
1545 dmin = tmp; 1545 dmin = tmp;
1546 } 1546 }
1592 { 1592 {
1593 // Calculate the 1-norm of matrix for rcond calculation 1593 // Calculate the 1-norm of matrix for rcond calculation
1594 for (octave_idx_type j = 0; j < nc; j++) 1594 for (octave_idx_type j = 0; j < nc; j++)
1595 { 1595 {
1596 double atmp = 0.; 1596 double atmp = 0.;
1597 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 1597 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
1598 atmp += std::abs(data(i)); 1598 atmp += std::abs (data (i));
1599 if (atmp > anorm) 1599 if (atmp > anorm)
1600 anorm = atmp; 1600 anorm = atmp;
1601 } 1601 }
1602 } 1602 }
1603 1603
1618 { 1618 {
1619 octave_idx_type kidx = perm[k]; 1619 octave_idx_type kidx = perm[k];
1620 1620
1621 if (work[k] != 0.) 1621 if (work[k] != 0.)
1622 { 1622 {
1623 if (ridx(cidx(kidx+1)-1) != k || 1623 if (ridx (cidx (kidx+1)-1) != k ||
1624 data(cidx(kidx+1)-1) == 0.) 1624 data (cidx (kidx+1)-1) == 0.)
1625 { 1625 {
1626 err = -2; 1626 err = -2;
1627 goto triangular_error; 1627 goto triangular_error;
1628 } 1628 }
1629 1629
1630 Complex tmp = work[k] / data(cidx(kidx+1)-1); 1630 Complex tmp = work[k] / data (cidx (kidx+1)-1);
1631 work[k] = tmp; 1631 work[k] = tmp;
1632 for (octave_idx_type i = cidx(kidx); 1632 for (octave_idx_type i = cidx (kidx);
1633 i < cidx(kidx+1)-1; i++) 1633 i < cidx (kidx+1)-1; i++)
1634 { 1634 {
1635 octave_idx_type iidx = ridx(i); 1635 octave_idx_type iidx = ridx (i);
1636 work[iidx] = work[iidx] - tmp * data(i); 1636 work[iidx] = work[iidx] - tmp * data (i);
1637 } 1637 }
1638 } 1638 }
1639 } 1639 }
1640 1640
1641 for (octave_idx_type i = 0; i < nc; i++) 1641 for (octave_idx_type i = 0; i < nc; i++)
1656 { 1656 {
1657 octave_idx_type iidx = perm[k]; 1657 octave_idx_type iidx = perm[k];
1658 1658
1659 if (work[k] != 0.) 1659 if (work[k] != 0.)
1660 { 1660 {
1661 Complex tmp = work[k] / data(cidx(iidx+1)-1); 1661 Complex tmp = work[k] / data (cidx (iidx+1)-1);
1662 work[k] = tmp; 1662 work[k] = tmp;
1663 for (octave_idx_type i = cidx(iidx); 1663 for (octave_idx_type i = cidx (iidx);
1664 i < cidx(iidx+1)-1; i++) 1664 i < cidx (iidx+1)-1; i++)
1665 { 1665 {
1666 octave_idx_type idx2 = ridx(i); 1666 octave_idx_type idx2 = ridx (i);
1667 work[idx2] = work[idx2] - tmp * data(i); 1667 work[idx2] = work[idx2] - tmp * data (i);
1668 } 1668 }
1669 } 1669 }
1670 } 1670 }
1671 double atmp = 0; 1671 double atmp = 0;
1672 for (octave_idx_type i = 0; i < j+1; i++) 1672 for (octave_idx_type i = 0; i < j+1; i++)
1673 { 1673 {
1674 atmp += std::abs(work[i]); 1674 atmp += std::abs (work[i]);
1675 work[i] = 0.; 1675 work[i] = 0.;
1676 } 1676 }
1677 if (atmp > ainvnorm) 1677 if (atmp > ainvnorm)
1678 ainvnorm = atmp; 1678 ainvnorm = atmp;
1679 } 1679 }
1694 1694
1695 for (octave_idx_type k = nc-1; k >= 0; k--) 1695 for (octave_idx_type k = nc-1; k >= 0; k--)
1696 { 1696 {
1697 if (work[k] != 0.) 1697 if (work[k] != 0.)
1698 { 1698 {
1699 if (ridx(cidx(k+1)-1) != k || 1699 if (ridx (cidx (k+1)-1) != k ||
1700 data(cidx(k+1)-1) == 0.) 1700 data (cidx (k+1)-1) == 0.)
1701 { 1701 {
1702 err = -2; 1702 err = -2;
1703 goto triangular_error; 1703 goto triangular_error;
1704 } 1704 }
1705 1705
1706 Complex tmp = work[k] / data(cidx(k+1)-1); 1706 Complex tmp = work[k] / data (cidx (k+1)-1);
1707 work[k] = tmp; 1707 work[k] = tmp;
1708 for (octave_idx_type i = cidx(k); i < cidx(k+1)-1; i++) 1708 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
1709 { 1709 {
1710 octave_idx_type iidx = ridx(i); 1710 octave_idx_type iidx = ridx (i);
1711 work[iidx] = work[iidx] - tmp * data(i); 1711 work[iidx] = work[iidx] - tmp * data (i);
1712 } 1712 }
1713 } 1713 }
1714 } 1714 }
1715 1715
1716 for (octave_idx_type i = 0; i < nc; i++) 1716 for (octave_idx_type i = 0; i < nc; i++)
1729 1729
1730 for (octave_idx_type k = j; k >= 0; k--) 1730 for (octave_idx_type k = j; k >= 0; k--)
1731 { 1731 {
1732 if (work[k] != 0.) 1732 if (work[k] != 0.)
1733 { 1733 {
1734 Complex tmp = work[k] / data(cidx(k+1)-1); 1734 Complex tmp = work[k] / data (cidx (k+1)-1);
1735 work[k] = tmp; 1735 work[k] = tmp;
1736 for (octave_idx_type i = cidx(k); 1736 for (octave_idx_type i = cidx (k);
1737 i < cidx(k+1)-1; i++) 1737 i < cidx (k+1)-1; i++)
1738 { 1738 {
1739 octave_idx_type iidx = ridx(i); 1739 octave_idx_type iidx = ridx (i);
1740 work[iidx] = work[iidx] - tmp * data(i); 1740 work[iidx] = work[iidx] - tmp * data (i);
1741 } 1741 }
1742 } 1742 }
1743 } 1743 }
1744 double atmp = 0; 1744 double atmp = 0;
1745 for (octave_idx_type i = 0; i < j+1; i++) 1745 for (octave_idx_type i = 0; i < j+1; i++)
1746 { 1746 {
1747 atmp += std::abs(work[i]); 1747 atmp += std::abs (work[i]);
1748 work[i] = 0.; 1748 work[i] = 0.;
1749 } 1749 }
1750 if (atmp > ainvnorm) 1750 if (atmp > ainvnorm)
1751 ainvnorm = atmp; 1751 ainvnorm = atmp;
1752 } 1752 }
1827 { 1827 {
1828 // Calculate the 1-norm of matrix for rcond calculation 1828 // Calculate the 1-norm of matrix for rcond calculation
1829 for (octave_idx_type j = 0; j < nc; j++) 1829 for (octave_idx_type j = 0; j < nc; j++)
1830 { 1830 {
1831 double atmp = 0.; 1831 double atmp = 0.;
1832 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 1832 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
1833 atmp += std::abs(data(i)); 1833 atmp += std::abs (data (i));
1834 if (atmp > anorm) 1834 if (atmp > anorm)
1835 anorm = atmp; 1835 anorm = atmp;
1836 } 1836 }
1837 } 1837 }
1838 1838
1839 octave_idx_type b_nc = b.cols (); 1839 octave_idx_type b_nc = b.cols ();
1840 octave_idx_type b_nz = b.nnz (); 1840 octave_idx_type b_nz = b.nnz ();
1841 retval = SparseComplexMatrix (nc, b_nc, b_nz); 1841 retval = SparseComplexMatrix (nc, b_nc, b_nz);
1842 retval.xcidx(0) = 0; 1842 retval.xcidx (0) = 0;
1843 octave_idx_type ii = 0; 1843 octave_idx_type ii = 0;
1844 octave_idx_type x_nz = b_nz; 1844 octave_idx_type x_nz = b_nz;
1845 1845
1846 if (typ == MatrixType::Permuted_Upper) 1846 if (typ == MatrixType::Permuted_Upper)
1847 { 1847 {
1854 1854
1855 for (octave_idx_type j = 0; j < b_nc; j++) 1855 for (octave_idx_type j = 0; j < b_nc; j++)
1856 { 1856 {
1857 for (octave_idx_type i = 0; i < nm; i++) 1857 for (octave_idx_type i = 0; i < nm; i++)
1858 work[i] = 0.; 1858 work[i] = 0.;
1859 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 1859 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
1860 work[b.ridx(i)] = b.data(i); 1860 work[b.ridx (i)] = b.data (i);
1861 1861
1862 for (octave_idx_type k = nc-1; k >= 0; k--) 1862 for (octave_idx_type k = nc-1; k >= 0; k--)
1863 { 1863 {
1864 octave_idx_type kidx = perm[k]; 1864 octave_idx_type kidx = perm[k];
1865 1865
1866 if (work[k] != 0.) 1866 if (work[k] != 0.)
1867 { 1867 {
1868 if (ridx(cidx(kidx+1)-1) != k || 1868 if (ridx (cidx (kidx+1)-1) != k ||
1869 data(cidx(kidx+1)-1) == 0.) 1869 data (cidx (kidx+1)-1) == 0.)
1870 { 1870 {
1871 err = -2; 1871 err = -2;
1872 goto triangular_error; 1872 goto triangular_error;
1873 } 1873 }
1874 1874
1875 Complex tmp = work[k] / data(cidx(kidx+1)-1); 1875 Complex tmp = work[k] / data (cidx (kidx+1)-1);
1876 work[k] = tmp; 1876 work[k] = tmp;
1877 for (octave_idx_type i = cidx(kidx); 1877 for (octave_idx_type i = cidx (kidx);
1878 i < cidx(kidx+1)-1; i++) 1878 i < cidx (kidx+1)-1; i++)
1879 { 1879 {
1880 octave_idx_type iidx = ridx(i); 1880 octave_idx_type iidx = ridx (i);
1881 work[iidx] = work[iidx] - tmp * data(i); 1881 work[iidx] = work[iidx] - tmp * data (i);
1882 } 1882 }
1883 } 1883 }
1884 } 1884 }
1885 1885
1886 // Count non-zeros in work vector and adjust space in 1886 // Count non-zeros in work vector and adjust space in
1899 } 1899 }
1900 1900
1901 for (octave_idx_type i = 0; i < nc; i++) 1901 for (octave_idx_type i = 0; i < nc; i++)
1902 if (work[rperm[i]] != 0.) 1902 if (work[rperm[i]] != 0.)
1903 { 1903 {
1904 retval.xridx(ii) = i; 1904 retval.xridx (ii) = i;
1905 retval.xdata(ii++) = work[rperm[i]]; 1905 retval.xdata (ii++) = work[rperm[i]];
1906 } 1906 }
1907 retval.xcidx(j+1) = ii; 1907 retval.xcidx (j+1) = ii;
1908 } 1908 }
1909 1909
1910 retval.maybe_compress (); 1910 retval.maybe_compress ();
1911 1911
1912 if (calc_cond) 1912 if (calc_cond)
1923 { 1923 {
1924 octave_idx_type iidx = perm[k]; 1924 octave_idx_type iidx = perm[k];
1925 1925
1926 if (work[k] != 0.) 1926 if (work[k] != 0.)
1927 { 1927 {
1928 Complex tmp = work[k] / data(cidx(iidx+1)-1); 1928 Complex tmp = work[k] / data (cidx (iidx+1)-1);
1929 work[k] = tmp; 1929 work[k] = tmp;
1930 for (octave_idx_type i = cidx(iidx); 1930 for (octave_idx_type i = cidx (iidx);
1931 i < cidx(iidx+1)-1; i++) 1931 i < cidx (iidx+1)-1; i++)
1932 { 1932 {
1933 octave_idx_type idx2 = ridx(i); 1933 octave_idx_type idx2 = ridx (i);
1934 work[idx2] = work[idx2] - tmp * data(i); 1934 work[idx2] = work[idx2] - tmp * data (i);
1935 } 1935 }
1936 } 1936 }
1937 } 1937 }
1938 double atmp = 0; 1938 double atmp = 0;
1939 for (octave_idx_type i = 0; i < j+1; i++) 1939 for (octave_idx_type i = 0; i < j+1; i++)
1940 { 1940 {
1941 atmp += std::abs(work[i]); 1941 atmp += std::abs (work[i]);
1942 work[i] = 0.; 1942 work[i] = 0.;
1943 } 1943 }
1944 if (atmp > ainvnorm) 1944 if (atmp > ainvnorm)
1945 ainvnorm = atmp; 1945 ainvnorm = atmp;
1946 } 1946 }
1953 1953
1954 for (octave_idx_type j = 0; j < b_nc; j++) 1954 for (octave_idx_type j = 0; j < b_nc; j++)
1955 { 1955 {
1956 for (octave_idx_type i = 0; i < nm; i++) 1956 for (octave_idx_type i = 0; i < nm; i++)
1957 work[i] = 0.; 1957 work[i] = 0.;
1958 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 1958 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
1959 work[b.ridx(i)] = b.data(i); 1959 work[b.ridx (i)] = b.data (i);
1960 1960
1961 for (octave_idx_type k = nc-1; k >= 0; k--) 1961 for (octave_idx_type k = nc-1; k >= 0; k--)
1962 { 1962 {
1963 if (work[k] != 0.) 1963 if (work[k] != 0.)
1964 { 1964 {
1965 if (ridx(cidx(k+1)-1) != k || 1965 if (ridx (cidx (k+1)-1) != k ||
1966 data(cidx(k+1)-1) == 0.) 1966 data (cidx (k+1)-1) == 0.)
1967 { 1967 {
1968 err = -2; 1968 err = -2;
1969 goto triangular_error; 1969 goto triangular_error;
1970 } 1970 }
1971 1971
1972 Complex tmp = work[k] / data(cidx(k+1)-1); 1972 Complex tmp = work[k] / data (cidx (k+1)-1);
1973 work[k] = tmp; 1973 work[k] = tmp;
1974 for (octave_idx_type i = cidx(k); i < cidx(k+1)-1; i++) 1974 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
1975 { 1975 {
1976 octave_idx_type iidx = ridx(i); 1976 octave_idx_type iidx = ridx (i);
1977 work[iidx] = work[iidx] - tmp * data(i); 1977 work[iidx] = work[iidx] - tmp * data (i);
1978 } 1978 }
1979 } 1979 }
1980 } 1980 }
1981 1981
1982 // Count non-zeros in work vector and adjust space in 1982 // Count non-zeros in work vector and adjust space in
1995 } 1995 }
1996 1996
1997 for (octave_idx_type i = 0; i < nc; i++) 1997 for (octave_idx_type i = 0; i < nc; i++)
1998 if (work[i] != 0.) 1998 if (work[i] != 0.)
1999 { 1999 {
2000 retval.xridx(ii) = i; 2000 retval.xridx (ii) = i;
2001 retval.xdata(ii++) = work[i]; 2001 retval.xdata (ii++) = work[i];
2002 } 2002 }
2003 retval.xcidx(j+1) = ii; 2003 retval.xcidx (j+1) = ii;
2004 } 2004 }
2005 2005
2006 retval.maybe_compress (); 2006 retval.maybe_compress ();
2007 2007
2008 if (calc_cond) 2008 if (calc_cond)
2017 2017
2018 for (octave_idx_type k = j; k >= 0; k--) 2018 for (octave_idx_type k = j; k >= 0; k--)
2019 { 2019 {
2020 if (work[k] != 0.) 2020 if (work[k] != 0.)
2021 { 2021 {
2022 Complex tmp = work[k] / data(cidx(k+1)-1); 2022 Complex tmp = work[k] / data (cidx (k+1)-1);
2023 work[k] = tmp; 2023 work[k] = tmp;
2024 for (octave_idx_type i = cidx(k); 2024 for (octave_idx_type i = cidx (k);
2025 i < cidx(k+1)-1; i++) 2025 i < cidx (k+1)-1; i++)
2026 { 2026 {
2027 octave_idx_type iidx = ridx(i); 2027 octave_idx_type iidx = ridx (i);
2028 work[iidx] = work[iidx] - tmp * data(i); 2028 work[iidx] = work[iidx] - tmp * data (i);
2029 } 2029 }
2030 } 2030 }
2031 } 2031 }
2032 double atmp = 0; 2032 double atmp = 0;
2033 for (octave_idx_type i = 0; i < j+1; i++) 2033 for (octave_idx_type i = 0; i < j+1; i++)
2034 { 2034 {
2035 atmp += std::abs(work[i]); 2035 atmp += std::abs (work[i]);
2036 work[i] = 0.; 2036 work[i] = 0.;
2037 } 2037 }
2038 if (atmp > ainvnorm) 2038 if (atmp > ainvnorm)
2039 ainvnorm = atmp; 2039 ainvnorm = atmp;
2040 } 2040 }
2115 { 2115 {
2116 // Calculate the 1-norm of matrix for rcond calculation 2116 // Calculate the 1-norm of matrix for rcond calculation
2117 for (octave_idx_type j = 0; j < nc; j++) 2117 for (octave_idx_type j = 0; j < nc; j++)
2118 { 2118 {
2119 double atmp = 0.; 2119 double atmp = 0.;
2120 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 2120 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
2121 atmp += std::abs(data(i)); 2121 atmp += std::abs (data (i));
2122 if (atmp > anorm) 2122 if (atmp > anorm)
2123 anorm = atmp; 2123 anorm = atmp;
2124 } 2124 }
2125 } 2125 }
2126 2126
2141 { 2141 {
2142 octave_idx_type kidx = perm[k]; 2142 octave_idx_type kidx = perm[k];
2143 2143
2144 if (work[k] != 0.) 2144 if (work[k] != 0.)
2145 { 2145 {
2146 if (ridx(cidx(kidx+1)-1) != k || 2146 if (ridx (cidx (kidx+1)-1) != k ||
2147 data(cidx(kidx+1)-1) == 0.) 2147 data (cidx (kidx+1)-1) == 0.)
2148 { 2148 {
2149 err = -2; 2149 err = -2;
2150 goto triangular_error; 2150 goto triangular_error;
2151 } 2151 }
2152 2152
2153 Complex tmp = work[k] / data(cidx(kidx+1)-1); 2153 Complex tmp = work[k] / data (cidx (kidx+1)-1);
2154 work[k] = tmp; 2154 work[k] = tmp;
2155 for (octave_idx_type i = cidx(kidx); 2155 for (octave_idx_type i = cidx (kidx);
2156 i < cidx(kidx+1)-1; i++) 2156 i < cidx (kidx+1)-1; i++)
2157 { 2157 {
2158 octave_idx_type iidx = ridx(i); 2158 octave_idx_type iidx = ridx (i);
2159 work[iidx] = work[iidx] - tmp * data(i); 2159 work[iidx] = work[iidx] - tmp * data (i);
2160 } 2160 }
2161 } 2161 }
2162 } 2162 }
2163 2163
2164 for (octave_idx_type i = 0; i < nc; i++) 2164 for (octave_idx_type i = 0; i < nc; i++)
2179 { 2179 {
2180 octave_idx_type iidx = perm[k]; 2180 octave_idx_type iidx = perm[k];
2181 2181
2182 if (work[k] != 0.) 2182 if (work[k] != 0.)
2183 { 2183 {
2184 Complex tmp = work[k] / data(cidx(iidx+1)-1); 2184 Complex tmp = work[k] / data (cidx (iidx+1)-1);
2185 work[k] = tmp; 2185 work[k] = tmp;
2186 for (octave_idx_type i = cidx(iidx); 2186 for (octave_idx_type i = cidx (iidx);
2187 i < cidx(iidx+1)-1; i++) 2187 i < cidx (iidx+1)-1; i++)
2188 { 2188 {
2189 octave_idx_type idx2 = ridx(i); 2189 octave_idx_type idx2 = ridx (i);
2190 work[idx2] = work[idx2] - tmp * data(i); 2190 work[idx2] = work[idx2] - tmp * data (i);
2191 } 2191 }
2192 } 2192 }
2193 } 2193 }
2194 double atmp = 0; 2194 double atmp = 0;
2195 for (octave_idx_type i = 0; i < j+1; i++) 2195 for (octave_idx_type i = 0; i < j+1; i++)
2196 { 2196 {
2197 atmp += std::abs(work[i]); 2197 atmp += std::abs (work[i]);
2198 work[i] = 0.; 2198 work[i] = 0.;
2199 } 2199 }
2200 if (atmp > ainvnorm) 2200 if (atmp > ainvnorm)
2201 ainvnorm = atmp; 2201 ainvnorm = atmp;
2202 } 2202 }
2217 2217
2218 for (octave_idx_type k = nc-1; k >= 0; k--) 2218 for (octave_idx_type k = nc-1; k >= 0; k--)
2219 { 2219 {
2220 if (work[k] != 0.) 2220 if (work[k] != 0.)
2221 { 2221 {
2222 if (ridx(cidx(k+1)-1) != k || 2222 if (ridx (cidx (k+1)-1) != k ||
2223 data(cidx(k+1)-1) == 0.) 2223 data (cidx (k+1)-1) == 0.)
2224 { 2224 {
2225 err = -2; 2225 err = -2;
2226 goto triangular_error; 2226 goto triangular_error;
2227 } 2227 }
2228 2228
2229 Complex tmp = work[k] / data(cidx(k+1)-1); 2229 Complex tmp = work[k] / data (cidx (k+1)-1);
2230 work[k] = tmp; 2230 work[k] = tmp;
2231 for (octave_idx_type i = cidx(k); i < cidx(k+1)-1; i++) 2231 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
2232 { 2232 {
2233 octave_idx_type iidx = ridx(i); 2233 octave_idx_type iidx = ridx (i);
2234 work[iidx] = work[iidx] - tmp * data(i); 2234 work[iidx] = work[iidx] - tmp * data (i);
2235 } 2235 }
2236 } 2236 }
2237 } 2237 }
2238 2238
2239 for (octave_idx_type i = 0; i < nc; i++) 2239 for (octave_idx_type i = 0; i < nc; i++)
2252 2252
2253 for (octave_idx_type k = j; k >= 0; k--) 2253 for (octave_idx_type k = j; k >= 0; k--)
2254 { 2254 {
2255 if (work[k] != 0.) 2255 if (work[k] != 0.)
2256 { 2256 {
2257 Complex tmp = work[k] / data(cidx(k+1)-1); 2257 Complex tmp = work[k] / data (cidx (k+1)-1);
2258 work[k] = tmp; 2258 work[k] = tmp;
2259 for (octave_idx_type i = cidx(k); 2259 for (octave_idx_type i = cidx (k);
2260 i < cidx(k+1)-1; i++) 2260 i < cidx (k+1)-1; i++)
2261 { 2261 {
2262 octave_idx_type iidx = ridx(i); 2262 octave_idx_type iidx = ridx (i);
2263 work[iidx] = work[iidx] - tmp * data(i); 2263 work[iidx] = work[iidx] - tmp * data (i);
2264 } 2264 }
2265 } 2265 }
2266 } 2266 }
2267 double atmp = 0; 2267 double atmp = 0;
2268 for (octave_idx_type i = 0; i < j+1; i++) 2268 for (octave_idx_type i = 0; i < j+1; i++)
2269 { 2269 {
2270 atmp += std::abs(work[i]); 2270 atmp += std::abs (work[i]);
2271 work[i] = 0.; 2271 work[i] = 0.;
2272 } 2272 }
2273 if (atmp > ainvnorm) 2273 if (atmp > ainvnorm)
2274 ainvnorm = atmp; 2274 ainvnorm = atmp;
2275 } 2275 }
2350 { 2350 {
2351 // Calculate the 1-norm of matrix for rcond calculation 2351 // Calculate the 1-norm of matrix for rcond calculation
2352 for (octave_idx_type j = 0; j < nc; j++) 2352 for (octave_idx_type j = 0; j < nc; j++)
2353 { 2353 {
2354 double atmp = 0.; 2354 double atmp = 0.;
2355 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 2355 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
2356 atmp += std::abs(data(i)); 2356 atmp += std::abs (data (i));
2357 if (atmp > anorm) 2357 if (atmp > anorm)
2358 anorm = atmp; 2358 anorm = atmp;
2359 } 2359 }
2360 } 2360 }
2361 2361
2362 octave_idx_type b_nc = b.cols (); 2362 octave_idx_type b_nc = b.cols ();
2363 octave_idx_type b_nz = b.nnz (); 2363 octave_idx_type b_nz = b.nnz ();
2364 retval = SparseComplexMatrix (nc, b_nc, b_nz); 2364 retval = SparseComplexMatrix (nc, b_nc, b_nz);
2365 retval.xcidx(0) = 0; 2365 retval.xcidx (0) = 0;
2366 octave_idx_type ii = 0; 2366 octave_idx_type ii = 0;
2367 octave_idx_type x_nz = b_nz; 2367 octave_idx_type x_nz = b_nz;
2368 2368
2369 if (typ == MatrixType::Permuted_Upper) 2369 if (typ == MatrixType::Permuted_Upper)
2370 { 2370 {
2377 2377
2378 for (octave_idx_type j = 0; j < b_nc; j++) 2378 for (octave_idx_type j = 0; j < b_nc; j++)
2379 { 2379 {
2380 for (octave_idx_type i = 0; i < nm; i++) 2380 for (octave_idx_type i = 0; i < nm; i++)
2381 work[i] = 0.; 2381 work[i] = 0.;
2382 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 2382 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
2383 work[b.ridx(i)] = b.data(i); 2383 work[b.ridx (i)] = b.data (i);
2384 2384
2385 for (octave_idx_type k = nc-1; k >= 0; k--) 2385 for (octave_idx_type k = nc-1; k >= 0; k--)
2386 { 2386 {
2387 octave_idx_type kidx = perm[k]; 2387 octave_idx_type kidx = perm[k];
2388 2388
2389 if (work[k] != 0.) 2389 if (work[k] != 0.)
2390 { 2390 {
2391 if (ridx(cidx(kidx+1)-1) != k || 2391 if (ridx (cidx (kidx+1)-1) != k ||
2392 data(cidx(kidx+1)-1) == 0.) 2392 data (cidx (kidx+1)-1) == 0.)
2393 { 2393 {
2394 err = -2; 2394 err = -2;
2395 goto triangular_error; 2395 goto triangular_error;
2396 } 2396 }
2397 2397
2398 Complex tmp = work[k] / data(cidx(kidx+1)-1); 2398 Complex tmp = work[k] / data (cidx (kidx+1)-1);
2399 work[k] = tmp; 2399 work[k] = tmp;
2400 for (octave_idx_type i = cidx(kidx); 2400 for (octave_idx_type i = cidx (kidx);
2401 i < cidx(kidx+1)-1; i++) 2401 i < cidx (kidx+1)-1; i++)
2402 { 2402 {
2403 octave_idx_type iidx = ridx(i); 2403 octave_idx_type iidx = ridx (i);
2404 work[iidx] = work[iidx] - tmp * data(i); 2404 work[iidx] = work[iidx] - tmp * data (i);
2405 } 2405 }
2406 } 2406 }
2407 } 2407 }
2408 2408
2409 // Count non-zeros in work vector and adjust space in 2409 // Count non-zeros in work vector and adjust space in
2422 } 2422 }
2423 2423
2424 for (octave_idx_type i = 0; i < nc; i++) 2424 for (octave_idx_type i = 0; i < nc; i++)
2425 if (work[rperm[i]] != 0.) 2425 if (work[rperm[i]] != 0.)
2426 { 2426 {
2427 retval.xridx(ii) = i; 2427 retval.xridx (ii) = i;
2428 retval.xdata(ii++) = work[rperm[i]]; 2428 retval.xdata (ii++) = work[rperm[i]];
2429 } 2429 }
2430 retval.xcidx(j+1) = ii; 2430 retval.xcidx (j+1) = ii;
2431 } 2431 }
2432 2432
2433 retval.maybe_compress (); 2433 retval.maybe_compress ();
2434 2434
2435 if (calc_cond) 2435 if (calc_cond)
2446 { 2446 {
2447 octave_idx_type iidx = perm[k]; 2447 octave_idx_type iidx = perm[k];
2448 2448
2449 if (work[k] != 0.) 2449 if (work[k] != 0.)
2450 { 2450 {
2451 Complex tmp = work[k] / data(cidx(iidx+1)-1); 2451 Complex tmp = work[k] / data (cidx (iidx+1)-1);
2452 work[k] = tmp; 2452 work[k] = tmp;
2453 for (octave_idx_type i = cidx(iidx); 2453 for (octave_idx_type i = cidx (iidx);
2454 i < cidx(iidx+1)-1; i++) 2454 i < cidx (iidx+1)-1; i++)
2455 { 2455 {
2456 octave_idx_type idx2 = ridx(i); 2456 octave_idx_type idx2 = ridx (i);
2457 work[idx2] = work[idx2] - tmp * data(i); 2457 work[idx2] = work[idx2] - tmp * data (i);
2458 } 2458 }
2459 } 2459 }
2460 } 2460 }
2461 double atmp = 0; 2461 double atmp = 0;
2462 for (octave_idx_type i = 0; i < j+1; i++) 2462 for (octave_idx_type i = 0; i < j+1; i++)
2463 { 2463 {
2464 atmp += std::abs(work[i]); 2464 atmp += std::abs (work[i]);
2465 work[i] = 0.; 2465 work[i] = 0.;
2466 } 2466 }
2467 if (atmp > ainvnorm) 2467 if (atmp > ainvnorm)
2468 ainvnorm = atmp; 2468 ainvnorm = atmp;
2469 } 2469 }
2476 2476
2477 for (octave_idx_type j = 0; j < b_nc; j++) 2477 for (octave_idx_type j = 0; j < b_nc; j++)
2478 { 2478 {
2479 for (octave_idx_type i = 0; i < nm; i++) 2479 for (octave_idx_type i = 0; i < nm; i++)
2480 work[i] = 0.; 2480 work[i] = 0.;
2481 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 2481 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
2482 work[b.ridx(i)] = b.data(i); 2482 work[b.ridx (i)] = b.data (i);
2483 2483
2484 for (octave_idx_type k = nr-1; k >= 0; k--) 2484 for (octave_idx_type k = nr-1; k >= 0; k--)
2485 { 2485 {
2486 if (work[k] != 0.) 2486 if (work[k] != 0.)
2487 { 2487 {
2488 if (ridx(cidx(k+1)-1) != k || 2488 if (ridx (cidx (k+1)-1) != k ||
2489 data(cidx(k+1)-1) == 0.) 2489 data (cidx (k+1)-1) == 0.)
2490 { 2490 {
2491 err = -2; 2491 err = -2;
2492 goto triangular_error; 2492 goto triangular_error;
2493 } 2493 }
2494 2494
2495 Complex tmp = work[k] / data(cidx(k+1)-1); 2495 Complex tmp = work[k] / data (cidx (k+1)-1);
2496 work[k] = tmp; 2496 work[k] = tmp;
2497 for (octave_idx_type i = cidx(k); i < cidx(k+1)-1; i++) 2497 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
2498 { 2498 {
2499 octave_idx_type iidx = ridx(i); 2499 octave_idx_type iidx = ridx (i);
2500 work[iidx] = work[iidx] - tmp * data(i); 2500 work[iidx] = work[iidx] - tmp * data (i);
2501 } 2501 }
2502 } 2502 }
2503 } 2503 }
2504 2504
2505 // Count non-zeros in work vector and adjust space in 2505 // Count non-zeros in work vector and adjust space in
2518 } 2518 }
2519 2519
2520 for (octave_idx_type i = 0; i < nc; i++) 2520 for (octave_idx_type i = 0; i < nc; i++)
2521 if (work[i] != 0.) 2521 if (work[i] != 0.)
2522 { 2522 {
2523 retval.xridx(ii) = i; 2523 retval.xridx (ii) = i;
2524 retval.xdata(ii++) = work[i]; 2524 retval.xdata (ii++) = work[i];
2525 } 2525 }
2526 retval.xcidx(j+1) = ii; 2526 retval.xcidx (j+1) = ii;
2527 } 2527 }
2528 2528
2529 retval.maybe_compress (); 2529 retval.maybe_compress ();
2530 2530
2531 if (calc_cond) 2531 if (calc_cond)
2540 2540
2541 for (octave_idx_type k = j; k >= 0; k--) 2541 for (octave_idx_type k = j; k >= 0; k--)
2542 { 2542 {
2543 if (work[k] != 0.) 2543 if (work[k] != 0.)
2544 { 2544 {
2545 Complex tmp = work[k] / data(cidx(k+1)-1); 2545 Complex tmp = work[k] / data (cidx (k+1)-1);
2546 work[k] = tmp; 2546 work[k] = tmp;
2547 for (octave_idx_type i = cidx(k); 2547 for (octave_idx_type i = cidx (k);
2548 i < cidx(k+1)-1; i++) 2548 i < cidx (k+1)-1; i++)
2549 { 2549 {
2550 octave_idx_type iidx = ridx(i); 2550 octave_idx_type iidx = ridx (i);
2551 work[iidx] = work[iidx] - tmp * data(i); 2551 work[iidx] = work[iidx] - tmp * data (i);
2552 } 2552 }
2553 } 2553 }
2554 } 2554 }
2555 double atmp = 0; 2555 double atmp = 0;
2556 for (octave_idx_type i = 0; i < j+1; i++) 2556 for (octave_idx_type i = 0; i < j+1; i++)
2557 { 2557 {
2558 atmp += std::abs(work[i]); 2558 atmp += std::abs (work[i]);
2559 work[i] = 0.; 2559 work[i] = 0.;
2560 } 2560 }
2561 if (atmp > ainvnorm) 2561 if (atmp > ainvnorm)
2562 ainvnorm = atmp; 2562 ainvnorm = atmp;
2563 } 2563 }
2639 { 2639 {
2640 // Calculate the 1-norm of matrix for rcond calculation 2640 // Calculate the 1-norm of matrix for rcond calculation
2641 for (octave_idx_type j = 0; j < nc; j++) 2641 for (octave_idx_type j = 0; j < nc; j++)
2642 { 2642 {
2643 double atmp = 0.; 2643 double atmp = 0.;
2644 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 2644 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
2645 atmp += std::abs(data(i)); 2645 atmp += std::abs (data (i));
2646 if (atmp > anorm) 2646 if (atmp > anorm)
2647 anorm = atmp; 2647 anorm = atmp;
2648 } 2648 }
2649 } 2649 }
2650 2650
2666 if (work[k] != 0.) 2666 if (work[k] != 0.)
2667 { 2667 {
2668 octave_idx_type minr = nr; 2668 octave_idx_type minr = nr;
2669 octave_idx_type mini = 0; 2669 octave_idx_type mini = 0;
2670 2670
2671 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 2671 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
2672 if (perm[ridx(i)] < minr) 2672 if (perm[ridx (i)] < minr)
2673 { 2673 {
2674 minr = perm[ridx(i)]; 2674 minr = perm[ridx (i)];
2675 mini = i; 2675 mini = i;
2676 } 2676 }
2677 2677
2678 if (minr != k || data (mini) == 0.) 2678 if (minr != k || data (mini) == 0.)
2679 { 2679 {
2680 err = -2; 2680 err = -2;
2681 goto triangular_error; 2681 goto triangular_error;
2682 } 2682 }
2683 2683
2684 Complex tmp = work[k] / data(mini); 2684 Complex tmp = work[k] / data (mini);
2685 work[k] = tmp; 2685 work[k] = tmp;
2686 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 2686 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
2687 { 2687 {
2688 if (i == mini) 2688 if (i == mini)
2689 continue; 2689 continue;
2690 2690
2691 octave_idx_type iidx = perm[ridx(i)]; 2691 octave_idx_type iidx = perm[ridx (i)];
2692 work[iidx] = work[iidx] - tmp * data(i); 2692 work[iidx] = work[iidx] - tmp * data (i);
2693 } 2693 }
2694 } 2694 }
2695 } 2695 }
2696 2696
2697 for (octave_idx_type i = 0; i < nc; i++) 2697 for (octave_idx_type i = 0; i < nc; i++)
2713 if (work[k] != 0.) 2713 if (work[k] != 0.)
2714 { 2714 {
2715 octave_idx_type minr = nr; 2715 octave_idx_type minr = nr;
2716 octave_idx_type mini = 0; 2716 octave_idx_type mini = 0;
2717 2717
2718 for (octave_idx_type i = cidx(k); 2718 for (octave_idx_type i = cidx (k);
2719 i < cidx(k+1); i++) 2719 i < cidx (k+1); i++)
2720 if (perm[ridx(i)] < minr) 2720 if (perm[ridx (i)] < minr)
2721 { 2721 {
2722 minr = perm[ridx(i)]; 2722 minr = perm[ridx (i)];
2723 mini = i; 2723 mini = i;
2724 } 2724 }
2725 2725
2726 Complex tmp = work[k] / data(mini); 2726 Complex tmp = work[k] / data (mini);
2727 work[k] = tmp; 2727 work[k] = tmp;
2728 for (octave_idx_type i = cidx(k); 2728 for (octave_idx_type i = cidx (k);
2729 i < cidx(k+1); i++) 2729 i < cidx (k+1); i++)
2730 { 2730 {
2731 if (i == mini) 2731 if (i == mini)
2732 continue; 2732 continue;
2733 2733
2734 octave_idx_type iidx = perm[ridx(i)]; 2734 octave_idx_type iidx = perm[ridx (i)];
2735 work[iidx] = work[iidx] - tmp * data(i); 2735 work[iidx] = work[iidx] - tmp * data (i);
2736 } 2736 }
2737 } 2737 }
2738 } 2738 }
2739 2739
2740 double atmp = 0; 2740 double atmp = 0;
2741 for (octave_idx_type i = j; i < nc; i++) 2741 for (octave_idx_type i = j; i < nc; i++)
2742 { 2742 {
2743 atmp += std::abs(work[i]); 2743 atmp += std::abs (work[i]);
2744 work[i] = 0.; 2744 work[i] = 0.;
2745 } 2745 }
2746 if (atmp > ainvnorm) 2746 if (atmp > ainvnorm)
2747 ainvnorm = atmp; 2747 ainvnorm = atmp;
2748 } 2748 }
2762 work[i] = 0.; 2762 work[i] = 0.;
2763 for (octave_idx_type k = 0; k < nc; k++) 2763 for (octave_idx_type k = 0; k < nc; k++)
2764 { 2764 {
2765 if (work[k] != 0.) 2765 if (work[k] != 0.)
2766 { 2766 {
2767 if (ridx(cidx(k)) != k || 2767 if (ridx (cidx (k)) != k ||
2768 data(cidx(k)) == 0.) 2768 data (cidx (k)) == 0.)
2769 { 2769 {
2770 err = -2; 2770 err = -2;
2771 goto triangular_error; 2771 goto triangular_error;
2772 } 2772 }
2773 2773
2774 Complex tmp = work[k] / data(cidx(k)); 2774 Complex tmp = work[k] / data (cidx (k));
2775 work[k] = tmp; 2775 work[k] = tmp;
2776 for (octave_idx_type i = cidx(k)+1; i < cidx(k+1); i++) 2776 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
2777 { 2777 {
2778 octave_idx_type iidx = ridx(i); 2778 octave_idx_type iidx = ridx (i);
2779 work[iidx] = work[iidx] - tmp * data(i); 2779 work[iidx] = work[iidx] - tmp * data (i);
2780 } 2780 }
2781 } 2781 }
2782 } 2782 }
2783 for (octave_idx_type i = 0; i < nc; i++) 2783 for (octave_idx_type i = 0; i < nc; i++)
2784 retval.xelem (i, j) = work[i]; 2784 retval.xelem (i, j) = work[i];
2797 for (octave_idx_type k = j; k < nc; k++) 2797 for (octave_idx_type k = j; k < nc; k++)
2798 { 2798 {
2799 2799
2800 if (work[k] != 0.) 2800 if (work[k] != 0.)
2801 { 2801 {
2802 Complex tmp = work[k] / data(cidx(k)); 2802 Complex tmp = work[k] / data (cidx (k));
2803 work[k] = tmp; 2803 work[k] = tmp;
2804 for (octave_idx_type i = cidx(k)+1; 2804 for (octave_idx_type i = cidx (k)+1;
2805 i < cidx(k+1); i++) 2805 i < cidx (k+1); i++)
2806 { 2806 {
2807 octave_idx_type iidx = ridx(i); 2807 octave_idx_type iidx = ridx (i);
2808 work[iidx] = work[iidx] - tmp * data(i); 2808 work[iidx] = work[iidx] - tmp * data (i);
2809 } 2809 }
2810 } 2810 }
2811 } 2811 }
2812 double atmp = 0; 2812 double atmp = 0;
2813 for (octave_idx_type i = j; i < nc; i++) 2813 for (octave_idx_type i = j; i < nc; i++)
2814 { 2814 {
2815 atmp += std::abs(work[i]); 2815 atmp += std::abs (work[i]);
2816 work[i] = 0.; 2816 work[i] = 0.;
2817 } 2817 }
2818 if (atmp > ainvnorm) 2818 if (atmp > ainvnorm)
2819 ainvnorm = atmp; 2819 ainvnorm = atmp;
2820 } 2820 }
2895 { 2895 {
2896 // Calculate the 1-norm of matrix for rcond calculation 2896 // Calculate the 1-norm of matrix for rcond calculation
2897 for (octave_idx_type j = 0; j < nc; j++) 2897 for (octave_idx_type j = 0; j < nc; j++)
2898 { 2898 {
2899 double atmp = 0.; 2899 double atmp = 0.;
2900 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 2900 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
2901 atmp += std::abs(data(i)); 2901 atmp += std::abs (data (i));
2902 if (atmp > anorm) 2902 if (atmp > anorm)
2903 anorm = atmp; 2903 anorm = atmp;
2904 } 2904 }
2905 } 2905 }
2906 2906
2907 octave_idx_type b_nc = b.cols (); 2907 octave_idx_type b_nc = b.cols ();
2908 octave_idx_type b_nz = b.nnz (); 2908 octave_idx_type b_nz = b.nnz ();
2909 retval = SparseComplexMatrix (nc, b_nc, b_nz); 2909 retval = SparseComplexMatrix (nc, b_nc, b_nz);
2910 retval.xcidx(0) = 0; 2910 retval.xcidx (0) = 0;
2911 octave_idx_type ii = 0; 2911 octave_idx_type ii = 0;
2912 octave_idx_type x_nz = b_nz; 2912 octave_idx_type x_nz = b_nz;
2913 2913
2914 if (typ == MatrixType::Permuted_Lower) 2914 if (typ == MatrixType::Permuted_Lower)
2915 { 2915 {
2918 2918
2919 for (octave_idx_type j = 0; j < b_nc; j++) 2919 for (octave_idx_type j = 0; j < b_nc; j++)
2920 { 2920 {
2921 for (octave_idx_type i = 0; i < nm; i++) 2921 for (octave_idx_type i = 0; i < nm; i++)
2922 work[i] = 0.; 2922 work[i] = 0.;
2923 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 2923 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
2924 work[perm[b.ridx(i)]] = b.data(i); 2924 work[perm[b.ridx (i)]] = b.data (i);
2925 2925
2926 for (octave_idx_type k = 0; k < nc; k++) 2926 for (octave_idx_type k = 0; k < nc; k++)
2927 { 2927 {
2928 if (work[k] != 0.) 2928 if (work[k] != 0.)
2929 { 2929 {
2930 octave_idx_type minr = nr; 2930 octave_idx_type minr = nr;
2931 octave_idx_type mini = 0; 2931 octave_idx_type mini = 0;
2932 2932
2933 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 2933 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
2934 if (perm[ridx(i)] < minr) 2934 if (perm[ridx (i)] < minr)
2935 { 2935 {
2936 minr = perm[ridx(i)]; 2936 minr = perm[ridx (i)];
2937 mini = i; 2937 mini = i;
2938 } 2938 }
2939 2939
2940 if (minr != k || data (mini) == 0.) 2940 if (minr != k || data (mini) == 0.)
2941 { 2941 {
2942 err = -2; 2942 err = -2;
2943 goto triangular_error; 2943 goto triangular_error;
2944 } 2944 }
2945 2945
2946 Complex tmp = work[k] / data(mini); 2946 Complex tmp = work[k] / data (mini);
2947 work[k] = tmp; 2947 work[k] = tmp;
2948 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 2948 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
2949 { 2949 {
2950 if (i == mini) 2950 if (i == mini)
2951 continue; 2951 continue;
2952 2952
2953 octave_idx_type iidx = perm[ridx(i)]; 2953 octave_idx_type iidx = perm[ridx (i)];
2954 work[iidx] = work[iidx] - tmp * data(i); 2954 work[iidx] = work[iidx] - tmp * data (i);
2955 } 2955 }
2956 } 2956 }
2957 } 2957 }
2958 2958
2959 // Count non-zeros in work vector and adjust space in 2959 // Count non-zeros in work vector and adjust space in
2972 } 2972 }
2973 2973
2974 for (octave_idx_type i = 0; i < nc; i++) 2974 for (octave_idx_type i = 0; i < nc; i++)
2975 if (work[i] != 0.) 2975 if (work[i] != 0.)
2976 { 2976 {
2977 retval.xridx(ii) = i; 2977 retval.xridx (ii) = i;
2978 retval.xdata(ii++) = work[i]; 2978 retval.xdata (ii++) = work[i];
2979 } 2979 }
2980 retval.xcidx(j+1) = ii; 2980 retval.xcidx (j+1) = ii;
2981 } 2981 }
2982 2982
2983 retval.maybe_compress (); 2983 retval.maybe_compress ();
2984 2984
2985 if (calc_cond) 2985 if (calc_cond)
2997 if (work[k] != 0.) 2997 if (work[k] != 0.)
2998 { 2998 {
2999 octave_idx_type minr = nr; 2999 octave_idx_type minr = nr;
3000 octave_idx_type mini = 0; 3000 octave_idx_type mini = 0;
3001 3001
3002 for (octave_idx_type i = cidx(k); 3002 for (octave_idx_type i = cidx (k);
3003 i < cidx(k+1); i++) 3003 i < cidx (k+1); i++)
3004 if (perm[ridx(i)] < minr) 3004 if (perm[ridx (i)] < minr)
3005 { 3005 {
3006 minr = perm[ridx(i)]; 3006 minr = perm[ridx (i)];
3007 mini = i; 3007 mini = i;
3008 } 3008 }
3009 3009
3010 Complex tmp = work[k] / data(mini); 3010 Complex tmp = work[k] / data (mini);
3011 work[k] = tmp; 3011 work[k] = tmp;
3012 for (octave_idx_type i = cidx(k); 3012 for (octave_idx_type i = cidx (k);
3013 i < cidx(k+1); i++) 3013 i < cidx (k+1); i++)
3014 { 3014 {
3015 if (i == mini) 3015 if (i == mini)
3016 continue; 3016 continue;
3017 3017
3018 octave_idx_type iidx = perm[ridx(i)]; 3018 octave_idx_type iidx = perm[ridx (i)];
3019 work[iidx] = work[iidx] - tmp * data(i); 3019 work[iidx] = work[iidx] - tmp * data (i);
3020 } 3020 }
3021 } 3021 }
3022 } 3022 }
3023 3023
3024 double atmp = 0; 3024 double atmp = 0;
3025 for (octave_idx_type i = j; i < nc; i++) 3025 for (octave_idx_type i = j; i < nc; i++)
3026 { 3026 {
3027 atmp += std::abs(work[i]); 3027 atmp += std::abs (work[i]);
3028 work[i] = 0.; 3028 work[i] = 0.;
3029 } 3029 }
3030 if (atmp > ainvnorm) 3030 if (atmp > ainvnorm)
3031 ainvnorm = atmp; 3031 ainvnorm = atmp;
3032 } 3032 }
3039 3039
3040 for (octave_idx_type j = 0; j < b_nc; j++) 3040 for (octave_idx_type j = 0; j < b_nc; j++)
3041 { 3041 {
3042 for (octave_idx_type i = 0; i < nm; i++) 3042 for (octave_idx_type i = 0; i < nm; i++)
3043 work[i] = 0.; 3043 work[i] = 0.;
3044 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 3044 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
3045 work[b.ridx(i)] = b.data(i); 3045 work[b.ridx (i)] = b.data (i);
3046 3046
3047 for (octave_idx_type k = 0; k < nc; k++) 3047 for (octave_idx_type k = 0; k < nc; k++)
3048 { 3048 {
3049 if (work[k] != 0.) 3049 if (work[k] != 0.)
3050 { 3050 {
3051 if (ridx(cidx(k)) != k || 3051 if (ridx (cidx (k)) != k ||
3052 data(cidx(k)) == 0.) 3052 data (cidx (k)) == 0.)
3053 { 3053 {
3054 err = -2; 3054 err = -2;
3055 goto triangular_error; 3055 goto triangular_error;
3056 } 3056 }
3057 3057
3058 Complex tmp = work[k] / data(cidx(k)); 3058 Complex tmp = work[k] / data (cidx (k));
3059 work[k] = tmp; 3059 work[k] = tmp;
3060 for (octave_idx_type i = cidx(k)+1; i < cidx(k+1); i++) 3060 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
3061 { 3061 {
3062 octave_idx_type iidx = ridx(i); 3062 octave_idx_type iidx = ridx (i);
3063 work[iidx] = work[iidx] - tmp * data(i); 3063 work[iidx] = work[iidx] - tmp * data (i);
3064 } 3064 }
3065 } 3065 }
3066 } 3066 }
3067 3067
3068 // Count non-zeros in work vector and adjust space in 3068 // Count non-zeros in work vector and adjust space in
3081 } 3081 }
3082 3082
3083 for (octave_idx_type i = 0; i < nc; i++) 3083 for (octave_idx_type i = 0; i < nc; i++)
3084 if (work[i] != 0.) 3084 if (work[i] != 0.)
3085 { 3085 {
3086 retval.xridx(ii) = i; 3086 retval.xridx (ii) = i;
3087 retval.xdata(ii++) = work[i]; 3087 retval.xdata (ii++) = work[i];
3088 } 3088 }
3089 retval.xcidx(j+1) = ii; 3089 retval.xcidx (j+1) = ii;
3090 } 3090 }
3091 3091
3092 retval.maybe_compress (); 3092 retval.maybe_compress ();
3093 3093
3094 if (calc_cond) 3094 if (calc_cond)
3104 for (octave_idx_type k = j; k < nc; k++) 3104 for (octave_idx_type k = j; k < nc; k++)
3105 { 3105 {
3106 3106
3107 if (work[k] != 0.) 3107 if (work[k] != 0.)
3108 { 3108 {
3109 Complex tmp = work[k] / data(cidx(k)); 3109 Complex tmp = work[k] / data (cidx (k));
3110 work[k] = tmp; 3110 work[k] = tmp;
3111 for (octave_idx_type i = cidx(k)+1; 3111 for (octave_idx_type i = cidx (k)+1;
3112 i < cidx(k+1); i++) 3112 i < cidx (k+1); i++)
3113 { 3113 {
3114 octave_idx_type iidx = ridx(i); 3114 octave_idx_type iidx = ridx (i);
3115 work[iidx] = work[iidx] - tmp * data(i); 3115 work[iidx] = work[iidx] - tmp * data (i);
3116 } 3116 }
3117 } 3117 }
3118 } 3118 }
3119 double atmp = 0; 3119 double atmp = 0;
3120 for (octave_idx_type i = j; i < nc; i++) 3120 for (octave_idx_type i = j; i < nc; i++)
3121 { 3121 {
3122 atmp += std::abs(work[i]); 3122 atmp += std::abs (work[i]);
3123 work[i] = 0.; 3123 work[i] = 0.;
3124 } 3124 }
3125 if (atmp > ainvnorm) 3125 if (atmp > ainvnorm)
3126 ainvnorm = atmp; 3126 ainvnorm = atmp;
3127 } 3127 }
3203 { 3203 {
3204 // Calculate the 1-norm of matrix for rcond calculation 3204 // Calculate the 1-norm of matrix for rcond calculation
3205 for (octave_idx_type j = 0; j < nc; j++) 3205 for (octave_idx_type j = 0; j < nc; j++)
3206 { 3206 {
3207 double atmp = 0.; 3207 double atmp = 0.;
3208 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 3208 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3209 atmp += std::abs(data(i)); 3209 atmp += std::abs (data (i));
3210 if (atmp > anorm) 3210 if (atmp > anorm)
3211 anorm = atmp; 3211 anorm = atmp;
3212 } 3212 }
3213 } 3213 }
3214 3214
3230 if (work[k] != 0.) 3230 if (work[k] != 0.)
3231 { 3231 {
3232 octave_idx_type minr = nr; 3232 octave_idx_type minr = nr;
3233 octave_idx_type mini = 0; 3233 octave_idx_type mini = 0;
3234 3234
3235 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 3235 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
3236 if (perm[ridx(i)] < minr) 3236 if (perm[ridx (i)] < minr)
3237 { 3237 {
3238 minr = perm[ridx(i)]; 3238 minr = perm[ridx (i)];
3239 mini = i; 3239 mini = i;
3240 } 3240 }
3241 3241
3242 if (minr != k || data (mini) == 0.) 3242 if (minr != k || data (mini) == 0.)
3243 { 3243 {
3244 err = -2; 3244 err = -2;
3245 goto triangular_error; 3245 goto triangular_error;
3246 } 3246 }
3247 3247
3248 Complex tmp = work[k] / data(mini); 3248 Complex tmp = work[k] / data (mini);
3249 work[k] = tmp; 3249 work[k] = tmp;
3250 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 3250 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
3251 { 3251 {
3252 if (i == mini) 3252 if (i == mini)
3253 continue; 3253 continue;
3254 3254
3255 octave_idx_type iidx = perm[ridx(i)]; 3255 octave_idx_type iidx = perm[ridx (i)];
3256 work[iidx] = work[iidx] - tmp * data(i); 3256 work[iidx] = work[iidx] - tmp * data (i);
3257 } 3257 }
3258 } 3258 }
3259 } 3259 }
3260 3260
3261 for (octave_idx_type i = 0; i < nc; i++) 3261 for (octave_idx_type i = 0; i < nc; i++)
3277 if (work[k] != 0.) 3277 if (work[k] != 0.)
3278 { 3278 {
3279 octave_idx_type minr = nr; 3279 octave_idx_type minr = nr;
3280 octave_idx_type mini = 0; 3280 octave_idx_type mini = 0;
3281 3281
3282 for (octave_idx_type i = cidx(k); 3282 for (octave_idx_type i = cidx (k);
3283 i < cidx(k+1); i++) 3283 i < cidx (k+1); i++)
3284 if (perm[ridx(i)] < minr) 3284 if (perm[ridx (i)] < minr)
3285 { 3285 {
3286 minr = perm[ridx(i)]; 3286 minr = perm[ridx (i)];
3287 mini = i; 3287 mini = i;
3288 } 3288 }
3289 3289
3290 Complex tmp = work[k] / data(mini); 3290 Complex tmp = work[k] / data (mini);
3291 work[k] = tmp; 3291 work[k] = tmp;
3292 for (octave_idx_type i = cidx(k); 3292 for (octave_idx_type i = cidx (k);
3293 i < cidx(k+1); i++) 3293 i < cidx (k+1); i++)
3294 { 3294 {
3295 if (i == mini) 3295 if (i == mini)
3296 continue; 3296 continue;
3297 3297
3298 octave_idx_type iidx = perm[ridx(i)]; 3298 octave_idx_type iidx = perm[ridx (i)];
3299 work[iidx] = work[iidx] - tmp * data(i); 3299 work[iidx] = work[iidx] - tmp * data (i);
3300 } 3300 }
3301 } 3301 }
3302 } 3302 }
3303 3303
3304 double atmp = 0; 3304 double atmp = 0;
3305 for (octave_idx_type i = j; i < nc; i++) 3305 for (octave_idx_type i = j; i < nc; i++)
3306 { 3306 {
3307 atmp += std::abs(work[i]); 3307 atmp += std::abs (work[i]);
3308 work[i] = 0.; 3308 work[i] = 0.;
3309 } 3309 }
3310 if (atmp > ainvnorm) 3310 if (atmp > ainvnorm)
3311 ainvnorm = atmp; 3311 ainvnorm = atmp;
3312 } 3312 }
3328 3328
3329 for (octave_idx_type k = 0; k < nc; k++) 3329 for (octave_idx_type k = 0; k < nc; k++)
3330 { 3330 {
3331 if (work[k] != 0.) 3331 if (work[k] != 0.)
3332 { 3332 {
3333 if (ridx(cidx(k)) != k || 3333 if (ridx (cidx (k)) != k ||
3334 data(cidx(k)) == 0.) 3334 data (cidx (k)) == 0.)
3335 { 3335 {
3336 err = -2; 3336 err = -2;
3337 goto triangular_error; 3337 goto triangular_error;
3338 } 3338 }
3339 3339
3340 Complex tmp = work[k] / data(cidx(k)); 3340 Complex tmp = work[k] / data (cidx (k));
3341 work[k] = tmp; 3341 work[k] = tmp;
3342 for (octave_idx_type i = cidx(k)+1; i < cidx(k+1); i++) 3342 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
3343 { 3343 {
3344 octave_idx_type iidx = ridx(i); 3344 octave_idx_type iidx = ridx (i);
3345 work[iidx] = work[iidx] - tmp * data(i); 3345 work[iidx] = work[iidx] - tmp * data (i);
3346 } 3346 }
3347 } 3347 }
3348 } 3348 }
3349 3349
3350 for (octave_idx_type i = 0; i < nc; i++) 3350 for (octave_idx_type i = 0; i < nc; i++)
3364 for (octave_idx_type k = j; k < nc; k++) 3364 for (octave_idx_type k = j; k < nc; k++)
3365 { 3365 {
3366 3366
3367 if (work[k] != 0.) 3367 if (work[k] != 0.)
3368 { 3368 {
3369 Complex tmp = work[k] / data(cidx(k)); 3369 Complex tmp = work[k] / data (cidx (k));
3370 work[k] = tmp; 3370 work[k] = tmp;
3371 for (octave_idx_type i = cidx(k)+1; 3371 for (octave_idx_type i = cidx (k)+1;
3372 i < cidx(k+1); i++) 3372 i < cidx (k+1); i++)
3373 { 3373 {
3374 octave_idx_type iidx = ridx(i); 3374 octave_idx_type iidx = ridx (i);
3375 work[iidx] = work[iidx] - tmp * data(i); 3375 work[iidx] = work[iidx] - tmp * data (i);
3376 } 3376 }
3377 } 3377 }
3378 } 3378 }
3379 double atmp = 0; 3379 double atmp = 0;
3380 for (octave_idx_type i = j; i < nc; i++) 3380 for (octave_idx_type i = j; i < nc; i++)
3381 { 3381 {
3382 atmp += std::abs(work[i]); 3382 atmp += std::abs (work[i]);
3383 work[i] = 0.; 3383 work[i] = 0.;
3384 } 3384 }
3385 if (atmp > ainvnorm) 3385 if (atmp > ainvnorm)
3386 ainvnorm = atmp; 3386 ainvnorm = atmp;
3387 } 3387 }
3462 { 3462 {
3463 // Calculate the 1-norm of matrix for rcond calculation 3463 // Calculate the 1-norm of matrix for rcond calculation
3464 for (octave_idx_type j = 0; j < nc; j++) 3464 for (octave_idx_type j = 0; j < nc; j++)
3465 { 3465 {
3466 double atmp = 0.; 3466 double atmp = 0.;
3467 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 3467 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3468 atmp += std::abs(data(i)); 3468 atmp += std::abs (data (i));
3469 if (atmp > anorm) 3469 if (atmp > anorm)
3470 anorm = atmp; 3470 anorm = atmp;
3471 } 3471 }
3472 } 3472 }
3473 3473
3474 octave_idx_type b_nc = b.cols (); 3474 octave_idx_type b_nc = b.cols ();
3475 octave_idx_type b_nz = b.nnz (); 3475 octave_idx_type b_nz = b.nnz ();
3476 retval = SparseComplexMatrix (nc, b_nc, b_nz); 3476 retval = SparseComplexMatrix (nc, b_nc, b_nz);
3477 retval.xcidx(0) = 0; 3477 retval.xcidx (0) = 0;
3478 octave_idx_type ii = 0; 3478 octave_idx_type ii = 0;
3479 octave_idx_type x_nz = b_nz; 3479 octave_idx_type x_nz = b_nz;
3480 3480
3481 if (typ == MatrixType::Permuted_Lower) 3481 if (typ == MatrixType::Permuted_Lower)
3482 { 3482 {
3485 3485
3486 for (octave_idx_type j = 0; j < b_nc; j++) 3486 for (octave_idx_type j = 0; j < b_nc; j++)
3487 { 3487 {
3488 for (octave_idx_type i = 0; i < nm; i++) 3488 for (octave_idx_type i = 0; i < nm; i++)
3489 work[i] = 0.; 3489 work[i] = 0.;
3490 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 3490 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
3491 work[perm[b.ridx(i)]] = b.data(i); 3491 work[perm[b.ridx (i)]] = b.data (i);
3492 3492
3493 for (octave_idx_type k = 0; k < nc; k++) 3493 for (octave_idx_type k = 0; k < nc; k++)
3494 { 3494 {
3495 if (work[k] != 0.) 3495 if (work[k] != 0.)
3496 { 3496 {
3497 octave_idx_type minr = nr; 3497 octave_idx_type minr = nr;
3498 octave_idx_type mini = 0; 3498 octave_idx_type mini = 0;
3499 3499
3500 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 3500 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
3501 if (perm[ridx(i)] < minr) 3501 if (perm[ridx (i)] < minr)
3502 { 3502 {
3503 minr = perm[ridx(i)]; 3503 minr = perm[ridx (i)];
3504 mini = i; 3504 mini = i;
3505 } 3505 }
3506 3506
3507 if (minr != k || data (mini) == 0.) 3507 if (minr != k || data (mini) == 0.)
3508 { 3508 {
3509 err = -2; 3509 err = -2;
3510 goto triangular_error; 3510 goto triangular_error;
3511 } 3511 }
3512 3512
3513 Complex tmp = work[k] / data(mini); 3513 Complex tmp = work[k] / data (mini);
3514 work[k] = tmp; 3514 work[k] = tmp;
3515 for (octave_idx_type i = cidx(k); i < cidx(k+1); i++) 3515 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
3516 { 3516 {
3517 if (i == mini) 3517 if (i == mini)
3518 continue; 3518 continue;
3519 3519
3520 octave_idx_type iidx = perm[ridx(i)]; 3520 octave_idx_type iidx = perm[ridx (i)];
3521 work[iidx] = work[iidx] - tmp * data(i); 3521 work[iidx] = work[iidx] - tmp * data (i);
3522 } 3522 }
3523 } 3523 }
3524 } 3524 }
3525 3525
3526 // Count non-zeros in work vector and adjust space in 3526 // Count non-zeros in work vector and adjust space in
3539 } 3539 }
3540 3540
3541 for (octave_idx_type i = 0; i < nc; i++) 3541 for (octave_idx_type i = 0; i < nc; i++)
3542 if (work[i] != 0.) 3542 if (work[i] != 0.)
3543 { 3543 {
3544 retval.xridx(ii) = i; 3544 retval.xridx (ii) = i;
3545 retval.xdata(ii++) = work[i]; 3545 retval.xdata (ii++) = work[i];
3546 } 3546 }
3547 retval.xcidx(j+1) = ii; 3547 retval.xcidx (j+1) = ii;
3548 } 3548 }
3549 3549
3550 retval.maybe_compress (); 3550 retval.maybe_compress ();
3551 3551
3552 if (calc_cond) 3552 if (calc_cond)
3564 if (work[k] != 0.) 3564 if (work[k] != 0.)
3565 { 3565 {
3566 octave_idx_type minr = nr; 3566 octave_idx_type minr = nr;
3567 octave_idx_type mini = 0; 3567 octave_idx_type mini = 0;
3568 3568
3569 for (octave_idx_type i = cidx(k); 3569 for (octave_idx_type i = cidx (k);
3570 i < cidx(k+1); i++) 3570 i < cidx (k+1); i++)
3571 if (perm[ridx(i)] < minr) 3571 if (perm[ridx (i)] < minr)
3572 { 3572 {
3573 minr = perm[ridx(i)]; 3573 minr = perm[ridx (i)];
3574 mini = i; 3574 mini = i;
3575 } 3575 }
3576 3576
3577 Complex tmp = work[k] / data(mini); 3577 Complex tmp = work[k] / data (mini);
3578 work[k] = tmp; 3578 work[k] = tmp;
3579 for (octave_idx_type i = cidx(k); 3579 for (octave_idx_type i = cidx (k);
3580 i < cidx(k+1); i++) 3580 i < cidx (k+1); i++)
3581 { 3581 {
3582 if (i == mini) 3582 if (i == mini)
3583 continue; 3583 continue;
3584 3584
3585 octave_idx_type iidx = perm[ridx(i)]; 3585 octave_idx_type iidx = perm[ridx (i)];
3586 work[iidx] = work[iidx] - tmp * data(i); 3586 work[iidx] = work[iidx] - tmp * data (i);
3587 } 3587 }
3588 } 3588 }
3589 } 3589 }
3590 3590
3591 double atmp = 0; 3591 double atmp = 0;
3592 for (octave_idx_type i = j; i < nc; i++) 3592 for (octave_idx_type i = j; i < nc; i++)
3593 { 3593 {
3594 atmp += std::abs(work[i]); 3594 atmp += std::abs (work[i]);
3595 work[i] = 0.; 3595 work[i] = 0.;
3596 } 3596 }
3597 if (atmp > ainvnorm) 3597 if (atmp > ainvnorm)
3598 ainvnorm = atmp; 3598 ainvnorm = atmp;
3599 } 3599 }
3606 3606
3607 for (octave_idx_type j = 0; j < b_nc; j++) 3607 for (octave_idx_type j = 0; j < b_nc; j++)
3608 { 3608 {
3609 for (octave_idx_type i = 0; i < nm; i++) 3609 for (octave_idx_type i = 0; i < nm; i++)
3610 work[i] = 0.; 3610 work[i] = 0.;
3611 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 3611 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
3612 work[b.ridx(i)] = b.data(i); 3612 work[b.ridx (i)] = b.data (i);
3613 3613
3614 for (octave_idx_type k = 0; k < nc; k++) 3614 for (octave_idx_type k = 0; k < nc; k++)
3615 { 3615 {
3616 if (work[k] != 0.) 3616 if (work[k] != 0.)
3617 { 3617 {
3618 if (ridx(cidx(k)) != k || 3618 if (ridx (cidx (k)) != k ||
3619 data(cidx(k)) == 0.) 3619 data (cidx (k)) == 0.)
3620 { 3620 {
3621 err = -2; 3621 err = -2;
3622 goto triangular_error; 3622 goto triangular_error;
3623 } 3623 }
3624 3624
3625 Complex tmp = work[k] / data(cidx(k)); 3625 Complex tmp = work[k] / data (cidx (k));
3626 work[k] = tmp; 3626 work[k] = tmp;
3627 for (octave_idx_type i = cidx(k)+1; i < cidx(k+1); i++) 3627 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
3628 { 3628 {
3629 octave_idx_type iidx = ridx(i); 3629 octave_idx_type iidx = ridx (i);
3630 work[iidx] = work[iidx] - tmp * data(i); 3630 work[iidx] = work[iidx] - tmp * data (i);
3631 } 3631 }
3632 } 3632 }
3633 } 3633 }
3634 3634
3635 // Count non-zeros in work vector and adjust space in 3635 // Count non-zeros in work vector and adjust space in
3648 } 3648 }
3649 3649
3650 for (octave_idx_type i = 0; i < nc; i++) 3650 for (octave_idx_type i = 0; i < nc; i++)
3651 if (work[i] != 0.) 3651 if (work[i] != 0.)
3652 { 3652 {
3653 retval.xridx(ii) = i; 3653 retval.xridx (ii) = i;
3654 retval.xdata(ii++) = work[i]; 3654 retval.xdata (ii++) = work[i];
3655 } 3655 }
3656 retval.xcidx(j+1) = ii; 3656 retval.xcidx (j+1) = ii;
3657 } 3657 }
3658 3658
3659 retval.maybe_compress (); 3659 retval.maybe_compress ();
3660 3660
3661 if (calc_cond) 3661 if (calc_cond)
3671 for (octave_idx_type k = j; k < nc; k++) 3671 for (octave_idx_type k = j; k < nc; k++)
3672 { 3672 {
3673 3673
3674 if (work[k] != 0.) 3674 if (work[k] != 0.)
3675 { 3675 {
3676 Complex tmp = work[k] / data(cidx(k)); 3676 Complex tmp = work[k] / data (cidx (k));
3677 work[k] = tmp; 3677 work[k] = tmp;
3678 for (octave_idx_type i = cidx(k)+1; 3678 for (octave_idx_type i = cidx (k)+1;
3679 i < cidx(k+1); i++) 3679 i < cidx (k+1); i++)
3680 { 3680 {
3681 octave_idx_type iidx = ridx(i); 3681 octave_idx_type iidx = ridx (i);
3682 work[iidx] = work[iidx] - tmp * data(i); 3682 work[iidx] = work[iidx] - tmp * data (i);
3683 } 3683 }
3684 } 3684 }
3685 } 3685 }
3686 double atmp = 0; 3686 double atmp = 0;
3687 for (octave_idx_type i = j; i < nc; i++) 3687 for (octave_idx_type i = j; i < nc; i++)
3688 { 3688 {
3689 atmp += std::abs(work[i]); 3689 atmp += std::abs (work[i]);
3690 work[i] = 0.; 3690 work[i] = 0.;
3691 } 3691 }
3692 if (atmp > ainvnorm) 3692 if (atmp > ainvnorm)
3693 ainvnorm = atmp; 3693 ainvnorm = atmp;
3694 } 3694 }
3769 { 3769 {
3770 octave_idx_type ii = 0; 3770 octave_idx_type ii = 0;
3771 3771
3772 for (octave_idx_type j = 0; j < nc-1; j++) 3772 for (octave_idx_type j = 0; j < nc-1; j++)
3773 { 3773 {
3774 D[j] = std::real(data(ii++)); 3774 D[j] = std::real (data (ii++));
3775 DL[j] = data(ii); 3775 DL[j] = data (ii);
3776 ii += 2; 3776 ii += 2;
3777 } 3777 }
3778 D[nc-1] = std::real(data(ii)); 3778 D[nc-1] = std::real (data (ii));
3779 } 3779 }
3780 else 3780 else
3781 { 3781 {
3782 D[0] = 0.; 3782 D[0] = 0.;
3783 for (octave_idx_type i = 0; i < nr - 1; i++) 3783 for (octave_idx_type i = 0; i < nr - 1; i++)
3785 D[i+1] = 0.; 3785 D[i+1] = 0.;
3786 DL[i] = 0.; 3786 DL[i] = 0.;
3787 } 3787 }
3788 3788
3789 for (octave_idx_type j = 0; j < nc; j++) 3789 for (octave_idx_type j = 0; j < nc; j++)
3790 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 3790 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3791 { 3791 {
3792 if (ridx(i) == j) 3792 if (ridx (i) == j)
3793 D[j] = std::real(data(i)); 3793 D[j] = std::real (data (i));
3794 else if (ridx(i) == j + 1) 3794 else if (ridx (i) == j + 1)
3795 DL[j] = data(i); 3795 DL[j] = data (i);
3796 } 3796 }
3797 } 3797 }
3798 3798
3799 octave_idx_type b_nc = b.cols (); 3799 octave_idx_type b_nc = b.cols ();
3800 retval = ComplexMatrix (b); 3800 retval = ComplexMatrix (b);
3823 { 3823 {
3824 octave_idx_type ii = 0; 3824 octave_idx_type ii = 0;
3825 3825
3826 for (octave_idx_type j = 0; j < nc-1; j++) 3826 for (octave_idx_type j = 0; j < nc-1; j++)
3827 { 3827 {
3828 D[j] = data(ii++); 3828 D[j] = data (ii++);
3829 DL[j] = data(ii++); 3829 DL[j] = data (ii++);
3830 DU[j] = data(ii++); 3830 DU[j] = data (ii++);
3831 } 3831 }
3832 D[nc-1] = data(ii); 3832 D[nc-1] = data (ii);
3833 } 3833 }
3834 else 3834 else
3835 { 3835 {
3836 D[0] = 0.; 3836 D[0] = 0.;
3837 for (octave_idx_type i = 0; i < nr - 1; i++) 3837 for (octave_idx_type i = 0; i < nr - 1; i++)
3840 DL[i] = 0.; 3840 DL[i] = 0.;
3841 DU[i] = 0.; 3841 DU[i] = 0.;
3842 } 3842 }
3843 3843
3844 for (octave_idx_type j = 0; j < nc; j++) 3844 for (octave_idx_type j = 0; j < nc; j++)
3845 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 3845 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3846 { 3846 {
3847 if (ridx(i) == j) 3847 if (ridx (i) == j)
3848 D[j] = data(i); 3848 D[j] = data (i);
3849 else if (ridx(i) == j + 1) 3849 else if (ridx (i) == j + 1)
3850 DL[j] = data(i); 3850 DL[j] = data (i);
3851 else if (ridx(i) == j - 1) 3851 else if (ridx (i) == j - 1)
3852 DU[j-1] = data(i); 3852 DU[j-1] = data (i);
3853 } 3853 }
3854 } 3854 }
3855 3855
3856 octave_idx_type b_nc = b.cols (); 3856 octave_idx_type b_nc = b.cols ();
3857 retval = ComplexMatrix (b); 3857 retval = ComplexMatrix (b);
3926 { 3926 {
3927 octave_idx_type ii = 0; 3927 octave_idx_type ii = 0;
3928 3928
3929 for (octave_idx_type j = 0; j < nc-1; j++) 3929 for (octave_idx_type j = 0; j < nc-1; j++)
3930 { 3930 {
3931 D[j] = data(ii++); 3931 D[j] = data (ii++);
3932 DL[j] = data(ii++); 3932 DL[j] = data (ii++);
3933 DU[j] = data(ii++); 3933 DU[j] = data (ii++);
3934 } 3934 }
3935 D[nc-1] = data(ii); 3935 D[nc-1] = data (ii);
3936 } 3936 }
3937 else 3937 else
3938 { 3938 {
3939 D[0] = 0.; 3939 D[0] = 0.;
3940 for (octave_idx_type i = 0; i < nr - 1; i++) 3940 for (octave_idx_type i = 0; i < nr - 1; i++)
3943 DL[i] = 0.; 3943 DL[i] = 0.;
3944 DU[i] = 0.; 3944 DU[i] = 0.;
3945 } 3945 }
3946 3946
3947 for (octave_idx_type j = 0; j < nc; j++) 3947 for (octave_idx_type j = 0; j < nc; j++)
3948 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 3948 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3949 { 3949 {
3950 if (ridx(i) == j) 3950 if (ridx (i) == j)
3951 D[j] = data(i); 3951 D[j] = data (i);
3952 else if (ridx(i) == j + 1) 3952 else if (ridx (i) == j + 1)
3953 DL[j] = data(i); 3953 DL[j] = data (i);
3954 else if (ridx(i) == j - 1) 3954 else if (ridx (i) == j - 1)
3955 DU[j-1] = data(i); 3955 DU[j-1] = data (i);
3956 } 3956 }
3957 } 3957 }
3958 3958
3959 F77_XFCN (zgttrf, ZGTTRF, (nr, DL, D, DU, DU2, pipvt, err)); 3959 F77_XFCN (zgttrf, ZGTTRF, (nr, DL, D, DU, DU2, pipvt, err));
3960 3960
3977 { 3977 {
3978 char job = 'N'; 3978 char job = 'N';
3979 volatile octave_idx_type x_nz = b.nnz (); 3979 volatile octave_idx_type x_nz = b.nnz ();
3980 octave_idx_type b_nc = b.cols (); 3980 octave_idx_type b_nc = b.cols ();
3981 retval = SparseComplexMatrix (nr, b_nc, x_nz); 3981 retval = SparseComplexMatrix (nr, b_nc, x_nz);
3982 retval.xcidx(0) = 0; 3982 retval.xcidx (0) = 0;
3983 volatile octave_idx_type ii = 0; 3983 volatile octave_idx_type ii = 0;
3984 rcond = 1.0; 3984 rcond = 1.0;
3985 3985
3986 OCTAVE_LOCAL_BUFFER (Complex, work, nr); 3986 OCTAVE_LOCAL_BUFFER (Complex, work, nr);
3987 3987
3988 for (volatile octave_idx_type j = 0; j < b_nc; j++) 3988 for (volatile octave_idx_type j = 0; j < b_nc; j++)
3989 { 3989 {
3990 for (octave_idx_type i = 0; i < nr; i++) 3990 for (octave_idx_type i = 0; i < nr; i++)
3991 work[i] = 0.; 3991 work[i] = 0.;
3992 for (octave_idx_type i = b.cidx(j); i < b.cidx(j+1); i++) 3992 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
3993 work[b.ridx(i)] = b.data(i); 3993 work[b.ridx (i)] = b.data (i);
3994 3994
3995 F77_XFCN (zgttrs, ZGTTRS, 3995 F77_XFCN (zgttrs, ZGTTRS,
3996 (F77_CONST_CHAR_ARG2 (&job, 1), 3996 (F77_CONST_CHAR_ARG2 (&job, 1),
3997 nr, 1, DL, D, DU, DU2, pipvt, 3997 nr, 1, DL, D, DU, DU2, pipvt,
3998 work, b.rows (), err 3998 work, b.rows (), err
4014 } 4014 }
4015 4015
4016 for (octave_idx_type i = 0; i < nr; i++) 4016 for (octave_idx_type i = 0; i < nr; i++)
4017 if (work[i] != 0.) 4017 if (work[i] != 0.)
4018 { 4018 {
4019 retval.xridx(ii) = i; 4019 retval.xridx (ii) = i;
4020 retval.xdata(ii++) = work[i]; 4020 retval.xdata (ii++) = work[i];
4021 } 4021 }
4022 retval.xcidx(j+1) = ii; 4022 retval.xcidx (j+1) = ii;
4023 } 4023 }
4024 4024
4025 retval.maybe_compress (); 4025 retval.maybe_compress ();
4026 } 4026 }
4027 } 4027 }
4067 { 4067 {
4068 octave_idx_type ii = 0; 4068 octave_idx_type ii = 0;
4069 4069
4070 for (octave_idx_type j = 0; j < nc-1; j++) 4070 for (octave_idx_type j = 0; j < nc-1; j++)
4071 { 4071 {
4072 D[j] = std::real(data(ii++)); 4072 D[j] = std::real (data (ii++));
4073 DL[j] = data(ii); 4073 DL[j] = data (ii);
4074 ii += 2; 4074 ii += 2;
4075 } 4075 }
4076 D[nc-1] = std::real(data(ii)); 4076 D[nc-1] = std::real (data (ii));
4077 } 4077 }
4078 else 4078 else
4079 { 4079 {
4080 D[0] = 0.; 4080 D[0] = 0.;
4081 for (octave_idx_type i = 0; i < nr - 1; i++) 4081 for (octave_idx_type i = 0; i < nr - 1; i++)
4083 D[i+1] = 0.; 4083 D[i+1] = 0.;
4084 DL[i] = 0.; 4084 DL[i] = 0.;
4085 } 4085 }
4086 4086
4087 for (octave_idx_type j = 0; j < nc; j++) 4087 for (octave_idx_type j = 0; j < nc; j++)
4088 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4088 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4089 { 4089 {
4090 if (ridx(i) == j) 4090 if (ridx (i) == j)
4091 D[j] = std::real (data(i)); 4091 D[j] = std::real (data (i));
4092 else if (ridx(i) == j + 1) 4092 else if (ridx (i) == j + 1)
4093 DL[j] = data(i); 4093 DL[j] = data (i);
4094 } 4094 }
4095 } 4095 }
4096 4096
4097 octave_idx_type b_nr = b.rows (); 4097 octave_idx_type b_nr = b.rows ();
4098 octave_idx_type b_nc = b.cols (); 4098 octave_idx_type b_nc = b.cols ();
4122 { 4122 {
4123 octave_idx_type ii = 0; 4123 octave_idx_type ii = 0;
4124 4124
4125 for (octave_idx_type j = 0; j < nc-1; j++) 4125 for (octave_idx_type j = 0; j < nc-1; j++)
4126 { 4126 {
4127 D[j] = data(ii++); 4127 D[j] = data (ii++);
4128 DL[j] = data(ii++); 4128 DL[j] = data (ii++);
4129 DU[j] = data(ii++); 4129 DU[j] = data (ii++);
4130 } 4130 }
4131 D[nc-1] = data(ii); 4131 D[nc-1] = data (ii);
4132 } 4132 }
4133 else 4133 else
4134 { 4134 {
4135 D[0] = 0.; 4135 D[0] = 0.;
4136 for (octave_idx_type i = 0; i < nr - 1; i++) 4136 for (octave_idx_type i = 0; i < nr - 1; i++)
4139 DL[i] = 0.; 4139 DL[i] = 0.;
4140 DU[i] = 0.; 4140 DU[i] = 0.;
4141 } 4141 }
4142 4142
4143 for (octave_idx_type j = 0; j < nc; j++) 4143 for (octave_idx_type j = 0; j < nc; j++)
4144 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4144 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4145 { 4145 {
4146 if (ridx(i) == j) 4146 if (ridx (i) == j)
4147 D[j] = data(i); 4147 D[j] = data (i);
4148 else if (ridx(i) == j + 1) 4148 else if (ridx (i) == j + 1)
4149 DL[j] = data(i); 4149 DL[j] = data (i);
4150 else if (ridx(i) == j - 1) 4150 else if (ridx (i) == j - 1)
4151 DU[j-1] = data(i); 4151 DU[j-1] = data (i);
4152 } 4152 }
4153 } 4153 }
4154 4154
4155 octave_idx_type b_nr = b.rows (); 4155 octave_idx_type b_nr = b.rows ();
4156 octave_idx_type b_nc = b.cols (); 4156 octave_idx_type b_nc = b.cols ();
4226 { 4226 {
4227 octave_idx_type ii = 0; 4227 octave_idx_type ii = 0;
4228 4228
4229 for (octave_idx_type j = 0; j < nc-1; j++) 4229 for (octave_idx_type j = 0; j < nc-1; j++)
4230 { 4230 {
4231 D[j] = data(ii++); 4231 D[j] = data (ii++);
4232 DL[j] = data(ii++); 4232 DL[j] = data (ii++);
4233 DU[j] = data(ii++); 4233 DU[j] = data (ii++);
4234 } 4234 }
4235 D[nc-1] = data(ii); 4235 D[nc-1] = data (ii);
4236 } 4236 }
4237 else 4237 else
4238 { 4238 {
4239 D[0] = 0.; 4239 D[0] = 0.;
4240 for (octave_idx_type i = 0; i < nr - 1; i++) 4240 for (octave_idx_type i = 0; i < nr - 1; i++)
4243 DL[i] = 0.; 4243 DL[i] = 0.;
4244 DU[i] = 0.; 4244 DU[i] = 0.;
4245 } 4245 }
4246 4246
4247 for (octave_idx_type j = 0; j < nc; j++) 4247 for (octave_idx_type j = 0; j < nc; j++)
4248 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4248 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4249 { 4249 {
4250 if (ridx(i) == j) 4250 if (ridx (i) == j)
4251 D[j] = data(i); 4251 D[j] = data (i);
4252 else if (ridx(i) == j + 1) 4252 else if (ridx (i) == j + 1)
4253 DL[j] = data(i); 4253 DL[j] = data (i);
4254 else if (ridx(i) == j - 1) 4254 else if (ridx (i) == j - 1)
4255 DU[j-1] = data(i); 4255 DU[j-1] = data (i);
4256 } 4256 }
4257 } 4257 }
4258 4258
4259 F77_XFCN (zgttrf, ZGTTRF, (nr, DL, D, DU, DU2, pipvt, err)); 4259 F77_XFCN (zgttrf, ZGTTRF, (nr, DL, D, DU, DU2, pipvt, err));
4260 4260
4284 // will be as many as in b 4284 // will be as many as in b
4285 volatile octave_idx_type x_nz = b.nnz (); 4285 volatile octave_idx_type x_nz = b.nnz ();
4286 volatile octave_idx_type ii = 0; 4286 volatile octave_idx_type ii = 0;
4287 retval = SparseComplexMatrix (b_nr, b_nc, x_nz); 4287 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
4288 4288
4289 retval.xcidx(0) = 0; 4289 retval.xcidx (0) = 0;
4290 for (volatile octave_idx_type j = 0; j < b_nc; j++) 4290 for (volatile octave_idx_type j = 0; j < b_nc; j++)
4291 { 4291 {
4292 4292
4293 for (octave_idx_type i = 0; i < b_nr; i++) 4293 for (octave_idx_type i = 0; i < b_nr; i++)
4294 Bx[i] = b (i,j); 4294 Bx[i] = b (i,j);
4324 } 4324 }
4325 4325
4326 for (octave_idx_type i = 0; i < nr; i++) 4326 for (octave_idx_type i = 0; i < nr; i++)
4327 if (Bx[i] != 0.) 4327 if (Bx[i] != 0.)
4328 { 4328 {
4329 retval.xridx(ii) = i; 4329 retval.xridx (ii) = i;
4330 retval.xdata(ii++) = Bx[i]; 4330 retval.xdata (ii++) = Bx[i];
4331 } 4331 }
4332 4332
4333 retval.xcidx(j+1) = ii; 4333 retval.xcidx (j+1) = ii;
4334 } 4334 }
4335 4335
4336 retval.maybe_compress (); 4336 retval.maybe_compress ();
4337 } 4337 }
4338 } 4338 }
4381 for (octave_idx_type i = 0; i < nc; i++) 4381 for (octave_idx_type i = 0; i < nc; i++)
4382 tmp_data[ii++] = 0.; 4382 tmp_data[ii++] = 0.;
4383 } 4383 }
4384 4384
4385 for (octave_idx_type j = 0; j < nc; j++) 4385 for (octave_idx_type j = 0; j < nc; j++)
4386 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4386 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4387 { 4387 {
4388 octave_idx_type ri = ridx (i); 4388 octave_idx_type ri = ridx (i);
4389 if (ri >= j) 4389 if (ri >= j)
4390 m_band(ri - j, j) = data(i); 4390 m_band(ri - j, j) = data (i);
4391 } 4391 }
4392 4392
4393 // Calculate the norm of the matrix, for later use. 4393 // Calculate the norm of the matrix, for later use.
4394 double anorm; 4394 double anorm;
4395 if (calc_cond) 4395 if (calc_cond)
4396 anorm = m_band.abs ().sum ().row(0).max (); 4396 anorm = m_band.abs ().sum ().row (0).max ();
4397 4397
4398 char job = 'L'; 4398 char job = 'L';
4399 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1), 4399 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
4400 nr, n_lower, tmp_data, ldm, err 4400 nr, n_lower, tmp_data, ldm, err
4401 F77_CHAR_ARG_LEN (1))); 4401 F77_CHAR_ARG_LEN (1)));
4488 for (octave_idx_type i = 0; i < nc; i++) 4488 for (octave_idx_type i = 0; i < nc; i++)
4489 tmp_data[ii++] = 0.; 4489 tmp_data[ii++] = 0.;
4490 } 4490 }
4491 4491
4492 for (octave_idx_type j = 0; j < nc; j++) 4492 for (octave_idx_type j = 0; j < nc; j++)
4493 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4493 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4494 m_band(ridx(i) - j + n_lower + n_upper, j) = data(i); 4494 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
4495 4495
4496 // Calculate the norm of the matrix, for later use. 4496 // Calculate the norm of the matrix, for later use.
4497 double anorm; 4497 double anorm;
4498 if (calc_cond) 4498 if (calc_cond)
4499 { 4499 {
4500 for (octave_idx_type j = 0; j < nr; j++) 4500 for (octave_idx_type j = 0; j < nr; j++)
4501 { 4501 {
4502 double atmp = 0.; 4502 double atmp = 0.;
4503 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4503 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4504 atmp += std::abs(data(i)); 4504 atmp += std::abs (data (i));
4505 if (atmp > anorm) 4505 if (atmp > anorm)
4506 anorm = atmp; 4506 anorm = atmp;
4507 } 4507 }
4508 } 4508 }
4509 4509
4630 for (octave_idx_type i = 0; i < nc; i++) 4630 for (octave_idx_type i = 0; i < nc; i++)
4631 tmp_data[ii++] = 0.; 4631 tmp_data[ii++] = 0.;
4632 } 4632 }
4633 4633
4634 for (octave_idx_type j = 0; j < nc; j++) 4634 for (octave_idx_type j = 0; j < nc; j++)
4635 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4635 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4636 { 4636 {
4637 octave_idx_type ri = ridx (i); 4637 octave_idx_type ri = ridx (i);
4638 if (ri >= j) 4638 if (ri >= j)
4639 m_band(ri - j, j) = data(i); 4639 m_band(ri - j, j) = data (i);
4640 } 4640 }
4641 4641
4642 // Calculate the norm of the matrix, for later use. 4642 // Calculate the norm of the matrix, for later use.
4643 double anorm; 4643 double anorm;
4644 if (calc_cond) 4644 if (calc_cond)
4645 anorm = m_band.abs ().sum ().row(0).max (); 4645 anorm = m_band.abs ().sum ().row (0).max ();
4646 4646
4647 char job = 'L'; 4647 char job = 'L';
4648 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1), 4648 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
4649 nr, n_lower, tmp_data, ldm, err 4649 nr, n_lower, tmp_data, ldm, err
4650 F77_CHAR_ARG_LEN (1))); 4650 F77_CHAR_ARG_LEN (1)));
4704 // will be as many as in b 4704 // will be as many as in b
4705 volatile octave_idx_type x_nz = b.nnz (); 4705 volatile octave_idx_type x_nz = b.nnz ();
4706 volatile octave_idx_type ii = 0; 4706 volatile octave_idx_type ii = 0;
4707 retval = SparseComplexMatrix (b_nr, b_nc, x_nz); 4707 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
4708 4708
4709 retval.xcidx(0) = 0; 4709 retval.xcidx (0) = 0;
4710 for (volatile octave_idx_type j = 0; j < b_nc; j++) 4710 for (volatile octave_idx_type j = 0; j < b_nc; j++)
4711 { 4711 {
4712 for (octave_idx_type i = 0; i < b_nr; i++) 4712 for (octave_idx_type i = 0; i < b_nr; i++)
4713 Bx[i] = b.elem (i, j); 4713 Bx[i] = b.elem (i, j);
4714 4714
4738 (b_nc - j) / b_nc; 4738 (b_nc - j) / b_nc;
4739 sz = (sz > 10 ? sz : 10) + x_nz; 4739 sz = (sz > 10 ? sz : 10) + x_nz;
4740 retval.change_capacity (sz); 4740 retval.change_capacity (sz);
4741 x_nz = sz; 4741 x_nz = sz;
4742 } 4742 }
4743 retval.xdata(ii) = tmp; 4743 retval.xdata (ii) = tmp;
4744 retval.xridx(ii++) = i; 4744 retval.xridx (ii++) = i;
4745 } 4745 }
4746 } 4746 }
4747 retval.xcidx(j+1) = ii; 4747 retval.xcidx (j+1) = ii;
4748 } 4748 }
4749 4749
4750 retval.maybe_compress (); 4750 retval.maybe_compress ();
4751 } 4751 }
4752 } 4752 }
4770 for (octave_idx_type i = 0; i < nc; i++) 4770 for (octave_idx_type i = 0; i < nc; i++)
4771 tmp_data[ii++] = 0.; 4771 tmp_data[ii++] = 0.;
4772 } 4772 }
4773 4773
4774 for (octave_idx_type j = 0; j < nc; j++) 4774 for (octave_idx_type j = 0; j < nc; j++)
4775 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4775 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4776 m_band(ridx(i) - j + n_lower + n_upper, j) = data(i); 4776 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
4777 4777
4778 // Calculate the norm of the matrix, for later use. 4778 // Calculate the norm of the matrix, for later use.
4779 double anorm; 4779 double anorm;
4780 if (calc_cond) 4780 if (calc_cond)
4781 { 4781 {
4782 for (octave_idx_type j = 0; j < nr; j++) 4782 for (octave_idx_type j = 0; j < nr; j++)
4783 { 4783 {
4784 double atmp = 0.; 4784 double atmp = 0.;
4785 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4785 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4786 atmp += std::abs(data(i)); 4786 atmp += std::abs (data (i));
4787 if (atmp > anorm) 4787 if (atmp > anorm)
4788 anorm = atmp; 4788 anorm = atmp;
4789 } 4789 }
4790 } 4790 }
4791 4791
4853 { 4853 {
4854 char job = 'N'; 4854 char job = 'N';
4855 volatile octave_idx_type x_nz = b.nnz (); 4855 volatile octave_idx_type x_nz = b.nnz ();
4856 octave_idx_type b_nc = b.cols (); 4856 octave_idx_type b_nc = b.cols ();
4857 retval = SparseComplexMatrix (nr, b_nc, x_nz); 4857 retval = SparseComplexMatrix (nr, b_nc, x_nz);
4858 retval.xcidx(0) = 0; 4858 retval.xcidx (0) = 0;
4859 volatile octave_idx_type ii = 0; 4859 volatile octave_idx_type ii = 0;
4860 4860
4861 OCTAVE_LOCAL_BUFFER (Complex, work, nr); 4861 OCTAVE_LOCAL_BUFFER (Complex, work, nr);
4862 4862
4863 for (volatile octave_idx_type j = 0; j < b_nc; j++) 4863 for (volatile octave_idx_type j = 0; j < b_nc; j++)
4864 { 4864 {
4865 for (octave_idx_type i = 0; i < nr; i++) 4865 for (octave_idx_type i = 0; i < nr; i++)
4866 work[i] = 0.; 4866 work[i] = 0.;
4867 for (octave_idx_type i = b.cidx(j); 4867 for (octave_idx_type i = b.cidx (j);
4868 i < b.cidx(j+1); i++) 4868 i < b.cidx (j+1); i++)
4869 work[b.ridx(i)] = b.data(i); 4869 work[b.ridx (i)] = b.data (i);
4870 4870
4871 F77_XFCN (zgbtrs, ZGBTRS, 4871 F77_XFCN (zgbtrs, ZGBTRS,
4872 (F77_CONST_CHAR_ARG2 (&job, 1), 4872 (F77_CONST_CHAR_ARG2 (&job, 1),
4873 nr, n_lower, n_upper, 1, tmp_data, 4873 nr, n_lower, n_upper, 1, tmp_data,
4874 ldm, pipvt, work, b.rows (), err 4874 ldm, pipvt, work, b.rows (), err
4890 } 4890 }
4891 4891
4892 for (octave_idx_type i = 0; i < nr; i++) 4892 for (octave_idx_type i = 0; i < nr; i++)
4893 if (work[i] != 0.) 4893 if (work[i] != 0.)
4894 { 4894 {
4895 retval.xridx(ii) = i; 4895 retval.xridx (ii) = i;
4896 retval.xdata(ii++) = work[i]; 4896 retval.xdata (ii++) = work[i];
4897 } 4897 }
4898 retval.xcidx(j+1) = ii; 4898 retval.xcidx (j+1) = ii;
4899 } 4899 }
4900 4900
4901 retval.maybe_compress (); 4901 retval.maybe_compress ();
4902 } 4902 }
4903 } 4903 }
4948 for (octave_idx_type i = 0; i < nc; i++) 4948 for (octave_idx_type i = 0; i < nc; i++)
4949 tmp_data[ii++] = 0.; 4949 tmp_data[ii++] = 0.;
4950 } 4950 }
4951 4951
4952 for (octave_idx_type j = 0; j < nc; j++) 4952 for (octave_idx_type j = 0; j < nc; j++)
4953 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 4953 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
4954 { 4954 {
4955 octave_idx_type ri = ridx (i); 4955 octave_idx_type ri = ridx (i);
4956 if (ri >= j) 4956 if (ri >= j)
4957 m_band(ri - j, j) = data(i); 4957 m_band(ri - j, j) = data (i);
4958 } 4958 }
4959 4959
4960 // Calculate the norm of the matrix, for later use. 4960 // Calculate the norm of the matrix, for later use.
4961 double anorm; 4961 double anorm;
4962 if (calc_cond) 4962 if (calc_cond)
4963 anorm = m_band.abs ().sum ().row(0).max (); 4963 anorm = m_band.abs ().sum ().row (0).max ();
4964 4964
4965 char job = 'L'; 4965 char job = 'L';
4966 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1), 4966 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
4967 nr, n_lower, tmp_data, ldm, err 4967 nr, n_lower, tmp_data, ldm, err
4968 F77_CHAR_ARG_LEN (1))); 4968 F77_CHAR_ARG_LEN (1)));
5055 for (octave_idx_type i = 0; i < nc; i++) 5055 for (octave_idx_type i = 0; i < nc; i++)
5056 tmp_data[ii++] = 0.; 5056 tmp_data[ii++] = 0.;
5057 } 5057 }
5058 5058
5059 for (octave_idx_type j = 0; j < nc; j++) 5059 for (octave_idx_type j = 0; j < nc; j++)
5060 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 5060 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
5061 m_band(ridx(i) - j + n_lower + n_upper, j) = data(i); 5061 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
5062 5062
5063 // Calculate the norm of the matrix, for later use. 5063 // Calculate the norm of the matrix, for later use.
5064 double anorm; 5064 double anorm;
5065 if (calc_cond) 5065 if (calc_cond)
5066 { 5066 {
5067 for (octave_idx_type j = 0; j < nr; j++) 5067 for (octave_idx_type j = 0; j < nr; j++)
5068 { 5068 {
5069 double atmp = 0.; 5069 double atmp = 0.;
5070 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 5070 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
5071 atmp += std::abs(data(i)); 5071 atmp += std::abs (data (i));
5072 if (atmp > anorm) 5072 if (atmp > anorm)
5073 anorm = atmp; 5073 anorm = atmp;
5074 } 5074 }
5075 } 5075 }
5076 5076
5194 for (octave_idx_type i = 0; i < nc; i++) 5194 for (octave_idx_type i = 0; i < nc; i++)
5195 tmp_data[ii++] = 0.; 5195 tmp_data[ii++] = 0.;
5196 } 5196 }
5197 5197
5198 for (octave_idx_type j = 0; j < nc; j++) 5198 for (octave_idx_type j = 0; j < nc; j++)
5199 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 5199 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
5200 { 5200 {
5201 octave_idx_type ri = ridx (i); 5201 octave_idx_type ri = ridx (i);
5202 if (ri >= j) 5202 if (ri >= j)
5203 m_band(ri - j, j) = data(i); 5203 m_band(ri - j, j) = data (i);
5204 } 5204 }
5205 5205
5206 // Calculate the norm of the matrix, for later use. 5206 // Calculate the norm of the matrix, for later use.
5207 double anorm; 5207 double anorm;
5208 if (calc_cond) 5208 if (calc_cond)
5209 anorm = m_band.abs ().sum ().row(0).max (); 5209 anorm = m_band.abs ().sum ().row (0).max ();
5210 5210
5211 char job = 'L'; 5211 char job = 'L';
5212 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1), 5212 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
5213 nr, n_lower, tmp_data, ldm, err 5213 nr, n_lower, tmp_data, ldm, err
5214 F77_CHAR_ARG_LEN (1))); 5214 F77_CHAR_ARG_LEN (1)));
5271 // will be as many as in b 5271 // will be as many as in b
5272 volatile octave_idx_type x_nz = b.nnz (); 5272 volatile octave_idx_type x_nz = b.nnz ();
5273 volatile octave_idx_type ii = 0; 5273 volatile octave_idx_type ii = 0;
5274 retval = SparseComplexMatrix (b_nr, b_nc, x_nz); 5274 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
5275 5275
5276 retval.xcidx(0) = 0; 5276 retval.xcidx (0) = 0;
5277 for (volatile octave_idx_type j = 0; j < b_nc; j++) 5277 for (volatile octave_idx_type j = 0; j < b_nc; j++)
5278 { 5278 {
5279 5279
5280 for (octave_idx_type i = 0; i < b_nr; i++) 5280 for (octave_idx_type i = 0; i < b_nr; i++)
5281 Bx[i] = b (i,j); 5281 Bx[i] = b (i,j);
5310 } 5310 }
5311 5311
5312 for (octave_idx_type i = 0; i < nr; i++) 5312 for (octave_idx_type i = 0; i < nr; i++)
5313 if (Bx[i] != 0.) 5313 if (Bx[i] != 0.)
5314 { 5314 {
5315 retval.xridx(ii) = i; 5315 retval.xridx (ii) = i;
5316 retval.xdata(ii++) = Bx[i]; 5316 retval.xdata (ii++) = Bx[i];
5317 } 5317 }
5318 5318
5319 retval.xcidx(j+1) = ii; 5319 retval.xcidx (j+1) = ii;
5320 } 5320 }
5321 5321
5322 retval.maybe_compress (); 5322 retval.maybe_compress ();
5323 } 5323 }
5324 } 5324 }
5342 for (octave_idx_type i = 0; i < nc; i++) 5342 for (octave_idx_type i = 0; i < nc; i++)
5343 tmp_data[ii++] = 0.; 5343 tmp_data[ii++] = 0.;
5344 } 5344 }
5345 5345
5346 for (octave_idx_type j = 0; j < nc; j++) 5346 for (octave_idx_type j = 0; j < nc; j++)
5347 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 5347 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
5348 m_band(ridx(i) - j + n_lower + n_upper, j) = data(i); 5348 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
5349 5349
5350 // Calculate the norm of the matrix, for later use. 5350 // Calculate the norm of the matrix, for later use.
5351 double anorm; 5351 double anorm;
5352 if (calc_cond) 5352 if (calc_cond)
5353 { 5353 {
5354 for (octave_idx_type j = 0; j < nr; j++) 5354 for (octave_idx_type j = 0; j < nr; j++)
5355 { 5355 {
5356 double atmp = 0.; 5356 double atmp = 0.;
5357 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) 5357 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
5358 atmp += std::abs(data(i)); 5358 atmp += std::abs (data (i));
5359 if (atmp > anorm) 5359 if (atmp > anorm)
5360 anorm = atmp; 5360 anorm = atmp;
5361 } 5361 }
5362 } 5362 }
5363 5363
5425 { 5425 {
5426 char job = 'N'; 5426 char job = 'N';
5427 volatile octave_idx_type x_nz = b.nnz (); 5427 volatile octave_idx_type x_nz = b.nnz ();
5428 octave_idx_type b_nc = b.cols (); 5428 octave_idx_type b_nc = b.cols ();
5429 retval = SparseComplexMatrix (nr, b_nc, x_nz); 5429 retval = SparseComplexMatrix (nr, b_nc, x_nz);
5430 retval.xcidx(0) = 0; 5430 retval.xcidx (0) = 0;
5431 volatile octave_idx_type ii = 0; 5431 volatile octave_idx_type ii = 0;
5432 5432
5433 OCTAVE_LOCAL_BUFFER (Complex, Bx, nr); 5433 OCTAVE_LOCAL_BUFFER (Complex, Bx, nr);
5434 5434
5435 for (volatile octave_idx_type j = 0; j < b_nc; j++) 5435 for (volatile octave_idx_type j = 0; j < b_nc; j++)
5436 { 5436 {
5437 for (octave_idx_type i = 0; i < nr; i++) 5437 for (octave_idx_type i = 0; i < nr; i++)
5438 Bx[i] = 0.; 5438 Bx[i] = 0.;
5439 5439
5440 for (octave_idx_type i = b.cidx(j); 5440 for (octave_idx_type i = b.cidx (j);
5441 i < b.cidx(j+1); i++) 5441 i < b.cidx (j+1); i++)
5442 Bx[b.ridx(i)] = b.data(i); 5442 Bx[b.ridx (i)] = b.data (i);
5443 5443
5444 F77_XFCN (zgbtrs, ZGBTRS, 5444 F77_XFCN (zgbtrs, ZGBTRS,
5445 (F77_CONST_CHAR_ARG2 (&job, 1), 5445 (F77_CONST_CHAR_ARG2 (&job, 1),
5446 nr, n_lower, n_upper, 1, tmp_data, 5446 nr, n_lower, n_upper, 1, tmp_data,
5447 ldm, pipvt, Bx, b.rows (), err 5447 ldm, pipvt, Bx, b.rows (), err
5463 } 5463 }
5464 5464
5465 for (octave_idx_type i = 0; i < nr; i++) 5465 for (octave_idx_type i = 0; i < nr; i++)
5466 if (Bx[i] != 0.) 5466 if (Bx[i] != 0.)
5467 { 5467 {
5468 retval.xridx(ii) = i; 5468 retval.xridx (ii) = i;
5469 retval.xdata(ii++) = Bx[i]; 5469 retval.xdata (ii++) = Bx[i];
5470 } 5470 }
5471 retval.xcidx(j+1) = ii; 5471 retval.xcidx (j+1) = ii;
5472 } 5472 }
5473 5473
5474 retval.maybe_compress (); 5474 retval.maybe_compress ();
5475 } 5475 }
5476 } 5476 }
5734 retval.resize (b.rows (), b.cols ()); 5734 retval.resize (b.rows (), b.cols ());
5735 for (octave_idx_type j = 0; j < b.cols (); j++) 5735 for (octave_idx_type j = 0; j < b.cols (); j++)
5736 { 5736 {
5737 octave_idx_type jr = j * b.rows (); 5737 octave_idx_type jr = j * b.rows ();
5738 for (octave_idx_type i = 0; i < b.rows (); i++) 5738 for (octave_idx_type i = 0; i < b.rows (); i++)
5739 retval.xelem(i,j) = static_cast<Complex *>(X->x)[jr + i]; 5739 retval.xelem (i,j) = static_cast<Complex *>(X->x)[jr + i];
5740 } 5740 }
5741 5741
5742 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; 5742 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
5743 CHOLMOD_NAME(free_dense) (&X, cm); 5743 CHOLMOD_NAME(free_dense) (&X, cm);
5744 CHOLMOD_NAME(free_factor) (&L, cm); 5744 CHOLMOD_NAME(free_factor) (&L, cm);
5988 (static_cast<octave_idx_type>(X->nrow), 5988 (static_cast<octave_idx_type>(X->nrow),
5989 static_cast<octave_idx_type>(X->ncol), 5989 static_cast<octave_idx_type>(X->ncol),
5990 static_cast<octave_idx_type>(X->nzmax)); 5990 static_cast<octave_idx_type>(X->nzmax));
5991 for (octave_idx_type j = 0; 5991 for (octave_idx_type j = 0;
5992 j <= static_cast<octave_idx_type>(X->ncol); j++) 5992 j <= static_cast<octave_idx_type>(X->ncol); j++)
5993 retval.xcidx(j) = static_cast<octave_idx_type *>(X->p)[j]; 5993 retval.xcidx (j) = static_cast<octave_idx_type *>(X->p)[j];
5994 for (octave_idx_type j = 0; 5994 for (octave_idx_type j = 0;
5995 j < static_cast<octave_idx_type>(X->nzmax); j++) 5995 j < static_cast<octave_idx_type>(X->nzmax); j++)
5996 { 5996 {
5997 retval.xridx(j) = static_cast<octave_idx_type *>(X->i)[j]; 5997 retval.xridx (j) = static_cast<octave_idx_type *>(X->i)[j];
5998 retval.xdata(j) = static_cast<Complex *>(X->x)[j]; 5998 retval.xdata (j) = static_cast<Complex *>(X->x)[j];
5999 } 5999 }
6000 6000
6001 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; 6001 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
6002 CHOLMOD_NAME(free_sparse) (&X, cm); 6002 CHOLMOD_NAME(free_sparse) (&X, cm);
6003 CHOLMOD_NAME(free_factor) (&L, cm); 6003 CHOLMOD_NAME(free_factor) (&L, cm);
6048 octave_idx_type ii = 0; 6048 octave_idx_type ii = 0;
6049 retval = SparseComplexMatrix (b_nr, b_nc, x_nz); 6049 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
6050 6050
6051 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr); 6051 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr);
6052 6052
6053 retval.xcidx(0) = 0; 6053 retval.xcidx (0) = 0;
6054 for (octave_idx_type j = 0; j < b_nc; j++) 6054 for (octave_idx_type j = 0; j < b_nc; j++)
6055 { 6055 {
6056 6056
6057 #ifdef UMFPACK_SEPARATE_SPLIT 6057 #ifdef UMFPACK_SEPARATE_SPLIT
6058 for (octave_idx_type i = 0; i < b_nr; i++) 6058 for (octave_idx_type i = 0; i < b_nr; i++)
6103 octave_idx_type sz = x_nz * (b_nc - j) / b_nc; 6103 octave_idx_type sz = x_nz * (b_nc - j) / b_nc;
6104 sz = (sz > 10 ? sz : 10) + x_nz; 6104 sz = (sz > 10 ? sz : 10) + x_nz;
6105 retval.change_capacity (sz); 6105 retval.change_capacity (sz);
6106 x_nz = sz; 6106 x_nz = sz;
6107 } 6107 }
6108 retval.xdata(ii) = tmp; 6108 retval.xdata (ii) = tmp;
6109 retval.xridx(ii++) = i; 6109 retval.xridx (ii++) = i;
6110 } 6110 }
6111 } 6111 }
6112 retval.xcidx(j+1) = ii; 6112 retval.xcidx (j+1) = ii;
6113 } 6113 }
6114 6114
6115 retval.maybe_compress (); 6115 retval.maybe_compress ();
6116 6116
6117 UMFPACK_ZNAME (report_info) (control, info); 6117 UMFPACK_ZNAME (report_info) (control, info);
6268 retval.resize (b.rows (), b.cols ()); 6268 retval.resize (b.rows (), b.cols ());
6269 for (octave_idx_type j = 0; j < b.cols (); j++) 6269 for (octave_idx_type j = 0; j < b.cols (); j++)
6270 { 6270 {
6271 octave_idx_type jr = j * b.rows (); 6271 octave_idx_type jr = j * b.rows ();
6272 for (octave_idx_type i = 0; i < b.rows (); i++) 6272 for (octave_idx_type i = 0; i < b.rows (); i++)
6273 retval.xelem(i,j) = static_cast<Complex *>(X->x)[jr + i]; 6273 retval.xelem (i,j) = static_cast<Complex *>(X->x)[jr + i];
6274 } 6274 }
6275 6275
6276 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; 6276 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
6277 CHOLMOD_NAME(free_dense) (&X, cm); 6277 CHOLMOD_NAME(free_dense) (&X, cm);
6278 CHOLMOD_NAME(free_factor) (&L, cm); 6278 CHOLMOD_NAME(free_factor) (&L, cm);
6501 (static_cast<octave_idx_type>(X->nrow), 6501 (static_cast<octave_idx_type>(X->nrow),
6502 static_cast<octave_idx_type>(X->ncol), 6502 static_cast<octave_idx_type>(X->ncol),
6503 static_cast<octave_idx_type>(X->nzmax)); 6503 static_cast<octave_idx_type>(X->nzmax));
6504 for (octave_idx_type j = 0; 6504 for (octave_idx_type j = 0;
6505 j <= static_cast<octave_idx_type>(X->ncol); j++) 6505 j <= static_cast<octave_idx_type>(X->ncol); j++)
6506 retval.xcidx(j) = static_cast<octave_idx_type *>(X->p)[j]; 6506 retval.xcidx (j) = static_cast<octave_idx_type *>(X->p)[j];
6507 for (octave_idx_type j = 0; 6507 for (octave_idx_type j = 0;
6508 j < static_cast<octave_idx_type>(X->nzmax); j++) 6508 j < static_cast<octave_idx_type>(X->nzmax); j++)
6509 { 6509 {
6510 retval.xridx(j) = static_cast<octave_idx_type *>(X->i)[j]; 6510 retval.xridx (j) = static_cast<octave_idx_type *>(X->i)[j];
6511 retval.xdata(j) = static_cast<Complex *>(X->x)[j]; 6511 retval.xdata (j) = static_cast<Complex *>(X->x)[j];
6512 } 6512 }
6513 6513
6514 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; 6514 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
6515 CHOLMOD_NAME(free_sparse) (&X, cm); 6515 CHOLMOD_NAME(free_sparse) (&X, cm);
6516 CHOLMOD_NAME(free_factor) (&L, cm); 6516 CHOLMOD_NAME(free_factor) (&L, cm);
6554 octave_idx_type ii = 0; 6554 octave_idx_type ii = 0;
6555 retval = SparseComplexMatrix (b_nr, b_nc, x_nz); 6555 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
6556 6556
6557 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr); 6557 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr);
6558 6558
6559 retval.xcidx(0) = 0; 6559 retval.xcidx (0) = 0;
6560 for (octave_idx_type j = 0; j < b_nc; j++) 6560 for (octave_idx_type j = 0; j < b_nc; j++)
6561 { 6561 {
6562 for (octave_idx_type i = 0; i < b_nr; i++) 6562 for (octave_idx_type i = 0; i < b_nr; i++)
6563 Bx[i] = b (i,j); 6563 Bx[i] = b (i,j);
6564 6564
6594 octave_idx_type sz = x_nz * (b_nc - j) / b_nc; 6594 octave_idx_type sz = x_nz * (b_nc - j) / b_nc;
6595 sz = (sz > 10 ? sz : 10) + x_nz; 6595 sz = (sz > 10 ? sz : 10) + x_nz;
6596 retval.change_capacity (sz); 6596 retval.change_capacity (sz);
6597 x_nz = sz; 6597 x_nz = sz;
6598 } 6598 }
6599 retval.xdata(ii) = tmp; 6599 retval.xdata (ii) = tmp;
6600 retval.xridx(ii++) = i; 6600 retval.xridx (ii++) = i;
6601 } 6601 }
6602 } 6602 }
6603 retval.xcidx(j+1) = ii; 6603 retval.xcidx (j+1) = ii;
6604 } 6604 }
6605 6605
6606 retval.maybe_compress (); 6606 retval.maybe_compress ();
6607 6607
6608 rcond = Info (UMFPACK_RCOND); 6608 rcond = Info (UMFPACK_RCOND);
6692 { 6692 {
6693 (*current_liboctave_error_handler) ("unknown matrix type"); 6693 (*current_liboctave_error_handler) ("unknown matrix type");
6694 return ComplexMatrix (); 6694 return ComplexMatrix ();
6695 } 6695 }
6696 6696
6697 if (singular_fallback && mattype.type(false) == MatrixType::Rectangular) 6697 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
6698 { 6698 {
6699 rcond = 1.; 6699 rcond = 1.;
6700 #ifdef USE_QRSOLVE 6700 #ifdef USE_QRSOLVE
6701 retval = qrsolve (*this, b, err); 6701 retval = qrsolve (*this, b, err);
6702 #else 6702 #else
6760 { 6760 {
6761 (*current_liboctave_error_handler) ("unknown matrix type"); 6761 (*current_liboctave_error_handler) ("unknown matrix type");
6762 return SparseComplexMatrix (); 6762 return SparseComplexMatrix ();
6763 } 6763 }
6764 6764
6765 if (singular_fallback && mattype.type(false) == MatrixType::Rectangular) 6765 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
6766 { 6766 {
6767 rcond = 1.; 6767 rcond = 1.;
6768 #ifdef USE_QRSOLVE 6768 #ifdef USE_QRSOLVE
6769 retval = qrsolve (*this, b, err); 6769 retval = qrsolve (*this, b, err);
6770 #else 6770 #else
6828 { 6828 {
6829 (*current_liboctave_error_handler) ("unknown matrix type"); 6829 (*current_liboctave_error_handler) ("unknown matrix type");
6830 return ComplexMatrix (); 6830 return ComplexMatrix ();
6831 } 6831 }
6832 6832
6833 if (singular_fallback && mattype.type(false) == MatrixType::Rectangular) 6833 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
6834 { 6834 {
6835 rcond = 1.; 6835 rcond = 1.;
6836 #ifdef USE_QRSOLVE 6836 #ifdef USE_QRSOLVE
6837 retval = qrsolve (*this, b, err); 6837 retval = qrsolve (*this, b, err);
6838 #else 6838 #else
6897 { 6897 {
6898 (*current_liboctave_error_handler) ("unknown matrix type"); 6898 (*current_liboctave_error_handler) ("unknown matrix type");
6899 return SparseComplexMatrix (); 6899 return SparseComplexMatrix ();
6900 } 6900 }
6901 6901
6902 if (singular_fallback && mattype.type(false) == MatrixType::Rectangular) 6902 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
6903 { 6903 {
6904 rcond = 1.; 6904 rcond = 1.;
6905 #ifdef USE_QRSOLVE 6905 #ifdef USE_QRSOLVE
6906 retval = qrsolve (*this, b, err); 6906 retval = qrsolve (*this, b, err);
6907 #else 6907 #else
7175 r.cidx (0) = 0; 7175 r.cidx (0) = 0;
7176 for (octave_idx_type i = 0; i < nc; i++) 7176 for (octave_idx_type i = 0; i < nc; i++)
7177 { 7177 {
7178 for (octave_idx_type j = 0; j < nr; j++) 7178 for (octave_idx_type j = 0; j < nr; j++)
7179 { 7179 {
7180 if (jj < cidx(i+1) && ridx(jj) == j) 7180 if (jj < cidx (i+1) && ridx (jj) == j)
7181 jj++; 7181 jj++;
7182 else 7182 else
7183 { 7183 {
7184 r.data(ii) = true; 7184 r.data (ii) = true;
7185 r.ridx(ii++) = j; 7185 r.ridx (ii++) = j;
7186 } 7186 }
7187 } 7187 }
7188 r.cidx (i+1) = ii; 7188 r.cidx (i+1) = ii;
7189 } 7189 }
7190 7190
7265 octave_idx_type nel = nnz (); 7265 octave_idx_type nel = nnz ();
7266 7266
7267 if (nel == 0) 7267 if (nel == 0)
7268 return false; 7268 return false;
7269 7269
7270 max_val = std::real(data (0)); 7270 max_val = std::real (data (0));
7271 min_val = std::real(data (0)); 7271 min_val = std::real (data (0));
7272 7272
7273 for (octave_idx_type i = 0; i < nel; i++) 7273 for (octave_idx_type i = 0; i < nel; i++)
7274 { 7274 {
7275 Complex val = data (i); 7275 Complex val = data (i);
7276 7276
7351 if ((rows () == 1 && dim == -1) || dim == 1) 7351 if ((rows () == 1 && dim == -1) || dim == 1)
7352 return transpose (). prod (0). transpose (); 7352 return transpose (). prod (0). transpose ();
7353 else 7353 else
7354 { 7354 {
7355 SPARSE_REDUCTION_OP (SparseComplexMatrix, Complex, *=, 7355 SPARSE_REDUCTION_OP (SparseComplexMatrix, Complex, *=,
7356 (cidx(j+1) - cidx(j) < nr ? 0.0 : 1.0), 1.0); 7356 (cidx (j+1) - cidx (j) < nr ? 0.0 : 1.0), 1.0);
7357 } 7357 }
7358 } 7358 }
7359 7359
7360 SparseComplexMatrix 7360 SparseComplexMatrix
7361 SparseComplexMatrix::sum (int dim) const 7361 SparseComplexMatrix::sum (int dim) const
7366 SparseComplexMatrix 7366 SparseComplexMatrix
7367 SparseComplexMatrix::sumsq (int dim) const 7367 SparseComplexMatrix::sumsq (int dim) const
7368 { 7368 {
7369 #define ROW_EXPR \ 7369 #define ROW_EXPR \
7370 Complex d = data (i); \ 7370 Complex d = data (i); \
7371 tmp [ridx(i)] += d * conj (d) 7371 tmp[ridx (i)] += d * conj (d)
7372 7372
7373 #define COL_EXPR \ 7373 #define COL_EXPR \
7374 Complex d = data (i); \ 7374 Complex d = data (i); \
7375 tmp [j] += d * conj (d) 7375 tmp[j] += d * conj (d)
7376 7376
7377 SPARSE_BASE_REDUCTION_OP (SparseComplexMatrix, Complex, ROW_EXPR, 7377 SPARSE_BASE_REDUCTION_OP (SparseComplexMatrix, Complex, ROW_EXPR,
7378 COL_EXPR, 0.0, 0.0); 7378 COL_EXPR, 0.0, 0.0);
7379 7379
7380 #undef ROW_EXPR 7380 #undef ROW_EXPR
7414 // add one to the printed indices to go from 7414 // add one to the printed indices to go from
7415 // zero-based to one-based arrays 7415 // zero-based to one-based arrays
7416 for (octave_idx_type j = 0; j < nc; j++) 7416 for (octave_idx_type j = 0; j < nc; j++)
7417 { 7417 {
7418 octave_quit (); 7418 octave_quit ();
7419 for (octave_idx_type i = a.cidx(j); i < a.cidx(j+1); i++) 7419 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
7420 { 7420 {
7421 os << a.ridx(i) + 1 << " " << j + 1 << " "; 7421 os << a.ridx (i) + 1 << " " << j + 1 << " ";
7422 octave_write_complex (os, a.data(i)); 7422 octave_write_complex (os, a.data (i));
7423 os << "\n"; 7423 os << "\n";
7424 } 7424 }
7425 } 7425 }
7426 7426
7427 return os; 7427 return os;
7638 octave_idx_type nr = m.rows (); 7638 octave_idx_type nr = m.rows ();
7639 octave_idx_type nc = m.columns (); 7639 octave_idx_type nc = m.columns ();
7640 7640
7641 EMPTY_RETURN_CHECK (SparseComplexMatrix); 7641 EMPTY_RETURN_CHECK (SparseComplexMatrix);
7642 7642
7643 if (abs(c) == 0.) 7643 if (abs (c) == 0.)
7644 return SparseComplexMatrix (nr, nc); 7644 return SparseComplexMatrix (nr, nc);
7645 else 7645 else
7646 { 7646 {
7647 result = SparseComplexMatrix (m); 7647 result = SparseComplexMatrix (m);
7648 7648
7649 for (octave_idx_type j = 0; j < nc; j++) 7649 for (octave_idx_type j = 0; j < nc; j++)
7650 for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) 7650 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
7651 result.data(i) = xmin(c, m.data(i)); 7651 result.data (i) = xmin (c, m.data (i));
7652 } 7652 }
7653 7653
7654 return result; 7654 return result;
7655 } 7655 }
7656 7656
7684 7684
7685 octave_idx_type jx = 0; 7685 octave_idx_type jx = 0;
7686 r.cidx (0) = 0; 7686 r.cidx (0) = 0;
7687 for (octave_idx_type i = 0 ; i < a_nc ; i++) 7687 for (octave_idx_type i = 0 ; i < a_nc ; i++)
7688 { 7688 {
7689 octave_idx_type ja = a.cidx(i); 7689 octave_idx_type ja = a.cidx (i);
7690 octave_idx_type ja_max = a.cidx(i+1); 7690 octave_idx_type ja_max = a.cidx (i+1);
7691 bool ja_lt_max= ja < ja_max; 7691 bool ja_lt_max= ja < ja_max;
7692 7692
7693 octave_idx_type jb = b.cidx(i); 7693 octave_idx_type jb = b.cidx (i);
7694 octave_idx_type jb_max = b.cidx(i+1); 7694 octave_idx_type jb_max = b.cidx (i+1);
7695 bool jb_lt_max = jb < jb_max; 7695 bool jb_lt_max = jb < jb_max;
7696 7696
7697 while (ja_lt_max || jb_lt_max ) 7697 while (ja_lt_max || jb_lt_max )
7698 { 7698 {
7699 octave_quit (); 7699 octave_quit ();
7700 if ((! jb_lt_max) || 7700 if ((! jb_lt_max) ||
7701 (ja_lt_max && (a.ridx(ja) < b.ridx(jb)))) 7701 (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
7702 { 7702 {
7703 Complex tmp = xmin (a.data(ja), 0.); 7703 Complex tmp = xmin (a.data (ja), 0.);
7704 if (tmp != 0.) 7704 if (tmp != 0.)
7705 { 7705 {
7706 r.ridx(jx) = a.ridx(ja); 7706 r.ridx (jx) = a.ridx (ja);
7707 r.data(jx) = tmp; 7707 r.data (jx) = tmp;
7708 jx++; 7708 jx++;
7709 } 7709 }
7710 ja++; 7710 ja++;
7711 ja_lt_max= ja < ja_max; 7711 ja_lt_max= ja < ja_max;
7712 } 7712 }
7713 else if (( !ja_lt_max ) || 7713 else if (( !ja_lt_max ) ||
7714 (jb_lt_max && (b.ridx(jb) < a.ridx(ja)) ) ) 7714 (jb_lt_max && (b.ridx (jb) < a.ridx (ja)) ) )
7715 { 7715 {
7716 Complex tmp = xmin (0., b.data(jb)); 7716 Complex tmp = xmin (0., b.data (jb));
7717 if (tmp != 0.) 7717 if (tmp != 0.)
7718 { 7718 {
7719 r.ridx(jx) = b.ridx(jb); 7719 r.ridx (jx) = b.ridx (jb);
7720 r.data(jx) = tmp; 7720 r.data (jx) = tmp;
7721 jx++; 7721 jx++;
7722 } 7722 }
7723 jb++; 7723 jb++;
7724 jb_lt_max= jb < jb_max; 7724 jb_lt_max= jb < jb_max;
7725 } 7725 }
7726 else 7726 else
7727 { 7727 {
7728 Complex tmp = xmin (a.data(ja), b.data(jb)); 7728 Complex tmp = xmin (a.data (ja), b.data (jb));
7729 if (tmp != 0.) 7729 if (tmp != 0.)
7730 { 7730 {
7731 r.data(jx) = tmp; 7731 r.data (jx) = tmp;
7732 r.ridx(jx) = a.ridx(ja); 7732 r.ridx (jx) = a.ridx (ja);
7733 jx++; 7733 jx++;
7734 } 7734 }
7735 ja++; 7735 ja++;
7736 ja_lt_max= ja < ja_max; 7736 ja_lt_max= ja < ja_max;
7737 jb++; 7737 jb++;
7738 jb_lt_max= jb < jb_max; 7738 jb_lt_max= jb < jb_max;
7739 } 7739 }
7740 } 7740 }
7741 r.cidx(i+1) = jx; 7741 r.cidx (i+1) = jx;
7742 } 7742 }
7743 7743
7744 r.maybe_compress (); 7744 r.maybe_compress ();
7745 } 7745 }
7746 } 7746 }
7759 octave_idx_type nc = m.columns (); 7759 octave_idx_type nc = m.columns ();
7760 7760
7761 EMPTY_RETURN_CHECK (SparseComplexMatrix); 7761 EMPTY_RETURN_CHECK (SparseComplexMatrix);
7762 7762
7763 // Count the number of non-zero elements 7763 // Count the number of non-zero elements
7764 if (xmax(c, 0.) != 0.) 7764 if (xmax (c, 0.) != 0.)
7765 { 7765 {
7766 result = SparseComplexMatrix (nr, nc, c); 7766 result = SparseComplexMatrix (nr, nc, c);
7767 for (octave_idx_type j = 0; j < nc; j++) 7767 for (octave_idx_type j = 0; j < nc; j++)
7768 for (octave_idx_type i = m.cidx(j); i < m.cidx(j+1); i++) 7768 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
7769 result.xdata(m.ridx(i) + j * nr) = xmax (c, m.data(i)); 7769 result.xdata (m.ridx (i) + j * nr) = xmax (c, m.data (i));
7770 } 7770 }
7771 else 7771 else
7772 result = SparseComplexMatrix (m); 7772 result = SparseComplexMatrix (m);
7773 7773
7774 return result; 7774 return result;
7808 7808
7809 octave_idx_type jx = 0; 7809 octave_idx_type jx = 0;
7810 r.cidx (0) = 0; 7810 r.cidx (0) = 0;
7811 for (octave_idx_type i = 0 ; i < a_nc ; i++) 7811 for (octave_idx_type i = 0 ; i < a_nc ; i++)
7812 { 7812 {
7813 octave_idx_type ja = a.cidx(i); 7813 octave_idx_type ja = a.cidx (i);
7814 octave_idx_type ja_max = a.cidx(i+1); 7814 octave_idx_type ja_max = a.cidx (i+1);
7815 bool ja_lt_max= ja < ja_max; 7815 bool ja_lt_max= ja < ja_max;
7816 7816
7817 octave_idx_type jb = b.cidx(i); 7817 octave_idx_type jb = b.cidx (i);
7818 octave_idx_type jb_max = b.cidx(i+1); 7818 octave_idx_type jb_max = b.cidx (i+1);
7819 bool jb_lt_max = jb < jb_max; 7819 bool jb_lt_max = jb < jb_max;
7820 7820
7821 while (ja_lt_max || jb_lt_max ) 7821 while (ja_lt_max || jb_lt_max )
7822 { 7822 {
7823 octave_quit (); 7823 octave_quit ();
7824 if ((! jb_lt_max) || 7824 if ((! jb_lt_max) ||
7825 (ja_lt_max && (a.ridx(ja) < b.ridx(jb)))) 7825 (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
7826 { 7826 {
7827 Complex tmp = xmax (a.data(ja), 0.); 7827 Complex tmp = xmax (a.data (ja), 0.);
7828 if (tmp != 0.) 7828 if (tmp != 0.)
7829 { 7829 {
7830 r.ridx(jx) = a.ridx(ja); 7830 r.ridx (jx) = a.ridx (ja);
7831 r.data(jx) = tmp; 7831 r.data (jx) = tmp;
7832 jx++; 7832 jx++;
7833 } 7833 }
7834 ja++; 7834 ja++;
7835 ja_lt_max= ja < ja_max; 7835 ja_lt_max= ja < ja_max;
7836 } 7836 }
7837 else if (( !ja_lt_max ) || 7837 else if (( !ja_lt_max ) ||
7838 (jb_lt_max && (b.ridx(jb) < a.ridx(ja)) ) ) 7838 (jb_lt_max && (b.ridx (jb) < a.ridx (ja)) ) )
7839 { 7839 {
7840 Complex tmp = xmax (0., b.data(jb)); 7840 Complex tmp = xmax (0., b.data (jb));
7841 if (tmp != 0.) 7841 if (tmp != 0.)
7842 { 7842 {
7843 r.ridx(jx) = b.ridx(jb); 7843 r.ridx (jx) = b.ridx (jb);
7844 r.data(jx) = tmp; 7844 r.data (jx) = tmp;
7845 jx++; 7845 jx++;
7846 } 7846 }
7847 jb++; 7847 jb++;
7848 jb_lt_max= jb < jb_max; 7848 jb_lt_max= jb < jb_max;
7849 } 7849 }
7850 else 7850 else
7851 { 7851 {
7852 Complex tmp = xmax (a.data(ja), b.data(jb)); 7852 Complex tmp = xmax (a.data (ja), b.data (jb));
7853 if (tmp != 0.) 7853 if (tmp != 0.)
7854 { 7854 {
7855 r.data(jx) = tmp; 7855 r.data (jx) = tmp;
7856 r.ridx(jx) = a.ridx(ja); 7856 r.ridx (jx) = a.ridx (ja);
7857 jx++; 7857 jx++;
7858 } 7858 }
7859 ja++; 7859 ja++;
7860 ja_lt_max= ja < ja_max; 7860 ja_lt_max= ja < ja_max;
7861 jb++; 7861 jb++;
7862 jb_lt_max= jb < jb_max; 7862 jb_lt_max= jb < jb_max;
7863 } 7863 }
7864 } 7864 }
7865 r.cidx(i+1) = jx; 7865 r.cidx (i+1) = jx;
7866 } 7866 }
7867 7867
7868 r.maybe_compress (); 7868 r.maybe_compress ();
7869 } 7869 }
7870 } 7870 }