clDNN
cldnn::tensor Struct Reference

N-dimensional vector. Mostly used to represent memory size. More...

#include <tensor.hpp>

Public Types

typedef int32_t value_type
 Values type stored in tensor.
 

Public Member Functions

 tensor (value_type default_size=0)
 
template<typename ... KindInitTys, typename = typename std::enable_if< meta::all< meta::is_any_of<KindInitTys, cldnn::details::dim_vec_kind_init<cldnn::details::dim_vec_kind::batch>, cldnn::details::dim_vec_kind_init<cldnn::details::dim_vec_kind::feature>, cldnn::details::dim_vec_kind_init<details::dim_vec_kind::spatial> >::value... >::value, void>::type>
 tensor (KindInitTys &&... kind_inits)
 Constructs tensor. More...
 
 tensor (value_type batch_num, value_type feature_num, value_type width, value_type height)
 Constructs tensor. More...
 
 tensor (const std::vector< value_type > &sizes, value_type default_size=1)
 Constructs tensor using vector of sizes. More...
 
 tensor (format fmt, const std::vector< value_type > &sizes, value_type default_size=1)
 
 tensor (const cldnn_tensor &other)
 Implicit conversion form C API :: cldnn_tensor.
 
 operator cldnn_tensor () const
 Implicit conversion to C API cldnn_tensor.
 
 tensor (const tensor &other)
 Copy construction.
 
tensoroperator= (const tensor &other)
 Copy assignment.
 
std::string to_string () const
 
tensor negate () const
 Returns a tensor with all negated elements.
 
tensor mul (value_type multiplier) const
 Returns a tensor with all elements multilied to multiplier.
 
tensor div (value_type divider) const
 Returns a tensor with all elements divided by divider.
 
tensor add (const tensor &rhs) const
 Returns a tensor with all elements added by appropriate elements of rhs.
 
tensor sub (const tensor &rhs) const
 Returns a tensor with all elements subtracted by appropriate elements of rhs.
 
tensoroperator+= (const tensor &rhs)
 Assign and add.
 
tensoroperator-= (const tensor &rhs)
 Assign and subtract.
 
std::vector< value_typesizes (cldnn::format fmt) const
 Returns a vector of tensors values, ordered regarding to format.
 
std::vector< value_typesizes () const
 Returns a vector of tensors values, ordered batch, feature, spatial_x, spatial_y.
 
size_t count () const
 Returns tensor elements count calculated as multiplication of all elements.
 
tensor transform (cldnn::format new_fmt, value_type default_size) const
 Returns new tensor based on current but transformed to new format. More...
 
size_t get_linear_offset (const tensor &coord, cldnn::format fmt) const
 Calculates linear offset for given coord within current tensor. More...
 

Static Public Member Functions

static tensor max (tensor const &lhs, tensor const &rhs)
 Returns a tensor containing values maximum from lhs and rhs.
 
static tensor min (tensor const &lhs, tensor const &rhs)
 Returns a tensor containing values minimum from lhs and rhs.
 

Public Attributes

mutable_array_ref< value_typeraw
 Raw representation of all dimensions.
 
mutable_array_ref< value_typebatch
 Batch dimensions.
 
mutable_array_ref< value_typefeature
 Feature maps.
 
mutable_array_ref< value_typespatial
 Spatial dimensions.
 

Friends

bool operator== (const tensor &lhs, const tensor &rhs)
 
bool operator!= (const tensor &lhs, const tensor &rhs)
 
bool operator< (const tensor &lhs, const tensor &rhs)
 
std::ostream & operator<< (std::ostream &os, const tensor &tensor)
 

Detailed Description

N-dimensional vector. Mostly used to represent memory size.

Definition at line 256 of file tensor.hpp.

Constructor & Destructor Documentation

◆ tensor() [1/3]

template<typename ... KindInitTys, typename = typename std::enable_if< meta::all< meta::is_any_of<KindInitTys, cldnn::details::dim_vec_kind_init<cldnn::details::dim_vec_kind::batch>, cldnn::details::dim_vec_kind_init<cldnn::details::dim_vec_kind::feature>, cldnn::details::dim_vec_kind_init<details::dim_vec_kind::spatial> >::value... >::value, void>::type>
cldnn::tensor::tensor ( KindInitTys &&...  kind_inits)
inline

Constructs tensor.

Parameters
[in]kind_initsDimensions defined using dim_vec_kind. If dimension is not provided it is set to 1.

Example:

tensor my_tensor(batch(2), spatial(5, 6)); // y=6, x=5, b=2, f - not set
cout << my_tensor.batch[0] << endl; // 2
cout << my_tensor.feature[0] << endl; // 1 - default_size
cout << "x=" << my_tensor.spatial[0] << endl; // x=5
cout << "y=" << my_tensor.spatial[1] << endl; // y=6

Definition at line 306 of file tensor.hpp.

◆ tensor() [2/3]

cldnn::tensor::tensor ( value_type  batch_num,
value_type  feature_num,
value_type  width,
value_type  height 
)
inline

Constructs tensor.

Example:

tensor my_tensor( 2, 3, 4, 5 ); // b=2, f=3, x=4, y=5
cout << my_tensor.batch[0] << endl; // 2
cout << my_tensor.feature[0] << endl; // 3
cout << "x=" << my_tensor.spatial[0] << endl; // x=4
cout << "y=" << my_tensor.spatial[1] << endl; // y=5

Definition at line 324 of file tensor.hpp.

◆ tensor() [3/3]

cldnn::tensor::tensor ( const std::vector< value_type > &  sizes,
value_type  default_size = 1 
)
inline

Constructs tensor using vector of sizes.

Parameters
[in]sizesdimensions need to be provided in the following order {batch, feature, spatial_x, spatial_y}.
[in]default_sizedefault_size for tensor dimensions.

Example:

tensor my_tensor = { 2, 3, 4, 5 }; // b=2, f=3, x=4, y=5
cout << my_tensor.batch[0] << endl; // 2
cout << my_tensor.feature[0] << endl; // 3
cout << "x=" << my_tensor.spatial[0] << endl; // x=4
cout << "y=" << my_tensor.spatial[1] << endl; // y=5

Definition at line 347 of file tensor.hpp.

Member Function Documentation

◆ get_linear_offset()

size_t cldnn::tensor::get_linear_offset ( const tensor coord,
cldnn::format  fmt 
) const
inline

Calculates linear offset for given coord within current tensor.

Parameters
coordThe coordinate within current tensor.

Definition at line 639 of file tensor.hpp.

◆ transform()

tensor cldnn::tensor::transform ( cldnn::format  new_fmt,
value_type  default_size 
) const
inline

Returns new tensor based on current but transformed to new format.

Parameters
[in]new_fmtFormat of new tensor.
[in]default_sizeDefault element values for positions not defined by current format.

Example:

tensor my_tensor({ 2, 3, 4, 5 });
auto my_sizes = my_tensor.sizes();
cout << "dims_num=" << my_sizes.size() << endl; // dims_num=2
cout << "b=" << my_sizes[0] << endl; // b=2
cout << "f=" << my_sizes[1] << endl; // f=3
cout << "x=" << my_sizes[2] << endl; // x=5
cout << "y=" << my_sizes[3] << endl; // y=4
auto new_tensor = my_tensor.transform(format::yxfb, 10);
auto new_sizes = new_tensor.sizes();
cout << "new_num=" << new_sizes.size() << endl; // new_num=4
for(auto dim : new_sizes) cout << " " << dim; // 5 4 3 2
cout << endl;

Definition at line 593 of file tensor.hpp.


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