@@ -2588,14 +2588,18 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const Matrix& b,
2588
2588
{
2589
2589
retval.resize (nc, b_nc);
2590
2590
OCTAVE_LOCAL_BUFFER (Complex, work, nm);
2591
+
2591
2592
octave_idx_type *perm = mattype.triangular_perm ();
2593
+ OCTAVE_LOCAL_BUFFER (octave_idx_type, inv_perm, nr);
2594
+ for (octave_idx_type i = 0 ; i < nr; i++)
2595
+ inv_perm[perm[i]] = i;
2592
2596
2593
2597
for (octave_idx_type j = 0 ; j < b_nc; j++)
2594
2598
{
2595
2599
for (octave_idx_type i = 0 ; i < nm; i++)
2596
2600
work[i] = 0 .;
2597
2601
for (octave_idx_type i = 0 ; i < nr; i++)
2598
- work[perm [i]] = b (i, j);
2602
+ work[inv_perm [i]] = b (i, j);
2599
2603
2600
2604
for (octave_idx_type k = 0 ; k < nc; k++)
2601
2605
{
@@ -2604,10 +2608,11 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const Matrix& b,
2604
2608
octave_idx_type minr = nr;
2605
2609
octave_idx_type mini = 0 ;
2606
2610
2611
+ // Check that permutation leads to lower triangular form
2607
2612
for (octave_idx_type i = cidx (k); i < cidx (k+1 ); i++)
2608
- if (perm [ridx (i)] < minr)
2613
+ if (inv_perm [ridx (i)] < minr)
2609
2614
{
2610
- minr = perm [ridx (i)];
2615
+ minr = inv_perm [ridx (i)];
2611
2616
mini = i;
2612
2617
}
2613
2618
@@ -2624,7 +2629,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const Matrix& b,
2624
2629
if (i == mini)
2625
2630
continue ;
2626
2631
2627
- octave_idx_type iidx = perm [ridx (i)];
2632
+ octave_idx_type iidx = inv_perm [ridx (i)];
2628
2633
work[iidx] = work[iidx] - tmp * data (i);
2629
2634
}
2630
2635
}
@@ -2653,9 +2658,9 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const Matrix& b,
2653
2658
2654
2659
for (octave_idx_type i = cidx (k);
2655
2660
i < cidx (k+1 ); i++)
2656
- if (perm [ridx (i)] < minr)
2661
+ if (inv_perm [ridx (i)] < minr)
2657
2662
{
2658
- minr = perm [ridx (i)];
2663
+ minr = inv_perm [ridx (i)];
2659
2664
mini = i;
2660
2665
}
2661
2666
@@ -2667,7 +2672,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const Matrix& b,
2667
2672
if (i == mini)
2668
2673
continue ;
2669
2674
2670
- octave_idx_type iidx = perm [ridx (i)];
2675
+ octave_idx_type iidx = inv_perm [ridx (i)];
2671
2676
work[iidx] = work[iidx] - tmp * data (i);
2672
2677
}
2673
2678
}
@@ -2841,14 +2846,18 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseMatrix& b,
2841
2846
if (typ == MatrixType::Permuted_Lower)
2842
2847
{
2843
2848
OCTAVE_LOCAL_BUFFER (Complex, work, nm);
2849
+
2844
2850
octave_idx_type *perm = mattype.triangular_perm ();
2851
+ OCTAVE_LOCAL_BUFFER (octave_idx_type, inv_perm, nr);
2852
+ for (octave_idx_type i = 0 ; i < nr; i++)
2853
+ inv_perm[perm[i]] = i;
2845
2854
2846
2855
for (octave_idx_type j = 0 ; j < b_nc; j++)
2847
2856
{
2848
2857
for (octave_idx_type i = 0 ; i < nm; i++)
2849
2858
work[i] = 0 .;
2850
2859
for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1 ); i++)
2851
- work[perm [b.ridx (i)]] = b.data (i);
2860
+ work[inv_perm [b.ridx (i)]] = b.data (i);
2852
2861
2853
2862
for (octave_idx_type k = 0 ; k < nc; k++)
2854
2863
{
@@ -2857,10 +2866,11 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseMatrix& b,
2857
2866
octave_idx_type minr = nr;
2858
2867
octave_idx_type mini = 0 ;
2859
2868
2869
+ // Check that permutation leads to lower triangular form
2860
2870
for (octave_idx_type i = cidx (k); i < cidx (k+1 ); i++)
2861
- if (perm [ridx (i)] < minr)
2871
+ if (inv_perm [ridx (i)] < minr)
2862
2872
{
2863
- minr = perm [ridx (i)];
2873
+ minr = inv_perm [ridx (i)];
2864
2874
mini = i;
2865
2875
}
2866
2876
@@ -2877,7 +2887,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseMatrix& b,
2877
2887
if (i == mini)
2878
2888
continue ;
2879
2889
2880
- octave_idx_type iidx = perm [ridx (i)];
2890
+ octave_idx_type iidx = inv_perm [ridx (i)];
2881
2891
work[iidx] = work[iidx] - tmp * data (i);
2882
2892
}
2883
2893
}
@@ -2928,9 +2938,9 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseMatrix& b,
2928
2938
2929
2939
for (octave_idx_type i = cidx (k);
2930
2940
i < cidx (k+1 ); i++)
2931
- if (perm [ridx (i)] < minr)
2941
+ if (inv_perm [ridx (i)] < minr)
2932
2942
{
2933
- minr = perm [ridx (i)];
2943
+ minr = inv_perm [ridx (i)];
2934
2944
mini = i;
2935
2945
}
2936
2946
@@ -2942,7 +2952,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseMatrix& b,
2942
2952
if (i == mini)
2943
2953
continue ;
2944
2954
2945
- octave_idx_type iidx = perm [ridx (i)];
2955
+ octave_idx_type iidx = inv_perm [ridx (i)];
2946
2956
work[iidx] = work[iidx] - tmp * data (i);
2947
2957
}
2948
2958
}
@@ -3134,14 +3144,18 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const ComplexMatrix& b,
3134
3144
{
3135
3145
retval.resize (nc, b_nc);
3136
3146
OCTAVE_LOCAL_BUFFER (Complex, work, nm);
3147
+
3137
3148
octave_idx_type *perm = mattype.triangular_perm ();
3149
+ OCTAVE_LOCAL_BUFFER (octave_idx_type, inv_perm, nr);
3150
+ for (octave_idx_type i = 0 ; i < nr; i++)
3151
+ inv_perm[perm[i]] = i;
3138
3152
3139
3153
for (octave_idx_type j = 0 ; j < b_nc; j++)
3140
3154
{
3141
3155
for (octave_idx_type i = 0 ; i < nm; i++)
3142
3156
work[i] = 0 .;
3143
3157
for (octave_idx_type i = 0 ; i < nr; i++)
3144
- work[perm [i]] = b (i, j);
3158
+ work[inv_perm [i]] = b (i, j);
3145
3159
3146
3160
for (octave_idx_type k = 0 ; k < nc; k++)
3147
3161
{
@@ -3151,9 +3165,9 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const ComplexMatrix& b,
3151
3165
octave_idx_type mini = 0 ;
3152
3166
3153
3167
for (octave_idx_type i = cidx (k); i < cidx (k+1 ); i++)
3154
- if (perm [ridx (i)] < minr)
3168
+ if (inv_perm [ridx (i)] < minr)
3155
3169
{
3156
- minr = perm [ridx (i)];
3170
+ minr = inv_perm [ridx (i)];
3157
3171
mini = i;
3158
3172
}
3159
3173
@@ -3170,7 +3184,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const ComplexMatrix& b,
3170
3184
if (i == mini)
3171
3185
continue ;
3172
3186
3173
- octave_idx_type iidx = perm [ridx (i)];
3187
+ octave_idx_type iidx = inv_perm [ridx (i)];
3174
3188
work[iidx] = work[iidx] - tmp * data (i);
3175
3189
}
3176
3190
}
@@ -3199,9 +3213,9 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const ComplexMatrix& b,
3199
3213
3200
3214
for (octave_idx_type i = cidx (k);
3201
3215
i < cidx (k+1 ); i++)
3202
- if (perm [ridx (i)] < minr)
3216
+ if (inv_perm [ridx (i)] < minr)
3203
3217
{
3204
- minr = perm [ridx (i)];
3218
+ minr = inv_perm [ridx (i)];
3205
3219
mini = i;
3206
3220
}
3207
3221
@@ -3213,7 +3227,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const ComplexMatrix& b,
3213
3227
if (i == mini)
3214
3228
continue ;
3215
3229
3216
- octave_idx_type iidx = perm [ridx (i)];
3230
+ octave_idx_type iidx = inv_perm [ridx (i)];
3217
3231
work[iidx] = work[iidx] - tmp * data (i);
3218
3232
}
3219
3233
}
@@ -3389,14 +3403,18 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
3389
3403
if (typ == MatrixType::Permuted_Lower)
3390
3404
{
3391
3405
OCTAVE_LOCAL_BUFFER (Complex, work, nm);
3406
+
3392
3407
octave_idx_type *perm = mattype.triangular_perm ();
3408
+ OCTAVE_LOCAL_BUFFER (octave_idx_type, inv_perm, nr);
3409
+ for (octave_idx_type i = 0 ; i < nr; i++)
3410
+ inv_perm[perm[i]] = i;
3393
3411
3394
3412
for (octave_idx_type j = 0 ; j < b_nc; j++)
3395
3413
{
3396
3414
for (octave_idx_type i = 0 ; i < nm; i++)
3397
3415
work[i] = 0 .;
3398
3416
for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1 ); i++)
3399
- work[perm [b.ridx (i)]] = b.data (i);
3417
+ work[inv_perm [b.ridx (i)]] = b.data (i);
3400
3418
3401
3419
for (octave_idx_type k = 0 ; k < nc; k++)
3402
3420
{
@@ -3406,9 +3424,9 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
3406
3424
octave_idx_type mini = 0 ;
3407
3425
3408
3426
for (octave_idx_type i = cidx (k); i < cidx (k+1 ); i++)
3409
- if (perm [ridx (i)] < minr)
3427
+ if (inv_perm [ridx (i)] < minr)
3410
3428
{
3411
- minr = perm [ridx (i)];
3429
+ minr = inv_perm [ridx (i)];
3412
3430
mini = i;
3413
3431
}
3414
3432
@@ -3425,7 +3443,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
3425
3443
if (i == mini)
3426
3444
continue ;
3427
3445
3428
- octave_idx_type iidx = perm [ridx (i)];
3446
+ octave_idx_type iidx = inv_perm [ridx (i)];
3429
3447
work[iidx] = work[iidx] - tmp * data (i);
3430
3448
}
3431
3449
}
@@ -3476,9 +3494,9 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
3476
3494
3477
3495
for (octave_idx_type i = cidx (k);
3478
3496
i < cidx (k+1 ); i++)
3479
- if (perm [ridx (i)] < minr)
3497
+ if (inv_perm [ridx (i)] < minr)
3480
3498
{
3481
- minr = perm [ridx (i)];
3499
+ minr = inv_perm [ridx (i)];
3482
3500
mini = i;
3483
3501
}
3484
3502
@@ -3490,7 +3508,7 @@ SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
3490
3508
if (i == mini)
3491
3509
continue ;
3492
3510
3493
- octave_idx_type iidx = perm [ridx (i)];
3511
+ octave_idx_type iidx = inv_perm [ridx (i)];
3494
3512
work[iidx] = work[iidx] - tmp * data (i);
3495
3513
}
3496
3514
}
0 commit comments