예제 #1
0
 /// <summary>
 /// Creates a new query that projects each element of a sequence into a new form.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of the query.</typeparam>
 /// <typeparam name="TResult">The type of the value returned by selector.</typeparam>
 /// <param name="query">A query whose values to invoke a transform function on.</param>
 /// <param name="selector">A transform function to apply to each element.</param>
 /// <returns>A query whose elements will be the result of invoking the transform function on each element of source.</returns>
 public static IGpuQueryExpr <IGpuArray <TResult> > Select <TSource, TResult>(this IGpuQueryExpr <IGpuArray <TSource> > query, Expression <Func <TSource, TResult> > selector)
 {
     return(new GpuQueryExpr <IGpuArray <TResult> >(QueryExpr.NewTransform(selector, query.Expr)));
 }
예제 #2
0
        /// <summary>
        /// Creates a query that projects each element of a sequence to an GpuArray, flattens the resulting sequences into one sequence, and invokes a result selector function on each element therein.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <typeparam name="TCol">The type of the intermediate elements collected by collectionSelector.</typeparam>
        /// <typeparam name="TResult">The type of the elements of the sequence returned by selector.</typeparam>
        /// <param name="query">A query whose values to project.</param>
        /// <param name="collectionSelector">A transform function to apply to each element of the input sequence.</param>
        /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
        /// <returns>A query whose elements are the result of invoking the one-to-many transform function on each element of the input sequence and the result selector function on each element therein.</returns>
        public static IGpuQueryExpr <IGpuArray <TResult> > SelectMany <TSource, TCol, TResult>(this IGpuQueryExpr <IGpuArray <TSource> > query, Expression <Func <TSource, IGpuArray <TCol> > > collectionSelector, Expression <Func <TSource, TCol, TResult> > resultSelector)
        {
            var paramExpr = collectionSelector.Parameters.Single();
            var bodyExpr  = collectionSelector.Body;

            if (bodyExpr.NodeType == ExpressionType.MemberAccess)
            {
                var nested = Tuple.Create(paramExpr, QueryExpr.NewSource((MemberExpression)bodyExpr, typeof(TCol), QueryExprType.Gpu));
                return(new GpuQueryExpr <IGpuArray <TResult> >(QueryExpr.NewNestedQueryTransform(nested, resultSelector, query.Expr)));
            }
            else
            {
                throw new InvalidOperationException("Not supported " + bodyExpr.ToString());
            }
        }
예제 #3
0
 /// <summary>
 /// A query that returns an array from an gpu array.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <param name="query">The query to create an array from.</param>
 /// <returns>A query that contains elements from the gpu array in an array form.</returns>
 public static IGpuQueryExpr <TSource[]> ToArray <TSource>(this IGpuQueryExpr <IGpuArray <TSource> > query)
 {
     return(new GpuQueryExpr <TSource[]>(QueryExpr.NewToArray(query.Expr)));
 }
예제 #4
0
 /// <summary>
 /// Creates a new query that returns the number of elements in a gpu array.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <param name="query">A query whose elements will be count.</param>
 /// <returns>A query that returns the number of elements in the gpu array.</returns>
 public static IGpuQueryExpr <int> Count <TSource>(this IGpuQueryExpr <IGpuArray <TSource> > query)
 {
     return(new GpuQueryExpr <int>(QueryExpr.NewCount(query.Expr)));
 }
예제 #5
0
 /// <summary>
 /// Creates a new query that computes the sum of a sequence of double values.
 /// </summary>
 /// <param name="query">A query whose sequence of int values to calculate the sum of.</param>
 /// <returns>A query that returns the sum of the values in the gpu array.</returns>
 public static IGpuQueryExpr <double> Sum(this IGpuQueryExpr <IGpuArray <double> > query)
 {
     return(new GpuQueryExpr <double>(QueryExpr.NewSum(query.Expr)));
 }
예제 #6
0
 /// <summary>
 /// Creates a new query that computes the sum of a sequence of float values.
 /// </summary>
 /// <param name="query">A query whose sequence of int values to calculate the sum of.</param>
 /// <returns>A query that returns the sum of the values in the gpu array.</returns>
 public static IGpuQueryExpr <float> Sum(this IGpuQueryExpr <IGpuArray <float> > query)
 {
     return(new GpuQueryExpr <float>(QueryExpr.NewSum(query.Expr)));
 }
예제 #7
0
 /// <summary>
 /// Creates a new query that filters a sequence of values based on a predicate.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of source.</typeparam>
 /// <param name="query">An query whose values to filter.</param>
 /// <param name="predicate">A function to test each element for a condition.</param>
 /// <returns>A query that contains elements from the input query that satisfy the condition.</returns>
 public static IGpuQueryExpr <IGpuArray <TSource> > Where <TSource>(this IGpuQueryExpr <IGpuArray <TSource> > query, Expression <Func <TSource, bool> > predicate)
 {
     return(new GpuQueryExpr <IGpuArray <TSource> >(QueryExpr.NewFilter(predicate, query.Expr)));
 }