public SynchronizedSlotCursor(IChannelProvider provider, SlotCursor cursor) : base(provider) { Contracts.AssertValue(cursor); // If the input is itself a sync-base, we can walk up the chain to get its root, // thereby making things more efficient. _root = cursor is SynchronizedSlotCursor sync ? sync._root : cursor; }
internal static ValueGetter <VBuffer <Single> > GetLabelGetter(SlotCursor cursor) { var type = cursor.GetSlotType().ItemType; if (type == NumberDataViewType.Single) { return(cursor.GetGetter <Single>()); } if (type == NumberDataViewType.Double || type is BooleanDataViewType) { return(GetVecGetterAs <Single>(NumberDataViewType.Single, cursor)); } if (!(type is KeyType keyType)) { throw Contracts.Except("Only floating point number, boolean, and key type values can be used as label."); } Contracts.Assert(TestGetLabelGetter(type) == null); ulong keyMax = (ulong)keyType.Count; if (keyMax == 0) { keyMax = ulong.MaxValue; } var getSrc = RowCursorUtils.GetVecGetterAs <ulong>(NumberDataViewType.UInt64, 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. var editor = VBufferEditor.Create(ref dst, src.Length); foreach (var kv in src.Items(all: true)) { if (0 < kv.Value && kv.Value <= keyMax) { editor.Values[kv.Key] = kv.Value - 1; } else { editor.Values[kv.Key] = Single.NaN; } } dst = editor.Commit(); }); }
public SlotImpl(SlotCursor cursor) { _cursor = cursor; }
public static GetterFactory Create(SlotCursor cursor) { return(new SlotImpl(cursor)); }
internal static ValueGetter <VBuffer <TDst> > GetVecGetterAs <TDst>(PrimitiveDataViewType typeDst, SlotCursor cursor) { Contracts.CheckValue(typeDst, nameof(typeDst)); Contracts.CheckParam(typeDst.RawType == typeof(TDst), nameof(typeDst)); var typeSrc = cursor.GetSlotType(); Func <VectorType, PrimitiveDataViewType, 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) })); }