private static PartialAddress partialAddress(TensorType addressType, TensorAddress address,
                                                 Set<String> retainDimensions, int sharedDimensionSize) {
        PartialAddress.Builder builder = new PartialAddress.Builder(sharedDimensionSize);
        for (int i = 0; i < addressType.dimensions().size(); i++) {
            String dimension = addressType.dimensions().get(i).name();
            if (retainDimensions.contains(dimension))
                builder.add(dimension, address.objectLabel(i));
        }
        return builder.build();
    }
Slow join which works for any two tensors
vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java