Class TensorExtensions
Tensor extension methods
Inherited Members
Namespace: Unity.Barracuda
Syntax
public static class TensorExtensions
Methods
ApplyBorder(TensorShape, Int32[])
Calculate new shape after applying border to current TensorShape
Declaration
public static TensorShape ApplyBorder(this TensorShape shape, int[] border)
Parameters
Type | Name | Description |
---|---|---|
TensorShape | shape | TensorShape |
Int32[] | border | border |
Returns
Type | Description |
---|---|
TensorShape | new TensorShape |
Approximately(Tensor, Tensor, Single, Int32)
Compare Tensor contents approximately
Declaration
public static bool Approximately(this Tensor X, Tensor Y, float epsilon = 0.0001F, int count = -1)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | left Tensor |
Tensor | Y | right Tensor |
Single | epsilon | comparison threshold |
Int32 | count | limit number of elements to compare |
Returns
Type | Description |
---|---|
Boolean |
|
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 |
---|---|
Boolean |
|
ArgMax(Tensor)
Calculate max value index
Declaration
public static int[] ArgMax(this Tensor X)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
Returns
Type | Description |
---|---|
Int32[] | 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 |
---|---|
Int32[][] | 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 |
---|---|
Single[] | 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 |
---|---|
Int32[] | Tensor data as int array |
Concat(Tensor[], Int32)
Concatenate Tensor
array along axis
and calculate output shape
Declaration
public static TensorShape Concat(Tensor[] tensors, int axis)
Parameters
Type | Name | Description |
---|---|---|
Tensor[] | tensors | Tensor array |
Int32 | axis | axis |
Returns
Type | Description |
---|---|
TensorShape | new |
Exceptions
Type | Condition |
---|---|
ArgumentException | Off-axis dimension mismatch |
Concat(TensorShape[], Int32)
Calculate concatenation output shape
Declaration
public static TensorShape Concat(TensorShape[] shapes, int axis)
Parameters
Type | Name | Description |
---|---|---|
TensorShape[] | shapes | input shapes |
Int32 | axis | concatenation axis |
Returns
Type | Description |
---|---|
TensorShape | output shape |
Exceptions
Type | Condition |
---|---|
ArgumentException | 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 |
TensorShape | shape | shape |
Returns
Type | Description |
---|---|
ITensorData | created ITensorData |
Exceptions
Type | Condition |
---|---|
NotImplementedException | thrown if unsupported texture type is supplied |
DataToString(Tensor, Int32)
Return Tensor data as string, limits number of elements to size
Declaration
public static string DataToString(this Tensor X, int size = 32)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
Int32 | size | element number limit |
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
Type | Name | Description |
---|---|---|
Tensor | X | left Tensor |
Tensor | Y | right Tensor |
Returns
Type | Description |
---|---|
Boolean |
|
Fill(Tensor, Single)
Fill Tensor with value
Declaration
public static void Fill(this Tensor X, float value)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
Single | value | value |
Gather(TensorShape[], Int32)
Calculate output shape for Gather operation
Declaration
public static TensorShape Gather(TensorShape[] shapes, int axis)
Parameters
Type | Name | Description |
---|---|---|
TensorShape[] | shapes | input shapes |
Int32 | axis | axis |
Returns
Type | Description |
---|---|
TensorShape | output shape |
Get8DPermutationsForNHWCPermutationsAndShape(TensorShape, Int32[])
Calculate 8D permutations from 4D
Declaration
public static int[] Get8DPermutationsForNHWCPermutationsAndShape(this TensorShape shape, int[] permutations)
Parameters
Type | Name | Description |
---|---|---|
TensorShape | shape | shape |
Int32[] | permutations | permutations |
Returns
Type | Description |
---|---|
Int32[] | 8D permutations |
Max(TensorShape[])
Calculate maximum shape that would cover all input shapes
Declaration
public static TensorShape Max(TensorShape[] shapes)
Parameters
Type | Name | Description |
---|---|---|
TensorShape[] | shapes | input shapes |
Returns
Type | Description |
---|---|
TensorShape | output shape |
MaxDifference(Tensor, Tensor)
Calculate max difference between two tensors
Declaration
public static float MaxDifference(this Tensor X, Tensor Y)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | first Tensor |
Tensor | Y | second Tensor |
Returns
Type | Description |
---|---|
Single |
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 |
---|---|
TensorShape | output shape |
Permute(Int32[], Int32[])
Calculate shape after applying permutations
Declaration
public static int[] Permute(int[] shape, int[] permutations)
Parameters
Type | Name | Description |
---|---|---|
Int32[] | shape | shape |
Int32[] | permutations | permutations |
Returns
Type | Description |
---|---|
Int32[] | new shape |
Permute(TensorShape, Int32[])
Calculate TensorShape after applying permutations
Declaration
public static TensorShape Permute(this TensorShape shape, int[] permutations)
Parameters
Type | Name | Description |
---|---|---|
TensorShape | shape | shape |
Int32[] | permutations | permutations |
Returns
Type | Description |
---|---|
TensorShape | new TensorShape |
Print(Tensor, String)
Print Tensor metadata to console
Declaration
public static void Print(this Tensor X, string msg = "")
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
String | msg | message prefix |
PrintDataPart(Tensor, Int32, String)
Print Tensor data to console
Declaration
public static void PrintDataPart(this Tensor X, int size, string msg = "")
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
Int32 | size | element number limit |
String | msg | message prefix |
Reduce(TensorShape, Int32)
Reduce TensorShape across specified axis
Declaration
public static TensorShape Reduce(this TensorShape shape, int axis)
Parameters
Type | Name | Description |
---|---|---|
TensorShape | shape | TensorShape |
Int32 | axis | axis |
Returns
Type | Description |
---|---|
TensorShape | output shape |
Reshape(Tensor, Int32[])
Reshape Tensor
Declaration
public static Tensor Reshape(this Tensor X, int[] size)
Parameters
Type | Name | Description |
---|---|---|
Tensor | X | Tensor |
Int32[] | 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, Int32[])
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 |
---|---|---|
TensorShape | shape | TensorShape |
Int32[] | size4Dor8D | new shape |
Returns
Type | Description |
---|---|
TensorShape | output shape |
Exceptions
Type | Condition |
---|---|
ArgumentException | more than one dimension is unspecified |
Scale(TensorShape, Int32[])
Scale TensorShape by the scale
factor
Declaration
public static TensorShape Scale(this TensorShape shape, int[] scale)
Parameters
Type | Name | Description |
---|---|---|
TensorShape | shape | TensorShape |
Int32[] | scale | scale |
Returns
Type | Description |
---|---|
TensorShape | 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 |
---|---|---|
TensorShape | shape | TensorShape |
TensorShape | scale | scale |
Returns
Type | Description |
---|---|
TensorShape | output shape |
WrapIndex(Int32, Int32)
Wrap index (emulate Python array index behavior)
Declaration
public static int WrapIndex(int i, int length)
Parameters
Type | Name | Description |
---|---|---|
Int32 | i | index |
Int32 | length | array length |
Returns
Type | Description |
---|---|
Int32 | wrapped around index |