@Override
    public StringBuilder toString(StringBuilder string, SerializationContext context, Deque<String> path, CompositeNode parent) {
        var optTC = context.typeContext();
        if (optTC.isPresent()) {
            TensorType inputType = input.type(optTC.get());
            var meta = analyze(inputType);
            string.append("map_subspaces").append("(");
            input.toString(string, context, path, this);
            string.append(", f(denseSubspaceInput)(");
            string.append(meta.outputDenseType()).append("("); // generate
            string.append("bit(denseSubspaceInput{");
            for (var dim : meta.outputDenseType().dimensions()) {
                String dName = dim.name();
                boolean last = dName.equals(meta.unpackDimension);
                string.append(dName);
                string.append(":(");
                string.append(dName);
                if (last) {
                    string.append("/8");
                }
                string.append(")");
                if (! last) {
                    string.append(", ");
                }
            }
            if (endian.equals(EndianNess.BIG_ENDIAN)) {
                string.append("}, 7-(");
            } else {
                string.append("}, (");
            }
            string.append(meta.unpackDimension);
            string.append(" % 8)");
            string.append("))))"); // bit, generate, f, map_subspaces
        } else {
            string.append(operationName);
            string.append("(");
            input.toString(string, context, path, this);
            string.append(",");
            string.append(targetCellType);
            string.append(",");
            string.append(endian);
            string.append(")");
        }
        return string;
    }
Macro that expands to the appropriate map_subspaces magic incantation

@author arnej
searchlib/src/main/java/com/yahoo/searchlib/rankingexpression/rule/UnpackBitsNode.java