diff --git a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
index 88b945d2..454b474f 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseMatrix.cs
@@ -43,11 +43,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
///
public class SparseMatrix : Matrix
{
- ///
- /// Object for use in "lock"
- ///
- private readonly object _lockObject = new object();
-
///
/// The array containing the row indices of the existing rows. Element "j" of the array gives the index of the
/// element in the array that is first non-zero element in a row "j"
@@ -613,11 +608,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
///
public override Complex At(int row, int column)
{
- lock (_lockObject)
- {
- var index = FindItem(row, column);
- return index >= 0 ? _nonZeroValues[index] : 0.0;
- }
+ var index = FindItem(row, column);
+ return index >= 0 ? _nonZeroValues[index] : 0.0;
}
///
@@ -634,10 +626,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
///
public override void At(int row, int column, Complex value)
{
- lock (_lockObject)
- {
- SetValueAt(row, column, value);
- }
+ SetValueAt(row, column, value);
}
#region Internal methods - CRS storage implementation
@@ -1276,7 +1265,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
var sparseResult = result as SparseMatrix;
if (sparseResult == null)
{
- base.DoMultiply(scalar, result);
+ result.Clear();
+
+ for (var row = 0; row < RowCount; row++)
+ {
+ var start = _rowIndex[row];
+ var end = _rowIndex[row + 1];
+
+ if (start == end)
+ {
+ continue;
+ }
+
+ for (var index = start; index < end; index++)
+ {
+ var column = _columnIndices[index];
+ result.At(row, column, _nonZeroValues[index] * scalar);
+ }
+ }
}
else
{
@@ -1296,16 +1302,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var otherSparseMatrix = other as SparseMatrix;
- var resultSparseMatrix = result as SparseMatrix;
- if (otherSparseMatrix == null || resultSparseMatrix == null)
- {
- base.DoMultiply(other, result);
- return;
- }
-
- resultSparseMatrix.Clear();
- var columnVector = new DenseVector(otherSparseMatrix.RowCount);
+ var columnVector = new DenseVector(other.RowCount);
for (var row = 0; row < RowCount; row++)
{
// Get the begin / end index for the current row
@@ -1316,15 +1313,15 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
continue;
}
- for (var column = 0; column < otherSparseMatrix.ColumnCount; column++)
+ for (var column = 0; column < other.ColumnCount; column++)
{
// Multiply row of matrix A on column of matrix B
- otherSparseMatrix.Column(column, columnVector);
+ other.Column(column, columnVector);
var sum = CommonParallel.Aggregate(
startIndex,
endIndex,
index => _nonZeroValues[index] * columnVector[_columnIndices[index]]);
- resultSparseMatrix.SetValueAt(row, column, sum);
+ result.At(row, column, sum);
}
}
}
@@ -1426,40 +1423,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
+ if (resVal != 0.0)
{
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
@@ -1474,40 +1449,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
+ if (resVal != 0.0)
{
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
index ee35a380..28f73412 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseMatrix.cs
@@ -43,11 +43,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
///
public class SparseMatrix : Matrix
{
- ///
- /// Object for use in "lock"
- ///
- private readonly object _lockObject = new object();
-
///
/// The array containing the row indices of the existing rows. Element "j" of the array gives the index of the
/// element in the array that is first non-zero element in a row "j"
@@ -608,13 +603,10 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
///
public override Complex32 At(int row, int column)
{
- lock (_lockObject)
- {
- var index = FindItem(row, column);
- return index >= 0 ? _nonZeroValues[index] : 0.0f;
- }
+ var index = FindItem(row, column);
+ return index >= 0 ? _nonZeroValues[index] : 0.0f;
}
-
+
///
/// Sets the value of the given element.
///
@@ -629,10 +621,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
///
public override void At(int row, int column, Complex32 value)
{
- lock (_lockObject)
- {
- SetValueAt(row, column, value);
- }
+ SetValueAt(row, column, value);
}
#region Internal methods - CRS storage implementation
@@ -1271,7 +1260,24 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
var sparseResult = result as SparseMatrix;
if (sparseResult == null)
{
- base.DoMultiply(scalar, result);
+ result.Clear();
+
+ for (var row = 0; row < RowCount; row++)
+ {
+ var start = _rowIndex[row];
+ var end = _rowIndex[row + 1];
+
+ if (start == end)
+ {
+ continue;
+ }
+
+ for (var index = start; index < end; index++)
+ {
+ var column = _columnIndices[index];
+ result.At(row, column, _nonZeroValues[index] * scalar);
+ }
+ }
}
else
{
@@ -1291,16 +1297,8 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var otherSparseMatrix = other as SparseMatrix;
- var resultSparseMatrix = result as SparseMatrix;
- if (otherSparseMatrix == null || resultSparseMatrix == null)
- {
- base.DoMultiply(other, result);
- return;
- }
-
- resultSparseMatrix.Clear();
- var columnVector = new DenseVector(otherSparseMatrix.RowCount);
+ result.Clear();
+ var columnVector = new DenseVector(other.RowCount);
for (var row = 0; row < RowCount; row++)
{
// Get the begin / end index for the current row
@@ -1311,15 +1309,15 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
continue;
}
- for (var column = 0; column < otherSparseMatrix.ColumnCount; column++)
+ for (var column = 0; column < other.ColumnCount; column++)
{
// Multiply row of matrix A on column of matrix B
- otherSparseMatrix.Column(column, columnVector);
+ other.Column(column, columnVector);
var sum = CommonParallel.Aggregate(
startIndex,
endIndex,
index => _nonZeroValues[index] * columnVector[_columnIndices[index]]);
- resultSparseMatrix.SetValueAt(row, column, sum);
+ result.At(row, column, sum);
}
}
}
@@ -1421,40 +1419,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0f)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
+ if (resVal != 0.0f)
{
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0f)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
@@ -1469,40 +1445,18 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0f)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
+ if (resVal != 0.0f)
{
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0f)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
diff --git a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
index 52e15e65..c1aa5299 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseMatrix.cs
@@ -42,11 +42,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
///
public class SparseMatrix : Matrix
{
- ///
- /// Object for use in "lock"
- ///
- private readonly object _lockObject = new object();
-
///
/// The array containing the row indices of the existing rows. Element "j" of the array gives the index of the
/// element in the array that is first non-zero element in a row "j"
@@ -606,10 +601,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
///
public override double At(int row, int column)
{
- lock (_lockObject)
- {
return GetValueAt(row, column);
- }
}
///
@@ -626,10 +618,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
///
public override void At(int row, int column, double value)
{
- lock (_lockObject)
- {
SetValueAt(row, column, value);
- }
}
#region Internal methods - CRS storage implementation
@@ -1287,7 +1276,24 @@ namespace MathNet.Numerics.LinearAlgebra.Double
var sparseResult = result as SparseMatrix;
if (sparseResult == null)
{
- base.DoMultiply(scalar, result);
+ result.Clear();
+
+ for (var row = 0; row < RowCount; row++)
+ {
+ var start = _rowIndex[row];
+ var end = _rowIndex[row + 1];
+
+ if (start == end)
+ {
+ continue;
+ }
+
+ for (var index = start; index < end; index++)
+ {
+ var column = _columnIndices[index];
+ result.At(row, column, _nonZeroValues[index] * scalar);
+ }
+ }
}
else
{
@@ -1307,16 +1313,8 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var otherSparseMatrix = other as SparseMatrix;
- var resultSparseMatrix = result as SparseMatrix;
- if (otherSparseMatrix == null || resultSparseMatrix == null)
- {
- base.DoMultiply(other, result);
- return;
- }
-
- resultSparseMatrix.Clear();
- var columnVector = new DenseVector(otherSparseMatrix.RowCount);
+ result.Clear();
+ var columnVector = new DenseVector(other.RowCount);
for (var row = 0; row < RowCount; row++)
{
// Get the begin / end index for the current row
@@ -1327,15 +1325,15 @@ namespace MathNet.Numerics.LinearAlgebra.Double
continue;
}
- for (var column = 0; column < otherSparseMatrix.ColumnCount; column++)
+ for (var column = 0; column < other.ColumnCount; column++)
{
// Multiply row of matrix A on column of matrix B
- otherSparseMatrix.Column(column, columnVector);
+ other.Column(column, columnVector);
var sum = CommonParallel.Aggregate(
startIndex,
endIndex,
index => _nonZeroValues[index] * columnVector[_columnIndices[index]]);
- resultSparseMatrix.SetValueAt(row, column, sum);
+ result.At(row, column, sum);
}
}
}
@@ -1437,40 +1435,18 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
+ if (resVal != 0.0)
{
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
@@ -1485,45 +1461,23 @@ namespace MathNet.Numerics.LinearAlgebra.Double
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
+ if (resVal != 0.0)
{
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
}
-
+
///
/// Iterates throw each element in the matrix (row-wise).
///
diff --git a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
index 037dd6b8..9efb5617 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseMatrix.cs
@@ -42,11 +42,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
///
public class SparseMatrix : Matrix
{
- ///
- /// Object for use in "lock"
- ///
- private readonly object _lockObject = new object();
-
///
/// The array containing the row indices of the existing rows. Element "j" of the array gives the index of the
/// element in the array that is first non-zero element in a row "j"
@@ -607,13 +602,10 @@ namespace MathNet.Numerics.LinearAlgebra.Single
///
public override float At(int row, int column)
{
- lock (_lockObject)
- {
- var index = FindItem(row, column);
- return index >= 0 ? _nonZeroValues[index] : 0.0f;
- }
+ var index = FindItem(row, column);
+ return index >= 0 ? _nonZeroValues[index] : 0.0f;
}
-
+
///
/// Sets the value of the given element.
///
@@ -628,10 +620,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
///
public override void At(int row, int column, float value)
{
- lock (_lockObject)
- {
- SetValueAt(row, column, value);
- }
+ SetValueAt(row, column, value);
}
#region Internal methods - CRS storage implementation
@@ -1270,7 +1259,24 @@ namespace MathNet.Numerics.LinearAlgebra.Single
var sparseResult = result as SparseMatrix;
if (sparseResult == null)
{
- base.DoMultiply(scalar, result);
+ result.Clear();
+
+ for (var row = 0; row < RowCount; row++)
+ {
+ var start = _rowIndex[row];
+ var end = _rowIndex[row + 1];
+
+ if (start == end)
+ {
+ continue;
+ }
+
+ for (var index = start; index < end; index++)
+ {
+ var column = _columnIndices[index];
+ result.At(row, column, _nonZeroValues[index] * scalar);
+ }
+ }
}
else
{
@@ -1290,16 +1296,9 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// The result of the multiplication.
protected override void DoMultiply(Matrix other, Matrix result)
{
- var otherSparseMatrix = other as SparseMatrix;
- var resultSparseMatrix = result as SparseMatrix;
- if (otherSparseMatrix == null || resultSparseMatrix == null)
- {
- base.DoMultiply(other, result);
- return;
- }
- resultSparseMatrix.Clear();
- var columnVector = new DenseVector(otherSparseMatrix.RowCount);
+ result.Clear();
+ var columnVector = new DenseVector(other.RowCount);
for (var row = 0; row < RowCount; row++)
{
// Get the begin / end index for the current row
@@ -1310,15 +1309,15 @@ namespace MathNet.Numerics.LinearAlgebra.Single
continue;
}
- for (var column = 0; column < otherSparseMatrix.ColumnCount; column++)
+ for (var column = 0; column < other.ColumnCount; column++)
{
// Multiply row of matrix A on column of matrix B
- otherSparseMatrix.Column(column, columnVector);
+ other.Column(column, columnVector);
var sum = CommonParallel.Aggregate(
startIndex,
endIndex,
index => _nonZeroValues[index] * columnVector[_columnIndices[index]]);
- resultSparseMatrix.SetValueAt(row, column, sum);
+ result.At(row, column, sum);
}
}
}
@@ -1420,40 +1419,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
+ if (resVal != 0.0)
{
- var resVal = _nonZeroValues[j] * other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
@@ -1468,40 +1445,18 @@ namespace MathNet.Numerics.LinearAlgebra.Single
{
result.Clear();
- var sparseResult = result as SparseMatrix;
- if (sparseResult == null)
+ for (var i = 0; i < other.RowCount; i++)
{
- for (var i = 0; i < other.RowCount; i++)
- {
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
+ // Get the begin / end index for the current row
+ var startIndex = _rowIndex[i];
+ var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
- for (var j = startIndex; j < endIndex; j++)
- {
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- result.At(i, _columnIndices[j], resVal);
- }
- }
- }
- }
- else
- {
- for (var i = 0; i < other.RowCount; i++)
+ for (var j = startIndex; j < endIndex; j++)
{
- // Get the begin / end index for the current row
- var startIndex = _rowIndex[i];
- var endIndex = i < _rowIndex.Length - 1 ? _rowIndex[i + 1] : NonZerosCount;
-
- for (var j = startIndex; j < endIndex; j++)
+ var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
+ if (resVal != 0.0)
{
- var resVal = _nonZeroValues[j] / other.At(i, _columnIndices[j]);
- if (resVal != 0.0)
- {
- sparseResult.SetValueAt(i, _columnIndices[j], resVal);
- }
+ result.At(i, _columnIndices[j], resVal);
}
}
}
diff --git a/src/Numerics/Threading/CommonParallel.cs b/src/Numerics/Threading/CommonParallel.cs
index 7f730354..dd03b6aa 100644
--- a/src/Numerics/Threading/CommonParallel.cs
+++ b/src/Numerics/Threading/CommonParallel.cs
@@ -41,7 +41,7 @@ namespace MathNet.Numerics.Threading
///
/// Used to simplify parallel code, particularly between the .NET 4.0 and Silverlight Code.
///
- internal static class CommonParallel
+ public static class CommonParallel
{
///
/// Executes a for loop in which iterations may run in parallel.
@@ -49,7 +49,7 @@ namespace MathNet.Numerics.Threading
/// The start index, inclusive.
/// The end index, exclusive.
/// The body to be invoked for each iteration.
- /// The argument is null.
+ /// The argument is null.
/// At least one invocation of the body threw an exception.
public static void For(int fromInclusive, int toExclusive, Action body)
{