예제 #1
0
        private IVowpalWabbitMarshalAction ParseFeatureReUsable()
        {
            // make sure the returned action is independent of the current parsing context, so we can ship it
            switch (reader.TokenType)
            {
            case JsonToken.Float:
                return(VowpalWabbitMarshalActions.Create((double)reader.Value));

            case JsonToken.Integer:
                return(VowpalWabbitMarshalActions.Create((long)reader.Value));

            case JsonToken.String:
                return(VowpalWabbitMarshalActions.Create((string)reader.Value));

            case JsonToken.Boolean:
                return(VowpalWabbitMarshalActions.Create((bool)reader.Value));

            case JsonToken.Comment:
            case JsonToken.Null:
                // probably best to ignore?
                break;

            case JsonToken.StartArray:
                return(this.ParseFeatureArrayReUsable());
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// Expects: "1,2.2,3]" (excluding the leading [)
        /// </summary>
        private IVowpalWabbitMarshalAction ParseFeatureArrayReUsable()
        {
            var values = new float[16];
            var index  = 0;

            while (reader.Read())
            {
                float val;
                switch (reader.TokenType)
                {
                case JsonToken.Integer:
                    val = (float)(long)reader.Value;
                    break;

                case JsonToken.Float:
                    val = (float)(double)reader.Value;
                    break;

                case JsonToken.EndArray:
                    goto done;

                default:
                    throw new VowpalWabbitJsonException(this.reader, "Unxpected token " + reader.TokenType + " while deserializing dense feature array");
                }

                if (index == values.Length)
                {
                    var newValues = new float[values.Length * 2];
                    Array.Copy(values, newValues, values.Length);
                    values = newValues;
                }

                values[index++] = val;
            }
done:

            return(VowpalWabbitMarshalActions.Create(values, index));
        }