Exemplo n.º 1
0
        /// <summary>
        /// Create Value object from dense input as batch of sequences data with sequenceStartFlags.
        /// </summary>
        /// <typeparam name="T">data type</typeparam>
        /// <param name="sampleShape">data shape</param>
        /// <param name="sequences">data sequence</param>
        /// <param name="sequenceStartFlag">true indicates that it is a new sequence.
        /// false means a continuation of a previous sequence.</param>
        /// <param name="device">device</param>
        /// <param name="readOnly">whether it a readonly value</param>
        /// <returns></returns>
        public static Value Create <T>(NDShape sampleShape,
                                       IEnumerable <IEnumerable <T> > sequences,
                                       IEnumerable <bool> sequenceStartFlags,
                                       DeviceDescriptor device,
                                       bool readOnly = false)
        {
            var seqFlags = Helper.AsBoolVector(sequenceStartFlags);

            if (typeof(T).Equals(typeof(float)))
            {
                var inputAsSequencesVector = new FloatVectorVector();
                foreach (var seq in sequences)
                {
                    var seqVector = Helper.AsFloatVector(seq);
                    // The seqVector is copied when adding to inputAsSequencesVector.
                    inputAsSequencesVector.Add(seqVector);
                }
                return(Value._CreateDenseFloat(sampleShape, inputAsSequencesVector, seqFlags, device, readOnly));
            }
            else if (typeof(T).Equals(typeof(double)))
            {
                var inputAsSequencesVector = new DoubleVectorVector();
                foreach (var seq in sequences)
                {
                    var seqVector = Helper.AsDoubleVector(seq);
                    inputAsSequencesVector.Add(seqVector);
                }
                return(Value._CreateDenseDouble(sampleShape, inputAsSequencesVector, seqFlags, device, readOnly));
            }
            else
            {
                throw new ArgumentException("The data type " + typeof(T).ToString() + " is not supported. Only float or double is supported by CNTK.");
            }
        }