• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# tensor.h
2
3
4## Overview
5
6Provides tensor-related APIs, which can be used to create tensors and modify tensor information. These APIs are non-thread-safe.
7
8**File to include**: <mindspore/tensor.h>
9
10**Library**: libmindspore_lite_ndk.so
11
12**System capability**: SystemCapability.Ai.MindSpore
13
14**Since**: 9
15
16**Related module**: [MindSpore](_mind_spore.md)
17
18
19## Summary
20
21
22### Types
23
24| Name| Description|
25| -------- | -------- |
26| [OH_AI_TensorHandle](_mind_spore.md#oh_ai_tensorhandle) | Defines the handle of a tensor object.|
27| [OH_AI_AllocatorHandle](_mind_spore.md#oh_ai_allocatorhandle) | Defines the handle of the memory allocator.|
28
29
30### Functions
31
32| Name| Description|
33| -------- | -------- |
34| [OH_AI_TensorCreate](_mind_spore.md#oh_ai_tensorcreate) (const char \*name, OH_AI_DataType type, const int64_t \*shape, <br>size_t shape_num, const void \*data, size_t data_len) | Creates a tensor object.|
35| [OH_AI_TensorDestroy](_mind_spore.md#oh_ai_tensordestroy) (OH_AI_TensorHandle \*tensor) | Destroys a tensor object.|
36| [OH_AI_TensorClone](_mind_spore.md#oh_ai_tensorclone) (OH_AI_TensorHandle tensor) | Clones a tensor.|
37| [OH_AI_TensorSetName](_mind_spore.md#oh_ai_tensorsetname) (OH_AI_TensorHandle tensor, const char \*name) | Sets the tensor name.|
38| [OH_AI_TensorGetName](_mind_spore.md#oh_ai_tensorgetname) (const OH_AI_TensorHandle tensor) | Obtains the tensor name.|
39| [OH_AI_TensorSetDataType](_mind_spore.md#oh_ai_tensorsetdatatype) (OH_AI_TensorHandle tensor, OH_AI_DataType type) | Sets the data type of a tensor.|
40| [OH_AI_TensorGetDataType](_mind_spore.md#oh_ai_tensorgetdatatype) (const OH_AI_TensorHandle tensor) | Obtains the tensor type.|
41| [OH_AI_TensorSetShape](_mind_spore.md#oh_ai_tensorsetshape) (OH_AI_TensorHandle tensor, <br>const int64_t \*shape, size_t shape_num) | Sets the tensor shape.|
42| [OH_AI_TensorGetShape](_mind_spore.md#oh_ai_tensorgetshape) (const OH_AI_TensorHandle tensor, size_t \*shape_num) | Obtains the tensor shape.|
43| [OH_AI_TensorSetFormat](_mind_spore.md#oh_ai_tensorsetformat) (OH_AI_TensorHandle tensor, OH_AI_Format format) | Sets the tensor data format.|
44| [OH_AI_TensorGetFormat](_mind_spore.md#oh_ai_tensorgetformat) (const OH_AI_TensorHandle tensor) | Obtains the tensor data format.|
45| [OH_AI_TensorSetData](_mind_spore.md#oh_ai_tensorsetdata) (OH_AI_TensorHandle tensor, void \*data) | Sets the tensor data.|
46| [OH_AI_TensorGetData](_mind_spore.md#oh_ai_tensorgetdata) (const OH_AI_TensorHandle tensor) | Obtains the pointer to tensor data.|
47| [OH_AI_TensorGetMutableData](_mind_spore.md#oh_ai_tensorgetmutabledata) (const OH_AI_TensorHandle tensor) | Obtains the pointer to variable tensor data. If the data is empty, memory will be allocated.|
48| [OH_AI_TensorGetElementNum](_mind_spore.md#oh_ai_tensorgetelementnum) (const OH_AI_TensorHandle tensor) | Obtains the number of tensor elements.|
49| [OH_AI_TensorGetDataSize](_mind_spore.md#oh_ai_tensorgetdatasize) (const OH_AI_TensorHandle tensor) | Obtains the number of bytes of the tensor data.|
50| [OH_AI_TensorSetUserData](_mind_spore.md#oh_ai_tensorsetuserdata) ([OH_AI_TensorHandle](_mind_spore.md#oh_ai_tensorhandle) tensor, void \*data, size_t data_size) | Sets the tensor as the user data. This function allows you to reuse user data as the model input, which helps to reduce data copy by one time.|
51| [OH_AI_TensorGetAllocator](_mind_spore.md#oh_ai_tensorgetallocator)([OH_AI_TensorHandle](_mind_spore.md#oh_ai_tensorhandle) tensor) | Obtains a memory allocator.|
52| [OH_AI_TensorSetAllocator](_mind_spore.md#oh_ai_tensorsetallocator)([OH_AI_TensorHandle](_mind_spore.md#oh_ai_tensorhandle) tensor, [OH_AI_AllocatorHandle](_mind_spore.md#oh_ai_allocatorhandle) allocator) | Sets the memory allocator.|
53