Search in sources :

Example 6 with IntUnaryOperator

use of java.util.function.IntUnaryOperator in project MindsEye by SimiaCryptus.

the class TestUtil method shuffle.

/**
 * Shuffle int stream.
 *
 * @param stream the stream
 * @return the int stream
 */
public static IntStream shuffle(@Nonnull IntStream stream) {
    // http://primes.utm.edu/lists/small/10000.txt
    long coprimeA = 41387;
    long coprimeB = 9967;
    long ringSize = coprimeA * coprimeB - 1;
    @Nonnull IntToLongFunction fn = x -> (x * coprimeA * coprimeA) % ringSize;
    @Nonnull LongToIntFunction inv = x -> (int) ((x * coprimeB * coprimeB) % ringSize);
    @Nonnull IntUnaryOperator conditions = x -> {
        assert x < ringSize;
        assert x >= 0;
        return x;
    };
    return stream.map(conditions).mapToLong(fn).sorted().mapToInt(inv);
}
Also used : Arrays(java.util.Arrays) ScheduledFuture(java.util.concurrent.ScheduledFuture) DoubleStatistics(com.simiacryptus.util.data.DoubleStatistics) IntUnaryOperator(java.util.function.IntUnaryOperator) BiFunction(java.util.function.BiFunction) LoggerFactory(org.slf4j.LoggerFactory) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) TrainingMonitor(com.simiacryptus.mindseye.opt.TrainingMonitor) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) Layer(com.simiacryptus.mindseye.lang.Layer) URI(java.net.URI) Graph(guru.nidi.graphviz.model.Graph) LongToIntFunction(java.util.function.LongToIntFunction) StochasticComponent(com.simiacryptus.mindseye.layers.java.StochasticComponent) BufferedImage(java.awt.image.BufferedImage) UUID(java.util.UUID) ComponentEvent(java.awt.event.ComponentEvent) WindowAdapter(java.awt.event.WindowAdapter) DAGNode(com.simiacryptus.mindseye.network.DAGNode) Collectors(java.util.stream.Collectors) WindowEvent(java.awt.event.WindowEvent) Executors(java.util.concurrent.Executors) List(java.util.List) Stream(java.util.stream.Stream) ScalarStatistics(com.simiacryptus.util.data.ScalarStatistics) LoggingWrapperLayer(com.simiacryptus.mindseye.layers.java.LoggingWrapperLayer) DAGNetwork(com.simiacryptus.mindseye.network.DAGNetwork) IntStream(java.util.stream.IntStream) MonitoringWrapperLayer(com.simiacryptus.mindseye.layers.java.MonitoringWrapperLayer) ActionListener(java.awt.event.ActionListener) ScatterPlot(smile.plot.ScatterPlot) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkSource(guru.nidi.graphviz.model.LinkSource) Tensor(com.simiacryptus.mindseye.lang.Tensor) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) JsonUtil(com.simiacryptus.util.io.JsonUtil) MutableNode(guru.nidi.graphviz.model.MutableNode) Charset(java.nio.charset.Charset) Factory(guru.nidi.graphviz.model.Factory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NotebookOutput(com.simiacryptus.util.io.NotebookOutput) WeakReference(java.lang.ref.WeakReference) LinkTarget(guru.nidi.graphviz.model.LinkTarget) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LongSummaryStatistics(java.util.LongSummaryStatistics) PrintStream(java.io.PrintStream) Logger(org.slf4j.Logger) PlotCanvas(smile.plot.PlotCanvas) RankDir(guru.nidi.graphviz.attribute.RankDir) IOException(java.io.IOException) FileFilter(javax.swing.filechooser.FileFilter) ActionEvent(java.awt.event.ActionEvent) PercentileStatistics(com.simiacryptus.util.data.PercentileStatistics) File(java.io.File) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) MonitoredObject(com.simiacryptus.util.MonitoredObject) IntToLongFunction(java.util.function.IntToLongFunction) Link(guru.nidi.graphviz.model.Link) Step(com.simiacryptus.mindseye.opt.Step) Comparator(java.util.Comparator) javax.swing(javax.swing) Nonnull(javax.annotation.Nonnull) LongToIntFunction(java.util.function.LongToIntFunction) IntToLongFunction(java.util.function.IntToLongFunction) IntUnaryOperator(java.util.function.IntUnaryOperator)

Example 7 with IntUnaryOperator

use of java.util.function.IntUnaryOperator in project ignite by apache.

the class IndexQueryRangeTest method check.

/**
 * @param left First cache key, inclusive.
 * @param right Last cache key, exclusive.
 */
