CreateTensor
Applicability
Product |
Supported or Not |
|---|---|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
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. |
Constraints
None
Examples
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); |
Parent topic: EsGraphBuilder