public ScalarLinqRenderer(Action <int, int, int> dp, Func <bool> abortFunc) : base(dp, abortFunc) { Pair[] pairs = Enumerable.Range(0, 312).SelectMany(y => Enumerable.Range(0, 534).Select(x => new Pair { X = x, Y = y })).ToArray(); int[] output = Enumerable.Range(0, pairs.Length).ToArray(); this.context = new GpuContext(); this._pairs = context.CreateGpuArray(pairs); this._output = context.CreateGpuArray(output); parFunc = ParallelExtensions.Compile <float, float, float, int[]>( (_ymin, _xmin, _step) => (from pair in pairs.AsParallelQueryExpr() let _y = _ymin + _step * pair.Y let _x = _xmin + _step * pair.X let c = new MyComplex(_x, _y) let iters = EnumerableEx.Generate(c, x => x.SquareLength < limit, x => x * x + c, x => x) .Take(max_iters) .Count() select iters).ToArray() ); seqFunc = Extensions.Compile <float, float, float, int[]>( (_ymin, _xmin, _step) => (from pair in pairs.AsQueryExpr() let _y = _ymin + _step * pair.Y let _x = _xmin + _step * pair.X let c = new MyComplex(_x, _y) let iters = EnumerableEx.Generate(c, x => x.SquareLength < limit, x => x * x + c, x => x) .Take(max_iters) .Count() select iters).ToArray() ); }
/// <summary> /// Enables a gpu query. /// </summary> /// <typeparam name="TSource">The type of the elements in the source array.</typeparam> /// <param name="source">An array to convert to an IGpuQueryExpr.</param> /// <returns>A query that returns the elements of the source array.</returns> public static IGpuQueryExpr <IGpuArray <TSource> > AsGpuQueryExpr <TSource>(this IGpuArray <TSource> source) { return(new GpuQueryExpr <IGpuArray <TSource> >(QueryExpr.NewSource(Expression.Constant(source), typeof(TSource), QueryExprType.Gpu))); }
/// <summary> /// Creates a query that applies a specified function to the corresponding elements of two gpu arrays, producing a sequence of the results. /// </summary> /// <param name="first">The first gpu array to merge.</param> /// <param name="second">The first gpu array to merge.</param> /// <param name="resultSelector">A function that specifies how to merge the elements from the two gpu arrays.</param> /// <returns>A query that contains merged elements of two gpu arrays.</returns> public static IGpuQueryExpr <IGpuArray <TResult> > Zip <TFirst, TSecond, TResult>(IGpuArray <TFirst> first, IGpuArray <TSecond> second, Expression <Func <TFirst, TSecond, TResult> > resultSelector) { return(new GpuQueryExpr <IGpuArray <TResult> >(QueryExpr.NewZipWith(Expression.Constant(first), Expression.Constant(second), resultSelector))); }