On 13/06/2019 15:59, Gary Gregory wrote:
Now that RNG is up and going, it seems odd to still have:
org.apache.commons.lang3.ArrayUtils.shuffle(double[], Random)
Should we deprecate these APIs in favor of Commons RNG and if so which RNG
APIs?
Gary
Shuffling is in the commons-rng-sampling component.
Shuffling for int[] primitive arrays is in the PermutationSampler [1].
Shuffling for a List<T> is in the ListSampler [2].
Currently there are methods to shuffle the entire length, or part of the
length starting from a position and shuffling to the start or end of the
array / list.
There is no method for:
- Shuffling a subsequence within the array / list defined by either
start and length or start and end.
- Shuffling an array T[]
- Shuffling primitive arrays other than int[] (This requires a bit of
work [3])
[Lang] ArrayUtils only shuffles the full array but supports all
primitive array types and Object[]. It does not support a shuffle of T[].
So there is only partial overlap between the libraries. There is not a
like for like swap to deprecate ArrayUtils methods in favour of Commons
RNG methods.
I think it is quite a common use case to want to shuffle full length
arrays. I'm not sure about sub-sequence shuffles but one is a super-set
of the other.
To deprecate ArrayUtils shuffle methods would require a new class in RNG
to support this for all primitives and a generic type T following this
prototype:
ArrayUtils.shuffle(UniformRandomProvider rng, double[] data)
ArrayUtils.shuffle(UniformRandomProvider rng, double[] data, int start,
int length)
I'm not opposed to adding the methods to Commons RNG. Either in the
current sampling module or perhaps a new commons-rng-utils module
instead since a shuffle is not really a sample unless you use a
subsequence from the shuffled array.
Alex
[1]
http://commons.apache.org/proper/commons-rng/commons-rng-sampling/javadocs/api-1.2/org/apache/commons/rng/sampling/PermutationSampler.html
[2]
http://commons.apache.org/proper/commons-rng/commons-rng-sampling/javadocs/api-1.2/org/apache/commons/rng/sampling/ListSampler.html
[3] Supporting all the primitive avoids the currently usage to shuffle a
non-integer array which requires:
- Clone the input array
- Shuffle a newly allocated int[] of ascending indices
- Use the shuffled indices to copy data from the clone back to the input
array
This has unnecessary allocation overhead.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org