Class Tensor

Inheritance Relationships

Base Type

Class Documentation

class Tensor : public nvcv::CoreResource<NVCVTensorHandle, Tensor>

Represents a tensor as a core resource in the system.

The Tensor class is built upon the CoreResource utility class, which handles the resource management of the tensor. This class provides various interfaces to access and manage tensor properties such as rank, shape, data type, and layout.

Public Types

using HandleType = NVCVTensorHandle
using Base = CoreResource<NVCVTensorHandle, Tensor>
using Requirements = NVCVTensorRequirements

Public Functions

inline int rank() const

Retrieves the rank (number of dimensions) of the tensor.

Returns:

Rank of the tensor.

inline TensorShape shape() const

Retrieves the shape of the tensor.

Returns:

Shape of the tensor.

inline DataType dtype() const

Retrieves the data type of the tensor elements.

Returns:

Data type of the tensor.

inline TensorLayout layout() const

Retrieves the layout of the tensor.

Returns:

Layout of the tensor.

inline TensorData exportData() const

Exports the data of the tensor.

Returns:

TensorData object representing the tensor’s data.

template<typename DerivedTensorData>
inline Optional<DerivedTensorData> exportData() const

Exports the tensor data and casts it to a specified derived data type.

Template Parameters:

DerivedTensorData – The derived tensor data type to cast to.

Returns:

An optional object of the derived tensor data type.

inline void setUserPointer(void *ptr)

Sets a user-defined pointer associated with the tensor.

Parameters:

ptr – Pointer to set.

inline void *userPointer() const

Retrieves the user-defined pointer associated with the tensor.

Returns:

User-defined pointer.

inline Tensor reshape(const TensorShape &new_shape)

Creates a view of the tensor with a new shape and layout.

inline Tensor(const Tensor &other)
inline Tensor(Tensor &&other)
inline Tensor &operator=(const Tensor &other)
inline Tensor &operator=(Tensor &&other)
inline explicit Tensor(const Requirements &reqs, const Allocator &alloc = nullptr)

Constructors.

inline explicit Tensor(const TensorShape &shape, DataType dtype, const MemAlignment &bufAlign = {}, const Allocator &alloc = nullptr)
inline explicit Tensor(int numImages, Size2D imgSize, ImageFormat fmt, const MemAlignment &bufAlign = {}, const Allocator &alloc = nullptr)

Public Static Functions

static inline Requirements CalcRequirements(const TensorShape &shape, DataType dtype, const MemAlignment &bufAlign = {})

Calculates the requirements for a tensor given its shape and data type.

Parameters:
  • shapeShape of the tensor.

  • dtype – Data type of the tensor elements.

  • bufAlign – Memory alignment for the tensor.

Returns:

Requirements object representing the tensor’s requirements.

static inline Requirements CalcRequirements(int numImages, Size2D imgSize, ImageFormat fmt, const MemAlignment &bufAlign = {})

Calculates the requirements for a tensor representing a set of images.

Parameters:
  • numImages – Number of images.

  • imgSize – Dimensions of the images.

  • fmt – Format of the images.

  • bufAlign – Memory alignment for the tensor.

Returns:

Requirements object representing the tensor’s requirements.