docs: public static <V extends NumberVector> V project(V v, long[] selectedAttributes, NumberVector.Factory<V> factory) {
      int card = BitsUtil.cardinality(selectedAttributes);
      if(factory instanceof SparseNumberVector.Factory) {
        final SparseNumberVector.Factory<?> sfactory = (SparseNumberVector.Factory<?>) factory;
        Int2DoubleOpenHashMap values = new Int2DoubleOpenHashMap(card, .8f);
        for(int d = BitsUtil.nextSetBit(selectedAttributes, 0); d >= 0; d = BitsUtil.nextSetBit(selectedAttributes, d + 1)) {
          if(v.doubleValue(d) != 0.0) {
            values.put(d, v.doubleValue(d));
          }
        }
        // We can't avoid this cast, because Java doesn't know that V is a
        // SparseNumberVector:
        @SuppressWarnings("unchecked")
        V projectedVector = (V) sfactory.newNumberVector(values, card);
        return projectedVector;
      }
      else {
        double[] newAttributes = new double[card];
        int i = 0;
        for(int d = BitsUtil.nextSetBit(selectedAttributes, 0); d >= 0; d = BitsUtil.nextSetBit(selectedAttributes, d + 1)) {
          newAttributes[i] = v.doubleValue(d);
          i++;
        }
        return factory.newNumberVector(newAttributes);
      }
    }