private static StatAggregator CreateStatAggregator(IChannel ch, DataViewType type, ReplacementKind?kind, bool bySlot, DataViewRowCursor cursor, int col) { ch.Assert(type.GetItemType() is NumberDataViewType); if (!(type is VectorType vectorType)) { // The type is a scalar. if (kind == ReplacementKind.Mean) { if (type.RawType == typeof(float)) { return(new R4.MeanAggregatorOne(ch, cursor, col)); } else if (type.RawType == typeof(double)) { return(new R8.MeanAggregatorOne(ch, cursor, col)); } } if (kind == ReplacementKind.Min || kind == ReplacementKind.Max) { if (type.RawType == typeof(float)) { return(new R4.MinMaxAggregatorOne(ch, cursor, col, kind == ReplacementKind.Max)); } else if (type.RawType == typeof(double)) { return(new R8.MinMaxAggregatorOne(ch, cursor, col, kind == ReplacementKind.Max)); } } }
public bool IsColumnSavable(DataViewType type) { _host.CheckValue(type, nameof(type)); // We can't transpose variable length columns at all, so nor can we save them. if (type is VectorType vectorType && !vectorType.IsKnownSize) { return(false); } // Since we'll be presumably saving vectors of these, attempt to construct // an artificial vector type out of this. Obviously if you can't make a vector // out of the items, then you could not save each slot's values. var itemType = type.GetItemType(); var primitiveType = itemType as PrimitiveDataViewType; if (primitiveType == null) { return(false); } var newVectorType = new VectorType(primitiveType, size: 2); return(_internalSaver.IsColumnSavable(newVectorType)); }
private Delegate GetIsNADelegate <T>(DataViewType type) => Data.Conversion.Conversions.Instance.GetIsNAPredicate <T>(type.GetItemType());
/// <summary> /// Returns the isNA predicate for the respective type. /// </summary> private Delegate GetIsNADelegate(DataViewType type) { Func <DataViewType, Delegate> func = GetIsNADelegate <int>; return(Utils.MarshalInvoke(func, type.GetItemType().RawType, type)); }
public CsrFiller(DataViewRow input, int idvColIndex, DataViewType type, DataAppender <TSrc> dataAppender, CsrData csrData) : base() { Contracts.AssertValue(input); Contracts.Assert(0 <= idvColIndex && idvColIndex < input.Schema.Count); if (type is VectorDataViewType) { _getVec = RowCursorUtils.GetVecGetterAs <TSrc>((PrimitiveDataViewType)type.GetItemType(), input, idvColIndex); } else { _get = RowCursorUtils.GetGetterAs <TSrc>(type, input, idvColIndex); } _csrData = csrData; _dataAppender = dataAppender; }
public static CsrFillerBase Create(EnvironmentBlock *penv, DataViewRow input, int idvCol, DataViewType idvColType, InternalDataKind outputDataKind, CsrData csrData) { if (outputDataKind == InternalDataKind.R4) { switch (idvColType.GetItemType().GetRawKind()) { case InternalDataKind.I1: DataAppender <sbyte> appendI1 = (sbyte val, int i) => csrData.AppendR4((float)val, i); return(new CsrFiller <sbyte>(input, idvCol, idvColType, appendI1, csrData)); case InternalDataKind.I2: DataAppender <short> appendI2 = (short val, int i) => csrData.AppendR4((float)val, i); return(new CsrFiller <short>(input, idvCol, idvColType, appendI2, csrData)); case InternalDataKind.U1: DataAppender <byte> appendU1 = (byte val, int i) => csrData.AppendR4((float)val, i); return(new CsrFiller <byte>(input, idvCol, idvColType, appendU1, csrData)); case InternalDataKind.U2: DataAppender <ushort> appendU2 = (ushort val, int i) => csrData.AppendR4((float)val, i); return(new CsrFiller <ushort>(input, idvCol, idvColType, appendU2, csrData)); case InternalDataKind.R4: DataAppender <float> appendR4 = (float val, int i) => csrData.AppendR4((float)val, i); return(new CsrFiller <float>(input, idvCol, idvColType, appendR4, csrData)); default: throw Contracts.Except("Source data type not supported"); } } else if (outputDataKind == InternalDataKind.R8) { switch (idvColType.GetItemType().GetRawKind()) { case InternalDataKind.I1: DataAppender <sbyte> appendI1 = (sbyte val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <sbyte>(input, idvCol, idvColType, appendI1, csrData)); case InternalDataKind.I2: DataAppender <short> appendI2 = (short val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <short>(input, idvCol, idvColType, appendI2, csrData)); case InternalDataKind.I4: DataAppender <int> appendI4 = (int val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <int>(input, idvCol, idvColType, appendI4, csrData)); case InternalDataKind.U1: DataAppender <byte> appendU1 = (byte val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <byte>(input, idvCol, idvColType, appendU1, csrData)); case InternalDataKind.U2: DataAppender <ushort> appendU2 = (ushort val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <ushort>(input, idvCol, idvColType, appendU2, csrData)); case InternalDataKind.U4: DataAppender <uint> appendU4 = (uint val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <uint>(input, idvCol, idvColType, appendU4, csrData)); case InternalDataKind.R4: DataAppender <float> appendR4 = (float val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <float>(input, idvCol, idvColType, appendR4, csrData)); case InternalDataKind.R8: DataAppender <double> appendR8 = (double val, int i) => csrData.AppendR8((double)val, i); return(new CsrFiller <double>(input, idvCol, idvColType, appendR8, csrData)); default: throw Contracts.Except("Source data type not supported"); } } throw Contracts.Except("Target data type not supported."); }
public Impl(DataViewRow input, int pyColIndex, int idvColIndex, DataViewType type, ValuePoker <TSrc> poker) : base(input, pyColIndex) { Contracts.AssertValue(input); Contracts.Assert(0 <= idvColIndex && idvColIndex < input.Schema.Count); if (type is VectorDataViewType) { _getVec = RowCursorUtils.GetVecGetterAs <TSrc>((PrimitiveDataViewType)type.GetItemType(), input, idvColIndex); } else { _get = RowCursorUtils.GetGetterAs <TSrc>(type, input, idvColIndex); } _poker = poker; }
public static BufferFillerBase Create(EnvironmentBlock *penv, DataViewRow input, int pyCol, int idvCol, InternalDataKind dataKind, DataViewType type, void *setter) { var itemType = type.GetItemType(); // We convert the unsigned types to signed types, with -1 indicating missing in Python. if (itemType.GetKeyCount() > 0) { var keyCount = itemType.GetKeyCount(); uint keyMax = (uint)keyCount; switch (itemType.GetRawKind()) { case InternalDataKind.U1: var fnI1 = MarshalDelegate <I1Setter>(setter); ValuePoker <byte> pokeU1 = (byte value, int col, long index) => fnI1(penv, col, index, value > keyMax ? (sbyte)-1 : (sbyte)(value - 1)); return(new Impl <byte>(input, pyCol, idvCol, type, pokeU1)); case InternalDataKind.U2: var fnI2 = MarshalDelegate <I2Setter>(setter); ValuePoker <ushort> pokeU2 = (ushort value, int col, long index) => fnI2(penv, col, index, value > keyMax ? (short)-1 : (short)(value - 1)); return(new Impl <ushort>(input, pyCol, idvCol, type, pokeU2)); case InternalDataKind.U4: var fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <uint> pokeU4 = (uint value, int col, long index) => fnI4(penv, col, index, value > keyMax ? -1 : (int)(value - 1)); return(new Impl <uint>(input, pyCol, idvCol, type, pokeU4)); case InternalDataKind.U8: // We convert U8 key types with key names to I4. fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <ulong> pokeU8 = (ulong value, int col, long index) => fnI4(penv, col, index, value > keyMax ? -1 : (int)(value - 1)); return(new Impl <ulong>(input, pyCol, idvCol, type, pokeU8)); } } // Key type with count=0 else if (itemType is KeyDataViewType) { switch (itemType.GetRawKind()) { case InternalDataKind.U1: var fnI1 = MarshalDelegate <I1Setter>(setter); ValuePoker <byte> pokeU1 = (byte value, int col, long index) => fnI1(penv, col, index, (sbyte)(value - 1)); return(new Impl <byte>(input, pyCol, idvCol, type, pokeU1)); case InternalDataKind.U2: var fnI2 = MarshalDelegate <I2Setter>(setter); ValuePoker <ushort> pokeU2 = (ushort value, int col, long index) => fnI2(penv, col, index, (short)(value - 1)); return(new Impl <ushort>(input, pyCol, idvCol, type, pokeU2)); case InternalDataKind.U4: var fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <uint> pokeU4 = (uint value, int col, long index) => fnI4(penv, col, index, (int)(value - 1)); return(new Impl <uint>(input, pyCol, idvCol, type, pokeU4)); case InternalDataKind.U8: // We convert U8 key types with key names to I4. fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <ulong> pokeU8 = (ulong value, int col, long index) => fnI4(penv, col, index, (int)(value - 1)); return(new Impl <ulong>(input, pyCol, idvCol, type, pokeU8)); } } else { switch (dataKind) { case InternalDataKind.R4: var fnR4 = MarshalDelegate <R4Setter>(setter); ValuePoker <float> pokeR4 = (float value, int col, long index) => fnR4(penv, col, index, value); return(new Impl <float>(input, pyCol, idvCol, type, pokeR4)); case InternalDataKind.R8: var fnR8 = MarshalDelegate <R8Setter>(setter); ValuePoker <double> pokeR8 = (double value, int col, long index) => fnR8(penv, col, index, value); return(new Impl <double>(input, pyCol, idvCol, type, pokeR8)); case InternalDataKind.BL: var fnBl = MarshalDelegate <BLSetter>(setter); ValuePoker <bool> pokeBl = (bool value, int col, long index) => fnBl(penv, col, index, !value ? (byte)0 : value ? (byte)1 : (byte)0xFF); return(new Impl <bool>(input, pyCol, idvCol, type, pokeBl)); case InternalDataKind.I1: var fnI1 = MarshalDelegate <I1Setter>(setter); ValuePoker <sbyte> pokeI1 = (sbyte value, int col, long index) => fnI1(penv, col, index, value); return(new Impl <sbyte>(input, pyCol, idvCol, type, pokeI1)); case InternalDataKind.I2: var fnI2 = MarshalDelegate <I2Setter>(setter); ValuePoker <short> pokeI2 = (short value, int col, long index) => fnI2(penv, col, index, value); return(new Impl <short>(input, pyCol, idvCol, type, pokeI2)); case InternalDataKind.I4: var fnI4 = MarshalDelegate <I4Setter>(setter); ValuePoker <int> pokeI4 = (int value, int col, long index) => fnI4(penv, col, index, value); return(new Impl <int>(input, pyCol, idvCol, type, pokeI4)); case InternalDataKind.I8: var fnI8 = MarshalDelegate <I8Setter>(setter); ValuePoker <long> pokeI8 = (long value, int col, long index) => fnI8(penv, col, index, value); return(new Impl <long>(input, pyCol, idvCol, type, pokeI8)); case InternalDataKind.U1: var fnU1 = MarshalDelegate <U1Setter>(setter); ValuePoker <byte> pokeU1 = (byte value, int col, long index) => fnU1(penv, col, index, value); return(new Impl <byte>(input, pyCol, idvCol, type, pokeU1)); case InternalDataKind.U2: var fnU2 = MarshalDelegate <U2Setter>(setter); ValuePoker <ushort> pokeU2 = (ushort value, int col, long index) => fnU2(penv, col, index, value); return(new Impl <ushort>(input, pyCol, idvCol, type, pokeU2)); case InternalDataKind.U4: var fnU4 = MarshalDelegate <U4Setter>(setter); ValuePoker <uint> pokeU4 = (uint value, int col, long index) => fnU4(penv, col, index, value); return(new Impl <uint>(input, pyCol, idvCol, type, pokeU4)); case InternalDataKind.U8: var fnU8 = MarshalDelegate <U8Setter>(setter); ValuePoker <ulong> pokeU8 = (ulong value, int col, long index) => fnU8(penv, col, index, value); return(new Impl <ulong>(input, pyCol, idvCol, type, pokeU8)); case InternalDataKind.TX: var fnTX = MarshalDelegate <TXSetter>(setter); ValuePoker <ReadOnlyMemory <char> > pokeTX = (ReadOnlyMemory <char> value, int col, long index) => { if (value.IsEmpty) { fnTX(penv, col, index, null, 0); } else { byte[] bt = Encoding.UTF8.GetBytes(value.ToString()); fixed(byte *pt = bt) fnTX(penv, col, index, (sbyte *)pt, bt.Length); } }; return(new Impl <ReadOnlyMemory <char> >(input, pyCol, idvCol, type, pokeTX)); default: throw Contracts.Except("Data type not handled"); } } Contracts.Assert(false, "Unhandled type!"); return(null); }