public SlotCursor(IChannelProvider provider, ISlotCursor cursor, VectorType typeDst) : base(provider, TransposerUtils.GetRowCursorShim(provider, cursor)) { Ch.Assert(Input.Schema.ColumnCount == 1); Ch.Assert(Input.Schema.GetColumnType(0) == cursor.GetSlotType()); Ch.AssertValue(typeDst); _getter = RowCursorUtils.GetVecGetterAs(typeDst.ItemType, Input, 0); _type = typeDst; }
protected override ISlotCursor GetSlotCursorCore(int iinfo) { Host.Assert(0 <= iinfo && iinfo < Infos.Length); Host.AssertValue(Infos[iinfo].SlotTypeSrc); ISlotCursor cursor = InputTranspose.GetSlotCursor(Infos[iinfo].Source); return(new SlotCursor(Host, cursor, GetSlotTypeCore(iinfo))); }
public SlotCursor(NAReplaceTransform parent, int iinfo, ISlotCursor cursor, VectorType type) : base(parent.Host, cursor) { Ch.Assert(0 <= iinfo && iinfo < parent.Infos.Length); Ch.AssertValue(cursor); Ch.AssertValue(type); var srcGetter = cursor.GetGetter <T>(); _type = type; _getter = CreateGetter(parent, iinfo, cursor, type); }
protected override ISlotCursor GetSlotCursorCore(int iinfo) { Host.Assert(0 <= iinfo && iinfo < Infos.Length); Host.AssertValue(Infos[iinfo].SlotTypeSrc); ISlotCursor cursor = InputTranspose.GetSlotCursor(Infos[iinfo].Source); var type = GetSlotTypeCore(iinfo); Host.AssertValue(type); return(Utils.MarshalInvoke(GetSlotCursorCore <int>, type.ItemType.RawType, this, iinfo, cursor, type)); }
private void InitVec <T>(int col) { var type = Schema.GetColumnType(col); Ch.Assert(type.IsVector); Ch.Assert(typeof(T) == type.ItemType.RawType); var trans = _parent.EnsureAndGetTransposer(col); ISlotCursor cursor = trans.GetSlotCursor(0); ValueGetter <VBuffer <T> > getter = cursor.GetGetter <T>(); int i = _colToActivesIndex[col]; _getters[i] = getter; _transCursors[i] = cursor; }
public static ValueGetter <VBuffer <Single> > GetLabelGetter(ISlotCursor cursor) { var type = cursor.GetSlotType().ItemType; if (type == NumberType.R4) { return(cursor.GetGetter <Single>()); } if (type == NumberType.R8 || type.IsBool) { return(GetVecGetterAs <Single>(NumberType.R4, cursor)); } Contracts.Check(type.IsKey, "Only floating point number, boolean, and key type values can be used as label."); Contracts.Assert(TestGetLabelGetter(type) == null); ulong keyMax = (ulong)type.KeyCount; if (keyMax == 0) { keyMax = ulong.MaxValue; } var getSrc = RowCursorUtils.GetVecGetterAs <ulong>(NumberType.U8, cursor); VBuffer <ulong> src = default(VBuffer <ulong>); return ((ref VBuffer <Single> dst) => { getSrc(ref src); // Unfortunately defaults in one to not translate to defaults of the other, // so this will not be sparsity preserving. Assume a dense output. Single[] vals = dst.Values; Utils.EnsureSize(ref vals, src.Length); foreach (var kv in src.Items(all: true)) { if (0 < kv.Value && kv.Value <= keyMax) { vals[kv.Key] = kv.Value - 1; } else { vals[kv.Key] = Single.NaN; } } dst = new VBuffer <Single>(src.Length, vals, dst.Indices); }); }
private void InitOne <T>(int col) { var type = Schema.GetColumnType(col); Ch.Assert(typeof(T) == type.RawType); var trans = _parent.EnsureAndGetTransposer(col); ISlotCursor cursor = trans.GetSlotCursor(0); ValueGetter <VBuffer <T> > getter = cursor.GetGetter <T>(); VBuffer <T> buff = default(VBuffer <T>); ValueGetter <T> oneGetter = (ref T value) => { getter(ref buff); Ch.Assert(buff.Length == 1); buff.GetItemOrDefault(0, ref value); }; int i = _colToActivesIndex[col]; _getters[i] = oneGetter; _transCursors[i] = cursor; }
public SlotImpl(ISlotCursor cursor) { _cursor = cursor; }
public static GetterFactory Create(ISlotCursor cursor) { return(new SlotImpl(cursor)); }
/// <summary> /// Given the item type, typeDst, and a slot cursor, return a ValueGetter{VBuffer{TDst}} for the /// vector-valued column with a conversion to a vector of typeDst, if needed. /// </summary> public static ValueGetter <VBuffer <TDst> > GetVecGetterAs <TDst>(PrimitiveType typeDst, ISlotCursor cursor) { Contracts.CheckValue(typeDst, nameof(typeDst)); Contracts.CheckParam(typeDst.RawType == typeof(TDst), nameof(typeDst)); var typeSrc = cursor.GetSlotType(); Func <VectorType, PrimitiveType, GetterFactory, ValueGetter <VBuffer <TDst> > > del = GetVecGetterAsCore <int, TDst>; var methodInfo = del.GetMethodInfo().GetGenericMethodDefinition().MakeGenericMethod(typeSrc.ItemType.RawType, typeof(TDst)); return((ValueGetter <VBuffer <TDst> >)methodInfo.Invoke(null, new object[] { typeSrc, typeDst, GetterFactory.Create(cursor) })); }
private ValueGetter <VBuffer <T> > CreateGetter(NAReplaceTransform parent, int iinfo, ISlotCursor cursor, VectorType type) { var src = default(VBuffer <T>); ValueGetter <VBuffer <T> > getter; var getSrc = cursor.GetGetter <T>(); var isNA = (RefPredicate <T>)parent._isNAs[iinfo]; var isDefault = Conversions.Instance.GetIsDefaultPredicate <T>(type.ItemType); if (parent._repIsDefault[iinfo] == null) { // One replacement value for all slots. Ch.Assert(parent._repValues[iinfo] is T); T rep = (T)parent._repValues[iinfo]; bool repIsDefault = isDefault(ref rep); return((ref VBuffer <T> dst) => { getSrc(ref src); parent.FillValues(ref src, ref dst, isNA, rep, repIsDefault); }); } // Replacement values by slot. Ch.Assert(parent._repValues[iinfo] is T[]); // The replacement array. T[] repArray = (T[])parent._repValues[iinfo]; return(getter = (ref VBuffer <T> dst) => { getSrc(ref src); Ch.Check(0 <= Position && Position < repArray.Length); T rep = repArray[(int)Position]; parent.FillValues(ref src, ref dst, isNA, rep, isDefault(ref rep)); }); }
private ISlotCursor GetSlotCursorCore <T>(NAReplaceTransform parent, int iinfo, ISlotCursor cursor, VectorType type) => new SlotCursor <T>(parent, iinfo, cursor, type);