|
28 | 28 | // </copyright> |
29 | 29 |
|
30 | 30 | using System; |
31 | | -using System.Linq; |
32 | 31 | using MathNet.Numerics.LinearAlgebra; |
33 | 32 | using MathNet.Numerics.LinearAlgebra.Double; |
34 | 33 | using MathNet.Numerics.LinearAlgebra.Storage; |
@@ -97,5 +96,25 @@ public void SparseCompressedRowMatrixStorage_CoordinateFormatDuplicateRemovalChe |
97 | 96 | Assert.True(Math.Abs(actual - expected) < tol, $"Expected {expected:E6} at ({r}, {c}), but got {actual:E6}"); |
98 | 97 | } |
99 | 98 | } |
| 99 | + |
| 100 | + [Test] |
| 101 | + public void PointwiseMultiplication_SparseReturnsSameResultAsDenseTest() |
| 102 | + { |
| 103 | + var x = SparseMatrix.OfDiagonalArray(new double[] { 1, 2, 3, 4 }); |
| 104 | + var y = DenseMatrix.OfDiagonalArray(new double[] { 5, -6, 7, -8 }); |
| 105 | + x.PointwiseMultiply(y, x); |
| 106 | + var result = SparseMatrix.OfDiagonalArray(new double[] { 5, -12, 21, -32 }); |
| 107 | + Assert.AreEqual(result, x); |
| 108 | + } |
| 109 | + |
| 110 | + [Test] |
| 111 | + public void PointwiseDivision_SparseReturnsSameResultAsDenseTest() |
| 112 | + { |
| 113 | + var x = SparseMatrix.OfDiagonalArray(new double[] { 30, 20, 10 }); |
| 114 | + var y = DenseMatrix.OfDiagonalArray(new double[] { 3, 4, 5 }); |
| 115 | + x.PointwiseDivide(y, x); |
| 116 | + var result = SparseMatrix.OfDiagonalArray(new double[] { 10, 5, 2 }); |
| 117 | + Assert.AreEqual(result, x); |
| 118 | + } |
100 | 119 | } |
101 | 120 | } |
0 commit comments