<commit_before>﻿#if PORTABLE
namespace MathNet.Numerics
{
    using System;
    using System.Threading;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
    public class SerializableAttribute : Attribute
    {
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class SpecialNameAttribute : Attribute
    {
    }

    internal static class Partitioner
    {
        public static IEnumerable<Tuple<int, int>> Create(int fromInclusive, int toExclusive)
        {
            var rangeSize = Math.Max(1, (toExclusive - fromInclusive) / Control.NumberOfParallelWorkerThreads);
            return Create(fromInclusive, toExclusive, rangeSize);
        }

        public static IEnumerable<Tuple<int, int>> Create(int fromInclusive, int toExclusive, int rangeSize)
        {
            if (toExclusive <= fromInclusive)
            {
                throw new ArgumentOutOfRangeException("toExclusive");
            }
            if (rangeSize <= 0)
            {
                throw new ArgumentOutOfRangeException("rangeSize");
            }

            return CreateRanges(fromInclusive, toExclusive, rangeSize);
        }

        private static IEnumerable<Tuple<int, int>> CreateRanges(int fromInclusive, int toExclusive, int rangeSize)
        {
            bool flag = false;
            int num = fromInclusive;
            while (num < toExclusive && !flag)
            {
                int item = num;
                int num2;
                try
                {
                    num2 = checked(num + rangeSize);
                }
                catch (OverflowException)
                {
                    num2 = toExclusive;
                    flag = true;
                }
                if (num2 > toExclusive)
                {
                    num2 = toExclusive;
                }
                yield return new Tuple<int, int>(item, num2);
                num += rangeSize;
            }
        }
    }

    internal class ParallelOptions
    {
        public TaskScheduler TaskScheduler { get; set; }
        public int MaxDegreeOfParallelism { get; set; }
        public CancellationToken CancellationToken { get; set; }

        public ParallelOptions()
        {
            TaskScheduler = TaskScheduler.Default;
            MaxDegreeOfParallelism = -1;
            CancellationToken = CancellationToken.None;
        }
    }

    internal class ParallelLoopState
    {
    }

    internal static class Parallel
    {
        public static void ForEach<TSource>(IEnumerable<TSource> source, ParallelOptions parallelOptions, Action<TSource> body)
        {
            var chunks = source.ToArray();
            var tasks = new Task[chunks.Length];

            for (var i = 0; i < tasks.Length; i++)
            {
                var chunk = chunks[i];
                tasks[i] = Task.Factory.StartNew(() => body(chunk), parallelOptions.CancellationToken, TaskCreationOptions.None, parallelOptions.TaskScheduler);
            }

            Task.WaitAll(tasks, parallelOptions.CancellationToken);
        }

        public static void Invoke(ParallelOptions parallelOptions, params Action[] actions)
        {
            var tasks = new Task[actions.Length];

            for (var i = 0; i < tasks.Length; i++)
            {
                var action = actions[i];
                if (action == null)
                {
                    throw new ArgumentException(String.Format(Properties.Resources.ArgumentItemNull, "actions"), "actions");
                }

                tasks[i] = Task.Factory.StartNew(action, parallelOptions.CancellationToken, TaskCreationOptions.None, parallelOptions.TaskScheduler);
            }

            Task.WaitAll(tasks);
        }

        public static void ForEach<TSource, TLocal>(
            IEnumerable<TSource> source,
            ParallelOptions parallelOptions,
            Func<TLocal> localInit,
            Func<TSource, ParallelLoopState, TLocal, TLocal> body,
            Action<TLocal> localFinally)
        {
            var chunks = source.ToArray();
            var tasks = new Task[chunks.Length];
            var loopState = new ParallelLoopState();

            for (var i = 0; i < tasks.Length; i++)
            {
                var chunk = chunks[i];

                tasks[i] = Task.Factory.StartNew(() =>
                {
                    var local = localInit();
                    local = body(chunk, loopState, local);
                    localFinally(local);
                    return local;
                }, parallelOptions.CancellationToken, TaskCreationOptions.None, parallelOptions.TaskScheduler);
            }

            Task.WaitAll(tasks, parallelOptions.CancellationToken);
        }
    }
}
#endif

#if (PORTABLE || NET35)
namespace MathNet.Numerics
{<commit_msg>small fixes in portable Parallel implementation<commit_after>﻿#if PORTABLE
namespace MathNet.Numerics
{
    using System;
    using System.Threading;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
    public class SerializableAttribute : Attribute
    {
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public class SpecialNameAttribute : Attribute
    {
    }

