public static INDArray max(INDArray first, INDArray second, boolean dup) {
        long[] outShape = broadcastResultShape(first, second);   //Also validates
        Preconditions.checkState(dup || Arrays.equals(outShape, first.shape()), "Cannot do inplace max operation when first input is not equal to result shape (%ndShape vs. result %s)",
                first, outShape);
        INDArray out = dup ? Nd4j.create(first.dataType(), outShape) : first;