Skip to content

Commit baab796

Browse files
committed
Simplification: value tuple swaps
1 parent ec03bfb commit baab796

21 files changed

Lines changed: 62 additions & 188 deletions

src/Numerics/LinearAlgebra/Complex/Factorization/UserLU.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ public override void Solve(Vector<Complex> input, Vector<Complex> result)
261261
}
262262

263263
var p = Pivots[i];
264-
var temp = result[p];
265-
result[p] = result[i];
266-
result[i] = temp;
264+
(result[p], result[i]) = (result[i], result[p]);
267265
}
268266

269267
var order = Factors.RowCount;

src/Numerics/LinearAlgebra/Complex/Solvers/ILUTPPreconditioner.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ public void Initialize(Matrix<Complex> matrix)
499499
SwapColumns(_upper, i, indexSorting[0]);
500500

501501
// Update P
502-
var temp = _pivots[i];
503-
_pivots[i] = _pivots[indexSorting[0]];
504-
_pivots[indexSorting[0]] = temp;
502+
(_pivots[i], _pivots[indexSorting[0]]) = (_pivots[indexSorting[0]], _pivots[i]);
505503
}
506504
}
507505

@@ -531,9 +529,7 @@ void PivotRow(Vector<Complex> row)
531529
// store the pivots in the hashtable
532530
knownPivots.Add(_pivots[i], i);
533531

534-
var t = row[i];
535-
row[i] = row[_pivots[i]];
536-
row[_pivots[i]] = t;
532+
(row[i], row[_pivots[i]]) = (row[_pivots[i]], row[i]);
537533
}
538534
}
539535
}
@@ -569,9 +565,7 @@ static void SwapColumns(Matrix<Complex> matrix, int firstColumn, int secondColum
569565
{
570566
for (var i = 0; i < matrix.RowCount; i++)
571567
{
572-
var temp = matrix[i, firstColumn];
573-
matrix[i, firstColumn] = matrix[i, secondColumn];
574-
matrix[i, secondColumn] = temp;
568+
(matrix[i, firstColumn], matrix[i, secondColumn]) = (matrix[i, secondColumn], matrix[i, firstColumn]);
575569
}
576570
}
577571

@@ -856,9 +850,7 @@ static void Sift(int[] values, int start, int count)
856850
/// <param name="second">Second value to exchange</param>
857851
static void Exchange(int[] values, int first, int second)
858852
{
859-
var t = values[first];
860-
values[first] = values[second];
861-
values[second] = t;
853+
(values[first], values[second]) = (values[second], values[first]);
862854
}
863855
}
864856
}

src/Numerics/LinearAlgebra/Complex32/Factorization/UserLU.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,7 @@ public override void Solve(Vector<Complex32> input, Vector<Complex32> result)
261261
}
262262

263263
var p = Pivots[i];
264-
var temp = result[p];
265-
result[p] = result[i];
266-
result[i] = temp;
264+
(result[p], result[i]) = (result[i], result[p]);
267265
}
268266

269267
var order = Factors.RowCount;

src/Numerics/LinearAlgebra/Complex32/Solvers/ILUTPPreconditioner.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,7 @@ public void Initialize(Matrix<Complex32> matrix)
499499
SwapColumns(_upper, i, indexSorting[0]);
500500

501501
// Update P
502-
var temp = _pivots[i];
503-
_pivots[i] = _pivots[indexSorting[0]];
504-
_pivots[indexSorting[0]] = temp;
502+
(_pivots[i], _pivots[indexSorting[0]]) = (_pivots[indexSorting[0]], _pivots[i]);
505503
}
506504
}
507505

@@ -531,9 +529,7 @@ void PivotRow(Vector<Complex32> row)
531529
// store the pivots in the hashtable
532530
knownPivots.Add(_pivots[i], i);
533531

534-
var t = row[i];
535-
row[i] = row[_pivots[i]];
536-
row[_pivots[i]] = t;
532+
(row[i], row[_pivots[i]]) = (row[_pivots[i]], row[i]);
537533
}
538534
}
539535
}
@@ -575,9 +571,7 @@ static void SwapColumns(Matrix<Complex32> matrix, int firstColumn, int secondCol
575571
{
576572
for (var i = 0; i < matrix.RowCount; i++)
577573
{
578-
var temp = matrix[i, firstColumn];
579-
matrix[i, firstColumn] = matrix[i, secondColumn];
580-
matrix[i, secondColumn] = temp;
574+
(matrix[i, firstColumn], matrix[i, secondColumn]) = (matrix[i, secondColumn], matrix[i, firstColumn]);
581575
}
582576
}
583577

@@ -862,9 +856,7 @@ static void Sift(int[] values, int start, int count)
862856
/// <param name="second">Second value to exchange</param>
863857
static void Exchange(int[] values, int first, int second)
864858
{
865-
var t = values[first];
866-
values[first] = values[second];
867-
values[second] = t;
859+
(values[first], values[second]) = (values[second], values[first]);
868860
}
869861
}
870862
}

src/Numerics/LinearAlgebra/Double/Factorization/UserLU.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ public override void Solve(Vector<double> input, Vector<double> result)
259259
}
260260

261261
var p = Pivots[i];
262-
var temp = result[p];
263-
result[p] = result[i];
264-
result[i] = temp;
262+
(result[p], result[i]) = (result[i], result[p]);
265263
}
266264

