Class MetaTensor

Inheritance Relationships

Base Type

  • public mindspore::Value

Derived Type

Class Documentation

class MetaTensor : public mindspore::Value

Subclassed by mindspore::tensor::Tensor

Public Functions

MetaTensor()

Construction.

MetaTensor(const TypeId data_type, const ShapeVector &shape)

Constructs a meta tensor of a tensor having data_type data and shape. The constructed MetaTensor is not a Tensor, but it has the data type and shape information of a Tensor.

Parameters
  • data_type[in] The data type of the tensor.

  • shape[in] The shape of the tensor.

MetaTensor(const MetaTensor &meta_tensor)

Copy constructor. The constructed MetaTensor object will have the same data type and shape as the meta_tensor.

Parameters

meta_tensor[in] An existing MetaTensor object.

~MetaTensor() override = default

Destrustor of MetaTensor.

MS_DECLARE_PARENT (MetaTensor, Value) virtual MetaTensor &operator

Overloads operator = for MetaTensor. The constructed MetaTensor object has the same type and shape with meta_tensor.

Parameters

meta_tensor[in] An existing MetaTensor object.

Returns

A MetaTensor object.

TypePtr Dtype() const

Get the data type of the tensor in its MetaTensor. All the types are defined in “ir/dtype.h”.

Returns

The data type of the tensor in its MetaTensor.

inline TypeId data_type() const

Get the data type of a tensor in its MetaTensor.

Returns

The data type.

inline virtual TypeId set_data_type(const TypeId data_type)

Set the data type of a tensor in its MetaTensor.

Parameters

data_type[in] The data type of the tensor to be set.

virtual TypePtr SetDtype(const TypePtr type_ptr)

Set the dtype of a tensor in its MetaTensor.

Parameters

type_ptr[in] The dtype of the tensor to be set.

inline const ShapeVector &shape() const

Get tensor’s shape. The shape of a tensor is stored in a vector<int>. Each element of the vector represents the size of a dimension of the tensor. The order of each element in the vector is the same as the the dimension’s order it represents.

Returns

A const vector<int> which represents the shape of the tensor.

inline size_t set_shape(const ShapeVector &shape)

Sets the shape of a tensor. The shape of a tensor is stored in a vector<int>. Each element of the vector represents the size of a dimension of the tensor. The order of each element in the vector is the same as the the dimension’s order it represents.

Parameters

shape[in] The shape of the tensor.

Returns

The shape’s size.

inline DeviceInfo device_info() const

Get tensor’s device info.

Returns

The device info of this tensor.

inline void set_device_info(const DeviceInfo &device_info)

Set tensor’s device info.

Parameters

device_info[in] The tensor’s device info.

void SetDeviceInfo(const std::string &format, const TypePtr &data_type, const std::string &host_format = "DefaultFormat")

Set tensor’s device info.

Parameters
  • format[in] The input format.

  • data_type[in] The input data type.

  • host_format[in] The input host format.

int64_t DimensionSize(size_t index) const

Get the size of a given dimension by its index number.

Returns

The size of a given dimension by its index number.

int ElementsNum() const

Get total number of elements in a tensor.

Returns

The total number of elements in a tensor.

inline ParamInfoPtr param_info() const

Get tensor’s param_info info.

Returns

The tensor’s param_info info.

inline bool is_parameter() const

Check whether this Tensor is a parameter.

Returns

Whether this Tensor is a parameter.

inline void set_param_info(const ParamInfoPtr &param_info)

Set tensor’s param_info info.

Parameters

param_info[in] The input param_info.