Skip to content

Commit a653a7d

Browse files
committed
is view
1 parent 7569125 commit a653a7d

File tree

3 files changed

+12
-38
lines changed

3 files changed

+12
-38
lines changed

deep_tensor/include/deep_tensor/tensor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class Tensor
211211
DataType dtype_;
212212
size_t byte_size_;
213213
void * data_;
214-
bool owns_data_;
214+
bool is_view_;
215215

216216
void calculate_strides();
217217
void allocate_memory();

deep_tensor/src/tensor.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ Tensor::Tensor()
6060
: dtype_(DataType::FLOAT32)
6161
, byte_size_(0)
6262
, data_(nullptr)
63-
, owns_data_(false)
63+
, is_view_(false)
6464
{}
6565

6666
Tensor::Tensor(const std::vector<size_t> & shape, DataType dtype)
6767
: shape_(shape)
6868
, dtype_(dtype)
69-
, owns_data_(true)
69+
, is_view_(true)
7070
{
7171
calculate_strides();
7272

@@ -80,7 +80,7 @@ Tensor::Tensor(void * data, const std::vector<size_t> & shape, DataType dtype)
8080
: shape_(shape)
8181
, dtype_(dtype)
8282
, data_(data)
83-
, owns_data_(false)
83+
, is_view_(false)
8484
{
8585
calculate_strides();
8686

@@ -98,7 +98,7 @@ Tensor::Tensor(const Tensor & other)
9898
, strides_(other.strides_)
9999
, dtype_(other.dtype_)
100100
, byte_size_(other.byte_size_)
101-
, owns_data_(true)
101+
, is_view_(true)
102102
{
103103
allocate_memory();
104104
if (other.data_ && data_) {
@@ -115,7 +115,7 @@ Tensor & Tensor::operator=(const Tensor & other)
115115
strides_ = other.strides_;
116116
dtype_ = other.dtype_;
117117
byte_size_ = other.byte_size_;
118-
owns_data_ = true;
118+
is_view_ = true;
119119

120120
allocate_memory();
121121
if (other.data_ && data_) {
@@ -131,10 +131,10 @@ Tensor::Tensor(Tensor && other) noexcept
131131
, dtype_(other.dtype_)
132132
, byte_size_(other.byte_size_)
133133
, data_(other.data_)
134-
, owns_data_(other.owns_data_)
134+
, is_view_(other.is_view_)
135135
{
136136
other.data_ = nullptr;
137-
other.owns_data_ = false;
137+
other.is_view_ = false;
138138
other.byte_size_ = 0;
139139
}
140140

@@ -148,10 +148,10 @@ Tensor & Tensor::operator=(Tensor && other) noexcept
148148
dtype_ = other.dtype_;
149149
byte_size_ = other.byte_size_;
150150
data_ = other.data_;
151-
owns_data_ = other.owns_data_;
151+
is_view_ = other.is_view_;
152152

153153
other.data_ = nullptr;
154-
other.owns_data_ = false;
154+
other.is_view_ = false;
155155
other.byte_size_ = 0;
156156
}
157157
return *this;
@@ -170,7 +170,7 @@ void Tensor::calculate_strides()
170170

171171
void Tensor::allocate_memory()
172172
{
173-
if (byte_size_ > 0 && owns_data_) {
173+
if (byte_size_ > 0 && is_view_) {
174174
data_ = std::aligned_alloc(32, byte_size_);
175175
if (!data_) {
176176
throw std::bad_alloc();
@@ -180,7 +180,7 @@ void Tensor::allocate_memory()
180180

181181
void Tensor::deallocate_memory()
182182
{
183-
if (owns_data_ && data_) {
183+
if (is_view_ && data_) {
184184
std::free(data_);
185185
data_ = nullptr;
186186
}

deep_tensor/test/test_ros_conversions.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,6 @@ TEST_CASE("Image encoding info parsing", "[ros_conversions]")
9393
REQUIRE(yuv444_16_info.bytes_per_channel == 2);
9494
}
9595

96-
SECTION("YUV formats - 10-bit")
97-
{
98-
auto yuv422_10_info = deep_ros::ros_conversions::get_image_encoding_info("yuv422_10");
99-
REQUIRE(yuv422_10_info.dtype == deep_ros::DataType::UINT16);
100-
REQUIRE(yuv422_10_info.channels == 2);
101-
REQUIRE(yuv422_10_info.bytes_per_channel == 2);
102-
103-
auto yuv444_10_info = deep_ros::ros_conversions::get_image_encoding_info("yuv444_10");
104-
REQUIRE(yuv444_10_info.dtype == deep_ros::DataType::UINT16);
105-
REQUIRE(yuv444_10_info.channels == 3);
106-
REQUIRE(yuv444_10_info.bytes_per_channel == 2);
107-
}
108-
109-
SECTION("YUV formats - 12-bit")
110-
{
111-
auto yuv422_12_info = deep_ros::ros_conversions::get_image_encoding_info("yuv422_12");
112-
REQUIRE(yuv422_12_info.dtype == deep_ros::DataType::UINT16);
113-
REQUIRE(yuv422_12_info.channels == 2);
114-
REQUIRE(yuv422_12_info.bytes_per_channel == 2);
115-
116-
auto yuv444_12_info = deep_ros::ros_conversions::get_image_encoding_info("yuv444_12");
117-
REQUIRE(yuv444_12_info.dtype == deep_ros::DataType::UINT16);
118-
REQUIRE(yuv444_12_info.channels == 3);
119-
REQUIRE(yuv444_12_info.bytes_per_channel == 2);
120-
}
121-
12296
SECTION("Unsupported encoding")
12397
{
12498
REQUIRE_THROWS_AS(deep_ros::ros_conversions::get_image_encoding_info("invalid_encoding"), std::runtime_error);

0 commit comments

Comments
 (0)