public RowCursor(IChannelProvider provider, OneToOneTransformBase parent, IRowCursor input, bool[] active) : base(provider, input) { Ch.AssertValue(parent); Ch.Assert(active == null || active.Length == parent._bindings.ColumnCount); _bindings = parent._bindings; _active = active; _getters = new Delegate[parent.Infos.Length]; // Build the delegates. List <Action> disposers = null; for (int iinfo = 0; iinfo < _getters.Length; iinfo++) { if (!IsColumnActive(parent._bindings.MapIinfoToCol(iinfo))) { continue; } Action disposer; _getters[iinfo] = parent.GetGetterCore(Ch, Input, iinfo, out disposer); if (disposer != null) { Utils.Add(ref disposers, disposer); } } if (Utils.Size(disposers) > 0) { _disposers = disposers.ToArray(); } }
public Cursor(IChannelProvider provider, OneToOneTransformBase parent, RowCursor input, bool[] active) : base(provider, input) { Ch.AssertValue(parent); Ch.Assert(active == null || active.Length == parent._bindings.ColumnCount); _bindings = parent._bindings; _active = active; _getters = new Delegate[parent.Infos.Length]; // Build the disposing delegate. Action masterDisposer = null; for (int iinfo = 0; iinfo < _getters.Length; iinfo++) { if (!IsColumnActive(parent._bindings.MapIinfoToCol(iinfo))) { continue; } _getters[iinfo] = parent.GetGetterCore(Ch, Input, iinfo, out Action disposer); if (disposer != null) { masterDisposer += disposer; } } _disposer = masterDisposer; }
public static Bindings Create(OneToOneTransformBase parent, ModelLoadContext ctx, ISchema input, ITransposeSchema transInput, Func <ColumnType, string> testType) { Contracts.AssertValue(parent); var host = parent.Host; host.CheckValue(ctx, nameof(ctx)); host.AssertValue(input); host.AssertValueOrNull(transInput); host.AssertValueOrNull(testType); // *** Binary format *** // int: number of added columns // for each added column // int: id of output column name // int: id of input column name int cinfo = ctx.Reader.ReadInt32(); host.CheckDecode(cinfo > 0); var names = new string[cinfo]; var infos = new ColInfo[cinfo]; for (int i = 0; i < cinfo; i++) { string dst = ctx.LoadNonEmptyString(); names[i] = dst; // Note that in old files, the source name may be null indicating that // the source column has the same name as the added column. string tmp = ctx.LoadStringOrNull(); string src = tmp ?? dst; host.CheckDecode(!string.IsNullOrEmpty(src)); int colSrc; if (!input.TryGetColumnIndex(src, out colSrc)) { throw host.Except("Source column '{0}' is required but not found", src); } var type = input.GetColumnType(colSrc); if (testType != null) { string reason = testType(type); if (reason != null) { throw host.Except(InvalidTypeErrorFormat, src, type, reason); } } var slotType = transInput == null ? null : transInput.GetSlotType(colSrc); infos[i] = new ColInfo(dst, colSrc, type, slotType); } return(new Bindings(parent, infos, input, false, names)); }
private Bindings(OneToOneTransformBase parent, ColInfo[] infos, ISchema input, bool user, string[] names) : base(input, user, names) { Contracts.AssertValue(parent); Contracts.AssertValue(parent.Host); Contracts.Assert(Utils.Size(infos) == InfoCount); _parent = parent; _inputTransposed = _parent.InputTranspose == null ? null : _parent.InputTranspose.TransposeSchema; Contracts.Assert((_inputTransposed == null) == (_parent.InputTranspose == null)); Infos = infos; }
/// <summary> /// Re-applying constructor. /// </summary> protected OneToOneTransformBase(IHostEnvironment env, string name, OneToOneTransformBase transform, IDataView newInput, Func <ColumnType, string> checkType) : base(env, name, newInput) { Host.CheckValueOrNull(checkType); InputTranspose = Source as ITransposeDataView; OneToOneColumn[] map = transform.Infos .Select(x => new ColumnTmp { Name = x.Name, Source = transform.Source.Schema.GetColumnName(x.Source), }) .ToArray(); _bindings = Bindings.Create(this, map, newInput.Schema, InputTransposeSchema, checkType); Infos = _bindings.Infos; Metadata = new MetadataDispatcher(Infos.Length); }
public static Bindings Create(OneToOneTransformBase parent, OneToOneColumn[] column, ISchema input, ITransposeSchema transInput, Func <ColumnType, string> testType) { Contracts.AssertValue(parent); var host = parent.Host; host.CheckUserArg(Utils.Size(column) > 0, nameof(column)); host.AssertValue(input); host.AssertValueOrNull(transInput); host.AssertValueOrNull(testType); var names = new string[column.Length]; var infos = new ColInfo[column.Length]; for (int i = 0; i < names.Length; i++) { var item = column[i]; host.CheckUserArg(item.TrySanitize(), nameof(OneToOneColumn.Name), "Invalid new column name"); names[i] = item.Name; int colSrc; if (!input.TryGetColumnIndex(item.Source, out colSrc)) { throw host.ExceptUserArg(nameof(OneToOneColumn.Source), "Source column '{0}' not found", item.Source); } var type = input.GetColumnType(colSrc); if (testType != null) { string reason = testType(type); if (reason != null) { throw host.ExceptUserArg(nameof(OneToOneColumn.Source), InvalidTypeErrorFormat, item.Source, type, reason); } } var slotType = transInput == null ? null : transInput.GetSlotType(colSrc); infos[i] = new ColInfo(names[i], colSrc, type, slotType); } return(new Bindings(parent, infos, input, true, names)); }