コード例 #1
0
        /// <summary>
        /// Run the prediction pipe. This will enumerate the <paramref name="examples"/> exactly once,
        /// cache all the examples (by reference) into its internal representation and then run
        /// the transformation pipe.
        /// </summary>
        /// <param name="examples">The examples to run the prediction on.</param>
        /// <param name="reuseRowObjects">If <c>true</c>, the engine will not allocate memory per output, and
        /// the returned <typeparamref name="TDst"/> objects will actually always be the same object. The user is
        /// expected to clone the values himself if needed.</param>
        /// <returns>The <see cref="IEnumerable{TDst}"/> that contains all the pipeline results.</returns>
        public IEnumerable <TDst> Predict(IEnumerable <TSrc> examples, bool reuseRowObjects)
        {
            Contracts.CheckValue(examples, nameof(examples));

            _pipeEngine.Reset();
            _srcDataView.SetData(examples);
            return(_pipeEngine.RunPipe(reuseRowObjects));
        }
コード例 #2
0
        /// <summary>
        /// Convert an <see cref="IDataView"/> into a strongly-typed <see cref="IEnumerable{TRow}"/>.
        /// </summary>
        /// <typeparam name="TRow">The user-defined row type.</typeparam>
        /// <param name="data">The underlying data view.</param>
        /// <param name="env">The environment.</param>
        /// <param name="reuseRowObject">Whether to return the same object on every row, or allocate a new one per row.</param>
        /// <param name="ignoreMissingColumns">Whether to ignore the case when a requested column is not present in the data view.</param>
        /// <param name="schemaDefinition">Optional user-provided schema definition. If it is not present, the schema is inferred from the definition of T.</param>
        /// <returns>The <see cref="IEnumerable{TRow}"/> that holds the data in <paramref name="data"/>. It can be enumerated multiple times.</returns>
        public static IEnumerable <TRow> AsEnumerable <TRow>(this IDataView data, IHostEnvironment env, bool reuseRowObject,
                                                             bool ignoreMissingColumns = false, SchemaDefinition schemaDefinition = null)
            where TRow : class, new()
        {
            Contracts.AssertValue(env);
            env.CheckValue(data, nameof(data));
            env.CheckValueOrNull(schemaDefinition);

            var engine = new PipeEngine <TRow>(env, data, ignoreMissingColumns, schemaDefinition);

            return(engine.RunPipe(reuseRowObject));
        }