|
42 | 42 | */ |
43 | 43 | @RunWith(Parameterized.class) |
44 | 44 | public class RollTest { |
45 | | - private final int shift; |
| 45 | + private final int shift; |
46 | 46 |
|
47 | | - // Input matrices |
48 | | - private MatrixBlock inputSparse; |
49 | | - private MatrixBlock inputDense; |
| 47 | + // Input matrices |
| 48 | + private MatrixBlock inputSparse; |
| 49 | + private MatrixBlock inputDense; |
50 | 50 |
|
51 | | - /** |
52 | | - * Constructor for parameterized test cases. |
53 | | - * |
54 | | - * @param rows Number of rows in the test matrix. |
55 | | - * @param cols Number of columns in the test matrix. |
56 | | - * @param sparsity Sparsity level of the test matrix (0.0 to 1.0). |
57 | | - * @param shift Shift value for the roll operation. |
58 | | - */ |
59 | | - public RollTest(int rows, int cols, double sparsity, int shift) { |
60 | | - this.shift = shift; |
| 51 | + /** |
| 52 | + * Constructor for parameterized test cases. |
| 53 | + * |
| 54 | + * @param rows Number of rows in the test matrix. |
| 55 | + * @param cols Number of columns in the test matrix. |
| 56 | + * @param sparsity Sparsity level of the test matrix (0.0 to 1.0). |
| 57 | + * @param shift Shift value for the roll operation. |
| 58 | + */ |
| 59 | + public RollTest(int rows, int cols, double sparsity, int shift) { |
| 60 | + this.shift = shift; |
61 | 61 |
|
62 | | - // Generate a MatrixBlock with the given parameters |
63 | | - inputSparse = TestUtils.generateTestMatrixBlock(rows, cols, 0, 10, sparsity, 1); |
64 | | - inputSparse.recomputeNonZeros(); |
| 62 | + // Generate a MatrixBlock with the given parameters |
| 63 | + inputSparse = TestUtils.generateTestMatrixBlock(rows, cols, 0, 10, sparsity, 1); |
| 64 | + inputSparse.recomputeNonZeros(); |
65 | 65 |
|
66 | | - inputDense = new MatrixBlock(rows, cols, false); // false indicates dense |
67 | | - inputDense.copy(inputSparse, false); // Copy without maintaining sparsity |
68 | | - inputDense.recomputeNonZeros(); |
69 | | - } |
| 66 | + inputDense = new MatrixBlock(rows, cols, false); // false indicates dense |
| 67 | + inputDense.copy(inputSparse, false); // Copy without maintaining sparsity |
| 68 | + inputDense.recomputeNonZeros(); |
| 69 | + } |
70 | 70 |
|
71 | | - /** |
72 | | - * Defines the parameters for the test cases. |
73 | | - * Each Object[] contains {rows, cols, sparsity, shift}. |
74 | | - * |
75 | | - * @return Collection of test parameters. |
76 | | - */ |
77 | | - @Parameters(name = "Rows: {0}, Cols: {1}, Sparsity: {2}, Shift: {3}") |
78 | | - public static Collection<Object[]> data() { |
79 | | - List<Object[]> tests = new ArrayList<>(); |
| 71 | + /** |
| 72 | + * Defines the parameters for the test cases. |
| 73 | + * Each Object[] contains {rows, cols, sparsity, shift}. |
| 74 | + * |
| 75 | + * @return Collection of test parameters. |
| 76 | + */ |
| 77 | + @Parameters(name = "Rows: {0}, Cols: {1}, Sparsity: {2}, Shift: {3}") |
| 78 | + public static Collection<Object[]> data() { |
| 79 | + List<Object[]> tests = new ArrayList<>(); |
80 | 80 |
|
81 | | - // Define various sizes, sparsity levels, and shift values |
82 | | - int[] rows = {1, 19, 1001, 2017}; |
83 | | - int[] cols = {1, 17, 1001, 2017}; |
84 | | - double[] sparsities = {0.01, 0.1, 0.7, 1.0}; |
85 | | - int[] shifts = {0, 1, 5, 10, 15}; |
| 81 | + // Define various sizes, sparsity levels, and shift values |
| 82 | + int[] rows = {1, 19, 1001, 2017}; |
| 83 | + int[] cols = {1, 17, 1001, 2017}; |
| 84 | + double[] sparsities = {0.01, 0.1, 0.7, 1.0}; |
| 85 | + int[] shifts = {0, 1, 5, 10, 15}; |
86 | 86 |
|
87 | | - // Generate all combinations of sizes, sparsities, and shifts |
88 | | - for (int row : rows) { |
89 | | - for (int col : cols) { |
90 | | - for (double sparsity : sparsities) { |
91 | | - for (int shift : shifts) { |
92 | | - tests.add(new Object[]{row, col, sparsity, shift}); |
93 | | - } |
94 | | - } |
95 | | - } |
96 | | - } |
97 | | - return tests; |
98 | | - } |
| 87 | + // Generate all combinations of sizes, sparsities, and shifts |
| 88 | + for (int row : rows) { |
| 89 | + for (int col : cols) { |
| 90 | + for (double sparsity : sparsities) { |
| 91 | + for (int shift : shifts) { |
| 92 | + tests.add(new Object[]{row, col, sparsity, shift}); |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + return tests; |
| 98 | + } |
99 | 99 |
|
100 | | - /** |
101 | | - * The actual test method that performs the roll operation on both |
102 | | - * sparse and dense matrices and compares the results. |
103 | | - */ |
104 | | - @Test |
105 | | - public void test() { |
106 | | - try { |
107 | | - IndexFunction op = new RollIndex(shift); |
108 | | - MatrixBlock outputDense = inputDense.reorgOperations( |
| 100 | + /** |
| 101 | + * The actual test method that performs the roll operation on both |
| 102 | + * sparse and dense matrices and compares the results. |
| 103 | + */ |
| 104 | + @Test |
| 105 | + public void test() { |
| 106 | + try { |
| 107 | + IndexFunction op = new RollIndex(shift); |
| 108 | + MatrixBlock outputDense = inputDense.reorgOperations( |
109 | 109 | new ReorgOperator(op), new MatrixBlock(), 0, 0, 0); |
110 | | - MatrixBlock outputSparse = inputSparse.reorgOperations( |
| 110 | + MatrixBlock outputSparse = inputSparse.reorgOperations( |
111 | 111 | new ReorgOperator(op), new MatrixBlock(), 0, 0, 0); |
112 | | - outputSparse.sparseToDense(); |
| 112 | + outputSparse.sparseToDense(); |
113 | 113 |
|
114 | | - // Compare the dense representations of both outputs |
115 | | - TestUtils.compareMatrices(outputSparse, outputDense, 1e-9, |
| 114 | + // Compare the dense representations of both outputs |
| 115 | + TestUtils.compareMatrices(outputSparse, outputDense, 1e-9, |
116 | 116 | "Compare Sparse and Dense Roll Results"); |
117 | 117 |
|
118 | | - } catch (Exception e) { |
119 | | - e.printStackTrace(); |
120 | | - fail("Exception occurred during roll function test: " + e.getMessage()); |
121 | | - } |
122 | | - } |
| 118 | + } catch (Exception e) { |
| 119 | + e.printStackTrace(); |
| 120 | + fail("Exception occurred during roll function test: " + e.getMessage()); |
| 121 | + } |
| 122 | + } |
123 | 123 | } |
0 commit comments