Tensor¶
- class
Tensor
¶ The base tensor class, manage memory or not.
Tensor is usually constructed with the shape info:
auto* a = new dragon::Tensor(std::vector<int64_t>({2, 3})); auto* b = dragon::Tensor().Reshape({2, 3}); // Equivalent
To allocate the data, type meta and device context are also required:
auto meta = dragon::TypeMeta::Make<float>(); auto* raw_data = a->raw_mutable_data<dragon::CPUContext>(meta); auto* data = b->mutable_data<float, dragon::CPUContext>();
Memory will be reset if required bytes is larger than capacity:
std::cout << a->nbytes() << " " << a->capacity() << std::endl; // 24, 24 std::cout << a->Reshape({2, 4})->size() << std::endl; // 8 std::cout << a->nbytes() << " " << a->capacity() << std::endl; // 32, 0 a->mutable_data<float, dragon::CPUContext>(); a->Reshape({2, 3}); std::cout << a->nbytes() << " " << a->capacity() << std::endl; // 24, 32
Constructors¶
Public Properties¶
conut¶
conut¶
conut¶
data¶
memory¶
- inline UnifiedMemory *
dragon::Tensor::
memory
(
bool required = false,
bool owned = false)¶ Return the memory.
memory_state¶
- inline UnifiedMemory::State
dragon::Tensor::
memory_state
()¶ Return the memory state.
mutable_data¶
raw_data¶
raw_mutable_data¶
Public Functions¶
CopyFrom¶
CopyFrom¶
- template<typename
TensorType
, typenameVectorType
>
inline Tensor *dragon::Tensor::
CopyFrom
(const vector<VectorType> &other)¶ Copy memory from a vector.
CopyTo¶
- template<typename
TensorType
, typenameVectorType
>
inline voiddragon::Tensor::
CopyTo
(vector<VectorType> &dest)¶ Copy memory to a vector.