Skip to content

CNTK Library Managed API

Zhou Wang edited this page May 18, 2017 · 34 revisions

The CNTK Library Managed Eval API is implemented in C#, and can be consumed by C# and other .NET languages. The page Using the CNTK Library Managed API presents how to use this API in your application. The following sections describe the classes and methods of the CNTK Library Managed Eval API.

class Function

A Function denotes a symbolic computation with zero or more input arguments and one or more outputs. A Function may be primitive or composite (comprised of other Function instances whose inputs and outputs are wired together). A Function effectively is a computation graph composed of other primitive Functions (denoting computation) as nodes and Variable objects (denoting data) as the edges and leaves of the graph.

The Function class contains the following properties and methods that are relevant to evaluation:


public string Name { get; }

Name of 'this' Function.


public IList<Variable> Arguments { get; }

List of all input Variables of 'this' Function that are not of type Parameter or Constant. These Variables are required inputs in order to compute the outputs of the Function.


public Variable Output { get; }

The single output Variable of 'this' Function, if there is only one. Otherwise a runtime exception is raised on access.


public IList<Variable> Outputs { get; }

List of all output Variables of 'this' Function.


public Function RootFunction { get; }

Returns the primitive Function at the root of the graph of Functions underlying 'this' Function. If 'this' Function itself is a primitive Function, then (this->RootFunction() == this).


public string OpName { get; }

The name of the operation that 'this' Function denotes.


public bool IsComposite { get; }

A boolean value indicating whether 'this' Function is a composite Function.


public bool IsPrimitive { get; }

A boolean value indicating whether 'this' Function is a primitive Function.


public bool IsBlock { get; }

A boolean value indicating whether 'this' Function is a block Function.


public void Evaluate(IDictionary<Variable, Value> inputs, IDictionary<Variable, Value> outputs, DeviceDescriptor computeDevice)

Evaluates the Function using the specified arguments as input. It computes the outputs of the Function based on the Values provided for each input variable specified in the inputs dictionary. The outputs are stored in the output Values corresponding to the output variables in the outputs dictionary.

Parameters:

  • inputs: the input variables and their values of the Function.
  • outputs: output values for each output variable. The caller may specify the Value object for storing the output or pass null in which case the function allocates the storage for the output results. In both cases, on return the Value object contains the result of the corresponding output of the Function. If a null Value was specified, the Value object returned by the method is temporary and only guaranteed to be valid until the next Forward/Backward call. If it needs to be accessed later, you should use the Evaluate() method below which allows you to create persistent Value objects, or you must explicitly DeepClone the temporary Value object.
  • computeDevice: the device on which the computation is executed. It should be aligned with the device on which the model is loaded.

public void Evaluate(IDictionary<Variable, Value> inputs, IDictionary<Variable, Value> outputs, bool createPersistentOutputValues, DeviceDescriptor computeDevice)

Evaluates the Function using the specified arguments as input. It computes the outputs of the Function based on the Values provided for each input variable specified in the inputs dictionary. The outputs are stored in the output Values corresponding to the output variables in the outputs dictionary.

Parameters:

  • inputs: the input variables and their values of the Function.
  • outputs: output values for each output variable. The caller may specify the Value object for storing the output or pass null in which case the method allocates the storage for the output results. In both cases, on return the Value object contains the result of the corresponding output of the Function. If a null Value was specified, and createPersistentOutputValues is false, the Value object returned by the method is temporary and only guaranteed to be valid until the next Forward/Backward call.
  • createPersistentOutputValues: Only relevant if a null Value was specified in outputs. If it is set to true, the method will create presistent Value objects, otherwise the Value objects are temporary and are only valid until the next Forward/Backward call.
  • computeDevice: the device on which the computation is executed. It should be aligned with the device on which the model is loaded.

public Function Clone(ParameterCloningMethod parameterCloneMethod = ParameterCloningMethod.Share)

Clones 'this' Function.

