Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="field"></param>
        /// <param name="other"></param>
        /// <param name="converter"></param>
        /// <param name="parallel"></param>
        public static void Sample <T, U>(this IDiscreteField2d <T> field, IField2d <U> other, Func <U, T> converter, bool parallel = false)
        {
            if (parallel)
            {
                Parallel.ForEach(Partitioner.Create(0, field.Count), range => Body(range.Item1, range.Item2));
            }
            else
            {
                Body(0, field.Count);
            }

            void Body(int from, int to)
            {
                var vals = field.Values;

                for (int i = from; i < to; i++)
                {
                    vals[i] = converter(other.ValueAt(field.CoordinateAt(i)));
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="field"></param>
        /// <param name="other"></param>
        /// <param name="converter"></param>
        /// <param name="parallel"></param>
        public static void Sample <T, U>(this IDiscreteField2d <T> field, IField2d <U> other, Func <U, T> converter, bool parallel = false)
        {
            var vals = field.Values;

            Action <Tuple <int, int> > body = range =>
            {
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    vals[i] = converter(other.ValueAt(field.CoordinateAt(i)));
                }
            };

            if (parallel)
            {
                Parallel.ForEach(Partitioner.Create(0, field.Count), body);
            }
            else
            {
                body(Tuple.Create(0, field.Count));
            }
        }