本文整理汇总了Java中it.unimi.dsi.fastutil.ints.IntArrays.shuffle方法的典型用法代码示例。如果您正苦于以下问题:Java IntArrays.shuffle方法的具体用法?Java IntArrays.shuffle怎么用?Java IntArrays.shuffle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.ints.IntArrays
的用法示例。
在下文中一共展示了IntArrays.shuffle方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBlocking
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Test
public void testBlocking() throws InterruptedException {
for(final int size: new int[] { 10, 100, 128, 256 }) {
for(final int d: new int[] { 1, 2, 3, 4 }) {
final ReorderingBlockingQueue<Integer> q = new ReorderingBlockingQueue<>(size / d);
final int[] perm = Util.identity(size);
IntArrays.shuffle(perm, new XoRoShiRo128PlusRandom());
for(int i = perm.length; i-- != 0;) {
final int t = perm[i];
new Thread() {
@Override
public void run() {
try {
q.put(Integer.valueOf(t), t);
}
catch (final InterruptedException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}.start();
}
for(int i = 0; i < perm.length; i++) assertEquals(i, q.take().intValue());
assertEquals(0, q.size());
}
}
}
示例2: learnNPassShuffled
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
public void learnNPassShuffled(int n) throws ReflectiveOperationException, IOException {
pl.info = classifier.shortStats();
pl.expectedUpdates = graph.numArcs() * 2 * n;
pl.start();
for (int pass = 0; pass < n; pass++) {
LOGGER.info("Starting learning pass #"+(pass+1)+"...");
int[] nodes = MathArrays.natural(numNodes);
nodes = IntArrays.shuffle(nodes, rnd);
for (int node : nodes)
learnNode(node, new IntOpenHashSet(
graph.successorArray(node), 0, graph.outdegree(node)
));
save(pass+1);
}
pl.done();
}
示例3: createTestingSet
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
public int[] createTestingSet(int numOfSamples) {
numOfSamples = Math.min(numOfSamples, numNodes);
if (verbose) LOGGER.info("Creating test set with "+numOfSamples+" nodes...");
if (numOfSamples >= (numNodes/2)) {
final Random rnd = RandomSingleton.get();
int[] samples = MathArrays.natural(numNodes);
IntArrays.shuffle(samples, rnd);
return IntArrays.trim(samples, numOfSamples);
} else {
IntSet set = new IntOpenHashSet();
while (set.size() < numOfSamples) {
set.add(rnd.nextInt(numNodes));
}
int[] r = set.toIntArray();
return r;
}
}
示例4: testNoBlocking
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Test
public void testNoBlocking() throws InterruptedException {
for(final int size: new int[] { 1, 10, 100, 128, 256 }) {
final ReorderingBlockingQueue<Integer> q = new ReorderingBlockingQueue<>(size);
final int[] perm = Util.identity(size);
IntArrays.shuffle(perm, new XoRoShiRo128PlusRandom());
for(int i = perm.length; i-- != 0;) q.put(Integer.valueOf(perm[i]), perm[i]);
for(int i = 0; i < perm.length; i++) assertEquals(i, q.take().intValue());
assertEquals(0, q.size());
}
}
示例5: shuffle
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Override
public void shuffle() {
IntArrays.shuffle(uidxs.elements(), 0, uidxs.size(), rnd);
}
示例6: testRadixSortIndirectStable
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Test
public void testRadixSortIndirectStable() {
double[] d = { 2, 1, 0, 4 };
int[] perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ d.length ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertEquals( i, perm[ i ] );
d = new double[] { 2, -1, 0, -4 };
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = DoubleArrays.shuffle( identity( 100 ), new Random( 0 ) );
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ 100 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
Random random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ d.length ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertEquals( i, perm[ i ] );
d = new double[ d.length ];
for( int i = 0; i < d.length; i++ ) d[ i ] = random.nextInt( 4 );
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) if ( d[ perm[ i ] ] == d[ perm[ i + 1 ] ] ) assertTrue( perm[ i ] < perm[ i + 1 ] );
d = new double[ 100 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, 10, 90, true );
for( int i = 10; i < 89; i++ ) assertTrue( Integer.toString( i ), d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
for( int i = 0; i < 10; i++ ) assertEquals( i, perm[ i ] );
for( int i = 90; i < 100; i++ ) assertEquals( i, perm[ i ] );
d = new double[ 100000 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertTrue( Integer.toString( i ), d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
IntArrays.shuffle( perm, new Random( 0 ) );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertTrue( Integer.toString( i ), d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ 10000000 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ d.length ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) assertEquals( i, perm[ i ] );
d = new double[ d.length ];
for( int i = 0; i < d.length; i++ ) d[ i ] = random.nextInt( 8 );
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, true );
for( int i = d.length - 1; i-- != 0; ) if ( d[ perm[ i ] ] == d[ perm[ i + 1 ] ] ) assertTrue( perm[ i ] < perm[ i + 1 ] );
}
示例7: testRadixSortIndirectUnstable
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Test
public void testRadixSortIndirectUnstable() {
double[] d = { 2, 1, 0, 4 };
int[] perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ d.length ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertEquals( i, perm[ i ] );
d = new double[] { 2, -1, 0, -4 };
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = DoubleArrays.shuffle( identity( 100 ), new Random( 0 ) );
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ 100 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
Random random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ 100 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, 10, 90, false );
for( int i = 10; i < 89; i++ ) assertTrue( Integer.toString( i ), d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
for( int i = 0; i < 10; i++ ) assertEquals( i, perm[ i ] );
for( int i = 90; i < 100; i++ ) assertEquals( i, perm[ i ] );
d = new double[ 100000 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertTrue( Integer.toString( i ), d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
IntArrays.shuffle( perm, new Random( 0 ) );
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertTrue( Integer.toString( i ), d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ 10000000 ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
random = new Random( 0 );
for( int i = d.length; i-- != 0; ) d[ i ] = random.nextInt();
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertTrue( d[ perm[ i ] ] <= d[ perm[ i + 1 ] ] );
d = new double[ d.length ];
perm = it.unimi.dsi.fastutil.ints.IntArraysTest.identity( d.length );
DoubleArrays.radixSortIndirect( perm, d, false );
for( int i = d.length - 1; i-- != 0; ) assertEquals( i, perm[ i ] );
}
示例8: randomPermutation
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
/** Returns a random permutation for a given graph.
*
* @param g an immutable graph.
* @param seed for {@link XorShift1024StarRandom}.
* @return a random permutation for the given graph
*/
public static int[] randomPermutation( final ImmutableGraph g, final long seed ) {
return IntArrays.shuffle( Util.identity( g.numNodes() ), new XorShift1024StarRandom( seed ) );
}