Parameters:

  • parameterCloneMethod: specifies how the parameters of Function are cloned: ParameterCloningMethod.Share - Parameters are shared between the Function being cloned and the new clone. This value should be used if the cloned Function is used for concurrent evaluation. ParameterCloningMethod.Clone - New learnable Parameters are created and initialized with the current values of the corresponding Parameters of the Function being cloned. ParameterCloningMethod.Freeze - Parameters are cloned and made immutable; i.e. Constants in the new clone (e.g. for use as a fixed feature extractor). ParameterCloningMethod is defined here.

public Function FindByName(string name, bool nestedSearchInsideBlockFunction)

Finds a function with the given name in the Function graph underlying 'this' Function. If more than one function with the same name exists, an exception is thrown. If nestedSearchInsideBlockFunction is true, search all functions inside block functions too.

Parameters:

  • name: the name to be searched for.
  • nestedSearchInsideBlockFunction: if it is true, all functions inside block functions are also examined.

public IList<Function> FindAllWithName(string name, bool nestedSearchInsideBlockFunction = false)

Finds a list of functions with the given name in the Function graph underlying 'this' Function. If nestedSearchInsideBlockFunction is true, search all functions inside block functions too.

Parameters:

  • name: the name to be searched for.
  • nestedSearchInsideBlockFunction: if it is true, all functions inside block functions are also examined.

public static Function Load(string modelFile, DeviceDescriptor computeDevice)

Loads a Function from a model file.

Parameters:

  • modelFile: the path to the model file.
  • computeDevice: the device on which the Function is loaded.

public static Function Load(byte[] modelBuffer, DeviceDescriptor computeDevice)

Loads a Function from a memory buffer representing a model.

Parameters:

  • modelBuffer: the byte array contains the serialized model content.
  • computeDevice: the device on which the Function is loaded.

public static Function Combine(IEnumerable<Variable> operands)

Creates a new Function instance which combines the outputs of the specified list of 'operands' of Functions. The 'Outputs' of the new 'Function' are union of the 'Outputs' of each of the specified 'operands' Functions. As an example, when creating a classification model, typically the CrossEntropy loss Function and the ClassificationError Function comprise the roots of the computation graph which can be "Combine"d to create a single Function with 2 outputs; viz. CrossEntropy loss and ClassificationError output.

Parameters:

  • operands: the list of the functions or variables that should be included in the Outputs of the new function.

public static Function AsComposite(Function rootFunction, string name = "")

Creates a composite Function that has the specified rootFunction as its root. The composite denotes a higher-level Function encapsulating the entire graph of Functions underlying the specified rootFunction.

Parameters:

  • rootFunction: the root of the composite function to be created.
  • name: the name of the composite function to be created.

public static Function Alias(Variable operand, string name = "")

Creates a new Function instance which is just an alias of the specified operand.

Parameters:

  • operand: the function or variable that the alias function is created for.
  • name: the name of the new function to be created.

class Value

A Value is a multi-dimensional array with an optional mask and is the actual data fed into or produced from a computation.


The following methods create a Value object using dense input with the specified tensor shape.


public static Value CreateBatch<T>(NDShape sampleShape, IEnumerable<T> batch, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a batch of samples. The number of samples in the batch is the number of elements in batch divided by the size of shape (A runtime error occurs if the remainder is not zero). The created Value object contains a copy of the specified data in batch.

Parameters:

  • sampleShape: the tensor shape of the Value object.
  • batch: the data to be contained in the Value object.
  • device: on which device the Value object should be created.
  • readOnly: the Value object is read-only if this flag is true.

public static Value CreateSequence<T>(NDShape sampleShape, IEnumerable<T> sequence, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples. The created Value object contains a copy of the specified data in sequence. The sequence length is the number of elements in sequence divided by the size of shape (A runtime error occurs if the remainder is not zero). The created sequence is a new sequence.

Parameters:

  • sampleShape: the tensor shape of the Value.
  • sequence: the data to be contained in the Value.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateSequence<T>(NDShape sampleShape, IEnumerable<T> sequence, bool sequenceStartFlag, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples. The created Value object contains a copy of the specified sequence data. The sequenceStartFlag specifies whether this sequence is a new sequence or continuation of a previous sequence from a previous call to this method. The sequence length is the number of elements in sequence divided by the size of shape (A runtime error occurs if the remainder is not zero).

Parameters:

  • sampleShape: the tensor shape of the Value.
  • sequence: the data to be contained in the Value.
  • sequenceStartFlag: true indicates that it is a new sequence. false means a continuation of a previous sequence.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateBatchOfSequences<T>(NDShape sampleShape, IEnumerable<IEnumerable<T>> batchOfSequences, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a batch of variable length sequences. The created Value object contains a copy of the specified data in batchOfSequences. The number of sequences in the batch is the size of batchOfSequences. The length of each sequence is the number of elements in the corresponding sequence of batchOfSequences divided by the size of shape (A runtime error occurs if the remainder is not zero). Each sequence in batchOfSequences is a new sequence.

Parameters:

  • sampleShape: the tensor shape of the Value.
  • batchOfSequences: the data to be stored in the Value. The outer IEnumerable represents a collection of sequences with variable length, and the inner IEnumerable represents each individual sequence.
  • device: on which device the Value should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateBatchOfSequences<T>(NDShape sampleShape, IEnumerable<IEnumerable<T>> batchOfSequences, IEnumerable<bool> sequenceStartFlags, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a batch of variable length sequences. The created Value object contains a copy of the specified data in batchOfSequences. The number of sequences in the batch is the size of batchOfSequences. The length of each sequence is the number of elements in the corresponding sequence of batchOfSequences divided by the size of shape (A runtime error occurs if the remainder is not zero).

Parameters:

  • sampleShape: the tensor shape of the Value.
  • batchOfSequences: the data to be stored in the Value. The outer IEnumerable represents a collection of sequences with variable length, and the inner IEnumerable represents each individual sequence.
  • sequenceStartFlags: A collection of boolean values. Each element represents whether the corresponding sequence in batchOfSequences is a new sequence (in case of true) or a continuation of a previous sequence (in case of false).
  • device: on which device the Value should be created.
  • readOnly: the Value is read-only if this flag is true.

The following methods create a Value object using one-hot vector input.


public static Value CreateBatch<T>(int dimension, IEnumerable<int> batch, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a batch of samples. Each sample is represented by an index value that points to the non-zero value in the one-hot vector of dimension elements. The number of samples in the batch is the number of elements in batch.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • dimension: the size of dimension of the one-hot vector.
  • batch: the collection of indexes representing the batch of samples.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateSequence<T>(int dimension, IEnumerable<int> sequence, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples. Each sample is represented by an index value that points to the non-zero value in the one-hot vector of dimension elements. The sequence length is the number of elements in sequence. The created sequence is a new sequence.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • dimension: the size of dimension of the one-hot vector.
  • sequence: the collection of indexes representing the sequence of samples.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateSequence<T>(int dimension, IEnumerable<int> sequence, bool sequenceStartFlag, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples. Each sample is represented by an index value that points to the non-zero value in the one-hot vector of dimension elements. The sequenceStartFlag specifies whether this sequence is a new sequence or continuation of a previous sequence from a previous call to this method. The sequence length is the number of elements in sequence.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • dimension: the size of dimension of the one-hot vector.
  • sequence: the collection of indexes representing the sequence of samples.
  • sequenceStartFlag: true indicates that it is a new sequence. false means a continuation of a previous sequence.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateBatchOfSequences<T>(int dimension, IEnumerable<IEnumerable<int>> batchOfSequences, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a batch of variable length sequences. Each sample is represented by an index value that points to the non-zero value in the one-hot vector of dimension elements. The number of sequences is the number of elements in the outer collection of batchOfSequences. The length of each sequence is the number of elements of the corresponding sequence in the collection list of batchOfSequences. Each sequence in batchOfSequences is a new sequence.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • dimension: the size of dimension of the one-hot vector.
  • batchOfSequences: the collection of indexes representing sequences of samples. The outer IEnumerable represents a collection of sequences with variable length, and the inner IEnumerable represents each individual sequence.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateBatchOfSequences<T>(int dimension, IEnumerable<IEnumerable<int>> batchOfSequences, IEnumerable<bool> sequenceStartFlags, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a batch of variable length sequences. Each sample is represented by an index value that points to the non-zero value in the one-hot vector of dimension elements. The number of sequences is the number of elements in the outer collection of batchOfSequences. The length of each sequence is the number of elements of the corresponding sequence in the inner collection of batchOfSequences.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • dimension: the size of dimension of the one-hot vector.
  • batchOfSequences: the collection of indexes representing sequences of samples. The outer IEnumerable represents a collection of sequences with variable length, and the inner IEnumerable represents each individual sequence.
  • sequenceStartFlags: A collection of boolean values. Each element represents whether the corresponding sequence in batchOfSequences is a new sequence (in case of true) or a continuation of a previous sequence (in case of false).
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

The following methods create a Value object using sparse input.

Currently the Compressed Sparse Column Format (CSC) is supported. The CSC format stores the matrix in column-major format, and the array containing the column indices is compressed. A matrix in CSC format is represented by the following parameters:

  • nonZeroValues: the data array that holds all nonzero values of the matrix in column-major format.
  • rowIndices: the array that contains the row indices of the corresponding elements in array nonZeroValues.
  • colStarts: the array that holds indices into the arrays rowIndices and nonZeroValues.

A detailed description of the CSC format can be found here.


public static Value CreateSequence<T>(NDShape sampleShape, int sequenceLength, int[] colStarts, int[] rowIndices, T[] nonZeroValues, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples using CSC sparse input format. The sequence length is the number of rows of the sparse matrix. The created sequence is a new sequence.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • sampleShape: the tensor shape of the Value. For sparse input, the tensor shape leading dimensionality must be the same as the total size of the tensor shape.
  • sequenceLength: the sequence length, which is also the number of rows in the sparse matrix.
  • colStarts: the array holds indices for each column into the arrays rowIndices and nonZeroValues.
  • rowIndices: the array that contains the row indices of the corresponding elements in array nonZeroValues.
  • nonZeroValues: the array that holds all nonzero values in the sparse matrix.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateSequence<T>(NDShape sampleShape, int sequenceLength, int[] colStarts, int[] rowIndices, T[] nonZeroValues, bool sequenceStartFlag, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples using CSC sparse input format. The sequence length is the number of rows of the sparse matrix. The sequenceStartFlag specifies whether this sequence is a new sequence or continuation of a previous sequence from a previous call to this method.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • sampleShape: the tensor shape of the Value. For sparse input, the tensor shape leading dimensionality must be the same as the total size of the tensor shape.
  • sequenceLength: the sequence length, which is also the number of rows in the sparse matrix.
  • colStarts: the array holds indices for each column into the arrays rowIndices and nonZeroValues.
  • rowIndices: the array that contains the row indices of the corresponding elements in array nonZeroValues.
  • nonZeroValues: the array that holds all nonzero values in the sparse matrix.
  • sequenceStartFlag: true indicates that it is a new sequence. false means a continuation of a previous sequence.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateSequence<T>(int dimension, int sequenceLength, int[] colStarts, int[] rowIndices, T[] nonZeroValues, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples using CSC sparse input format. The sequence length is the number of rows of the sparse matrix. The created sequence is a new sequence.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • dimension: the number of columns in the sparse matrix.
  • sequenceLength: the sequence length, which is also the number of rows in the sparse matrix.
  • colStarts: the array holds indices for each column into the arrays rowIndices and nonZeroValues.
  • rowIndices: the array that contains the row indices of the corresponding elements in array nonZeroValues.
  • nonZeroValues: the array that holds all nonzero values in the sparse matrix.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value CreateSequence<T>(int dimension, int sequenceLength, int[] colStarts, int[] rowIndices, T[] nonZeroValues, bool sequenceStartFlag, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object containing a sequence of samples using CSC sparse input format. The sequence length is the number of rows of the sparse matrix. The sequenceStartFlag specifies whether this sequence is a new sequence or continuation of a previous sequence.

Parameters:

  • T: data type of the created Value object. Currently, float and double are supported.
  • dimension: the number of columns in the sparse matrix.
  • sequenceLength: the sequence length, which is also the number of rows in the sparse matrix.
  • colStarts: the array holds indices for each column into the arrays rowIndices and nonZeroValues.
  • rowIndices: the array that contains the row indices of the corresponding elements in array nonZeroValues.
  • nonZeroValues: the array that holds all nonzero values in the sparse matrix.
  • sequenceStartFlag: true indicates that it is a new sequence. false means a continuation of a previous sequence.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

The following methods create a Value object from NDArrayView.


public static Value Create(NDShape sampleShape, IEnumerable<NDArrayView> sequences, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object based on a collection of NDArrayViews. Each sequence in sequences is a new sequence.

Parameters:

  • sampleShape: the tensor shape of the Value being created.
  • sequences: a collection of sequences represented by NDArrayView. Each NDArrayView represents a sequence.
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

public static Value Create(NDShape sampleShape, IEnumerable<NDArrayView> sequences, IEnumerable<bool> sequenceStartFlags, DeviceDescriptor device, bool readOnly = false)

Creates a new Value object based on a collection of NDArrayViews. The sequenceStartFlags specifies whether a sequence is a new sequence or continuation of a previous sequence.

Parameters:

  • sampleShape: the tensor shape of the Value being created.
  • sequences: a collection of sequences represented by NDArrayView. Each NDArrayView represents a sequence.
  • sequenceStartFlags: A collection of boolean values. Each element represents whether the corresponding sequence in sequences is a new sequence (in case of true) or a continuation of a previous sequence (in case of false).
  • device: on which device the Value object should be created.
  • readOnly: the Value is read-only if this flag is true.

A Value object contains the following properties and methods.


public Value(NDArrayView data)

Constructs a multi-dimensional value with no mask.


public Value(NDArrayView data, NDMask mask)

Constructs a multi-dimensional value with an associated mask.


public DataType DataType { get; }

DataType of the data contained in 'this' Value object.


public DeviceDescriptor Device { get; }

The descriptor of the device that 'this' Value resides on.


public NDShape Shape { get; }

The shape of 'this' Value.


public StroageFormat StorageFormat { get; }

The storage format of 'this' Value.


public bool IsSparse { get; }

A boolean value indicating whether 'this' Value contains data in sparse storage format.


public bool IsReadOnly { get; }

A boolean value indicating whether 'this' Value is read-only.


public int maskedCount { get; }

The number of masked/invalid values in 'this' Value.


public void CopyFrom(Value Source)

Copies the contents of source to 'this' Value. The shapes of the Source's data and mask must be identical to 'this' Value's data and mask.

Parameter:

  • Source: The source object from which 'this' Value is copied.

public Value DeepClone()

Creates a new Value with newly allocated storage on the same device as 'this' Value and copies 'this' Value's contents into the newly allocated Value.


public Value DeepClone(bool readOnly)

Creates a new Value with newly allocated storage on the same device as 'this' Value and copies 'this' Value's contents into the newly allocated Value.

Parameter:

  • readOnly: the new Value object is read-only if this flag is true.

public Value Alias(bool readOnly)

Creates a new Value which is an alias of 'this' Value. Parameter:

  • readOnly: the new Value object is read-only if this flag is true.

public IList<IList<T>> GetDenseData<T>(Variable outputVariable)

Gets the data stored in the Value object as a list of sequences with variable length in dense format. This method returns an IList<IList>. Each element of the outer list represents a sequence. Each sequence, represented by IList, contains a variable number of samples. Each sample consists of a fixed number of elements with type of 'T'. The number of elements is determined by the shape of outputVariable. The number of samples is the count of elements in IList divided by the count of elements of the sample.

Parameter:

  • outputVariable: The variable that 'this' Value denotes to. The shape of the variable should match the shape of 'this' Value.

public IList<IList<int>> GetOneHotData(Variable outputVariable)

Gets the data stored in the Value object as a list of sequences with variable length in one-hot vector format. This method returns an IList<IList>. Each element of the outer list represents a sequence. Each sequence, represented by IList, contains a variable number of samples. Each sample is represented by an index to the one-hot vector. The number of samples is the count of elements in IList.

Parameter:

  • outputVariable: The variable that 'this' Value denotes to. The size of the one-hot vector should match that defined in the variable.

The following methods will be deprecated soon. Please use GetDenseData() and GetOneHotData() described above.


public void CopyVariableValueTo<T>(Variable outputVariable, List<List<T>> sequences)

Copies the data stored in the Value into the buffer provided by sequences. The sequences is a list of sequences with variable length. The number of items contained in the outer list of sequences is the number of sequences in the Value. Each element of the outer list represents a sequence. Each sequence, represented by List<T>, contains a variable number of samples. Each sample consists of a fixed number of elements with type of T. The number of elements of a sample is determined by the shape of outputVariable. The shape of the variable should match the shape of the Value.

Parameters:

  • outputVariable: denotes the shape and dynamic axes when copying data from 'this' Value to the sequences.
  • sequences: the output buffer used to store the data copied from the Value.

public void CopyVariableValueTo(Variable outputVariable, List<List<uint>> sequences

Copies the data stored in the Value object into the buffer provided by sequences. The sequences is a list of sequences with variable length. The number of items contained in the outer list of sequences is the number of sequences in the Value. Each element of the outer list represents a sequence. Each sequence, represented by List<uint>, contains a variable number of samples. Each sample is represented by an index pointing to the non-zero value in the one-hot vector. The dimension size of the one-hot vector should match that defined in the outputVariable.

Parameters:

  • outputVariable: denotes the shape and dynamic axes when copying data from 'this' Value to the sequences.
  • sequences: the output buffer used to store the data copied from the Value.

class Variable

Denotes a symbolic entity corresponding to the inputs and outputs of a Function.

The properties of Variable that are often used in evaluation include:


public string Name { get; }

Name of 'this' Variable.


public NDShape Shape { get; }

Shape of 'this' Variable.


public DataType DataTye { get; }

DataType(./CNTK-Library-Managed-API#enum-datatype) of the data that 'this' Variable represents.


public VariableKind Kind { get; }

The VariableKind of 'this' Variable.


public bool IsSparse { get; }

A boolean value indicating whether 'this' Variable denotes sparse data.


public bool IsInput { get; }

A boolean value indicating whether 'this' Variable is an Input.


public bool IsOutput { get; }

A boolean value indicating whether 'this' Variable is an Output.


public bool IsParameter { get; }

A boolean value indicating whether 'this' Variable is a Parameter.


public bool IsConstant { get; }

A boolean value indicating whether 'this' Variable is a Constant.


public bool IsPlaceholder { get; }

A boolean value indicating whether 'this' Variable is a Placeholder.


public IList<Axis> DynamicAxes { get; }

Returns the dynamic axes of 'this' Variable.


public Function Owner { get; }

Returns the Function which 'this' Variable is an output of. Returns null when 'this' Variable is not of VariableKind Output.

class DeviceDescriptor

Denotes a computation device instance.

The class DeviceDescriptor contains the following properties and methods:


public int Id { get; }

The Id of 'this' device.


public DeviceKind Type { get; }

DeviceKind of 'this' device.


public static DeviceDescriptor CPUDevice { get; }

The DeviceDescriptor representing the CPU device on the local system.


public static DeviceDescriptor GPUDevice(int deviceId)

Gets the DeviceDescriptor of the GPU device on the local system with the specified CUDA device ID.

Parameter:

  • deviceId: the CUDA device ID.

public static IList<DeviceDescriptor> AllDevices()

Gets a list of descriptors of all available/supported devices.

class NDShape

Denotes a multi-dimensional rectangular shape.


public NDShape()

Constructs a NDShape with 0 axes, which denotes a scalar.


public NDShape(int numAxes, int dimension)

Constructs a NDShape instance with the specified rank and dimension size. Each axis has the same dimensionality.

Parameter:

  • numAxes: the number of axes of the shape.
  • dimension: the dimension size, applied to each axis.

public NDShape(int numAxes)

Constructs a NDShape instance with the specified rank. The dimensionality in each axis is NDShape.InferredDimension.

Parameter:

  • numAxes: the number of axes of the shape.

public static NDShape CreateNDShape(IEnumerable<int> dimensions)

Creates a NDShape instance with specified dimensions. Parameter:

  • dimensions: the dimension size of each axis.

public int Rank { get; }

The rank of 'this' NDShape.


public IList<int> Dimensions { get; }

The dimensions of 'this' NDShape.


public int TotalSize { get; }

The total size of the rectangular shape that 'this' Shape denotes.


public int this[int key] { get; }

Returns the dimension size of the specified axis.


public int IsUnknown { get; }

A boolean indicating if 'this' shape is the special Unknown shape.


public int HasInferredDimension { get; }

A boolean value indicating if the dimension size for any of the axes of 'this' shape is unknown/inferred (NDShape.InferredDimension).


public NDShape AppendShape(NDShape shape)

Creates and returns a new shape constructed by appending the dimensions of the specified 'shape' to 'this' shape's dimensions.


public NDShape SubShape(int beginAxisId, int endAxisId)

Creates and returns a new NDShape instance with the same dimensions as 'this' shape's specified axis range [beginAxisId, endAxisId).


public NDShape SubShape(int beginAxisId)

Creates and returns a new NDShape instance with the same dimensions as 'this' shape's axis range between the beginAxisId axis (inclusive) and the last axis (inclusive).

class NDArrayView

Denotes a multi-dimensional writable or read-only array of elemental values. This type denotes a view and there may be multiple simultaneous views of the data underlying a NDArrayView instance. The underlying data is stored in sparse or dense format, and is located on a specific device.


public NDArrayView(NDShape viewShape, float[] dataBuffer, DeviceDescriptor device, bool readOnly = false) public NDArrayView(NDShape viewShape, double[] dataBuffer, DeviceDescriptor device, bool readOnly = false)

Constructs a NDArrayView with the specified 'dataBuffer' in dense format as the backing storage on the specified device.

Parameter:

  • viewShape: the shape of the NDArrayView being created.
  • dataBuffer: the data values contained in the NDArrayView. The 'dataBuffer' must be at least as large as the total size of the specified 'viewShape' and must outlive the created NDArrayView object.
  • device: on which device the NDArrayView object should be created.
  • readOnly: the NDArrayView object is read-only if this flag is true.

public NDArrayView(NDShape viewShape, int[] colStarts, int[] rowIndices, float[] nonZeroValues, DeviceDescriptor device, bool readOnly = false) public NDArrayView(NDShape viewShape, int[] colStarts, int[] rowIndices, double[] nonZeroValues, DeviceDescriptor device, bool readOnly = false)

Constructs a NDArrayView with the specified storage in sparse CSC format on the specified device. The specified sparse data must outlive the created NDArrayView object.

Parameter:

  • viewShape: the shape of the NDArrayView being created.
  • colStarts: the array holds indices for each column into the arrays rowIndices and nonZeroValues.
  • rowIndices: the array that contains the row indices of the corresponding elements in array nonZeroValues.
  • nonZeroValues: the array that holds all nonzero values in the sparse matrix. The specified sparse data must outlive the created NDArrayView object.
  • device: on which device the NDArrayView object should be created.
  • readOnly: the NDArrayView object is read-only if this flag is true.

public DeviceDescriptor Device

The DeviceDescriptor of the device that 'this' NDArrayView resides on.


public NDShape Shape

The shape of 'this' NDArrayView.


public DataType DataType

The DataType of the data that 'this' NDArrayView stores.


public StroageFormat StorageFormat

The storage format of 'this' NDArrayView.


public bool IsSparse

A boolean value indicating whether 'this' NDArrayView contains data in sparse storage format.


public bool IsReadOnly

A boolean value indicating whether 'this' NDArrayView is read-only.


public NDArrayView DeepClone()

Creates a new NDArrayView with newly allocated storage on the same device as 'this' view and copies 'this' view's contents into the newly allocated view.


public NDArrayView DeepClone(bool readOnly)

Creates a new NDArrayView with newly allocated storage on the same device as 'this' view and copies 'this' view's contents into the newly allocated view.

Parameter:

  • readOnly: the new NDArrayView object is read-only if this flag is true.

public NDArrayView DeepClone(DeviceDescriptor device, bool readOnly)

Creates a new NDArrayView with newly allocated storage on the specified device and copies 'this' view's contents into the newly allocated view.

Parameter:

  • device: on which device the new NDArrayView object should be created.
  • readOnly: the new NDArrayView object is read-only if this flag is true.

public NDArrayView Alias(bool readOnly)

Creates a new NDArrayView which is an alias of 'this' view; i.e. a new view of the same shape as 'this' over the same underlying data.

Parameter:

  • readOnly: the new NDArrayView object is read-only if this flag is true.

public NDArrayView AsShape(NDShape newShape)

Creates a new NDArrayView which is an alias of 'this' view but with a new shape.

Parameter:

  • newShape: the shape of the new NDArrayView object.

public void CopyFrom(NDArrayView source)

Copies the contents of the 'source' NDArrayView to 'this' view. The shapes of the 'source' view and 'this' view must be identical.

Parameter:

  • source: the source NDArrayView whose content is copied to 'this' view.

public void ChangeDevice(DeviceDescriptor device)

Changes the device of 'this' NDArrayView to the specified device.

Parameter:

  • device: the target device of 'this' NDArrayView object.

class Axis

Denotes an Axis of a Variable. Besides the static axes corresponding to each of the axes of the Variable's shape, Variables of kind 'Input' and any 'Output' Variables dependent on an 'Input' Variable also have 2 additional dynamic axes whose dimensions are known only when the Variable is bound to actual data during compute (viz. sequence axis and batch axis denoting the axis along which multiple sequences are batched)

The following properties are defined in the class Axis


public string Name { get; }

Name of 'this' Axis.


public bool IsStatic { get; }

Returns a boolean value indicating whether 'this' Axis corresponds to a static axis.


public bool IsDynamic { get; }

Returns a boolean value indicating whether 'this' Axis corresponds to a dynamic axis.

class Utils


public static void SetMaxNumCPUThreads(int numCPUThreads)

Sets the process-wide maximum number of CPU threads to be used by any individual compute operation.


public static int GetMaxNumCPUThreads()

Returns the process-wide maximum number of CPU threads to be used by any individual compute operation.


public static void SetTraceLevel(TraceLevel value)

Specifies global logging verbosity level.


public static TraceLevel GetTraceLevel()

Returns current logging verbosity level.

enum VariableKind

Denotes the kind of a symbolic Variable object


{
Input = 0,
Output = 1,
Parameter = 2,
Constant = 3,
Placeholder = 4
}

enum DataType

Denotes data type of symbolic data entities or actual data.


{
Unknown = 0,
Float = 1,
Double = 2
}

enum DeviceKind

Denotes the type of a computation device.


{
CPU, // A CPU device.
GPU // A GPU device.
}

enum StorageFormat

Denotes the format of storage underlying an instance of a NDArrayView.


{
Dense,
SparseCSC,
SparseBlockCol
}

enum ParameterCloningMethod

Denotes how Parameters are handled when cloning a Function.


{
Share, // Parameters are shared between the Function being cloned and the new clone.
Clone, // New learnable Parameters are created and initialized with the current values of the corresponding Parameters of the Function being cloned.
Freeze // Parameters are cloned and made immutable.
}

enum TraceLevel

Denotes logging verbosity levels.


{
Error,
Warning,
Info
}

Clone this wiki locally