Exemplo n.º 1
0
            public ValueGetter <TValue> GetGetterCore <TValue>(int col, Action checkIsGood)
            {
                bool isSrc;
                int  index = _parent._bindings.MapColumnIndex(out isSrc, col);

                if (isSrc)
                {
                    return(_input.GetGetter <TValue>(index));
                }

                var appendedGetter = _appendedRow.GetGetter <TValue>(index);

                return
                    ((ref TValue value) =>
                {
                    checkIsGood?.Invoke();
                    if (_lastServedPosition != _input.Position)
                    {
                        _input.FillValues(_src);
                        // REVIEW: what if this throws? Maybe swallow the exception?
                        _parent._mapAction(_src, _dst);
                        _lastServedPosition = _input.Position;
                    }

                    appendedGetter(ref value);
                });
            }
            public Cursor(StatefulCustomMappingFilter <TSrc, TState> parent, DataViewRowCursor input, bool[] active)
                : base(parent.Host, input, input.Schema, active)
            {
                Contracts.AssertValue(parent);

                IRowReadableAs <TSrc> inputRow = parent.TypedSrc.GetRow(input);

                TSrc   src   = new TSrc();
                TState state = new TState();

                parent._stateInitAction(state);
                long   lastServedPosition = -1;
                Action refresh            = () =>
                {
                    if (lastServedPosition != input.Position)
                    {
                        inputRow.FillValues(src);
                        lastServedPosition = input.Position;
                    }
                };

                var predicate = parent._predicate;

                _accept = () =>
                {
                    refresh();
                    return(!predicate(src, state));
                };
            }
 /// <summary>
 /// Run prediction pipeline on one example.
 /// </summary>
 /// <param name="example">The example to run on.</param>
 /// <param name="prediction">The object to store the prediction in. If it's <c>null</c>, a new one will be created, otherwise the old one
 /// is reused.</param>
 public void Predict(TSrc example, ref TDst prediction)
 {
     Contracts.CheckValue(example, nameof(example));
     _inputRow.ExtractValues(example);
     if (prediction == null)
     {
         prediction = new TDst();
     }
     _outputRow.FillValues(prediction);
 }
 /// <summary>
 /// Run prediction pipeline on one example.
 /// </summary>
 /// <param name="example">The example to run on.</param>
 /// <returns>The result of prediction. A new object is created for every call.</returns>
 public TDst Predict(TSrc example)
 {
     Contracts.CheckValue(example, nameof(example));
     _inputRow.ExtractValues(example);
     if (_result == null)
     {
         _result = new TDst();
     }
     _outputRow.FillValues(_result);
     return(_result);
 }
Exemplo n.º 5
0
                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);
                    }
                }
Exemplo n.º 6
0
            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);
            }
Exemplo n.º 7
0
            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);
            }
 protected void FillValues(TDst prediction) => _outputRow.FillValues(prediction);