Exemplo n.º 1
0
        /// <summary>
        /// Create Value object from OneHotVector input as batch of sequences data with sequenceStratFlags, for 1D tensor only.
        /// </summary>
        /// <typeparam name="T">data type</typeparam>
        /// <param name="dimension">data dimension</param>
        /// <param name="sequences">data sequences</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>(int dimension,
                                       IEnumerable <IEnumerable <int> > sequences,
                                       IEnumerable <bool> sequenceStartFlags,
                                       DeviceDescriptor device,
                                       bool readOnly = false)
        {
            var seqFlags       = Helper.AsBoolVector(sequenceStartFlags);
            var inputSeqVector = new SizeTVectorVector();

            foreach (var seq in sequences)
            {
                var s = Helper.AsSizeTVector(seq);
                inputSeqVector.Add(s);
            }
            if (typeof(T).Equals(typeof(float)))
            {
                return(Value._CreateOneHotFloat((uint)dimension, inputSeqVector, seqFlags, device, readOnly));
            }
            else if (typeof(T).Equals(typeof(double)))
            {
                return(Value._CreateOneHotDouble((uint)dimension, inputSeqVector, seqFlags, device, readOnly));
            }
            else
            {
                throw new ArgumentException("The data type " + typeof(T).ToString() + " is not supported. Only float or double is supported by CNTK.");
            }
        }