Schema.DetachedColumn[] IRowMapper.GetOutputColumns() { var dstRow = new DataViewConstructionUtils.InputRow <TDst>(_host, _parent.AddedSchema); // All the output columns of dstRow are our outputs. return(Enumerable.Range(0, dstRow.Schema.ColumnCount).Select(x => new Schema.DetachedColumn(dstRow.Schema[x])).ToArray()); }
public Schema.Column[] GetOutputColumns() { var dstRow = new DataViewConstructionUtils.InputRow <TDst>(_host, _parent._addedSchema); // All the output columns of dstRow are our outputs. return(Enumerable.Range(0, dstRow.Schema.ColumnCount).Select(x => dstRow.Schema[x]).ToArray()); }
private protected virtual void PredictionEngineCore(IHostEnvironment env, DataViewConstructionUtils.InputRow <TSrc> inputRow, IRowToRowMapper mapper, bool ignoreMissingColumns, SchemaDefinition outputSchemaDefinition, out Action disposer, out IRowReadableAs <TDst> outputRow) { var cursorable = TypedCursorable <TDst> .Create(env, new EmptyDataView(env, mapper.OutputSchema), ignoreMissingColumns, outputSchemaDefinition); var outputRowLocal = mapper.GetRow(inputRow, mapper.OutputSchema); outputRow = cursorable.GetRow(outputRowLocal); disposer = inputRow.Dispose; }
internal override void PredictionEngineCore(IHostEnvironment env, DataViewConstructionUtils.InputRow <TSrc> inputRow, IRowToRowMapper mapper, bool ignoreMissingColumns, SchemaDefinition inputSchemaDefinition, SchemaDefinition outputSchemaDefinition, out Action disposer, out IRowReadableAs <TDst> outputRow) { List <IStatefulRow> rows = new List <IStatefulRow>(); IRow outputRowLocal = outputRowLocal = GetStatefulRows(inputRow, mapper, col => true, rows, out disposer); var cursorable = TypedCursorable <TDst> .Create(env, new EmptyDataView(env, mapper.Schema), ignoreMissingColumns, outputSchemaDefinition); _pinger = CreatePinger(rows); outputRow = cursorable.GetRow(outputRowLocal); }
private protected PredictionEngineBase(IHostEnvironment env, ITransformer transformer, bool ignoreMissingColumns, SchemaDefinition inputSchemaDefinition = null, SchemaDefinition outputSchemaDefinition = null) { Contracts.CheckValue(env, nameof(env)); env.AssertValue(transformer); Transformer = transformer; var makeMapper = TransformerChecker(env, transformer); env.AssertValue(makeMapper); _inputRow = DataViewConstructionUtils.CreateInputRow <TSrc>(env, inputSchemaDefinition); PredictionEngineCore(env, _inputRow, makeMapper(_inputRow.Schema), ignoreMissingColumns, inputSchemaDefinition, outputSchemaDefinition, out _disposer, out _outputRow); }
public RowToRowMapper(IHostEnvironment env, StatefulCustomMappingTransformer <TSrc, TDst, TState> parent, IDataView input) : base(env, "StatefulCustom", input) { Host.CheckValue(parent, nameof(parent)); _parent = parent; var dstRow = new DataViewConstructionUtils.InputRow <TDst>(Host, _parent.AddedSchema); // All the output columns of dstRow are our outputs. var cols = Enumerable.Range(0, dstRow.Schema.Count).Select(x => new DataViewSchema.DetachedColumn(dstRow.Schema[x])).ToArray(); _bindings = new ColumnBindings(input.Schema, cols); _typedSrc = TypedCursorable <TSrc> .Create(Host, input, false, null); }
public Cursor(RowToRowMapper parent, DataViewRowCursor input, bool[] active) : base(parent.Host, input) { Ch.AssertValue(parent); Ch.Assert(active == null || active.Length == parent.OutputSchema.Count); _parent = parent; _active = active; _getters = new Delegate[parent._parent.AddedSchema.Columns.Length]; var dstRow = new DataViewConstructionUtils.InputRow <TDst>(_parent.Host, _parent._parent.AddedSchema); IRowReadableAs <TSrc> inputRow = _parent._typedSrc.GetRow(input); TSrc src = new TSrc(); TState state = new TState(); TDst dst = new TDst(); _parent._parent._stateInitAction(state); long lastServedPosition = -1; Action refresh = () => { if (lastServedPosition != input.Position) { inputRow.FillValues(src); _parent._parent._mapAction(src, dst, state); dstRow.ExtractValues(dst); lastServedPosition = input.Position; } }; for (int i = 0; i < active.Length; i++) { var iinfo = _parent._bindings.MapColumnIndex(out var isSrc, i); if (isSrc) { continue; } _getters[iinfo] = Utils.MarshalInvoke(_parent.GetDstGetter <int>, _parent._bindings.Schema[i].Type.RawType, dstRow, _parent._bindings.Schema[i].Name, refresh); } }
public Delegate[] CreateGetters(IRow input, Func <int, bool> activeOutput, out Action disposer) { disposer = null; // If no outputs are active, we short-circuit to empty array of getters. var result = new Delegate[_parent.AddedSchema.Columns.Length]; if (!Enumerable.Range(0, result.Length).Any(activeOutput)) { return(result); } var dstRow = new DataViewConstructionUtils.InputRow <TDst>(_host, _parent.AddedSchema); IRowReadableAs <TSrc> inputRow = _typedSrc.GetRow(input); TSrc src = new TSrc(); TDst dst = new TDst(); long lastServedPosition = -1; Action refresh = () => { if (lastServedPosition != input.Position) { inputRow.FillValues(src); _parent._mapAction(src, dst); dstRow.ExtractValues(dst); lastServedPosition = input.Position; } }; for (int i = 0; i < result.Length; i++) { if (!activeOutput(i)) { continue; } result[i] = Utils.MarshalInvoke(GetDstGetter <int>, dstRow.Schema[i].Type.RawType, dstRow, i, refresh); } return(result); }
protected override Delegate[] CreateGetters(DataViewRow input, IEnumerable <DataViewSchema.Column> activeColumns, out Action disp) { disp = null; var getters = new Delegate[_parent.AddedSchema.Columns.Length]; var dstRow = new DataViewConstructionUtils.InputRow <TDst>(Host, _parent.AddedSchema); IRowReadableAs <TSrc> inputRow = _typedSrc.GetRow(input); TSrc src = new TSrc(); TState state = new TState(); TDst dst = new TDst(); _parent._stateInitAction(state); long lastServedPosition = -1; Action refresh = () => { if (lastServedPosition != input.Position) { inputRow.FillValues(src); _parent._mapAction(src, dst, state); dstRow.ExtractValues(dst); lastServedPosition = input.Position; } }; foreach (var col in activeColumns) { var iinfo = _bindings.MapColumnIndex(out var isSrc, col.Index); if (isSrc) { continue; } getters[iinfo] = Utils.MarshalInvoke(GetDstGetter <int>, col.Type.RawType, dstRow, col.Name, refresh); } return(getters); }