zipvec

Contents

zipvec#

Zips together multiple operators to yield a vectorized operator, like float2. zipvec can be used, for example, to create a 2D/3D set of coordinates stored as float2/float3 using operators that represent the independent coordinate components.

template<typename ...Ts>
__MATX_INLINE__ __MATX_HOST__ auto matx::zipvec(const Ts&... ts)#

zipvec zips multiple operators together into a vectorized operator. This allows combining multiple operators that represent scalar types into an operator with vectorized types. For example, two operators of type float can be combined into an operator of type float2.

The input operators must have the same rank and size in all dimensions and the types must be compatible. This is only supported for the types for which CUDA has corresponding vector types, including char, short, int, long, float, and double. The integer types also support unsigned variants (uchar, ushort, etc.). For these sizes, the number of input operators and the corresponding zipped vector length can be 1-4.

The components from the input operators are accessed by the fields x, y, z, and w, respectively, in the zipped operator.

Template Parameters:

Ts – input operator types

Parameters:

ts – input operators

Returns:

zipped operator

Examples#

auto v = linspace<float>(0.25f, 1.0f, 4);
auto duplicate_rows = clone<2>(v, {4, matxKeepDim});
auto duplicate_cols = clone<2>(v, {matxKeepDim, 4});
// Form a 2D grid of coordinates by replicating v along the rows and columns
// and zipping the two 2D tensors together into a 2D vector tensor. This creates
// coordinates in the form:
//   [ (0.25, 0.25) (0.5, 0.25) (0.75, 0.25) (1.0, 0.25) ]
//   [ (0.25, 0.5)  (0.5, 0.5)  (0.75, 0.5)  (1.0, 0.5)  ]
//   [ (0.25, 0.75) (0.5, 0.75) (0.75, 0.75) (1.0, 0.75) ]
//   [ (0.25, 1.0)  (0.5, 1.0)  (0.75, 1.0)  (1.0, 1.0)  ]
auto coords = make_tensor<float2>({4, 4});
(coords = zipvec(duplicate_rows, duplicate_cols)).run(exec);
exec.sync();

for (int r = 0; r < 4; r++) {
  for (int c = 0; c < 4; c++) {
    ASSERT_EQ(coords(r,c).x, static_cast<TestType>((c+1)*0.25f));
    ASSERT_EQ(coords(r,c).y, static_cast<TestType>((r+1)*0.25f));
  }
}