Пример #1
0
 private static bool OutputTypeMatches(ColumnType scoreType)
 {
     return(scoreType is VectorType vectorType &&
            vectorType.IsKnownSize &&
            vectorType.ItemType == NumberType.Float);
 }
Пример #2
0
 public GetterInfoPrimitive(string kind, ColumnType type, TValue value)
     : base(kind, type)
 {
     Contracts.Check(type.RawType == typeof(TValue), "Incompatible types");
     Value = value;
 }
Пример #3
0
 private static ColumnType GetPredColType(ColumnType scoreType, ISchemaBoundRowMapper mapper)
 {
     return(new KeyType(typeof(uint), scoreType.GetVectorSize()));
 }
Пример #4
0
 public static string TestGetLabelGetter(ColumnType type)
 {
     return(TestGetLabelGetter(type, true));
 }
Пример #5
0
        private static ValueGetter <TDst> GetGetterAsCore <TSrc, TDst>(ColumnType typeSrc, ColumnType typeDst, Row row, int col)
        {
            Contracts.Assert(typeof(TSrc) == typeSrc.RawType);
            Contracts.Assert(typeof(TDst) == typeDst.RawType);

            var  getter = row.GetGetter <TSrc>(col);
            bool identity;
            var  conv = Conversions.Instance.GetStandardConversion <TSrc, TDst>(typeSrc, typeDst, out identity);

            if (identity)
            {
                Contracts.Assert(typeof(TSrc) == typeof(TDst));
                return((ValueGetter <TDst>)(Delegate) getter);
            }

            var src = default(TSrc);

            return
                ((ref TDst dst) =>
            {
                getter(ref src);
                conv(in src, ref dst);
            });
        }
            //private Delegate CreateGetter(SchemaProxy schema, int index, Delegate peek)
            private Delegate CreateGetter(ColumnType colType, InternalSchemaDefinition.Column column, Delegate peek)
            {
                var outputType  = column.OutputType;
                var genericType = outputType;
                Func <Delegate, Delegate> del;

                if (outputType.IsArray)
                {
                    VectorType vectorType = colType as VectorType;
                    Host.Assert(vectorType != null);

                    // String[] -> ReadOnlyMemory<char>
                    if (outputType.GetElementType() == typeof(string))
                    {
                        Host.Assert(vectorType.ItemType is TextType);
                        return(CreateConvertingArrayGetterDelegate <string, ReadOnlyMemory <char> >(peek, x => x != null ? x.AsMemory() : ReadOnlyMemory <char> .Empty));
                    }

                    // T[] -> VBuffer<T>
                    if (outputType.GetElementType().IsGenericType&& outputType.GetElementType().GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        Host.Assert(Nullable.GetUnderlyingType(outputType.GetElementType()) == vectorType.ItemType.RawType);
                    }
                    else
                    {
                        Host.Assert(outputType.GetElementType() == vectorType.ItemType.RawType);
                    }
                    del         = CreateDirectArrayGetterDelegate <int>;
                    genericType = outputType.GetElementType();
                }
                else if (colType is VectorType vectorType)
                {
                    // VBuffer<T> -> VBuffer<T>
                    // REVIEW: Do we care about accomodating VBuffer<string> -> ReadOnlyMemory<char>?
                    Host.Assert(outputType.IsGenericType);
                    Host.Assert(outputType.GetGenericTypeDefinition() == typeof(VBuffer <>));
                    Host.Assert(outputType.GetGenericArguments()[0] == vectorType.ItemType.RawType);
                    del         = CreateDirectVBufferGetterDelegate <int>;
                    genericType = vectorType.ItemType.RawType;
                }
                else if (colType is PrimitiveType)
                {
                    if (outputType == typeof(string))
                    {
                        // String -> ReadOnlyMemory<char>
                        Host.Assert(colType is TextType);
                        return(CreateConvertingGetterDelegate <String, ReadOnlyMemory <char> >(peek, x => x != null ? x.AsMemory() : ReadOnlyMemory <char> .Empty));
                    }

                    // T -> T
                    if (outputType.IsGenericType && outputType.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        Host.Assert(colType.RawType == Nullable.GetUnderlyingType(outputType));
                    }
                    else
                    {
                        Host.Assert(colType.RawType == outputType);
                    }

                    if (!(colType is KeyType keyType))
                    {
                        del = CreateDirectGetterDelegate <int>;
                    }
                    else
                    {
                        var keyRawType = colType.RawType;
                        Host.Assert(keyType.Contiguous);
                        Func <Delegate, ColumnType, Delegate> delForKey = CreateKeyGetterDelegate <uint>;
                        return(Utils.MarshalInvoke(delForKey, keyRawType, peek, colType));
                    }
                }
Пример #7
0
        private static ValueGetter <StringBuilder> GetGetterAsStringBuilderCore <TSrc>(ColumnType typeSrc, Row row, int col)
        {
            Contracts.Assert(typeof(TSrc) == typeSrc.RawType);

            var getter = row.GetGetter <TSrc>(col);
            var conv   = Conversions.Instance.GetStringConversion <TSrc>(typeSrc);

            var src = default(TSrc);

            return
                ((ref StringBuilder dst) =>
            {
                getter(ref src);
                conv(in src, ref dst);
            });
        }
Пример #8
0
 internal static KeyValuePair <string, ColumnType> GetPair(this ColumnType type, string kind)
 {
     Contracts.CheckValue(type, nameof(type));
     return(new KeyValuePair <string, ColumnType>(kind, type));
 }
            public FeatureContributionSchema(IExceptionContext ectx, string columnName, ColumnType columnType, Schema parentSchema, int featureCol)
            {
                Contracts.CheckValueOrNull(ectx);
                Contracts.CheckValue(parentSchema, nameof(parentSchema));
                _ectx = ectx;
                _ectx.CheckNonEmpty(columnName, nameof(columnName));
                _parentSchema      = parentSchema;
                _featureCol        = featureCol;
                _featureVectorSize = _parentSchema[_featureCol].Type.VectorSize;
                _hasSlotNames      = _parentSchema[_featureCol].HasSlotNames(_featureVectorSize);

                _names         = new string[] { columnName };
                _types         = new ColumnType[] { columnType };
                _columnNameMap = new Dictionary <string, int>()
                {
                    { columnName, 0 }
                };
            }
Пример #10
0
 private Delegate CreateGetterDelegateCore <TValue>(int col, ColumnType type)
 {
     return((Delegate)GetterDelegateCore <TValue>(col, type));
 }
Пример #11
0
 private static bool OutputTypeMatches(ColumnType scoreType)
 => scoreType == NumberType.Float;
Пример #12
0
 public Column(ColumnType type)
 {
     Type = type;
 }