public FloatVectorVector(FloatVectorVector other) : this(CNTKLibPINVOKE.new_FloatVectorVector__SWIG_1(FloatVectorVector.getCPtr(other)), true) { if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } }
public FloatVectorVectorEnumerator(FloatVectorVector collection) { collectionRef = collection; currentIndex = -1; currentObject = null; currentSize = collectionRef.Count; }
// Create Value object from dense input as batch of sequences data with sequenceStartFlags. public static Value Create <T>(NDShape sampleShape, System.Collections.Generic.IEnumerable <System.Collections.Generic.IEnumerable <T> > sequences, System.Collections.Generic.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 System.ArgumentException("The data type " + typeof(T).ToString() + " is not supported. Only float or double is supported by CNTK."); } }
private void _CopyVariableValueToFloat(Variable outputVariable, FloatVectorVector sequences) { CNTKLibPINVOKE.Value__CopyVariableValueToFloat__SWIG_0(swigCPtr, Variable.getCPtr(outputVariable), FloatVectorVector.getCPtr(sequences)); if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } }
public void SetRange(int index, FloatVectorVector values) { CNTKLibPINVOKE.FloatVectorVector_SetRange(swigCPtr, index, FloatVectorVector.getCPtr(values)); if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } }
private static Value _CreateDenseFloat(NDShape sampleShape, FloatVectorVector sequences, BoolVector sequenceStartFlags, DeviceDescriptor device) { global::System.IntPtr cPtr = CNTKLibPINVOKE.Value__CreateDenseFloat__SWIG_3(NDShape.getCPtr(sampleShape), FloatVectorVector.getCPtr(sequences), BoolVector.getCPtr(sequenceStartFlags), DeviceDescriptor.getCPtr(device)); Value ret = (cPtr == global::System.IntPtr.Zero) ? null : new Value(cPtr, true); if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public static FloatVectorVector Repeat(FloatVector value, int count) { global::System.IntPtr cPtr = CNTKLibPINVOKE.FloatVectorVector_Repeat(FloatVector.getCPtr(value), count); FloatVectorVector ret = (cPtr == global::System.IntPtr.Zero) ? null : new FloatVectorVector(cPtr, true); if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public FloatVectorVector GetRange(int index, int count) { global::System.IntPtr cPtr = CNTKLibPINVOKE.FloatVectorVector_GetRange(swigCPtr, index, count); FloatVectorVector ret = (cPtr == global::System.IntPtr.Zero) ? null : new FloatVectorVector(cPtr, true); if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
// // Return the data of the Value object as a list of sequences with variable length. // This method returns an IList<IList<T>>. Each element of the outer list represents a sequence. // Each sequence, represented by IList<T>, contains a variable number of samples. // Each sample consits of a fixed number of elements with type of 'T'. The number of elements is determined by the variable shape. // The number of samples = (the count of elements in IList<T>)/(the count of elements of the sample) // The shape of the variable should match the shape of the Value object. // public System.Collections.Generic.IList <System.Collections.Generic.IList <T> > GetDenseData <T>(Variable outputVariable) { var sequences = new System.Collections.Generic.List <System.Collections.Generic.IList <T> >(); if (typeof(T).Equals(typeof(float))) { if (_GetDataType() != DataType.Float) { throw new System.ArgumentException("The value type does not match the list type."); } var seqVec = new FloatVectorVector(); _CopyVariableValueToFloat(outputVariable, seqVec); foreach (var seq in seqVec) { var seqList = seq as System.Collections.Generic.IList <T>; if (seqList == null) { throw new System.TypeAccessException("Cannot convert to the value type."); } // It is required to create a new List from seq, since seq is dependent on the life cycle of seqVec. sequences.Add(new System.Collections.Generic.List <T>(seqList)); } } else if (typeof(T).Equals(typeof(double))) { if (_GetDataType() != DataType.Double) { throw new System.ArgumentException("The value type does not match the list type."); } var seqVec = new DoubleVectorVector(); _CopyVariableValueToDouble(outputVariable, seqVec); foreach (var seq in seqVec) { var seqList = seq as System.Collections.Generic.IList <T>; if (seqList == null) { throw new System.TypeAccessException("Cannot convert to the value type."); } // It is required to create a new List from seq, since seq is dependent on the life cycle of seqVec. sequences.Add(new System.Collections.Generic.List <T>(seqList)); } } else { throw new System.ArgumentException("The value type does not match the list type."); } return(sequences); }
public void CopyVariableValueTo <T>(Variable outputVariable, System.Collections.Generic.List <System.Collections.Generic.List <T> > sequences) { sequences.Clear(); if (typeof(T).Equals(typeof(float))) { if (_GetDataType() != DataType.Float) { throw new System.ArgumentException("The value type does not match the list type."); } var seqVec = new FloatVectorVector(); _CopyVariableValueToFloat(outputVariable, seqVec); foreach (var seq in seqVec) { var seqList = seq as System.Collections.Generic.IList <T>; if (seqList == null) { throw new System.TypeAccessException("Cannot convert to the value type."); } sequences.Add(new System.Collections.Generic.List <T>(seqList)); } } else if (typeof(T).Equals(typeof(double))) { if (_GetDataType() != DataType.Double) { throw new System.ArgumentException("The value type does not match the list type."); } var seqVec = new DoubleVectorVector(); _CopyVariableValueToDouble(outputVariable, seqVec); foreach (var seq in seqVec) { var seqList = seq as System.Collections.Generic.IList <T>; if (seqList == null) { throw new System.TypeAccessException("Cannot convert to the value type."); } sequences.Add(new System.Collections.Generic.List <T>(seqList)); } } else { throw new System.ArgumentException("The value type does not match the list type."); } }
public static void EvaluateUsingCreateValue() { // Load the model var myFunc = Function.LoadModel("01_OneHidden"); // Ouput funciton info. OutputFunctionInfo(myFunc); // prepare input for evaluation uint numOfSamples = 1; const string inputNodeName = "features"; var inputVar = myFunc.Arguments.Where(variable => string.Equals(variable.Name, inputNodeName)).Single(); // Todo: get size directly from inputVar. uint numOfInputData = inputVar.Shape.TotalSize; var inputData = new List <float>(); for (uint i = 0; i < numOfInputData; ++i) { inputData.Add(i % 255); } var inputVector = new FloatVector(inputData); var data = new FloatVectorVector() { inputVector }; // Create value directly from data. var inputValue = Value.CreateDenseFloat(inputVar.Shape, data, DeviceDescriptor.CPUDevice); // Create input map // Todo: create a Dictionary wrapper? var inputMap = new UnorderedMapVariableValuePtr(); inputMap.Add(inputVar, inputValue); // Prepare output const string outputNodeName = "out.z_output"; var outputVar = myFunc.Outputs.Where(variable => string.Equals(variable.Name, outputNodeName)).Single(); // Create ouput map. Using null as Value to indicate using system allocated memory. var outputMap = new UnorderedMapVariableValuePtr(); outputMap.Add(outputVar, null); // Evalaute // Todo: test on GPUDevice()? myFunc.Evaluate(inputMap, outputMap, DeviceDescriptor.CPUDevice); // Get output value after evaluation var outputValue = outputMap[outputVar]; var outputNDArrayView = outputValue.Data(); var dynamicAxisShape = new SizeTVector() { 1, numOfSamples }; var outputShape = outputVar.Shape.AppendShape(new NDShape(dynamicAxisShape)); // Copy the data from the output buffer. // Todo: directly access the data in output buffer if it is on CPU? uint numOfOutputData = outputNDArrayView.Shape().TotalSize; float[] outputData = new float[numOfOutputData]; var cpuOutputNDArrayView = new NDArrayView(outputShape, outputData, numOfOutputData, DeviceDescriptor.CPUDevice); cpuOutputNDArrayView.CopyFrom(outputNDArrayView); // Output results Console.WriteLine("Evaluation results:"); for (uint i = 0; i < numOfOutputData; ++i) { Console.WriteLine(outputData[i]); } }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FloatVectorVector obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }