Class TensorExtensions
Tensor extension methods
Inherited Members
Namespace: Unity.Barracuda
Assembly: solution.dll
Syntax
public static class TensorExtensions
Methods
ApplyBorder(TensorShape, int[])
Calculate new shape after applying border to current TensorShape
Declaration
public static TensorShape ApplyBorder(this TensorShape shape, int[] border)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shape | TensorShape |
int[] | border | border |
Returns
Type | Description |
---|---|
Tensor |
new TensorShape |
Approximately(Tensor, Tensor, float, int)
Compare Tensor contents approximately
Declaration
public static bool Approximately(this Tensor X, Tensor Y, float epsilon = 0.0001, int count = -1)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | left Tensor |
Tensor | Y | right Tensor |
float | epsilon | comparison threshold |
int | count | limit number of elements to compare |
Returns
Type | Description |
---|---|
bool |
|
AreAllTensorsConvertibleTo4D(Tensor[])
Check if all tensors are convertible to 4D tensors
Declaration
public static bool AreAllTensorsConvertibleTo4D(Tensor[] tensors)
Parameters
Type | Name | Description |
---|---|---|
Tensor[] | tensors | tensors |
Returns
Type | Description |
---|---|
bool |
|
ArgMax(Tensor)
Calculate max value index
Declaration
public static int[] ArgMax(this Tensor X)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
Returns
Type | Description |
---|---|
int[] | max value index |
ArgSort(Tensor)
Return indices in order that would produce sorted Tensor values
Declaration
public static int[][] ArgSort(this Tensor X)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
Returns
Type | Description |
---|---|
int[][] | indices in order that would produce sorted Tensor values |
AsFloats(Tensor)
Return Tensor data as float array, this will create a blocking read operation
Declaration
public static float[] AsFloats(this Tensor x)
Parameters
Type | Name | Description |
---|---|---|
Tensor | x | Tensor |
Returns
Type | Description |
---|---|
float[] | Tensor data as float array |
AsInts(Tensor)
Return Tensor data as int array (slow operation), this will create a blocking read operation
Declaration
public static int[] AsInts(this Tensor x)
Parameters
Type | Name | Description |
---|---|---|
Tensor | x | Tensor |
Returns
Type | Description |
---|---|
int[] | Tensor data as int array |
Concat(TensorShape[], int)
Calculate concatenation output shape
Declaration
public static TensorShape Concat(TensorShape[] shapes, int axis)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shapes | input shapes |
int | axis | concatenation axis |
Returns
Type | Description |
---|---|
Tensor |
output shape |
Exceptions
Type | Condition |
---|---|
Argument |
Off-axis dimension mismatch |
Concat(Tensor[], int)
Concatenate Tensor
array along axis
and calculate output shape
Declaration
public static TensorShape Concat(Tensor[] tensors, int axis)
Parameters
Returns
Type | Description |
---|---|
Tensor |
new |
Exceptions
Type | Condition |
---|---|
Argument |
Off-axis dimension mismatch |
CreateFromTexture(Texture, TensorShape)
Create ITensorData from Texture
Declaration
public static ITensorData CreateFromTexture(Texture tex, TensorShape shape)
Parameters
Type | Name | Description |
---|---|---|
Texture | tex | Texture |
Tensor |
shape | shape |
Returns
Type | Description |
---|---|
ITensor |
created ITensorData |
Exceptions
Type | Condition |
---|---|
Not |
thrown if unsupported texture type is supplied |
DataToString(Tensor, int)
Return Tensor data as string, limits number of elements to size
Declaration
public static string DataToString(this Tensor X, int size = 32)
Parameters
Returns
Type | Description |
---|---|
string | Returns Tensor data as string |
Equals(Tensor, Tensor)
Compare Tensor contents
Declaration
public static bool Equals(this Tensor X, Tensor Y)
Parameters
Returns
Type | Description |
---|---|
bool |
|
Fill(Tensor, float)
Fill Tensor with value
Declaration
public static void Fill(this Tensor X, float value)
Parameters
Gather(TensorShape[], int)
Calculate output shape for Gather operation
Declaration
public static TensorShape Gather(TensorShape[] shapes, int axis)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shapes | input shapes |
int | axis | axis |
Returns
Type | Description |
---|---|
Tensor |
output shape |
Get8DPermutationsForNHWCPermutationsAndShape(TensorShape, int[])
Calculate 8D permutations from 4D
Declaration
public static int[] Get8DPermutationsForNHWCPermutationsAndShape(this TensorShape shape, int[] permutations)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shape | shape |
int[] | permutations | permutations |
Returns
Type | Description |
---|---|
int[] | 8D permutations |
Max(TensorShape[])
Calculate maximum shape that would cover all input shapes
Declaration
public static TensorShape Max(TensorShape[] shapes)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shapes | input shapes |
Returns
Type | Description |
---|---|
Tensor |
output shape |
MaxDifference(Tensor, Tensor)
Calculate max difference between two tensors
Declaration
public static float MaxDifference(this Tensor X, Tensor Y)
Parameters
Returns
Type | Description |
---|---|
float |
MaxShape(Tensor[])
Calculate maximum shape that would cover all input tensors
Declaration
public static TensorShape MaxShape(Tensor[] tensors)
Parameters
Type | Name | Description |
---|---|---|
Tensor[] | tensors | input tensors |
Returns
Type | Description |
---|---|
Tensor |
output shape |
Permute(int[], int[])
Calculate shape after applying permutations
Declaration
public static int[] Permute(int[] shape, int[] permutations)
Parameters
Returns
Type | Description |
---|---|
int[] | new shape |
Permute(TensorShape, int[])
Calculate TensorShape after applying permutations
Declaration
public static TensorShape Permute(this TensorShape shape, int[] permutations)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shape | shape |
int[] | permutations | permutations |
Returns
Type | Description |
---|---|
Tensor |
new TensorShape |
Print(Tensor, string)
Print Tensor metadata to console
Declaration
public static void Print(this Tensor X, string msg = "")
Parameters
PrintDataPart(Tensor, int, string)
Print Tensor data to console
Declaration
public static void PrintDataPart(this Tensor X, int size, string msg = "")
Parameters
Reduce(TensorShape, int)
Reduce TensorShape across specified axis
Declaration
public static TensorShape Reduce(this TensorShape shape, int axis)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shape | TensorShape |
int | axis | axis |
Returns
Type | Description |
---|---|
Tensor |
output shape |
Reshape(Tensor, int[])
Reshape Tensor
Declaration
public static Tensor Reshape(this Tensor X, int[] size)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
int[] | size | new shape as array of int (expected as size 4 for NHWC or size 8 for SRNTDHWC) |
Returns
Type | Description |
---|---|
Tensor | reshaped Tensor |
Reshape(TensorShape, int[])
Reshape TensorShape into new shape specified by size
. At most one dimension of the new shape can be -1.
See: https://github.com/onnx/onnx/blob/master/docs/Operators.md#Reshape
Declaration
public static TensorShape Reshape(this TensorShape shape, int[] size4Dor8D)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shape | TensorShape |
int[] | size4Dor8D | new shape |
Returns
Type | Description |
---|---|
Tensor |
output shape |
Exceptions
Type | Condition |
---|---|
Argument |
more than one dimension is unspecified |
Scale(TensorShape, int[])
Scale TensorShape by the scale
factor
Declaration
public static TensorShape Scale(this TensorShape shape, int[] scale)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shape | TensorShape |
int[] | scale | scale |
Returns
Type | Description |
---|---|
Tensor |
output shape |
Scale(TensorShape, TensorShape)
Scale TensorShape by the scale
factor
Declaration
public static TensorShape Scale(this TensorShape shape, TensorShape scale)
Parameters
Type | Name | Description |
---|---|---|
Tensor |
shape | TensorShape |
Tensor |
scale | scale |
Returns
Type | Description |
---|---|
Tensor |
output shape |
WrapIndex(int, int)
Wrap index (emulate Python array index behavior)
Declaration
public static int WrapIndex(int i, int length)
Parameters
Returns
Type | Description |
---|---|
int | wrapped around index |