Skip to content

Commit 4aaa869

Browse files
committed
More tests and minor changes.
1 parent 1f1357a commit 4aaa869

File tree

8 files changed

+97
-16
lines changed

8 files changed

+97
-16
lines changed

CSparse.Tests/Complex/DenseMatrixTest.cs

+38
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,44 @@ public void TestMatrixMultiply(int rows, int columns)
273273
CollectionAssert.AreEqual(data.AmBT.Values, actual.Values, ComplexNumberComparer.Default);
274274
}
275275

276+
[Test]
277+
public void TestMatrixPointwiseMultiply()
278+
{
279+
var A = DenseMatrix.OfRowMajor(2, 3, new Complex[]
280+
{
281+
1.0, 2.0, 3.0,
282+
4.0, 5.0, 6.0
283+
});
284+
285+
var B = DenseMatrix.OfRowMajor(2, 3, new Complex[]
286+
{
287+
2.0, 0.5, 2.0,
288+
0.5, 0.1, 0.5
289+
});
290+
291+
var expected = DenseMatrix.OfRowMajor(2, 3, new Complex[]
292+
{
293+
2.0, 1.0, 6.0,
294+
2.0, 0.5, 3.0
295+
});
296+
297+
var actual = new DenseMatrix(2, 3);
298+
299+
A.PointwiseMultiply(B, actual);
300+
301+
CollectionAssert.AreEqual(expected.Values, actual.Values);
302+
303+
// Test exceptions:
304+
305+
actual = new DenseMatrix(2, 2);
306+
307+
Assert.Throws<ArgumentException>(() => A.PointwiseMultiply(B, actual));
308+
309+
B = new DenseMatrix(2, 2);
310+
311+
Assert.Throws<ArgumentException>(() => A.PointwiseMultiply(B, actual));
312+
}
313+
276314
[Test]
277315
public void TestMatrixParallelMultiply()
278316
{

CSparse.Tests/Double/DenseMatrixTest.cs

+38
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,44 @@ public void TestMatrixMultiply(int rows, int columns)
284284
CollectionAssert.AreEqual(data.AmBT.Values, actual.Values);
285285
}
286286

287+
[Test]
288+
public void TestMatrixPointwiseMultiply()
289+
{
290+
var A = DenseMatrix.OfRowMajor(2, 3, new double[]
291+
{
292+
1.0, 2.0, 3.0,
293+
4.0, 5.0, 6.0
294+
});
295+
296+
var B = DenseMatrix.OfRowMajor(2, 3, new double[]
297+
{
298+
2.0, 0.5, 2.0,
299+
0.5, 0.1, 0.5
300+
});
301+
302+
var expected = DenseMatrix.OfRowMajor(2, 3, new double[]
303+
{
304+
2.0, 1.0, 6.0,
305+
2.0, 0.5, 3.0
306+
});
307+
308+
var actual = new DenseMatrix(2, 3);
309+
310+
A.PointwiseMultiply(B, actual);
311+
312+
CollectionAssert.AreEqual(expected.Values, actual.Values);
313+
314+
// Test exceptions:
315+
316+
actual = new DenseMatrix(2, 2);
317+
318+
Assert.Throws<ArgumentException>(() => A.PointwiseMultiply(B, actual));
319+
320+
B = new DenseMatrix(2, 2);
321+
322+
Assert.Throws<ArgumentException>(() => A.PointwiseMultiply(B, actual));
323+
}
324+
287325
[Test]
288326
public void TestMatrixParallelMultiply()
289327
{

CSparse.Tests/ResourceLoader.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public static CompressedColumnStorage<T> Get<T>(string resource)
4444

4545
return matrix;
4646
}
47-
catch (Exception e)
47+
catch
4848
{
49-
throw e;
49+
throw;
5050
}
5151
}
5252
}

CSparse.sln

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.572
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31025.194
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSparse", "CSparse\CSparse.csproj", "{BE369FD3-02F6-4A13-8DA2-E44A819FAE3C}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSparse.Tests", "CSparse.Tests\CSparse.Tests.csproj", "{84D239FA-7BA0-4E5D-89FF-C29C5267CDB0}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CSparse.Tests", "CSparse.Tests\CSparse.Tests.csproj", "{84D239FA-7BA0-4E5D-89FF-C29C5267CDB0}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A01A8F54-DCC1-4E01-B6B4-1C653B382D30}"
11+
ProjectSection(SolutionItems) = preProject
12+
README.md = README.md
13+
EndProjectSection
914
EndProject
1015
Global
1116
GlobalSection(SolutionConfigurationPlatforms) = preSolution

