Esempio n. 1
0
            public CsrData(EnvironmentBlock *penv, void **setters, InternalDataKind outputDataKind)
            {
                col = 0;

                _row   = 0;
                _index = 0;
                _penv  = penv;

                if (outputDataKind == InternalDataKind.R4)
                {
                    _r4DataSetter = MarshalDelegate <R4Setter>(setters[DataCol]);
                    _r8DataSetter = null;
                }
                else if (outputDataKind == InternalDataKind.R8)
                {
                    _r4DataSetter = null;
                    _r8DataSetter = MarshalDelegate <R8Setter>(setters[DataCol]);
                }

                _indicesSetter = MarshalDelegate <I4Setter>(setters[IndicesCol]);
                _indptrSetter  = MarshalDelegate <I4Setter>(setters[IndPtrCol]);
                _shapeSetter   = MarshalDelegate <I4Setter>(setters[ShapeCol]);

                _indptrSetter(_penv, IndPtrCol, 0, 0);
            }
Esempio n. 2
0
        /// <summary>
        /// For integer DataKinds, this returns the minimum legal value. For un-supported kinds,
        /// it returns one.
        /// </summary>
        public static long ToMinInt(this InternalDataKind kind)
        {
            switch (kind)
            {
            case InternalDataKind.I1:
                return(sbyte.MinValue);

            case InternalDataKind.U1:
                return(byte.MinValue);

            case InternalDataKind.I2:
                return(short.MinValue);

            case InternalDataKind.U2:
                return(ushort.MinValue);

            case InternalDataKind.I4:
                return(int.MinValue);

            case InternalDataKind.U4:
                return(uint.MinValue);

            case InternalDataKind.I8:
                return(long.MinValue);

            case InternalDataKind.U8:
                return(0);
            }

            return(1);
        }
Esempio n. 3
0
 // Contstuct a representation for a key-typed column loaded from a text file. Key values are assumed to be contiguous.
 public MyKey(Reconciler rec, InternalDataKind kind, int oridinal, ulong?keyCount = null)
     : base(rec, null)
 {
     _kind     = kind;
     _oridinal = oridinal;
     _keyCount = keyCount;
 }
Esempio n. 4
0
 public MyVector(Reconciler rec, InternalDataKind kind, int min, int?max)
     : base(rec, null)
 {
     _kind = kind;
     _min  = min;
     _max  = max;
 }
