Dragon - C++ API
A Computation Graph Virtual Machine Based Deep Learning Framework
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
dragon::Tensor Class Reference

#include <tensor.h>

Public Member Functions

 Tensor ()
 Default Constructor. More...
 
 Tensor (const string &name)
 Constructor with the known name. More...
 
 Tensor (const vec64_t &dims)
 Constructor with the known int64 dimensions. More...
 
 Tensor (const vec32_t &dims)
 Constructor with the known int32 dimensions. More...
 
TensorReshape (const vec64_t &dims)
 Reshape to the given dimensions. More...
 
TensorReshapeLike (const Tensor &other)
 Reshape the dimensions like the given tensor. More...
 
const string & name () const
 Return the tensor name. More...
 
int64_t axis (const int64_t i) const
 Return a canonical axis. More...
 
int ndim () const
 Return the number of dimensions. More...
 
int64_t dim (int64_t i) const
 Return the dimension of given axis. More...
 
const vec64_tdims () const
 Return all the dimensions. More...
 
size_t size () const
 Return the total number of elements of this tensor. More...
 
size_t nbytes () const
 Return the total number bytes of this tensor. More...
 
size_t capacity () const
 Return the capacity of the internal memory. More...
 
int64_t count (int64_t start, int64_t end) const
 Return the number of elements along the [start, end) axes. More...
 
int64_t count () const
 Return the total number of elements of this tensor. More...
 
int64_t count (int64_t start) const
 Return the number of elements from the start axis. More...
 
int64_t stride (int64_t i) const
 Return the stride of given axis. More...
 
const vec64_tstrides () const
 Return all the strides. More...
 
string DimString () const
 Return a string to describe the dimensions of this tensor. More...
 
int version () const
 Return the version of this tensor. More...
 
void set_version (int version)
 Set the version of this tensor. More...
 
bool has_memory () const
 Whether this tensor holds a valid memory. More...
 
MixedMemorymemory () const
 Return the pointer of internal memory. More...
 
void set_memory (MixedMemory *mem)
 Set the memory from a external pointer. More...
 
MixedMemory::State memory_state () const
 Return the state of the internal memory. More...
 
void SwitchToDevice (int device_id)
 Switch the memory to the specific device. More...
 
const TypeMetameta () const
 Return the type meta of this tensor. More...
 
void SetMeta (const TypeMeta &meta)
 Set the type meta. More...
 
template<typename T >
bool IsType ()
 Whether the data type of this tensor is <T> More...
 
template<class Context >
void mutable_data_ptr (void **data_ptr)
 Try to get the raw mutable data pointer. More...
 
template<class Context >
const void * const_data_ptr () const
 Try to get the raw const data pointer. More...
 
template<class Context >
void * raw_mutable_data (const TypeMeta &meta)
 Try to allocate the raw data memory. More...
 
template<class Context >
void * raw_mutable_data ()
 Get the raw mutable data pointer. More...
 
template<class Context >
const void * raw_data () const
 Get the raw const data pointer. More...
 
template<typename T , class Context >
T * mutable_data ()
 Get the typed mutable data pointer. More...
 
template<typename T , class Context >
const T * data () const
 Get the typed const data pointer. More...
 
template<class Context >
TensorCopyFrom (const Tensor &other, Context *ctx)
 Copy the contents from the given tensor. More...
 
void Move (MixedMemory *mem)
 Move the external memory. More...
 
void Share (MixedMemory *mem)
 Share the external memory. More...
 
void Reset ()
 Reset the memory. More...
 
 ~Tensor ()
 Deconstructor. More...
 

Static Public Member Functions

static string DimString (const vector< int64_t > &dims)
 Return a string to describe the given dimensions. More...
 

Public Attributes

std::function< void()> DECREFPyArray
 Reset the owned PyArray memory. More...
 

Constructor & Destructor Documentation

◆ Tensor() [1/4]

dragon::Tensor::Tensor ( )
inline

Default Constructor.

◆ Tensor() [2/4]

dragon::Tensor::Tensor ( const string &  name)
inline

Constructor with the known name.

◆ Tensor() [3/4]

dragon::Tensor::Tensor ( const vec64_t dims)
inline

Constructor with the known int64 dimensions.

◆ Tensor() [4/4]

dragon::Tensor::Tensor ( const vec32_t dims)
inline

Constructor with the known int32 dimensions.

◆ ~Tensor()

dragon::Tensor::~Tensor ( )
inline

Deconstructor.

DO NOT CALL DECREFARRAY

Member Function Documentation

◆ axis()

int64_t dragon::Tensor::axis ( const int64_t  i) const
inline

Return a canonical axis.

◆ capacity()

size_t dragon::Tensor::capacity ( ) const
inline

Return the capacity of the internal memory.

◆ const_data_ptr()

