Skip to content

Commit cf52d99

Browse files
committed
Minor cleanup.
1 parent ba894ca commit cf52d99

File tree

6 files changed

+97
-138
lines changed

6 files changed

+97
-138
lines changed

CSparse/Complex/DenseMatrix.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override double InfinityNorm()
8585
/// <inheritdoc />
8686
public override double FrobeniusNorm()
8787
{
88-
double sum = 0.0, norm = 0.0;
88+
double sum, norm = 0.0;
8989

9090
int length = rows * columns;
9191

@@ -208,7 +208,7 @@ public override void Add(DenseColumnMajorStorage<Complex> other, DenseColumnMajo
208208

209209
var target = result.Values;
210210

211-
var a = this.Values;
211+
var a = Values;
212212
var b = other.Values;
213213

214214
int length = m * n;

CSparse/Complex/SparseMatrix.cs

+37-41
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public override int Keep(Func<int, int, Complex, bool> func)
9090
if (AutoTrimStorage)
9191
{
9292
// Remove extra space.
93-
this.Resize(0);
93+
Resize(0);
9494
}
9595

9696
return nz;
@@ -99,8 +99,6 @@ public override int Keep(Func<int, int, Complex, bool> func)
9999
/// <inheritdoc />
100100
public override double L1Norm()
101101
{
102-
int nz = this.NonZerosCount;
103-
104102
double sum, norm = 0.0;
105103

106104
for (int j = 0; j < columns; j++)
@@ -119,8 +117,6 @@ public override double L1Norm()
119117
/// <inheritdoc />
120118
public override double InfinityNorm()
121119
{
122-
int nz = this.NonZerosCount;
123-
124120
var work = new double[rows];
125121

126122
for (int j = 0; j < columns; j++)
@@ -144,9 +140,9 @@ public override double InfinityNorm()
144140
/// <inheritdoc />
145141
public override double FrobeniusNorm()
146142
{
147-
int nz = this.NonZerosCount;
143+
int nz = NonZerosCount;
148144

149-
double sum = 0.0, norm = 0.0;
145+
double sum, norm = 0.0;
150146

151147
for (int i = 0; i < nz; i++)
152148
{
@@ -164,9 +160,9 @@ public override double FrobeniusNorm()
164160
/// <inheritdoc />
165161
public override void Multiply(ReadOnlySpan<Complex> x, Span<Complex> y)
166162
{
167-
var ax = this.Values;
168-
var ap = this.ColumnPointers;
169-
var ai = this.RowIndices;
163+
var ax = Values;
164+
var ap = ColumnPointers;
165+
var ai = RowIndices;
170166

171167
// Clear y.
172168
for (int i = 0; i < rows; i++)
@@ -191,9 +187,9 @@ public override void Multiply(ReadOnlySpan<Complex> x, Span<Complex> y)
191187
/// <inheritdoc />
192188
public override void Multiply(Complex alpha, ReadOnlySpan<Complex> x, Complex beta, Span<Complex> y)
193189
{
194-
var ax = this.Values;
195-
var ap = this.ColumnPointers;
196-
var ai = this.RowIndices;
190+
var ax = Values;
191+
var ap = ColumnPointers;
192+
var ai = RowIndices;
197193

198194
// Scale y by beta
199195
for (int j = 0; j < rows; j++)
@@ -220,9 +216,9 @@ public override void Multiply(Complex alpha, ReadOnlySpan<Complex> x, Complex be
220216
/// <inheritdoc />
221217
public override void TransposeMultiply(ReadOnlySpan<Complex> x, Span<Complex> y)
222218
{
223-
var ax = this.Values;
224-
var ap = this.ColumnPointers;
225-
var ai = this.RowIndices;
219+
var ax = Values;
220+
var ap = ColumnPointers;
221+
var ai = RowIndices;
226222

227223
Complex yi;
228224

@@ -244,9 +240,9 @@ public override void TransposeMultiply(ReadOnlySpan<Complex> x, Span<Complex> y)
244240
/// <inheritdoc />
245241
public override void TransposeMultiply(Complex alpha, ReadOnlySpan<Complex> x, Complex beta, Span<Complex> y)
246242
{
247-
var ax = this.Values;
248-
var ap = this.ColumnPointers;
249-
var ai = this.RowIndices;
243+
var ax = Values;
244+
var ap = ColumnPointers;
245+
var ai = RowIndices;
250246

251247
Complex yi;
252248

@@ -334,8 +330,8 @@ public override void Add(Complex alpha, Complex beta, CompressedColumnStorage<Co
334330

335331
int p, j, nz = 0;
336332

337-
int m = this.rows;
338-
int n = this.columns;
333+
int m = rows;
334+
int n = columns;
339335

340336
// check inputs
341337
if (m != other.RowCount || n != other.ColumnCount)
@@ -356,7 +352,7 @@ public override void Add(Complex alpha, Complex beta, CompressedColumnStorage<Co
356352
for (j = 0; j < n; j++)
357353
{
358354
ci[j] = nz; // column j of C starts here
359-
nz = this.Scatter(j, alpha, w, x, j + 1, result, nz); // alpha*A(:,j)
355+
nz = Scatter(j, alpha, w, x, j + 1, result, nz); // alpha*A(:,j)
360356
nz = other.Scatter(j, beta, w, x, j + 1, result, nz); // beta*B(:,j)
361357

362358
for (p = ci[j]; p < nz; p++)
@@ -394,18 +390,18 @@ public override void Multiply(CompressedColumnStorage<Complex> other, Compressed
394390
int[] cp, ci;
395391
Complex[] cx;
396392

397-
int m = this.rows;
393+
int m = rows;
398394
int n = other.ColumnCount;
399395

400-
int anz = this.NonZerosCount;
396+
int anz = NonZerosCount;
401397
int bnz = other.NonZerosCount;
402398

403-
if (this.ColumnCount != other.RowCount)
399+
if (ColumnCount != other.RowCount)
404400
{
405401
throw new ArgumentException(Resources.MatrixDimensions, nameof(other));
406402
}
407403

408-
if ((m > 0 && this.ColumnCount == 0) || (other.RowCount == 0 && n > 0))
404+
if ((m > 0 && ColumnCount == 0) || (other.RowCount == 0 && n > 0))
409405
{
410406
throw new Exception(Resources.InvalidDimensions);
411407
}
@@ -436,7 +432,7 @@ public override void Multiply(CompressedColumnStorage<Complex> other, Compressed
436432
cp[j] = nz; // column j of C starts here
437433
for (p = bp[j]; p < bp[j + 1]; p++)
438434
{
439-
nz = this.Scatter(bi[p], bx[p], w, x, j + 1, result, nz);
435+
nz = Scatter(bi[p], bx[p], w, x, j + 1, result, nz);
440436
}
441437

442438
for (p = cp[j]; p < nz; p++)
@@ -461,16 +457,16 @@ public override void Multiply(CompressedColumnStorage<Complex> other, Compressed
461457
/// </summary>
462458
public override bool IsSymmetric()
463459
{
464-
int n = this.ColumnCount;
460+
int n = ColumnCount;
465461

466-
if (this.RowCount != n)
462+
if (RowCount != n)
467463
{
468464
return false;
469465
}
470466

471-
var ax = this.Values;
472-
var ap = this.ColumnPointers;
473-
var ai = this.RowIndices;
467+
var ax = Values;
468+
var ap = ColumnPointers;
469+
var ai = RowIndices;
474470

475471
for (var i = 0; i < n; i++)
476472
{
@@ -500,30 +496,30 @@ public override bool Equals(Matrix<Complex> other, double tolerance)
500496
return false;
501497
}
502498

503-
int nz = this.NonZerosCount;
499+
int nz = NonZerosCount;
504500

505-
if (this.columns != o.ColumnCount || this.rows != o.RowCount || nz != o.NonZerosCount)
501+
if (columns != o.ColumnCount || rows != o.RowCount || nz != o.NonZerosCount)
506502
{
507503
return false;
508504
}
509505

510-
for (int i = 0; i < this.columns; i++)
506+
for (int i = 0; i < columns; i++)
511507
{
512-
if (this.ColumnPointers[i] != o.ColumnPointers[i])
508+
if (ColumnPointers[i] != o.ColumnPointers[i])
513509
{
514510
return false;
515511
}
516512
}
517513

518514
for (int i = 0; i < nz; i++)
519515
{
520-
if (this.RowIndices[i] != o.RowIndices[i])
516+
if (RowIndices[i] != o.RowIndices[i])
521517
{
522518
return false;
523519
}
524520

525-
if (Math.Abs(this.Values[i].Real - o.Values[i].Real) > tolerance ||
526-
Math.Abs(this.Values[i].Imaginary - o.Values[i].Imaginary) > tolerance)
521+
if (Math.Abs(Values[i].Real - o.Values[i].Real) > tolerance ||
522+
Math.Abs(Values[i].Imaginary - o.Values[i].Imaginary) > tolerance)
527523
{
528524
return false;
529525
}
@@ -566,12 +562,12 @@ internal override void Cleanup()
566562
ColumnPointers[i] = q; // Record start of row i
567563
}
568564

569-
this.ColumnPointers[columns] = nnz;
565+
ColumnPointers[columns] = nnz;
570566

571567
if (AutoTrimStorage)
572568
{
573569
// Remove extra space from arrays
574-
this.Resize(0);
570+
Resize(0);
575571
}
576572
}
577573

CSparse/Double/DenseMatrix.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public override double InfinityNorm()
8585
/// <inheritdoc />
8686
public override double FrobeniusNorm()
8787
{
88-
double sum = 0.0, norm = 0.0;
88+
double sum, norm = 0.0;
8989

9090
int length = rows * columns;
9191

@@ -213,7 +213,7 @@ public override void Add(DenseColumnMajorStorage<double> other, DenseColumnMajor
213213

214214
var target = result.Values;
215215

216-
var a = this.Values;
216+
var a = Values;
217217
var b = other.Values;
218218

219219
int length = rows * columns;

0 commit comments

Comments
 (0)