267265
var order = Factors.RowCount;

src/Numerics/LinearAlgebra/Double/Solvers/ILUTPPreconditioner.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,7 @@ public void Initialize(Matrix<double> matrix)
497497
SwapColumns(_upper, i, indexSorting[0]);
498498

499499
// Update P
500-
var temp = _pivots[i];
501-
_pivots[i] = _pivots[indexSorting[0]];
502-
_pivots[indexSorting[0]] = temp;
500+
(_pivots[i], _pivots[indexSorting[0]]) = (_pivots[indexSorting[0]], _pivots[i]);
503501
}
504502
}
505503

@@ -529,9 +527,7 @@ void PivotRow(Vector<double> row)
529527
// store the pivots in the hashtable
530528
knownPivots.Add(_pivots[i], i);
531529

532-
var t = row[i];
533-
row[i] = row[_pivots[i]];
534-
row[_pivots[i]] = t;
530+
(row[i], row[_pivots[i]]) = (row[_pivots[i]], row[i]);
535531
}
536532
}
537533
}
@@ -573,9 +569,7 @@ static void SwapColumns(Matrix<double> matrix, int firstColumn, int secondColumn
573569
{
574570
for (var i = 0; i < matrix.RowCount; i++)
575571
{
576-
var temp = matrix[i, firstColumn];
577-
matrix[i, firstColumn] = matrix[i, secondColumn];
578-
matrix[i, secondColumn] = temp;
572+
(matrix[i, firstColumn], matrix[i, secondColumn]) = (matrix[i, secondColumn], matrix[i, firstColumn]);
579573
}
580574
}
581575

@@ -860,9 +854,7 @@ static void Sift(int[] values, int start, int count)
860854
/// <param name="second">Second value to exchange</param>
861855
static void Exchange(int[] values, int first, int second)
862856
{
863-
var t = values[first];
864-
values[first] = values[second];
865-
values[second] = t;
857+
(values[first], values[second]) = (values[second], values[first]);
866858
}
867859
}
868860
}

src/Numerics/LinearAlgebra/Single/Factorization/UserLU.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ public override void Solve(Vector<float> input, Vector<float> result)
259259
}
260260

261261
var p = Pivots[i];
262-
var temp = result[p];
263-
result[p] = result[i];
264-
result[i] = temp;
262+
(result[p], result[i]) = (result[i], result[p]);
265263
}
266264

267265
var order = Factors.RowCount;

src/Numerics/LinearAlgebra/Single/Solvers/ILUTPPreconditioner.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,7 @@ public void Initialize(Matrix<float> matrix)
497497
SwapColumns(_upper, i, indexSorting[0]);
498498

499499
// Update P
500-
var temp = _pivots[i];
501-
_pivots[i] = _pivots[indexSorting[0]];
502-
_pivots[indexSorting[0]] = temp;
500+
(_pivots[i], _pivots[indexSorting[0]]) = (_pivots[indexSorting[0]], _pivots[i]);
503501
}
504502
}
505503

@@ -529,9 +527,7 @@ void PivotRow(Vector<float> row)
529527
// store the pivots in the hashtable
530528
knownPivots.Add(_pivots[i], i);
531529

532-
var t = row[i];
533-
row[i] = row[_pivots[i]];
534-
row[_pivots[i]] = t;
530+
(row[i], row[_pivots[i]]) = (row[_pivots[i]], row[i]);
535531
}
536532
}
537533
}
@@ -573,9 +569,7 @@ static void SwapColumns(Matrix<float> matrix, int firstColumn, int secondColumn)
573569
{
574570
for (var i = 0; i < matrix.RowCount; i++)
575571
{
576-
var temp = matrix[i, firstColumn];
577-
matrix[i, firstColumn] = matrix[i, secondColumn];
578-
matrix[i, secondColumn] = temp;
572+
(matrix[i, firstColumn], matrix[i, secondColumn]) = (matrix[i, secondColumn], matrix[i, firstColumn]);
579573
}
580574
}
581575

@@ -860,9 +854,7 @@ static void Sift(int[] values, int start, int count)
860854
/// <param name="second">Second value to exchange</param>
861855
static void Exchange(int[] values, int first, int second)
862856
{
863-
var t = values[first];
864-
values[first] = values[second];
865-
values[second] = t;
857+
(values[first], values[second]) = (values[second], values[first]);
866858
}
867859
}
868860
}

src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,7 @@ public static SparseCompressedRowMatrixStorage<T> OfCoordinateFormat(int rows, i
11371137

11381138
for (int i = 0, last = 0; i <= rows; i++)
11391139
{
1140-
var temp = csrRowPointers[i];
1141-
csrRowPointers[i] = last;
1142-
last = temp;
1140+
(csrRowPointers[i], last) = (last, csrRowPointers[i]);
11431141
}
11441142

11451143
storage.ColumnIndices = csrColumnIndices;

src/Numerics/Permutation.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ public static Permutation FromInversions(int[] inv)
113113
{
114114
if (idx[i] != inv[i])
115115
{
116-
int t = idx[i];
117-
idx[i] = idx[inv[i]];
118-
idx[inv[i]] = t;
116+
(idx[i], idx[inv[i]]) = (idx[inv[i]], idx[i]);
119117
}
120118
}
121119

0 commit comments

Comments
 (0)