public boolean canOptimize(Tensor a, Tensor b) {
        if (a.type().dimensions().isEmpty() || b.type().dimensions().isEmpty())  // TODO: support scalars
            return false;
        if ( ! (a instanceof IndexedTensor))
            return false;
        if ( ! (a.type().hasOnlyIndexedBoundDimensions()))
            return false;
        if ( ! (b instanceof IndexedTensor))
            return false;
        if ( ! (b.type().hasOnlyIndexedBoundDimensions()))
            return false;

        TensorType commonDimensions = dimensionsInCommon((IndexedTensor)a, (IndexedTensor)b);
        if (dimensions.isEmpty()) {
            if (a.type().dimensions().size() != commonDimensions.dimensions().size())
                return false;
            if (b.type().dimensions().size() != commonDimensions.dimensions().size())
                return false;
        } else if (dimensions.size() != commonDimensions.dimensions().size()) {
            return false;
        } else {
            for (TensorType.Dimension dimension : commonDimensions.dimensions()) {
                if (!dimensions.contains(dimension.name()))
                    return false;
            }
        }
        return true;
    }
Tests whether or not the reduce is over the join dimensions. The
remaining logic in this class assumes this to be true.

If no dimensions are given, the join must be on all tensor dimensions.

@return {@code true} if the implementation can optimize evaluation
        given the two tensors.
vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java