Esempio n. 5
0
        /// <summary>
        /// For integer DataKinds, this returns the maximum legal value. For un-supported kinds,
        /// it returns zero.
        /// </summary>
        public static ulong ToMaxInt(this InternalDataKind kind)
        {
            switch (kind)
            {
            case InternalDataKind.I1:
                return((ulong)sbyte.MaxValue);

            case InternalDataKind.U1:
                return(byte.MaxValue);

            case InternalDataKind.I2:
                return((ulong)short.MaxValue);

            case InternalDataKind.U2:
                return(ushort.MaxValue);

            case InternalDataKind.I4:
                return(int.MaxValue);

            case InternalDataKind.U4:
                return(uint.MaxValue);

            case InternalDataKind.I8:
                return(long.MaxValue);

            case InternalDataKind.U8:
                return(ulong.MaxValue);
            }

            return(0);
        }
 public static PrimitiveDataViewType PrimitiveTypeFromKind(InternalDataKind kind)
 {
     if (kind == InternalDataKind.TX)
     {
         return(TextDataViewType.Instance);
     }
     if (kind == InternalDataKind.BL)
     {
         return(BooleanDataViewType.Instance);
     }
     if (kind == InternalDataKind.TS)
     {
         return(TimeSpanDataViewType.Instance);
     }
     if (kind == InternalDataKind.DT)
     {
         return(DateTimeDataViewType.Instance);
     }
     if (kind == InternalDataKind.DZ)
     {
         return(DateTimeOffsetDataViewType.Instance);
     }
     if (kind == InternalDataKind.UG)
     {
         return(RowIdDataViewType.Instance);
     }
     return(NumberTypeFromKind(kind));
 }
        /// <summary>
        /// Attempt to parse the string into a data kind and (optionally) a keyCount. This method does not check whether
        /// the returned <see cref="InternalDataKind"/> can really be made into a key with the specified <paramref name="keyCount"/>.
        /// </summary>
        /// <param name="str">The string to parse.</param>
        /// <param name="dataKind">The parsed data kind.</param>
        /// <param name="keyCount">The parsed key count, or null if there's no key specification.</param>
        /// <returns>Whether the parsing succeeded or not.</returns>
        public static bool TryParseDataKind(string str, out InternalDataKind dataKind, out KeyCount keyCount)
        {
            Contracts.CheckValue(str, nameof(str));
            keyCount = null;
            dataKind = default;

            int ich = str.IndexOf('[');

            if (0 <= ich)
            {
                if (str[str.Length - 1] != ']')
                {
                    return(false);
                }
                keyCount = KeyCount.Parse(str.Substring(ich + 1, str.Length - ich - 2));
                if (keyCount == null)
                {
                    return(false);
                }
                if (ich == 0)
                {
                    return(true);
                }
                str = str.Substring(0, ich);
            }

            if (!Enum.TryParse(str, true, out dataKind))
            {
                return(false);
            }

            return(true);
        }
        public static DataKind Internal2DataKind(InternalDataKind kind)
        {
            switch (kind)
            {
            case InternalDataKind.BL: return(DataKind.Boolean);

            case InternalDataKind.I1: return(DataKind.SByte);

            case InternalDataKind.U1: return(DataKind.Byte);

            case InternalDataKind.I2: return(DataKind.Int16);

            case InternalDataKind.U2: return(DataKind.UInt16);

            case InternalDataKind.I4: return(DataKind.Int32);

            case InternalDataKind.U4: return(DataKind.UInt32);

            case InternalDataKind.I8: return(DataKind.Int64);

            case InternalDataKind.U8: return(DataKind.UInt64);

            case InternalDataKind.R4: return(DataKind.Single);

            case InternalDataKind.R8: return(DataKind.Double);

            case InternalDataKind.TX: return(DataKind.String);

            default:
                throw Contracts.ExceptNotImpl($"Datakind not implemented for kind {kind}.");
            }
        }
Esempio n. 9
0
            private Vector <T> Load <T>(InternalDataKind kind, int minOrdinal, int?maxOrdinal)
            {
                Contracts.CheckParam(minOrdinal >= 0, nameof(minOrdinal), "Should be non-negative");
                var v = maxOrdinal >= minOrdinal;

                Contracts.CheckParam(!(maxOrdinal < minOrdinal), nameof(maxOrdinal), "If specified, cannot be less than " + nameof(minOrdinal));
                return(new MyVector <T>(_rec, kind, minOrdinal, maxOrdinal));
            }
Esempio n. 10
0
        /// <summary>
        /// Maps a DataKind to the associated .Net representation type.
        /// </summary>
        public static Type ToType(this InternalDataKind kind)
        {
            switch (kind)
            {
            case InternalDataKind.I1:
                return(typeof(sbyte));

            case InternalDataKind.U1:
                return(typeof(byte));

            case InternalDataKind.I2:
                return(typeof(short));

            case InternalDataKind.U2:
                return(typeof(ushort));

            case InternalDataKind.I4:
                return(typeof(int));

            case InternalDataKind.U4:
                return(typeof(uint));

            case InternalDataKind.I8:
                return(typeof(long));

            case InternalDataKind.U8:
                return(typeof(ulong));

            case InternalDataKind.R4:
                return(typeof(Single));

            case InternalDataKind.R8:
                return(typeof(Double));

            case InternalDataKind.TX:
                return(typeof(ReadOnlyMemory <char>));

            case InternalDataKind.BL:
                return(typeof(bool));

            case InternalDataKind.TS:
                return(typeof(TimeSpan));

            case InternalDataKind.DT:
                return(typeof(DateTime));

            case InternalDataKind.DZ:
                return(typeof(DateTimeOffset));

            case InternalDataKind.UG:
                return(typeof(DataViewRowId));
            }

            return(null);
        }
