ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | List of all members
container::TensorMap Class Reference

A multi-dimensional reference array of elements of a single data type. More...

#include <tensor_map.h>

Inheritance diagram for container::TensorMap:
Collaboration diagram for container::TensorMap:

Public Member Functions

 TensorMap (void *data, DataType data_type, DeviceType device, const TensorShape &shape)
 Constructor that map the given data pointer to a tensor object with the given data type, device type and shape.
 
 TensorMap (void *data, const Tensor &other, const TensorShape &shape)
 Constructs a TensorMap from the provided data, with the specified shape.
 
 TensorMap (void *data, const Tensor &other)
 Constructs a TensorMap from the provided data, using the shape of the provided Tensor.
 
- Public Member Functions inherited from container::Tensor
 Tensor ()
 Creates a 1-dimentional, 0-element float tensor.
 
 Tensor (DataType data_type)
 Explicit constructor for the Tensor class.
 
 Tensor (DataType data_type, const TensorShape &shape)
 Constructor that creates a tensor with the given data type and shape using the default allocator.
 
 Tensor (DataType data_type, DeviceType device, const TensorShape &shape)
 Construct a new Tensor object with the given data type, shape and device type.
 
 Tensor (base::core::Allocator *a, DataType data_type, DeviceType device, const TensorShape &shape)
 
 Tensor (const Tensor &other)
 Construct a new Tensor object by copying another Tensor.
 
 Tensor (Tensor &&other) noexcept
 Move constructor for the Tensor class.
 
 ~Tensor ()
 
template<typename T >
 Tensor (std::initializer_list< T > values, DeviceType device=DeviceType::CpuDevice)
 Constructor for the Tensor class using an initializer list of values.
 
DataType data_type () const
 Get the data type of the tensor.
 
DeviceType device_type () const
 Get the data type of the tensor.
 
const TensorShapeshape () const
 Get the shape of the tensor.
 
int64_t NumElements () const
 Get the total number of elements in the tensor.
 
void * data () const
 Get a pointer to the data buffer of the tensor.
 
template<typename T >
Tdata () const
 Get a typed pointer to the data buffer of the tensor.
 
const TensorBufferbuffer () const
 Get the TensorBuffer object that holds the data of the tensor.
 
template<typename DEVICE >
Tensor to_device () const
 Method to transform data from a given tensor object to the output tensor with a given device type.
 
template<typename DEVICE , typename T >
void copy_from_device (const T *data, int64_t num_elements=-1)
 Copies data from a given device to the current tensor object.
 
template<typename T >
Tensor cast () const
 Method to transform data from a given tensor object to the output tensor with a given data type.
 
void zero ()
 Set all elements in current tensor object to zero.
 
void reshape (TensorShape shape)
 Set all elements in current tensor object to zero.
 
Tensor shaped (const TensorShape &shape) const
 Set all elements in current tensor object to zero.
 
Tensor slice (const std::vector< int > &start, const std::vector< int > &size) const
 Return a new Tensor slice starting at the specified indices with the given size.
 
void resize (const TensorShape &new_shape)
 Resize the tensor to the new shape.
 
template<typename T , typename... Indices>
Tget_value (Indices... indices) const
 Get the element at the specified indices.
 
template<typename T >
Tinner_most_ptr (const int &index) const
 Get the pointer to the specified row.
 
bool operator== (const Tensor &other) const
 Equality comparison operator for tensors.
 
Tensoroperator= (const Tensor &other)
 Assignment operator overload for the Tensor class.
 
Tensoroperator= (Tensor &&other) noexcept
 Move assignment operator overload for the Tensor class.
 
bool CopyFrom (const Tensor &other)
 Copy the data from another tensor into this tensor.
 
bool CopyFrom (const Tensor &other, const TensorShape &shape)
 Copy the data from another tensor into this tensor while reshaping it.
 
bool AllocateFrom (const Tensor &other, const TensorShape &shape)
 Copies data from another Tensor with memory allocation and specified shape.
 
template<typename T , size_t N, typename index_t = int64_t>
TensorAccessor< T, N, index_t > accessor () const &
 Accessor function for a multi-dimensional tensor.
 
template<typename T , size_t N, typename index_t = int>
TensorAccessor< T, N, index_t > accessor () &&=delete
 
void sync (const Tensor &rhs)
 Synchronize the current Tensor with another Tensor.
 
Tensor operator[] (const int &index) const
 Access a sub-Tensor based on an index.
 
 operator bool () const
 
template<typename T >
void set_value (T value)
 

Additional Inherited Members

- Static Public Member Functions inherited from container::Tensor
static size_t SizeOfType (DataType data_type)
 Returns the size of a single element for a given data type.
 
static base::core::AllocatorGetAllocator (DeviceType device)
 Get the Allocator object according to the given device type.
 
- Protected Member Functions inherited from container::Tensor
template<typename... Indices>
size_t calculateLinearIndex (Indices... indices) const
 Calculates the linear index corresponding to the given indices.
 
void CopyFromInternal (const Tensor &other, const TensorShape &shape)
 
- Protected Attributes inherited from container::Tensor
DataType data_type_
 The data type of the tensor.
 
DeviceType device_
 The device type of the tensor.
 
TensorShape shape_
 The shape of the tensor.
 
TensorBufferbuffer_ {}
 The TensorBuffer object that holds the data of the tensor.
 

Detailed Description

A multi-dimensional reference array of elements of a single data type.

This class represents a Tensor, which is a fundamental concept in container. A Tensor has a data type, shape, and memory buffer that stores the actual data.

This class is not thread-safe and should not be accessed by multiple threads concurrently.

Constructor & Destructor Documentation

◆ TensorMap() [1/3]

container::TensorMap::TensorMap ( void *  data,
DataType  data_type,
DeviceType  device,
const TensorShape shape 
)

Constructor that map the given data pointer to a tensor object with the given data type, device type and shape.

This tensor does not own memory.

Parameters
dataThe data pointer.
data_typeThe data type of the tensor.
deviceThe data type of the tensor.
shapeThe shape of the tensor.

◆ TensorMap() [2/3]

container::TensorMap::TensorMap ( void *  data,
const Tensor other,
const TensorShape shape 
)

Constructs a TensorMap from the provided data, with the specified shape.

This constructor creates a TensorMap that references the data pointed to by the 'data' parameter, and associates it with the given Tensor 'other' and TensorShape 'shape'. The TensorMap allows access to the data with the specified shape without owning the data.

Parameters
dataA pointer to the data to be referenced by the TensorMap.
otherThe Tensor object to be associated with the TensorMap.
shapeThe shape of the data referenced by the TensorMap.

◆ TensorMap() [3/3]

container::TensorMap::TensorMap ( void *  data,
const Tensor other 
)

Constructs a TensorMap from the provided data, using the shape of the provided Tensor.

This constructor creates a TensorMap that references the data pointed to by the 'data' parameter, and associates it with the given Tensor 'other'. The shape of the data is determined by the shape of the 'other' Tensor. The TensorMap allows access to the data with the shape of 'other' without owning the data.

Parameters
dataA pointer to the data to be referenced by the TensorMap.
otherThe Tensor object to be associated with the TensorMap, which defines the shape.

The documentation for this class was generated from the following files: