예제 #1
0
        public Estimator <TInShape, TNewOutShape, ITransformer> Append <[IsShape] TNewOutShape>(Func <TOutShape, TNewOutShape> mapper)
        {
            Contracts.CheckValue(mapper, nameof(mapper));

            using (var ch = Env.Start(nameof(Append)))
            {
                var method = mapper.Method;

                // Construct the dummy column structure, then apply the mapping.
                var input = StaticPipeInternalUtils.MakeAnalysisInstance <TOutShape>(out var fakeReconciler);
                KeyValuePair <string, PipelineColumn>[] inPairs = StaticPipeInternalUtils.GetNamesValues(input, method.GetParameters()[0]);

                // Initially we suppose we've only assigned names to the inputs.
                var inputColToName = new Dictionary <PipelineColumn, string>();
                foreach (var p in inPairs)
                {
                    inputColToName[p.Value] = p.Key;
                }
                string NameMap(PipelineColumn col)
                {
                    inputColToName.TryGetValue(col, out var val);
                    return(val);
                }

                var readerEst = StaticPipeUtils.GeneralFunctionAnalyzer(Env, ch, input, fakeReconciler, mapper, out var estTail, NameMap);
                ch.Assert(readerEst == null);
                ch.AssertValue(estTail);

                var est    = AsDynamic.Append(estTail);
                var newOut = StaticSchemaShape.Make <TNewOutShape>(method.ReturnParameter);
                return(new Estimator <TInShape, TNewOutShape, ITransformer>(Env, est, _inShape, newOut));
            }
        }
예제 #2
0
        public static DataReader <TIn, T> AssertStatic <TIn, [IsShape] T>(this IDataReader <TIn> reader, IHostEnvironment env,
                                                                          Func <SchemaAssertionContext, T> outputDecl)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(reader, nameof(reader));
            env.CheckValue(outputDecl, nameof(outputDecl));

            var schema = StaticSchemaShape.Make <T>(outputDecl.Method.ReturnParameter);

            return(new DataReader <TIn, T>(env, reader, schema));
        }
        LoaderEstimatorAnalyzerHelper <TIn, TDelegateInput, TOutShape>(
            IHostEnvironment env,
            IChannel ch,
            TDelegateInput input,
            LoaderReconciler <TIn> baseReconciler,
            Func <TDelegateInput, TOutShape> mapper)
        {
            var loaderEstimator = GeneralFunctionAnalyzer(env, ch, input, baseReconciler, mapper, out var est, col => null);
            var schema          = StaticSchemaShape.Make <TOutShape>(mapper.Method.ReturnParameter);

            return(new DataLoaderEstimator <TIn, TOutShape, IDataLoader <TIn> >(env, loaderEstimator, schema));
        }
예제 #4
0
        public static DataLoaderEstimator <TIn, T, TLoader> AssertStatic <TIn, [IsShape] T, TLoader>(
            this IDataLoaderEstimator <TIn, TLoader> loaderEstimator, IHostEnvironment env,
            Func <SchemaAssertionContext, T> outputDecl)
            where TLoader : class, IDataLoader <TIn>
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(loaderEstimator, nameof(loaderEstimator));
            env.CheckValue(outputDecl, nameof(outputDecl));

            var schema = StaticSchemaShape.Make <T>(outputDecl.Method.ReturnParameter);

            return(new DataLoaderEstimator <TIn, T, TLoader>(env, loaderEstimator, schema));
        }
예제 #5
0
        /// <summary>
        /// Asserts that a given data view has the indicated schema. If this method returns without
        /// throwing then the view has been validated to have columns with the indicated names and types.
        /// </summary>
        /// <typeparam name="T">The type representing the view's schema shape</typeparam>
        /// <param name="view">The view to assert the static schema on</param>
        /// <param name="env">The host environment to keep in the statically typed variant</param>
        /// <param name="outputDecl">The delegate through which we declare the schema, which ought to
        /// use the input <see cref="SchemaAssertionContext"/> to declare a <see cref="ValueTuple"/>
        /// of the <see cref="PipelineColumn"/> indices, properly named</param>
        /// <returns>A statically typed wrapping of the input view</returns>
        public static DataView <T> AssertStatic <[IsShape] T>(this IDataView view, IHostEnvironment env,
                                                              Func <SchemaAssertionContext, T> outputDecl)
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(view, nameof(view));
            env.CheckValue(outputDecl, nameof(outputDecl));

            // We don't actually need to call the method, it's just there to give the declaration.
#if DEBUG
            outputDecl(SchemaAssertionContext.Inst);
#endif

            var schema = StaticSchemaShape.Make <T>(outputDecl.Method.ReturnParameter);
            return(new DataView <T>(env, view, schema));
        }
예제 #6
0
        public static Estimator <TIn, TOut, TTrans> AssertStatic <[IsShape] TIn, [IsShape] TOut, TTrans>(
            this IEstimator <TTrans> estimator, IHostEnvironment env,
            Func <SchemaAssertionContext, TIn> inputDecl,
            Func <SchemaAssertionContext, TOut> outputDecl)
            where TTrans : class, ITransformer
        {
            Contracts.CheckValue(env, nameof(env));
            env.CheckValue(estimator, nameof(estimator));
            env.CheckValue(inputDecl, nameof(inputDecl));
            env.CheckValue(outputDecl, nameof(outputDecl));

            var inSchema  = StaticSchemaShape.Make <TIn>(inputDecl.Method.ReturnParameter);
            var outSchema = StaticSchemaShape.Make <TOut>(outputDecl.Method.ReturnParameter);

            return(new Estimator <TIn, TOut, TTrans>(env, estimator, inSchema, outSchema));
        }