Esempio n. 11
0
        /// <summary>
        /// Get the canonical string for a DataKind. Note that using DataKind.ToString() is not stable
        /// and is also slow, so use this instead.
        /// </summary>
        public static string GetString(this InternalDataKind kind)
        {
            switch (kind)
            {
            case InternalDataKind.I1:
                return("I1");

            case InternalDataKind.I2:
                return("I2");

            case InternalDataKind.I4:
                return("I4");

            case InternalDataKind.I8:
                return("I8");

            case InternalDataKind.U1:
                return("U1");

            case InternalDataKind.U2:
                return("U2");

            case InternalDataKind.U4:
                return("U4");

            case InternalDataKind.U8:
                return("U8");

            case InternalDataKind.R4:
                return("R4");

            case InternalDataKind.R8:
                return("R8");

            case InternalDataKind.BL:
                return("BL");

            case InternalDataKind.TX:
                return("TX");

            case InternalDataKind.TS:
                return("TS");

            case InternalDataKind.DT:
                return("DT");

            case InternalDataKind.DZ:
                return("DZ");

            case InternalDataKind.UG:
                return("UG");
            }
            return("");
        }
Esempio n. 12
0
            internal void Save(ModelSaveContext ctx)
            {
                Contracts.AssertValue(ctx);

                // *** Binary format ***
                // int: number of columns
                // foreach column:
                //   int: id of column name
                //   byte: DataKind
                //   byte: bool of whether this is a key type
                //   for a key type:
                //     ulong: count for key range
                //   int: number of segments
                //   foreach segment:
                //     string id: name
                //     int: min
                //     int: lim
                //     byte: force vector (verWrittenCur: verIsVectorSupported)
                ctx.Writer.Write(Infos.Length);
                for (int iinfo = 0; iinfo < Infos.Length; iinfo++)
                {
                    var info = Infos[iinfo];
                    ctx.SaveNonEmptyString(info.Name);
                    var type = info.ColType.GetItemType();
                    InternalDataKind rawKind = type.GetRawKind();
                    Contracts.Assert((InternalDataKind)(byte)rawKind == rawKind);
                    ctx.Writer.Write((byte)rawKind);
                    ctx.Writer.WriteBoolByte(type is KeyDataViewType);
                    if (type is KeyDataViewType key)
                    {
                        ctx.Writer.Write(key.Count);
                    }

                    if (info.Segments is null)
                    {
                        ctx.Writer.Write(0);
                    }
                    else
                    {
                        ctx.Writer.Write(info.Segments.Length);
                        foreach (var seg in info.Segments)
                        {
                            ctx.SaveStringOrNull(seg.Name);
                            ctx.Writer.Write(seg.Min);
                            ctx.Writer.Write(seg.Lim);
                            ctx.Writer.WriteBoolByte(seg.ForceVector);
                        }
                    }
                }
            }
