Rate This Document
Findability
Accuracy
Completeness
Readability

make_coord

Create a Coord to describe matrix indices, which are used for indexing operations on tensor objects.

Interface Definition

template<typename... Args>

Coord<Args...> make_coord(Args ... args);

Parameters

Table 1 Parameter definition

Parameter

Type

Description

Input/Output

args...

Argument that accepts Int<>, Underscore, int, or Coord<> objects

Defines the matrix index. For a non-peak matrix, pass an Int<>, Underscore, or int object. Among these, Int<> and Underscore type variables represent variables that can be determined at compile time, where Underscore specifically represents all indices within that dimension. An int type variable represents a variable determined at runtime. For a peak matrix, pass a Shape<> object for nested description.

Input

Return Value

Returns a Coord<Args...> object.

Examples

#include "stdlib.h"
#include "kupl_mma.h"
using namespace kupl::tensor;

int main()
{
    constexpr int MATRIX_M  = 32;
    constexpr int MATRIX_N  = 16;
    double *data = (double *)malloc(sizeof(double) * MATRIX_M * MATRIX_N);

    auto shape = make_shape(Int<32>{}, Int<16>{});
    auto stride = make_stride(Int<16>{}, Int<1>{});
    auto layout = make_layout(shape, stride);
    atuo tensor = make_tensor(data, layout);

    // Obtain the tensor element whose index is (2, 2).
    auto coord1 = make_coord(Int<2>{}, Int<2>{});
    auto ret1 = tensor(coord1);
    // Use an Underscore variable to implement tensor slicing. coord2 indicates that all tensor elements in the second row are obtained.
    auto coord2 = make_coord(Int<2>{}, Underscore{});
    auto ret2 = tensor(coord2);
    auto coord3 = make_coord(Int<2>{});
    auto ret3 = ret2(coord3);

    free(data);
    return 0;
}

The preceding example demonstrates the indexing and slicing operations on a 32*16 tensor object. make_coord indicates how to generate a Coord index object.