CreateTensor

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

Header File/Library File

  • Header file: #include <ge/es_graph_builder.h>
  • Library files: libeager_style_graph_builder_base.so and libeager_style_graph_builder_base_static.a

Function Usage

Creates a tensor of the specified data type and tensor shape.

Prototype

1
2
3
4
5
template <typename T>
std::unique_ptr<Tensor> CreateTensor(const std::vector<T> &value, const std::vector<int64_t> &dims, DataType dt, Format format = FORMAT_ND);

template <typename T>
std::unique_ptr<Tensor> CreateTensor(const T *value, const int64_t *dims, int64_t dim_num, DataType dt, Format format = FORMAT_ND);

Parameters

Parameter

Input/Output

Description

T

Input

Tensor data type.

value

Input

Pointer to the tensor data.

dims

Input

Pointer to the tensor dimension array.

dim_num

Input

Number of tensor dimensions.

dt

Input

Tensor data type.

format

Input

Tensor format. The default value is FORMAT_ND.

Returns

Parameter

Type

Description

-

std::unique_ptr<Tensor>

Smart pointer to the created tensor. If the operation fails, nullptr is returned.

Restrictions

None

Example

Template 1:

1
2
3
4
EsGraphBuilder builder("graph_name");
std::vector<float> data = {1.0f, 2.0f, 3.0f};
std::vector<int64_t> dims = {3};
auto tensor = builder.CreateTensor<float>(data, dims, ge::DT_FLOAT);

Template 2:

1
2
3
std::vector<float> data = {1.0f, 2.0f, 3.0f};
std::vector<int64_t> dims = {3};
auto tensor = ge::es::CreateTensor<float>(data.data(), dims.data(), dims.size(), ge::DT_FLOAT);