Search in sources :

Example 1 with ParallelIterable

use of org.eclipse.collections.api.ParallelIterable in project eclipse-collections by eclipse.

the class ParallelIterableTestCase method sumOfFloatConsistentRounding.

@Test
public void sumOfFloatConsistentRounding() {
    FloatFunction<Integer> roundingSensitiveElementFunction = i -> (i <= 99995) ? 1.0e-18f : 1.0f;
    MutableList<Integer> list = Interval.oneTo(100_000).toList().shuffleThis();
    double baseline = this.getExpectedWith(list.toArray(new Integer[] {})).sumOfFloat(roundingSensitiveElementFunction);
    for (Integer batchSize : BATCH_SIZES) {
        this.batchSize = batchSize;
        ParallelIterable<Integer> testCollection = this.newWith(list.toArray(new Integer[] {}));
        Assert.assertEquals("Batch size: " + this.batchSize, baseline, testCollection.sumOfFloat(roundingSensitiveElementFunction), 1.0e-15d);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelSortedSetIterable(org.eclipse.collections.api.set.sorted.ParallelSortedSetIterable) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) Procedures2(org.eclipse.collections.impl.block.factory.Procedures2) Function(org.eclipse.collections.api.block.function.Function) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Verify(org.eclipse.collections.impl.test.Verify) CheckedPredicate(org.eclipse.collections.impl.block.predicate.checked.CheckedPredicate) MutableList(org.eclipse.collections.api.list.MutableList) ParallelIterable(org.eclipse.collections.api.ParallelIterable) RichIterable(org.eclipse.collections.api.RichIterable) Function0(org.eclipse.collections.api.block.function.Function0) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Function2(org.eclipse.collections.api.block.function.Function2) CheckedFunction(org.eclipse.collections.impl.block.function.checked.CheckedFunction) After(org.junit.After) Tuples(org.eclipse.collections.impl.tuple.Tuples) ParallelListIterable(org.eclipse.collections.api.list.ParallelListIterable) Interval(org.eclipse.collections.impl.list.Interval) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) MutableCollection(org.eclipse.collections.api.collection.MutableCollection) ExecutorService(java.util.concurrent.ExecutorService) Comparators(org.eclipse.collections.impl.block.factory.Comparators) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) CheckedProcedure(org.eclipse.collections.impl.block.procedure.checked.CheckedProcedure) IOException(java.io.IOException) Test(org.junit.Test) PassThruFunction0(org.eclipse.collections.impl.block.function.PassThruFunction0) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) ParallelSetIterable(org.eclipse.collections.api.set.ParallelSetIterable) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Lists(org.eclipse.collections.impl.factory.Lists) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) Test(org.junit.Test)

Example 2 with ParallelIterable

use of org.eclipse.collections.api.ParallelIterable in project eclipse-collections by eclipse.

the class ParallelIterableTestCase method sumOfDoubleConsistentRounding.

@Test
public void sumOfDoubleConsistentRounding() {
    DoubleFunction<Integer> roundingSensitiveElementFunction = i -> (i <= 99995) ? 1.0e-18d : 1.0d;
    MutableList<Integer> list = Interval.oneTo(100_000).toList().shuffleThis();
    double baseline = this.getExpectedWith(list.toArray(new Integer[] {})).sumOfDouble(roundingSensitiveElementFunction);
    for (Integer batchSize : BATCH_SIZES) {
        this.batchSize = batchSize;
        ParallelIterable<Integer> testCollection = this.newWith(list.toArray(new Integer[] {}));
        Assert.assertEquals("Batch size: " + this.batchSize, baseline, testCollection.sumOfDouble(roundingSensitiveElementFunction), 1.0e-15d);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelSortedSetIterable(org.eclipse.collections.api.set.sorted.ParallelSortedSetIterable) NegativeIntervalFunction(org.eclipse.collections.impl.block.function.NegativeIntervalFunction) CharHashBag(org.eclipse.collections.impl.bag.mutable.primitive.CharHashBag) Procedures2(org.eclipse.collections.impl.block.factory.Procedures2) Function(org.eclipse.collections.api.block.function.Function) Predicate(org.eclipse.collections.api.block.predicate.Predicate) Verify(org.eclipse.collections.impl.test.Verify) CheckedPredicate(org.eclipse.collections.impl.block.predicate.checked.CheckedPredicate) MutableList(org.eclipse.collections.api.list.MutableList) ParallelIterable(org.eclipse.collections.api.ParallelIterable) RichIterable(org.eclipse.collections.api.RichIterable) Function0(org.eclipse.collections.api.block.function.Function0) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Function2(org.eclipse.collections.api.block.function.Function2) CheckedFunction(org.eclipse.collections.impl.block.function.checked.CheckedFunction) After(org.junit.After) Tuples(org.eclipse.collections.impl.tuple.Tuples) ParallelListIterable(org.eclipse.collections.api.list.ParallelListIterable) Interval(org.eclipse.collections.impl.list.Interval) NoSuchElementException(java.util.NoSuchElementException) Pair(org.eclipse.collections.api.tuple.Pair) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) MutableCollection(org.eclipse.collections.api.collection.MutableCollection) ExecutorService(java.util.concurrent.ExecutorService) Comparators(org.eclipse.collections.impl.block.factory.Comparators) Predicates(org.eclipse.collections.impl.block.factory.Predicates) Before(org.junit.Before) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) CollectionAddProcedure(org.eclipse.collections.impl.block.procedure.CollectionAddProcedure) IntegerPredicates(org.eclipse.collections.impl.block.factory.IntegerPredicates) CheckedProcedure(org.eclipse.collections.impl.block.procedure.checked.CheckedProcedure) IOException(java.io.IOException) Test(org.junit.Test) PassThruFunction0(org.eclipse.collections.impl.block.function.PassThruFunction0) Executors(java.util.concurrent.Executors) ExecutionException(java.util.concurrent.ExecutionException) ParallelSetIterable(org.eclipse.collections.api.set.ParallelSetIterable) ImmutableList(org.eclipse.collections.api.list.ImmutableList) Lists(org.eclipse.collections.impl.factory.Lists) Pattern(java.util.regex.Pattern) Assert(org.junit.Assert) FloatFunction(org.eclipse.collections.api.block.function.primitive.FloatFunction) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)2 NoSuchElementException (java.util.NoSuchElementException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Pattern (java.util.regex.Pattern)2 ParallelIterable (org.eclipse.collections.api.ParallelIterable)2 RichIterable (org.eclipse.collections.api.RichIterable)2 Function (org.eclipse.collections.api.block.function.Function)2 Function0 (org.eclipse.collections.api.block.function.Function0)2 Function2 (org.eclipse.collections.api.block.function.Function2)2 DoubleFunction (org.eclipse.collections.api.block.function.primitive.DoubleFunction)2 FloatFunction (org.eclipse.collections.api.block.function.primitive.FloatFunction)2 Predicate (org.eclipse.collections.api.block.predicate.Predicate)2 MutableCollection (org.eclipse.collections.api.collection.MutableCollection)2 ImmutableList (org.eclipse.collections.api.list.ImmutableList)2 MutableList (org.eclipse.collections.api.list.MutableList)2 ParallelListIterable (org.eclipse.collections.api.list.ParallelListIterable)2 ParallelSetIterable (org.eclipse.collections.api.set.ParallelSetIterable)2