Class TensorLayout
Defined in File TensorLayout.hpp
Class Documentation
-
class TensorLayout
Represents the layout of a tensor.
This class wraps around the NVCVTensorLayout structure and provides additional functionality for handling and manipulating tensor layouts. The class allows for easy construction from character descriptions or from other tensor layout structures. It also supports a range of operations including subsetting and checking for prefixes or suffixes.
Public Types
-
using const_iterator = const char*
-
using iterator = const_iterator
-
using value_type = char
Public Functions
-
TensorLayout() = default
-
inline constexpr TensorLayout(const NVCVTensorLayout &layout)
Constructs a TensorLayout from an NVCVTensorLayout.
- Parameters:
layout – The NVCVTensorLayout to wrap.
-
inline explicit TensorLayout(const char *descr)
Constructs a TensorLayout from a character description.
- Parameters:
descr – The character description of the layout.
-
template<class IT, class = detail::IsRandomAccessIterator<IT>>
inline explicit TensorLayout(IT itbeg, IT itend) Constructs a TensorLayout from a range of iterators.
- Template Parameters:
IT – The type of the iterators.
- Parameters:
itbeg – The beginning of the range.
itend – The end of the range.
-
constexpr char operator[](int idx) const
Fetches the character representation of a dimension at a specified index.
- Parameters:
idx – The index of the dimension.
- Returns:
The character representation of the dimension.
-
constexpr int rank() const
Gets the rank (number of dimensions) of the tensor layout.
- Returns:
The rank of the tensor layout.
-
inline int find(char dimLabel, int start = 0) const
Finds the index of the first occurrence of a specified dimension label.
- Parameters:
dimLabel – The dimension label to search for.
start – The starting index for the search.
- Returns:
The index of the first occurrence of the dimension label, or -1 if not found.
-
inline bool startsWith(const TensorLayout &test) const
Checks if the current layout starts with a specified layout.
- Parameters:
test – The layout to check against.
- Returns:
true if the current layout starts with the test layout, false otherwise.
-
inline bool endsWith(const TensorLayout &test) const
Checks if the current layout ends with a specified layout.
- Parameters:
test – The layout to check against.
- Returns:
true if the current layout ends with the test layout, false otherwise.
-
inline TensorLayout subRange(int beg, int end) const
Creates a sub-layout from a specified range.
- Parameters:
beg – The starting index of the range.
end – The ending index of the range.
- Returns:
A new TensorLayout representing the sub-range.
-
inline TensorLayout first(int n) const
Creates a sub-layout consisting of the first n dimensions.
- Parameters:
n – The number of dimensions to include.
- Returns:
A new TensorLayout representing the first n dimensions.
-
inline TensorLayout last(int n) const
Creates a sub-layout consisting of the last n dimensions.
- Parameters:
n – The number of dimensions to include.
- Returns:
A new TensorLayout representing the last n dimensions.
-
inline bool operator!=(const TensorLayout &that) const
-
inline bool operator<(const TensorLayout &that) const
-
constexpr const_iterator begin() const
-
inline constexpr const_iterator end() const
-
constexpr const_iterator cbegin() const
-
constexpr const_iterator cend() const
-
constexpr operator const NVCVTensorLayout&() const
Public Members
-
NVCVTensorLayout m_layout
Friends
-
friend bool operator==(const TensorLayout &a, const TensorLayout &b)
-
friend std::ostream &operator<<(std::ostream &out, const TensorLayout &that)
Outputs the TensorLayout to a stream.
- Parameters:
out – The output stream.
that – The TensorLayout to output.
- Returns:
The output stream.
-
using const_iterator = const char*