Skip to main content

TensorMath.argSortMasked

Function

Applies a list of indices of a tensor in sorted order of their corresponding values in the tensor to the given outTensor.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

argSortMasked(inTensor, mask, outTensor, order): number

Applies a list of indices of a tensor in sorted order of their corresponding values in the tensor to the given outTensor. Only indices whose corresponding values are not equal to 0 in the provided mask will be returned. Indices from the original tensor, before applying the mask, will be returned in the provided array. Returns the size of the list of indices applied to the outTensor (note: this will be equal to the number of non-zero values provided in the mask). eg:

var inTensor = [5.0, 2.0, 1.0, 3.0, 7.0, -1.0, -5.0];
var mask = [1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0];
var outTensor = new Uint32Array(7);
var order = SortOrder.Ascending;
var size = TensorMath.argSortMasked(inTensor, mask, outTensor, order);
print(outTensor.subarray(size)); // Expected: [2, 1, 3, 0, 4]

Parameters

ParameterType
inTensorFloat32Array
maskFloat32Array
outTensorUint32Array
orderSortOrder

Returns

number