Beispiel #1
0
        private bool SaveAsOnnxCore(OnnxContext ctx, string srcVariableName, DataViewType columnType)
        {
            Type type = columnType.RawType;

            int size;

            if (columnType is VectorDataViewType && columnType.IsKnownSizeVector())
            {
                size = columnType.GetVectorSize();
            }
            else
            {
                size = 1;
            }

            if ((type == typeof(int)) ||
                (type == typeof(short)) || (type == typeof(ushort)) ||
                (type == typeof(sbyte)) || (type == typeof(byte)))
            {
                ctx.AddInitializer(new int[size], type, new long[] { 1, size }, srcVariableName, false);
            }
            else if (type == typeof(uint) || (type == typeof(ulong)))
            {
                ctx.AddInitializer(new ulong[size], type == typeof(ulong), new long[] { 1, size }, srcVariableName, false);
            }
            else if (type == typeof(bool))
            {
                ctx.AddInitializer(new bool[size], new long[] { 1, size }, srcVariableName, false);
            }
            else if (type == typeof(long))
            {
                ctx.AddInitializer(new long[size], new long[] { 1, size }, srcVariableName, false);
            }
            else if (type == typeof(float))
            {
                ctx.AddInitializer(new float[size], new long[] { 1, size }, srcVariableName, false);
            }
            else if (type == typeof(double))
            {
                ctx.AddInitializer(new double[size], new long[] { 1, size }, srcVariableName, false);
            }
            else if ((type == typeof(string)) || (columnType is TextDataViewType))
            {
                string[] values = new string[size];
                for (int i = 0; i < size; i++)
                {
                    values[i] = "";
                }

                ctx.AddInitializer(values, new long[] { 1, size }, srcVariableName, false);
            }
            else
            {
                return(false);
            }

            return(true);
        }