public OrderedTensorType rename(DimensionRenamer renamer) {
        List<TensorType.Dimension> renamedDimensions = new ArrayList<>(dimensions.size());
        Map<String, String> new2Old = new HashMap<>(); // Just to create meaningful error messages
        for (TensorType.Dimension dimension : dimensions) {
            String oldName = dimension.name();
            Optional<String> newName = renamer.dimensionNameOf(oldName);
            if ( newName.isEmpty()) return this; // presumably already renamed

            if (new2Old.containsKey(newName.get()))
                throw new IllegalArgumentException("Can not rename '" + oldName + "' to '" + newName.get() + "' in " + this +
                                                   " as '" + new2Old.get(newName.get()) + "' should also be renamed to it");
            new2Old.put(newName.get(), oldName);

            TensorType.Dimension.Type dimensionType = dimension.type();
            if (dimensionType == TensorType.Dimension.Type.indexedBound) {
                renamedDimensions.add(TensorType.Dimension.indexed(newName.get(), dimension.size().get()));
            } else if (dimensionType == TensorType.Dimension.Type.indexedUnbound) {
                renamedDimensions.add(TensorType.Dimension.indexed(newName.get()));
            } else if (dimensionType == TensorType.Dimension.Type.mapped) {
                renamedDimensions.add(TensorType.Dimension.mapped(newName.get()));
            }
        }
        return new OrderedTensorType(type.valueType(), renamedDimensions);
    }
When dimension ordering between Vespa and imported differs, i.e.
after dimension renaming, use the dimension map to read in values
so that they are correctly laid out in memory for Vespa.
Used when importing tensors.
model-integration/src/main/java/ai/vespa/rankingexpression/importer/OrderedTensorType.java