CSparse/Complex/DenseMatrix.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,12 @@ public override void PointwiseMultiply(DenseColumnMajorStorage<Complex> other, D
242242
{
243243
if (RowCount != other.RowCount || ColumnCount != other.ColumnCount)
244244
{
245-
throw new ArgumentException(Resources.MatrixDimensions);
245+
throw new ArgumentException(Resources.MatrixDimensions, nameof(other));
246246
}
247247

248248
if (RowCount != result.RowCount || ColumnCount != result.ColumnCount)
249249
{
250-
throw new ArgumentException(Resources.MatrixDimensions);
250+
throw new ArgumentException(Resources.MatrixDimensions, nameof(result));
251251
}
252252

253253
var x = Values;

CSparse/Double/DenseMatrix.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ public override void PointwiseMultiply(DenseColumnMajorStorage<double> other, De
302302
{
303303
if (RowCount != other.RowCount || ColumnCount != other.ColumnCount)
304304
{
305-
throw new ArgumentException(Resources.MatrixDimensions);
305+
throw new ArgumentException(Resources.MatrixDimensions, nameof(other));
306306
}
307307

308308
if (RowCount != result.RowCount || ColumnCount != result.ColumnCount)
309309
{
310-
throw new ArgumentException(Resources.MatrixDimensions);
310+
throw new ArgumentException(Resources.MatrixDimensions, nameof(result));
311311
}
312312

313313
var x = Values;

CSparse/Storage/CompressedColumnStorage.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,12 @@ public void PermuteRows(int[] perm, CompressedColumnStorage<T> target)
602602

603603
if (target.rows != rows || target.columns != columns)
604604
{
605-
throw new ArgumentException(Resources.InvalidDimensions, "target");
605+
throw new ArgumentException(Resources.InvalidDimensions, nameof(target));
606606
}
607607

608608
if (perm.Length < rows)
609609
{
610-
throw new ArgumentException("Invalid permutation length.", "perm");
610+
throw new ArgumentException("Invalid permutation length.", nameof(perm));
611611
}
612612

613613
PermuteRows(Values, ColumnPointers, RowIndices, bx, bp, bi, perm);
@@ -637,17 +637,17 @@ public void PermuteColumns(int[] perm, CompressedColumnStorage<T> target)
637637

638638
if (ReferenceEquals(this, target))
639639
{
640-
throw new ArgumentException("Cannot use this instance as target.", "target");
640+
throw new ArgumentException("Cannot use this instance as target.", nameof(target));
641641
}
642642

643643
if (target.rows != rows || target.columns != columns)
644644
{
645-
throw new ArgumentException(Resources.InvalidDimensions, "target");
645+
throw new ArgumentException(Resources.InvalidDimensions, nameof(target));
646646
}
647647

648648
if (perm.Length < columns)
649649
{
650-
throw new ArgumentException("Invalid permutation length.", "perm");
650+
throw new ArgumentException("Invalid permutation length.", nameof(perm));
651651
}
652652

653653
PermuteColumns(Values, ColumnPointers, RowIndices, bx, bp, bi, perm);

CSparse/Storage/DenseColumnMajorStorage.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public virtual void LowerTriangle(DenseColumnMajorStorage<T> result)
469469

470470
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
471471
{
472-
throw new ArgumentException(Resources.MatrixDimensions, "result");
472+
throw new ArgumentException(Resources.MatrixDimensions, nameof(result));
473473
}
474474

475475
for (var row = 0; row < RowCount; row++)
@@ -496,7 +496,7 @@ public virtual void UpperTriangle(DenseColumnMajorStorage<T> result)
496496

497497
if (result.RowCount != RowCount || result.ColumnCount != ColumnCount)
498498
{
499-
throw new ArgumentException(Resources.MatrixDimensions, "result");
499+
throw new ArgumentException(Resources.MatrixDimensions, nameof(result));
500500
}
501501

502502
for (var row = 0; row < RowCount; row++)

0 commit comments

Comments
 (0)