private void assertIndexMatchesVals(ColumnarLongs indexed, long[] vals) { Assert.assertEquals(vals.length, indexed.size()); // sequential access int[] indices = new int[vals.length]; for (int i = 0; i < indexed.size(); ++i) { Assert.assertEquals(vals[i], indexed.get(i)); indices[i] = i; } // random access, limited to 1000 elements for large lists (every element would take too long) IntArrays.shuffle(indices, ThreadLocalRandom.current()); final int limit = Math.min(indexed.size(), 1000); for (int i = 0; i < limit; ++i) { int k = indices[i]; Assert.assertEquals(vals[k], indexed.get(k)); } }
private void assertIndexMatchesVals() { Assert.assertEquals(vals.length, columnarInts.size()); // sequential access int[] indices = new int[vals.length]; for (int i = 0, size = columnarInts.size(); i < size; ++i) { Assert.assertEquals(vals[i], columnarInts.get(i), 0.0); indices[i] = i; } // random access, limited to 1000 elements for large lists (every element would take too long) IntArrays.shuffle(indices, ThreadLocalRandom.current()); final int limit = Math.min(columnarInts.size(), 1000); for (int i = 0; i < limit; ++i) { int k = indices[i]; Assert.assertEquals(vals[k], columnarInts.get(k), 0.0); } } }
private void assertIndexMatchesVals(ColumnarFloats indexed, float[] vals) { Assert.assertEquals(vals.length, indexed.size()); // sequential access int[] indices = new int[vals.length]; for (int i = 0; i < indexed.size(); ++i) { Assert.assertEquals(vals[i], indexed.get(i), DELTA); indices[i] = i; } // random access, limited to 1000 elements for large lists (every element would take too long) IntArrays.shuffle(indices, ThreadLocalRandom.current()); final int limit = Math.min(indexed.size(), 1000); for (int i = 0; i < limit; ++i) { int k = indices[i]; Assert.assertEquals(vals[k], indexed.get(k), DELTA); } }
private void assertIndexMatchesVals() { Assert.assertEquals(vals.length, columnarInts.size()); // sequential access of every element int[] indices = new int[vals.length]; for (int i = 0, size = columnarInts.size(); i < size; ++i) { final int expected = vals[i]; final int actual = columnarInts.get(i); Assert.assertEquals(expected, actual); indices[i] = i; } // random access, limited to 1000 elements for large lists (every element would take too long) IntArrays.shuffle(indices, ThreadLocalRandom.current()); final int limit = Math.min(columnarInts.size(), 1000); for (int i = 0; i < limit; ++i) { int k = indices[i]; Assert.assertEquals(vals[k], columnarInts.get(k)); } } }
@Override public void shuffle() { IntArrays.shuffle(uidxs.elements(), 0, uidxs.size(), rnd); }
@Override public void shuffle() { IntArrays.shuffle(uidxs.elements(), 0, uidxs.size(), rnd); }
@Override public Frame apply(Frame df) { int[] mapping = IntStream.range(0, df.rowCount()).toArray(); IntArrays.shuffle(mapping, RandomSource.getRandom()); return df.mapRows(Mapping.wrap(mapping)); } }
/** Returns a random permutation for a given graph. * * @param g an immutable graph. * @param seed for {@link XoRoShiRo128PlusRandom}. * @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 XoRoShiRo128PlusRandom(seed)); }
@Override public Var apply(Var var) { int[] mapping = new int[var.rowCount()]; for (int i = 0; i < mapping.length; i++) { mapping[i] = i; } IntArrays.shuffle(mapping, RandomSource.getRandom()); return var.mapRows(Mapping.wrap(mapping)); }
public static Frame[] randomSampleSlices(Frame frame, double... freq) { normalize(freq); int[] rows = new int[frame.rowCount()]; for (int i = 0; i < rows.length; i++) { rows[i] = i; } IntArrays.shuffle(rows, RandomSource.getRandom()); Frame[] result = new Frame[freq.length]; int start = 0; for (int i = 0; i < freq.length; i++) { int len = (int) (freq[i] * frame.rowCount()); if (i == freq.length - 1) { len = frame.rowCount() - start; } result[i] = frame.mapRows(Arrays.copyOfRange(rows, start, start + len)); start += len; } return result; }
/** Creates an object ready for solving queries. * * @param parser the parser to be used when solving queries. * @param indexMap the map from index alias to indices. * @param graph the graph whence we are going to extract subgraphs. * @param grapht the transpose graph, only needed if <code>maxIn</code> or <code>maxOut</code> are positive and finite. * @param maxIn how many nodes should be taken (at most) from the in-neighborhood. * @param maxOut how many nodes should be taken (at most) from the out-neighborhood. * @param random the random number generator to be used for selecting neighbors. */ public GraphFromQuery( final SimpleParser parser, final Object2ReferenceLinkedOpenHashMap<String,Index> indexMap, final ImmutableGraph graph, final ImmutableGraph grapht, final int maxIn, final int maxOut, final Random random ) { this.parser = parser; this.graph = graph; this.grapht = grapht; this.maxIn = maxIn; this.maxOut = maxOut; int n = graph.numNodes(); if ( maxIn > 0 && maxIn < Integer.MAX_VALUE || maxOut > 0 && maxOut < Integer.MAX_VALUE ) { nodePermutation = Util.identity( n ); IntArrays.shuffle( nodePermutation, random ); } else nodePermutation = null; documentIteratorBuilderVisitor = new DocumentIteratorBuilderVisitor( indexMap, indexMap.get( parser.defaultIndex ), Integer.MAX_VALUE ); }
seq[i] = i; IntArrays.shuffle(seq, RandomSource.getRandom());