Class MSTensor
- Defined in File types.h 
Class Documentation
- 
class MSTensor
- The MSTensor class defines a tensor in MindSpore. - Public Functions - Constructor of MSTensor. 
 - 
inline MSTensor(const std::string &name, DataType type, const std::vector<int64_t> &shape, const void *data, size_t data_len)
- Constructor of MSTensor. 
 - 
enum DataType DataType() const
- Obtains the data type of the MSTensor. - 返回
- The data type of the MSTensor. 
 
 - 
const std::vector<int64_t> &Shape() const
- Obtains the shape of the MSTensor. - 返回
- The shape of the MSTensor. 
 
 - 
int64_t ElementNum() const
- Obtains the number of elements of the MSTensor. - 返回
- The number of elements of the MSTensor. 
 
 - 
std::shared_ptr<const void> Data() const
- Obtains a shared pointer to the copy of data of the MSTensor. The data can be read on host. - 返回
- A shared pointer to the copy of data of the MSTensor. 
 
 - 
void *MutableData()
- Obtains the pointer to the data of the MSTensor. If the MSTensor is a device tensor, the data cannot be accessed directly on host. - 返回
- A pointer to the data of the MSTensor. 
 
 - 
size_t DataSize() const
- Obtains the length of the data of the MSTensor, in bytes. - 返回
- The length of the data of the MSTensor, in bytes. 
 
 - 
bool IsDevice() const
- Gets the boolean value that indicates whether the memory of MSTensor is on device. - 返回
- The boolean value that indicates whether the memory of MSTensor is on device. 
 
 - 
MSTensor *Clone() const
- Gets a deep copy of the MSTensor, must be used in pair with DestroyTensorPtr. - 返回
- A pointer points to a deep copy of the MSTensor. 
 
 - 
bool operator==(std::nullptr_t) const
- Gets the boolean value that indicates whether the MSTensor is valid. - 返回
- The boolean value that indicates whether the MSTensor is valid. 
 
 - 
bool operator!=(std::nullptr_t) const
- Gets the boolean value that indicates whether the MSTensor is valid. - 返回
- The boolean value that indicates whether the MSTensor is valid. 
 
 - 
bool operator==(const MSTensor &tensor) const
- Get the boolean value that indicates whether the MSTensor equals tensor. 
 - 
bool operator!=(const MSTensor &tensor) const
- Get the boolean value that indicates whether the MSTensor not equals tensor. 
 - 
void SetShape(const std::vector<int64_t> &shape)
- Set the shape of for the MSTensor. - 参数
- shape – [in] Shape of the MSTensor, a vector of int64_t. 
 
 - 
void SetDataType(enum DataType data_type)
- Set the data type for the MSTensor. - 参数
- data_type – [in] The data type of the MSTensor. 
 
 - 
inline void SetTensorName(const std::string &name)
- Set the name for the MSTensor. - 参数
- name – [in] The name of the MSTensor. 
 
 - 
std::shared_ptr<Allocator> allocator() const
- Obtain the Allocator of the MSTensor. - 返回
- A pointer to Allocator. 
 
 - 
void SetFormat(mindspore::Format format)
- Set the format for the MSTensor. - 参数
- format – [in] The format of the MSTensor. 
 
 - 
void SetData(void *data, bool own_data = true)
- Set the data for the MSTensor. - 说明 - Deprecated, this interface will be removed in the next iteration - 说明 - A pointer to the data should be created by malloc interface - 说明 - The memory pointed to origin data pointer of MSTensor needs to be managed by the user 
 - 
void SetDeviceData(void *data)
- Set the device data address for the MSTensor. Only valid for Lite. - 说明 - The memory pointed to origin data pointer of MSTensor needs to be managed by the user - 参数
- data – [in] A pointer to the device data of the MSTensor. 
 
 - 
void *GetDeviceData()
- Get the device data address of the MSTensor set by SetDeviceData. Only valid for Lite. - 返回
- A pointer to the device data of the MSTensor. 
 
 - 
std::vector<QuantParam> QuantParams() const
- Get the quantization parameters of the MSTensor. - 返回
- The quantization parameters of the MSTensor. 
 
 - 
void SetQuantParams(std::vector<QuantParam> quant_params)
- Set the quantization parameters for the MSTensor. - 参数
- quant_params – [in] The quantization parameters of the MSTensor. 
 
 - Public Static Functions - 
static inline MSTensor *CreateTensor(const std::string &name, DataType type, const std::vector<int64_t> &shape, const void *data, size_t data_len, const std::string &device = "", int device_id = -1) noexcept
- Creates a MSTensor object, whose data need to be copied before accessed by Model, must be used in pairs with DestroyTensorPtr. - 参数
- name – [in] The name of the MSTensor. 
- type – [in] The data type of the MSTensor. 
- shape – [in] The shape of the MSTensor. 
- data – [in] The data pointer that points to allocated memory. 
- data_len – [in] The length of the memory, in bytes. 
- device – [in] The tensor of device type. 
- device_id – [in] The tensor of device id. 
 
- 返回
- A pointer of MSTensor. 
 
 - 
static inline MSTensor *CreateTensor(const std::string &name, const MSTensor &tensor, const std::string &device = "", int device_id = -1) noexcept
- Creates a MSTensor object, whose data need to be copied before accessed by Model, must be used in pairs with DestroyTensorPtr. 
 - 
static inline MSTensor *CreateRefTensor(const std::string &name, DataType type, const std::vector<int64_t> &shape, const void *data, size_t data_len, bool own_data = true) noexcept
- Creates a MSTensor object, whose data can be directly accessed by Model, must be used in pairs with DestroyTensorPtr. - 参数
- name – [in] The name of the MSTensor. 
- type – [in] The data type of the MSTensor. 
- shape – [in] The shape of the MSTensor. 
- data – [in] The data pointer that points to allocated memory. 
- data_len – [in] The length of the memory, in bytes. 
- own_data – [in] Whether the data memory should be freed in MSTensor destruction. 
 
- 返回
- A pointer of MSTensor. 
 
 - 
static inline MSTensor CreateDeviceTensor(const std::string &name, DataType type, const std::vector<int64_t> &shape, void *data, size_t data_len) noexcept
- Creates a MSTensor object, whose device data can be directly accessed by Model, must be used in pairs with DestroyTensorPtr. 
 - 
static inline MSTensor *CreateTensorFromFile(const std::string &file, DataType type = DataType::kNumberTypeUInt8, const std::vector<int64_t> &shape = {}) noexcept
- Creates a MSTensor object from local file, must be used in pairs with DestroyTensorPtr. 
 - 
static inline MSTensor *StringsToTensor(const std::string &name, const std::vector<std::string> &str)
- Create a string type MSTensor object whose data can be accessed by Model only after being copied, must be used in pair with DestroyTensorPtr.