@Override
    public Tensor evaluate(EvaluationContext<NAMETYPE> context) {
        Tensor input = argument().evaluate(context);
        var splitter = new AddressSplitter(input.type());
        Map<TensorAddress, Tensor.Builder> builders = new HashMap<>();
        for (Iterator<Tensor.Cell> iter = input.cellIterator(); iter.hasNext(); ) {
            var cell = iter.next();
            var split = splitter.split(cell.getKey());
            var builder = builders.computeIfAbsent(split.sparsePart(), k -> Tensor.Builder.of(splitter.denseType));
            builder.cell(split.densePart(), cell.getValue());
        }
        Tensor.Builder builder = Tensor.Builder.of(splitter.fullType);
        for (var entry : builders.entrySet()) {
            TensorAddress mappedAddr = entry.getKey();
            Tensor denseInput = entry.getValue().build();
            Tensor filterResult = function.map(denseInput).sum();
            if (filterResult.asDouble() != 0) {
                for (Iterator<Tensor.Cell> iter = denseInput.cellIterator(); iter.hasNext(); ) {
                    var cell = iter.next();
                    var denseAddr = cell.getKey();
                    var fullAddr = splitter.combine(mappedAddr, denseAddr);
                    builder.cell(fullAddr, cell.getValue());
                }
            }
        }
        return builder.build();
    }
The <i>filter_subspaces</i> tensor function selects some cells or subspaces in a mapped or mixed tensor

@author arnej
vespajlib/src/main/java/com/yahoo/tensor/functions/FilterSubspaces.java