template<class Context >
const void* dragon::Tensor::const_data_ptr ( ) const
inline

Try to get the raw const data pointer.

◆ CopyFrom()

template<class Context >
Tensor* dragon::Tensor::CopyFrom ( const Tensor other,
Context *  ctx 
)
inline

Copy the contents from the given tensor.

◆ count() [1/3]

int64_t dragon::Tensor::count ( int64_t  start,
int64_t  end 
) const
inline

Return the number of elements along the [start, end) axes.

◆ count() [2/3]

int64_t dragon::Tensor::count ( ) const
inline

Return the total number of elements of this tensor.

◆ count() [3/3]

int64_t dragon::Tensor::count ( int64_t  start) const
inline

Return the number of elements from the start axis.

◆ data()

template<typename T , class Context >
const T* dragon::Tensor::data ( ) const
inline

Get the typed const data pointer.

◆ dim()

int64_t dragon::Tensor::dim ( int64_t  i) const
inline

Return the dimension of given axis.

◆ dims()

const vec64_t& dragon::Tensor::dims ( ) const
inline

Return all the dimensions.

◆ DimString() [1/2]

static string dragon::Tensor::DimString ( const vector< int64_t > &  dims)
inlinestatic

Return a string to describe the given dimensions.

◆ DimString() [2/2]

string dragon::Tensor::DimString ( ) const
inline

Return a string to describe the dimensions of this tensor.

◆ has_memory()

bool dragon::Tensor::has_memory ( ) const
inline

Whether this tensor holds a valid memory.

◆ IsType()

template<typename T >
bool dragon::Tensor::IsType ( )
inline

Whether the data type of this tensor is <T>

◆ memory()

MixedMemory* dragon::Tensor::memory ( ) const
inline

Return the pointer of internal memory.

◆ memory_state()

MixedMemory::State dragon::Tensor::memory_state ( ) const
inline

Return the state of the internal memory.

◆ meta()

const TypeMeta& dragon::Tensor::meta ( ) const
inline

Return the type meta of this tensor.

◆ Move()

void dragon::Tensor::Move ( MixedMemory mem)
inline

Move the external memory.

◆ mutable_data()

template<typename T , class Context >
T* dragon::Tensor::mutable_data ( )
inline

Get the typed mutable data pointer.

◆ mutable_data_ptr()

template<class Context >
void dragon::Tensor::mutable_data_ptr ( void **  data_ptr)
inline

Try to get the raw mutable data pointer.

◆ name()

const string& dragon::Tensor::name ( ) const
inline

Return the tensor name.

◆ nbytes()

size_t dragon::Tensor::nbytes ( ) const
inline

Return the total number bytes of this tensor.

◆ ndim()

int dragon::Tensor::ndim ( ) const
inline

Return the number of dimensions.

◆ raw_data()

template<class Context >
const void* dragon::Tensor::raw_data ( ) const
inline

Get the raw const data pointer.

◆ raw_mutable_data() [1/2]

template<class Context >
void* dragon::Tensor::raw_mutable_data ( const TypeMeta meta)
inline

Try to allocate the raw data memory.

◆ raw_mutable_data() [2/2]

template<class Context >
void* dragon::Tensor::raw_mutable_data ( )
inline

Get the raw mutable data pointer.

◆ Reset()

void dragon::Tensor::Reset ( )
inline

Reset the memory.

◆ Reshape()

Tensor* dragon::Tensor::Reshape ( const vec64_t dims)
inline

Reshape to the given dimensions.

◆ ReshapeLike()

Tensor* dragon::Tensor::ReshapeLike ( const Tensor other)
inline

Reshape the dimensions like the given tensor.

◆ set_memory()

void dragon::Tensor::set_memory ( MixedMemory mem)
inline

Set the memory from a external pointer.

◆ set_version()

void dragon::Tensor::set_version ( int  version)
inline

Set the version of this tensor.

◆ SetMeta()

void dragon::Tensor::SetMeta ( const TypeMeta meta)
inline

Set the type meta.

◆ Share()

void dragon::Tensor::Share ( MixedMemory mem)
inline

Share the external memory.

◆ size()

size_t dragon::Tensor::size ( ) const
inline

Return the total number of elements of this tensor.

◆ stride()

int64_t dragon::Tensor::stride ( int64_t  i) const
inline

Return the stride of given axis.

◆ strides()

const vec64_t& dragon::Tensor::strides ( ) const
inline

Return all the strides.

◆ SwitchToDevice()

void dragon::Tensor::SwitchToDevice ( int  device_id)
inline

Switch the memory to the specific device.

◆ version()

int dragon::Tensor::version ( ) const
inline

Return the version of this tensor.

Member Data Documentation

◆ DECREFPyArray

std::function<void()> dragon::Tensor::DECREFPyArray

Reset the owned PyArray memory.


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