Esempio n. 13
0
        public static DataViewType DataKind2ColumnType(InternalDataKind kind, IChannel ch = null)
        {
            switch (kind)
            {
            case InternalDataKind.BL:
                return(BooleanDataViewType.Instance);

            case InternalDataKind.R4:
                return(NumberDataViewType.Single);

            case InternalDataKind.R8:
                return(NumberDataViewType.Double);

            case InternalDataKind.I1:
                return(NumberDataViewType.SByte);

            case InternalDataKind.I2:
                return(NumberDataViewType.Int16);

            case InternalDataKind.I4:
                return(NumberDataViewType.Int32);

            case InternalDataKind.I8:
                return(NumberDataViewType.Int64);

            case InternalDataKind.U1:
                return(NumberDataViewType.Byte);

            case InternalDataKind.U2:
                return(NumberDataViewType.UInt16);

            case InternalDataKind.U4:
                return(NumberDataViewType.UInt32);

            case InternalDataKind.U8:
                return(NumberDataViewType.UInt64);

            case InternalDataKind.TX:
                return(TextDataViewType.Instance);

            case InternalDataKind.DateTime:
                return(DateTimeDataViewType.Instance);

            case InternalDataKind.DateTimeZone:
                return(DateTimeOffsetDataViewType.Instance);

            default:
                throw ch != null?ch.Except("Unknown kind {0}", kind) : Contracts.Except("Unknown kind {0}", kind);
            }
        }
        private static NumberDataViewType NumberTypeFromKind(InternalDataKind kind)
        {
            switch (kind)
            {
            case InternalDataKind.I1:
                return(NumberDataViewType.SByte);

            case InternalDataKind.U1:
                return(NumberDataViewType.Byte);

            case InternalDataKind.I2:
                return(NumberDataViewType.Int16);

            case InternalDataKind.U2:
                return(NumberDataViewType.UInt16);

            case InternalDataKind.I4:
                return(NumberDataViewType.Int32);

            case InternalDataKind.U4:
                return(NumberDataViewType.UInt32);

            case InternalDataKind.I8:
                return(NumberDataViewType.Int64);

            case InternalDataKind.U8:
                return(NumberDataViewType.UInt64);

            case InternalDataKind.R4:
                return(NumberDataViewType.Single);

            case InternalDataKind.R8:
                return(NumberDataViewType.Double);
            }

            Contracts.Assert(false);
            throw new InvalidOperationException($"Bad data kind in {nameof(ColumnTypeExtensions)}.{nameof(NumberTypeFromKind)}: {kind}");
        }
            internal void Save(ModelSaveContext ctx)
            {
                Contracts.AssertValue(ctx);

                // *** Binary format ***
                // int: number of columns
                // foreach column:
                //   int: id of column name
                //   byte: DataKind
                //   byte: bool of whether this is a key type
                //   for a key type:
                //     ulong: count for key range
                //   byte: bool of whether the source index is valid
                //   for a valid source index:
                //     int: source index
                ctx.Writer.Write(Infos.Length);
                for (int iinfo = 0; iinfo < Infos.Length; iinfo++)
                {
                    var info = Infos[iinfo];
                    ctx.SaveNonEmptyString(info.Name);
                    var type = info.ColType.GetItemType();
                    InternalDataKind rawKind = type.GetRawKind();
                    Contracts.Assert((InternalDataKind)(byte)rawKind == rawKind);
                    ctx.Writer.Write((byte)rawKind);
                    ctx.Writer.WriteBoolByte(type is KeyDataViewType);
                    if (type is KeyDataViewType key)
                    {
                        ctx.Writer.Write(key.Count);
                    }
                    ctx.Writer.WriteBoolByte(info.SourceIndex.HasValue);
                    if (info.SourceIndex.HasValue)
                    {
                        ctx.Writer.Write(info.SourceIndex.GetValueOrDefault());
                    }
                }
            }
Esempio n. 16
0
        public static DataKind InternalDataKind2DataKind(InternalDataKind kind, IChannel ch = null)
        {
            switch (kind)
            {
            case InternalDataKind.BL: return(DataKind.Boolean);

            case InternalDataKind.R4: return(DataKind.Single);

            case InternalDataKind.R8: return(DataKind.Double);

            case InternalDataKind.I1: return(DataKind.SByte);

            case InternalDataKind.I2: return(DataKind.Int16);

            case InternalDataKind.I4: return(DataKind.Int32);

            case InternalDataKind.I8: return(DataKind.Int64);

            case InternalDataKind.U1: return(DataKind.Byte);

            case InternalDataKind.U2: return(DataKind.UInt16);

            case InternalDataKind.U4: return(DataKind.UInt32);

            case InternalDataKind.U8: return(DataKind.UInt64);

            case InternalDataKind.TX: return(DataKind.String);

            case InternalDataKind.DateTime: return(DataKind.DateTime);

            case InternalDataKind.DateTimeZone: return(DataKind.DateTimeOffset);

            default:
                throw ch != null?ch.Except("Unknown kind {0}", kind) : Contracts.Except("Unknown kind {0}", kind);
            }
        }
Esempio n. 17
0
 private Scalar <T> Load <T>(InternalDataKind kind, int ordinal)
 {
     Contracts.CheckParam(ordinal >= 0, nameof(ordinal), "Should be non-negative");
     return(new MyScalar <T>(_rec, kind, ordinal));
 }
Esempio n. 18
0
 /// <summary>
 /// This function converts <paramref name="kind"/> to <see cref="DataKind"/>.
 /// Because <see cref="DataKind"/> is a subset of <see cref="InternalDataKind"/>, we should check if <paramref name="kind"/>
 /// can be found in <see cref="DataKind"/>.
 /// </summary>
 public static DataKind ToDataKind(this InternalDataKind kind)
 {
     Contracts.Check(kind != InternalDataKind.UG);
     return((DataKind)kind);
 }
