@@ -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
6666Tensor::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
171171void 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
181181void Tensor::deallocate_memory ()
182182{
183- if (owns_data_ && data_) {
183+ if (is_view_ && data_) {
184184 std::free (data_);
185185 data_ = nullptr ;
186186 }
0 commit comments