Skip to content

Commit 50eb7c9

Browse files
wo80epsi1on
andcommitted
Minor performance optimization
Co-authored-by: epsi1on <ehsan.ma@gmx.com>
1 parent 01fe120 commit 50eb7c9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CSparse/Complex/SparseMatrix.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,18 @@ public override void Multiply(ReadOnlySpan<Complex> x, Span<Complex> y)
171171
}
172172

173173
int end;
174+
Complex xj;
174175

175176
for (int j = 0; j < columns; j++)
176177
{
177178
end = ap[j + 1];
178179

180+
xj = x[j];
181+
179182
// Loop over the rows
180183
for (int k = ap[j]; k < end; k++)
181184
{
182-
y[ai[k]] += x[j] * ax[k];
185+
y[ai[k]] += xj * ax[k];
183186
}
184187
}
185188
}

CSparse/Double/SparseMatrix.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,18 @@ public override void Multiply(ReadOnlySpan<double> x, Span<double> y)
171171
}
172172

173173
int end;
174+
double xj;
174175

175176
for (int j = 0; j < columns; j++)
176177
{
177178
end = ap[j + 1];
178179

180+
xj = x[j];
181+
179182
// Loop over the rows.
180183
for (int k = ap[j]; k < end; k++)
181184
{
182-
y[ai[k]] += x[j] * ax[k];
185+
y[ai[k]] += xj * ax[k];
183186
}
184187
}
185188
}

0 commit comments

Comments
 (0)