### Question:
ElementwiseMax extends SingleParentVariable<Matrix> { @Override public Matrix apply(ComputationContext ctx) { Matrix max = Matrix.fill(Double.NEGATIVE_INFINITY, rows, cols); double[] parentData = ctx.data(parent()).data(); for (int row = 0; row < rows; row++) { int[] neighbors = this.adjacencyMatrix[row]; for(int col = 0; col < cols; col++) { int resultElementIndex = row * cols + col; if (neighbors.length > 0) { for (int neighbor : neighbors) { int neighborElementIndex = neighbor * cols + col; max.setDataAt( resultElementIndex, Math.max(parentData[neighborElementIndex], max.dataAt(resultElementIndex)) ); } } else { max.setDataAt(resultElementIndex, 0); } } } return max; } ElementwiseMax(Variable<?> parent, int[][] adjacencyMatrix); @Override Matrix apply(ComputationContext ctx); @Override Tensor<?> gradient(Variable<?> parent, ComputationContext ctx);  }### Answer:
@Test void testApply() { int[][] adjacencyMatrix = { new int[]{}, new int[]{0, 1, 2} }; Variable<Matrix> max = new ElementwiseMax(weights, adjacencyMatrix); double[] expected = new double[]{ 0, 0, 0, 3, 3, 3 }; assertArrayEquals(expected, ctx.forward(max).data()); }