/// <summary>
 /// Create batch data as a Value object from a dense source buffer.
 /// Batch data of the specified dataSize are copied from the source buffer
 /// starting at the specified starting position
 /// </summary>
 /// <typeparam name="T">float or double</typeparam>
 /// <param name="sampleShape">shape of the Value</param>
 /// <param name="dataBuffer">source data buffer</param>
 /// <param name="dataStart">index to the source data buffer where batch data start</param>
 /// <param name="dataSize">size of the data</param>
 /// <param name="device">device where data are allocated</param>
 /// <param name="readOnly">whether data are mutable</param>
 /// <returns>the batch data value</returns>
 public static Value CreateBatch <T>(NDShape sampleShape, T[] dataBuffer, int dataStart, int dataSize,
                                     DeviceDescriptor device, bool readOnly = false)
 {
     if (typeof(T).Equals(typeof(float)))
     {
         return(Value._CreateBatchFloat(sampleShape, dataBuffer as float[], dataStart, dataSize, device, readOnly));
     }
     else if (typeof(T).Equals(typeof(double)))
     {
         return(Value._CreateBatchDouble(sampleShape, dataBuffer as double[], dataStart, dataSize, device, readOnly));
     }
     else
     {
         throw new ArgumentException("The data type " + typeof(T).ToString() + " is not supported. Only float or double is supported by CNTK.");
     }
 }
Beispiel #2
0
        /// <summary>
        /// Create Value object from OneHotVector input as batch data, for 1D tensor only.
        /// </summary>
        /// <typeparam name="T">data type</typeparam>
        /// <param name="dimension">data dimension</param>
        /// <param name="batch">data batches</param>
        /// <param name="device">device</param>
        /// <param name="readOnly">whether it a readonly value</param>
        /// <returns></returns>
        public static Value CreateBatch <T>(int dimension, IEnumerable <int> batch, DeviceDescriptor device, bool readOnly = false)
        {
            var inputVector = Helper.AsSizeTVector(batch);

            if (typeof(T).Equals(typeof(float)))
            {
                return(Value._CreateBatchFloat((uint)dimension, inputVector, device, readOnly));
            }
            else if (typeof(T).Equals(typeof(double)))
            {
                return(Value._CreateBatchDouble((uint)dimension, inputVector, device, readOnly));
            }
            else
            {
                throw new ArgumentException("The data type " + typeof(T).ToString() + " is not supported. Only float or double is supported by CNTK.");
            }
        }
Beispiel #3
0
 /// <summary>
 /// Create Value object from dense input as batch data.
 /// </summary>
 /// <typeparam name="T">float or double</typeparam>
 /// <param name="sampleShape">shape of the Value</param>
 /// <param name="batch">batch of data</param>
 /// <param name="device">device</param>
 /// <param name="readOnly">readonly value</param>
 /// <returns>the value</returns>
 public static Value CreateBatch <T>(NDShape sampleShape, IEnumerable <T> batch, DeviceDescriptor device, bool readOnly = false)
 {
     if (typeof(T).Equals(typeof(float)))
     {
         var inputVector = Helper.AsFloatVector(batch);
         return(Value._CreateBatchFloat(sampleShape, inputVector, device, readOnly));
     }
     else if (typeof(T).Equals(typeof(double)))
     {
         var inputVector = Helper.AsDoubleVector(batch);
         return(Value._CreateBatchDouble(sampleShape, inputVector, device, readOnly));
     }
     else
     {
         throw new ArgumentException("The data type " + typeof(T).ToString() + " is not supported. Only float or double is supported by CNTK.");
     }
 }