Esempio n. 19
0
        /// <summary>Maps a <see cref="InternalDataKind"/> to the associated <see cref="DbType"/>.</summary>
        public static DbType ToDbType(this InternalDataKind dataKind)
        {
            switch (dataKind)
            {
            case InternalDataKind.I1:
            {
                return(DbType.SByte);
            }

            case InternalDataKind.U1:
            {
                return(DbType.Byte);
            }

            case InternalDataKind.I2:
            {
                return(DbType.Int16);
            }

            case InternalDataKind.U2:
            {
                return(DbType.UInt16);
            }

            case InternalDataKind.I4:
            {
                return(DbType.Int32);
            }

            case InternalDataKind.U4:
            {
                return(DbType.UInt32);
            }

            case InternalDataKind.I8:
            {
                return(DbType.Int64);
            }

            case InternalDataKind.U8:
            {
                return(DbType.UInt64);
            }

            case InternalDataKind.R4:
            {
                return(DbType.Single);
            }

            case InternalDataKind.R8:
            {
                return(DbType.Double);
            }

            case InternalDataKind.TX:
            {
                return(DbType.String);
            }

            case InternalDataKind.BL:
            {
                return(DbType.Boolean);
            }

            case InternalDataKind.DT:
            {
                return(DbType.DateTime);
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Esempio n. 20
0
 public MyScalar(Reconciler rec, InternalDataKind kind, int ordinal)
     : base(rec, null)
 {
     _kind    = kind;
     _ordinal = ordinal;
 }
Esempio n. 21
0
        /// <summary>
        /// Try to map a System.Type to a corresponding DataKind value.
        /// </summary>
        public static bool TryGetDataKind(this Type type, out InternalDataKind kind)
        {
            Contracts.CheckValueOrNull(type);

            // REVIEW: Make this more efficient. Should we have a global dictionary?
            if (type == typeof(sbyte))
            {
                kind = InternalDataKind.I1;
            }
            else if (type == typeof(byte))
            {
                kind = InternalDataKind.U1;
            }
            else if (type == typeof(short))
            {
                kind = InternalDataKind.I2;
            }
            else if (type == typeof(ushort))
            {
                kind = InternalDataKind.U2;
            }
            else if (type == typeof(int))
            {
                kind = InternalDataKind.I4;
            }
            else if (type == typeof(uint))
            {
                kind = InternalDataKind.U4;
            }
            else if (type == typeof(long))
            {
                kind = InternalDataKind.I8;
            }
            else if (type == typeof(ulong))
            {
                kind = InternalDataKind.U8;
            }
            else if (type == typeof(Single))
            {
                kind = InternalDataKind.R4;
            }
            else if (type == typeof(Double))
            {
                kind = InternalDataKind.R8;
            }
            else if (type == typeof(ReadOnlyMemory <char>) || type == typeof(string))
            {
                kind = InternalDataKind.TX;
            }
            else if (type == typeof(bool))
            {
                kind = InternalDataKind.BL;
            }
            else if (type == typeof(TimeSpan))
            {
                kind = InternalDataKind.TS;
            }
            else if (type == typeof(DateTime))
            {
                kind = InternalDataKind.DT;
            }
            else if (type == typeof(DateTimeOffset))
            {
                kind = InternalDataKind.DZ;
            }
            else if (type == typeof(DataViewRowId))
            {
                kind = InternalDataKind.UG;
            }
            else
            {
                kind = default(InternalDataKind);
                return(false);
            }

            return(true);
        }
Esempio n. 22
0
            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);
            }
Esempio n. 23
0
 private Key <T> Load <T>(InternalDataKind kind, int ordinal, ulong?keyCount)
 {
     Contracts.CheckParam(ordinal >= 0, nameof(ordinal), "Should be non-negative");
     return(new MyKey <T>(_rec, kind, ordinal, keyCount));
 }
Esempio n. 24
0
            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.");
            }
Esempio n. 25
0
 /// <summary>
 /// Maps a DataKind to a value suitable for indexing into an array of size KindCount.
 /// </summary>
 public static int ToIndex(this InternalDataKind kind)
 {
     return(kind - KindMin);
 }
Esempio n. 26
0
        /// <summary>
        /// The string representation of the <see cref="KeyType"/>.
        /// </summary>
        /// <returns>A formatted string.</returns>
        public override string ToString()
        {
            InternalDataKind rawKind = this.GetRawKind();

            return(string.Format("Key<{0}, {1}-{2}>", rawKind.GetString(), 0, Count - 1));
        }