Class MSTensor

Class Documentation

class MSTensor

MSTensor defined tensor in MindSpore Lite.

Public Functions

MSTensor() = default

Constructor of MindSpore Lite MSTensor.

Returns

Instance of MindSpore Lite MSTensor.

virtual ~MSTensor() = default

Destructor of MindSpore Lite Model.

virtual void set_allocator(AllocatorPtr allocator) = 0

Set memory allocator for current MSTensor.

Parameters

allocator[in] Define memory allocator, which is shown in allocator.h.

virtual AllocatorPtr allocator() const = 0

Get memory allocator of current MSTensor.

Returns

Pointer of memory allocator class.

virtual TypeId data_type() const = 0

Get data type of the MindSpore Lite MSTensor.

Note

TypeId is defined in mindspore/mindspore/include/api/type_id.h. Only number types in TypeId enum are suitable for MSTensor.

Returns

MindSpore Lite TypeId of the MindSpore Lite MSTensor.

virtual void set_data_type(TypeId data_type) = 0

Set data type of current MSTensor.

Parameters

data_type[in] Define data type, which is shown in type_id.h.

virtual void set_format(mindspore::Format format) = 0

Set format of current MSTensor.

Parameters

format[in] Define format of data, which is shown in format.h

virtual mindspore::Format format() const = 0

Get format of current MSTensor.

Returns

format, which is shown in format.h

virtual Vector<int> shape() const = 0

Get shape of the MindSpore Lite MSTensor.

Returns

A vector of int as the shape of the MindSpore Lite MSTensor.

virtual void set_shape(const Vector<int> &shape) = 0

Set the shape of MSTensor.

virtual int64_t ElementsNum() const = 0

Get number of element in MSTensor.

Returns

Number of element in MSTensor.

virtual size_t Size() const = 0

Get byte size of data in MSTensor.

Returns

Byte size of data in MSTensor.

virtual String tensor_name() const = 0

Get the name of MSTensor.

Returns

the name of MSTensor.

virtual void set_tensor_name(const String &name) = 0

Set the name of MSTensor.

virtual void *MutableData() = 0

Get the pointer of data in MSTensor.

Note

The data pointer can be used to both write and read data in MSTensor. The memory buffer will be automatically allocated.

Returns

the pointer points to data in MSTensor.

virtual void *data() = 0

Get the pointer of data in MSTensor.

Note

The data pointer can be used to both write and read data in MSTensor. No memory buffer will be allocated.

Returns

the pointer points to data in MSTensor.

virtual void set_data(void *data) = 0

Set the data of MSTensor.

\node MSTensor will hold this data and free this data in destructor.

Parameters

data – The data pointer delivered into MSTensor.

virtual bool IsConst() const = 0

Get whether the MSTensor data is const data.

Returns

Const flag of MSTensor

Public Static Functions

static MSTensor *CreateTensor(const String &name, TypeId type, const Vector<int> &shape, const void *data, size_t data_len)

Create a MSTensor.

Returns

Pointer to an instance of MindSpore Lite MSTensor.