    internal static class Partitioner
    {
        public static IEnumerable<Tuple<int, int>> Create(int fromInclusive, int toExclusive)
        {
            var rangeSize = Math.Max(1, (toExclusive - fromInclusive) / Control.NumberOfParallelWorkerThreads);
            return Create(fromInclusive, toExclusive, rangeSize);
        }

        public static IEnumerable<Tuple<int, int>> Create(int fromInclusive, int toExclusive, int rangeSize)
        {
            if (toExclusive <= fromInclusive)
            {
                throw new ArgumentOutOfRangeException("toExclusive");
            }
            if (rangeSize <= 0)
            {
                throw new ArgumentOutOfRangeException("rangeSize");
            }

            return CreateRanges(fromInclusive, toExclusive, rangeSize);
        }

        private static IEnumerable<Tuple<int, int>> CreateRanges(int fromInclusive, int toExclusive, int rangeSize)
        {
            bool flag = false;
            int num = fromInclusive;
            while (num < toExclusive && !flag)
            {
                int item = num;
                int num2;
                try
                {
                    num2 = checked(num + rangeSize);
                }
                catch (OverflowException)
                {
                    num2 = toExclusive;
                    flag = true;
                }
                if (num2 > toExclusive)
                {
                    num2 = toExclusive;
                }
                yield return new Tuple<int, int>(item, num2);
                num += rangeSize;
            }
        }
    }

    internal class ParallelOptions
    {
        public TaskScheduler TaskScheduler { get; set; }
        public int MaxDegreeOfParallelism { get; set; }
        public CancellationToken CancellationToken { get; set; }

        public ParallelOptions()
        {
            TaskScheduler = TaskScheduler.Default;
            MaxDegreeOfParallelism = -1;
            CancellationToken = CancellationToken.None;
        }
    }

    internal class ParallelLoopState
    {
    }

    internal static class Parallel
    {
        public static void ForEach<TSource>(IEnumerable<TSource> source, ParallelOptions parallelOptions, Action<TSource> body)
        {
            var chunks = source.ToArray();
            var tasks = new Task[chunks.Length];

            for (var i = 0; i < tasks.Length; i++)
            {
                var chunk = chunks[i];
                tasks[i] = Task.Factory.StartNew(() => body(chunk), parallelOptions.CancellationToken, TaskCreationOptions.None, parallelOptions.TaskScheduler);
            }

            Task.WaitAll(tasks, parallelOptions.CancellationToken);
        }

        public static void Invoke(ParallelOptions parallelOptions, params Action[] actions)
        {
            var tasks = new Task[actions.Length];

            for (var i = 0; i < tasks.Length; i++)
            {
                var action = actions[i];
                if (action == null)
                {
                    throw new ArgumentException(String.Format(Properties.Resources.ArgumentItemNull, "actions"), "actions");
                }

                tasks[i] = Task.Factory.StartNew(action, parallelOptions.CancellationToken, TaskCreationOptions.None, parallelOptions.TaskScheduler);
            }

            Task.WaitAll(tasks, parallelOptions.CancellationToken);
        }

        public static void ForEach<TSource, TLocal>(
            IEnumerable<TSource> source,
            ParallelOptions parallelOptions,
            Func<TLocal> localInit,
            Func<TSource, ParallelLoopState, TLocal, TLocal> body,
            Action<TLocal> localFinally)
        {
            var chunks = source.ToArray();
            var tasks = new Task[chunks.Length];
            var loopState = new ParallelLoopState();

            for (var i = 0; i < tasks.Length; i++)
            {
                var chunk = chunks[i];
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    var local = localInit();
                    local = body(chunk, loopState, local);
                    localFinally(local);
                }, parallelOptions.CancellationToken, TaskCreationOptions.None, parallelOptions.TaskScheduler);
            }

            Task.WaitAll(tasks, parallelOptions.CancellationToken);
        }
    }
}
#endif

#if (PORTABLE || NET35)
namespace MathNet.Numerics
{
{'fraction_non_alphanumeric': 0.08492079406456787, 'fraction_numerical': 0.0028072989773410867, 'mean_word_length': 1.7321281840591618, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4866434', 'n_tokens_mistral': 2553, 'n_tokens_neox': 2469, 'n_words': 584}