private void check(Query<Cache.Entry<Long, Person>> qry, int left, int right) throws Exception {
    QueryCursor<Cache.Entry<Long, Person>> cursor = cache.query(qry);
    int expSize = (right - left) * duplicates;
    Set<Long> expKeys = new HashSet<>(expSize);
    List<Integer> expOrderedValues = new LinkedList<>();
    boolean desc = idxName.equals(DESC_IDX);
    int from = desc ? right - 1 : left;
    int to = desc ? left - 1 : right;
    IntUnaryOperator op = (i) -> desc ? i - 1 : i + 1;
    for (int i = from; i != to; i = op.applyAsInt(i)) {
        for (int j = 0; j < duplicates; j++) {
            expOrderedValues.add(i);
            expKeys.add((long) CNT * j + i);
        }
    }
    AtomicInteger actSize = new AtomicInteger();
    ((QueryCursorEx<Cache.Entry<Long, Person>>) cursor).getAll(entry -> {
        assertEquals(expOrderedValues.remove(0).intValue(), entry.getValue().id);
        assertTrue(expKeys.remove(entry.getKey()));
        int persId = entry.getKey().intValue() % CNT;
        assertEquals(new Person(persId), entry.getValue());
        actSize.incrementAndGet();
    });
    assertEquals(expSize, actSize.get());
    assertTrue(expKeys.isEmpty());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IndexQueryCriteriaBuilder.gt(org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.gt) IndexQueryCriteriaBuilder.eq(org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.eq) IntUnaryOperator(java.util.function.IntUnaryOperator) RunWith(org.junit.runner.RunWith) Random(java.util.Random) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) Cache(javax.cache.Cache) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) LinkedList(java.util.LinkedList) Parameterized(org.junit.runners.Parameterized) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IndexQueryCriteriaBuilder.lte(org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.lte) QuerySqlField(org.apache.ignite.cache.query.annotations.QuerySqlField) IndexQueryCriteriaBuilder.gte(org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.gte) Collection(java.util.Collection) IndexQueryCriteriaBuilder.lt(org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.lt) Set(java.util.Set) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) QueryCursorEx(org.apache.ignite.internal.processors.cache.query.QueryCursorEx) IgniteCache(org.apache.ignite.IgniteCache) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) Objects(java.util.Objects) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IndexQueryCriteriaBuilder.between(org.apache.ignite.cache.query.IndexQueryCriteriaBuilder.between) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) CacheMode(org.apache.ignite.cache.CacheMode) IntUnaryOperator(java.util.function.IntUnaryOperator) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryCursorEx(org.apache.ignite.internal.processors.cache.query.QueryCursorEx) HashSet(java.util.HashSet) Cache(javax.cache.Cache) IgniteCache(org.apache.ignite.IgniteCache)

Example 8 with IntUnaryOperator

use of java.util.function.IntUnaryOperator in project j2objc by google.

the class IntUnaryOperatorTest method testAndThen_null.

public void testAndThen_null() throws Exception {
    IntUnaryOperator plusOne = x -> x + 1;
    try {
        plusOne.andThen(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : IntUnaryOperator(java.util.function.IntUnaryOperator) TestCase(junit.framework.TestCase) IntUnaryOperator(java.util.function.IntUnaryOperator)

Example 9 with IntUnaryOperator

use of java.util.function.IntUnaryOperator in project j2objc by google.

the class IntUnaryOperatorTest method testCompose.

public void testCompose() throws Exception {
    IntUnaryOperator plusOne = x -> x + 1;
    IntUnaryOperator twice = x -> 2 * x;
    assertEquals(11, plusOne.compose(twice).applyAsInt(5));
}
Also used : IntUnaryOperator(java.util.function.IntUnaryOperator) TestCase(junit.framework.TestCase) IntUnaryOperator(java.util.function.IntUnaryOperator)

Example 10 with IntUnaryOperator

use of java.util.function.IntUnaryOperator in project j2objc by google.

the class IntUnaryOperatorTest method testAndThen.

public void testAndThen() throws Exception {
    IntUnaryOperator plusOne = x -> x + 1;
    IntUnaryOperator twice = x -> 2 * x;
    assertEquals(12, plusOne.andThen(twice).applyAsInt(5));
}
Also used : IntUnaryOperator(java.util.function.IntUnaryOperator) TestCase(junit.framework.TestCase) IntUnaryOperator(java.util.function.IntUnaryOperator)

Aggregations

IntUnaryOperator (java.util.function.IntUnaryOperator)13 List (java.util.List)6 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 IntStream (java.util.stream.IntStream)4 TestCase (junit.framework.TestCase)4 ArrayList (java.util.ArrayList)3 Comparator (java.util.Comparator)3 TimeUnit (java.util.concurrent.TimeUnit)3 Function (java.util.function.Function)3 Stream (java.util.stream.Stream)3 File (java.io.File)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Parameter (com.beust.jcommander.Parameter)1 IOUtils (com.github.lindenb.jvarkit.io.IOUtils)1