当前位置: 首页>>代码示例>>Java>>正文


Java IntArrays.shuffle方法代码示例

本文整理汇总了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());
		}
	}
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:27,代码来源:ReorderingBlockingQueueTest.java

示例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();
}
 
开发者ID:corradomonti,项目名称:llamafur,代码行数:22,代码来源:LatentMatrixEstimator.java

示例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;
	}
}
 
开发者ID:corradomonti,项目名称:llamafur,代码行数:19,代码来源:TestMatrix.java

示例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());
	}
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:12,代码来源:ReorderingBlockingQueueTest.java

示例5: shuffle

import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Override
public void shuffle() {
    IntArrays.shuffle(uidxs.elements(), 0, uidxs.size(), rnd);
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:5,代码来源:OneClassPreferenceFMData.java

示例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 ] );
}
 
开发者ID:phishman3579,项目名称:fastutil,代码行数:79,代码来源:DoubleArraysTest.java

示例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 ] );
}
 
开发者ID:phishman3579,项目名称:fastutil,代码行数:62,代码来源:DoubleArraysTest.java

示例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 ) );
}
 
开发者ID:lhelwerd,项目名称:WebGraph,代码行数:10,代码来源:Transform.java


注:本文中的it.unimi.dsi.fastutil.ints.IntArrays.shuffle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。