Returns a new set containing the first n elements in this grouped and sorted {@link DataSet}.
@param n The desired number of elements for each group.
@return A GroupReduceOperator that represents the DataSet containing the elements.
1061
public GroupReduceOperator<T, T> first(int n) {
		if (n < 1) {
			throw new InvalidProgramException("Parameter n of first(n) must be at least 1.");
		}

		return reduceGroup(new FirstReducer<T>(n));
	}
869861
public GeometryExpression<Geometry> geometryN(Integer n) {
        return GeometryExpressions.geometryOperation(SpatialOps.GEOMETRYN, mixin, ConstantImpl.create(n));
    }
808436
public static <T> SortedSet<T> nullToEmpty(final SortedSet<T> set) {
        return set == null ? N.<T> emptySortedSet() : set;
    }
370
public SortedSet<T> firstSubset(SortedSet<T> set) {
        if (this.rootNodes.isEmpty() || set == null || set.isEmpty()) {
            return null;
        }
        return firstSubset(set, this.rootNodes);
    }
1245822
@SafeVarargs
	public static <E> HashSet<E> newHashSet(E... elements) {
		HashSet<E> set = new HashSet<E>();
		Collections.addAll(set, elements);
		return set;
	}
393393
public function generate(int $n) : Dataset
    {
        $dataset = Labeled::quick();

        foreach ($this->generators as $label => $generator) {
            $p = (int) round($this->weights[$label] * $n);

            if ($p < 1) {
                continue 1;
            }

            $samples = $generator->generate($p)->samples();

            $labels = array_fill(0, $p, $label);

            $stratum = Labeled::quick($samples, $labels);

            $dataset = $dataset->append($stratum);
        }

        return $dataset;
    }
279308
public Collection<TermFrequency> top(int N)
    {
        MaxHeap<TermFrequency> heap = new MaxHeap<TermFrequency>(N, new Comparator<TermFrequency>()
        {
            @Override
            public int compare(TermFrequency o1, TermFrequency o2)
            {
                return o1.compareTo(o2);
            }
        });
        heap.addAll(termFrequencyMap.values());
        return heap.toList();
    }
1002267
public static <E> Set<E> createHashSet(int expectedMapSize) {
        final int initialCapacity = (int) (expectedMapSize / HASHSET_DEFAULT_LOAD_FACTOR) + 1;
        return new HashSet<E>(initialCapacity, HASHSET_DEFAULT_LOAD_FACTOR);
    }
725103
public static MultiDataSet toMultiDataSet(DataSet dataSet) {
        INDArray f = dataSet.getFeatures();
        INDArray l = dataSet.getLabels();
        INDArray fMask = dataSet.getFeaturesMaskArray();
        INDArray lMask = dataSet.getLabelsMaskArray();

        INDArray[] fNew = f == null ? null : new INDArray[] {f};
        INDArray[] lNew = l == null ? null : new INDArray[] {l};
        INDArray[] fMaskNew = (fMask != null ? new INDArray[] {fMask} : null);
        INDArray[] lMaskNew = (lMask != null ? new INDArray[] {lMask} : null);

        return new org.nd4j.linalg.dataset.MultiDataSet(fNew, lNew, fMaskNew, lMaskNew);
    }
700175
public final Set<K> keySet() {
	return new AbstractSet<K>() {
	    public Iterator<K> iterator() {
		final Iterator<Map.Entry<K,V>> ite = entryIterator();
		return new Iterator<K>() {
		    public boolean hasNext() { return ite.hasNext(); }
		    public void    remove()  { ite.remove(); }
		    public K       next()    { return ite.next().getKey(); }
		};
	    }
	    public int size() {
		return size;
	    }
	};
    }
1079638
public static <T> Set<T> toSorted(SortedSet<T> self) {
        return new LinkedHashSet<T>(self);
    }
384252
public static <T> HashSet<T> newHashSet(Collection<T> collection) {
		return newHashSet(false, collection);
	}
828066
public List<Object> getAll(int dataSet) throws SerializationException {
		List<Object> result = new ArrayList<Object>();
		for (Iterator<DataSet> i = dataSets.iterator(); i.hasNext();) {
			DataSet ds = i.next();
			DataSetInfo info = ds.getInfo();
			if (info.getDataSetNumber() == dataSet) {
				result.add(getData(ds));
			}
		}
		return result;
	}
946987
public static ArrayList<String> toList( Set<String> set )
	{
		int n = set.size();
		ArrayList<String> list = new ArrayList<String>( n );
		for (String string : set)
		{
			list.add(string);
		}
		return list;
	}
1333990
public static char[] getLabelsArray(Set dataSet) {
        switch (dataSet) {
            case COMPLETE:
                return LABELS_COMPLETE;
            case MERGE:
                return LABELS_MERGE;
            case BALANCED:
                return LABELS_BALANCED;
            case LETTERS:
                return LABELS_LETTERS;
            case DIGITS:
            case MNIST:
                return LABELS_DIGITS;
            default:
                throw new UnsupportedOperationException("Unknown Set: " + dataSet);
        }
    }
529480
public static <A> Set<A> set(A... elements) {
        final Set<A> set = new HashSet<A>(elements.length);
        for (A element : elements) {
            set.add(element);
        }
        return set;
    }
938741
public static <T> DataSet<Tuple2<Integer, Long>> countElementsPerPartition(DataSet<T> input) {
		return input.mapPartition(new RichMapPartitionFunction<T, Tuple2<Integer, Long>>() {
			@Override
			public void mapPartition(Iterable<T> values, Collector<Tuple2<Integer, Long>> out) throws Exception {
				long counter = 0;
				for (T value : values) {
					counter++;
				}
				out.collect(new Tuple2<>(getRuntimeContext().getIndexOfThisSubtask(), counter));
			}
		});
	}