Fix Tensor issues

This commit is contained in:
2025-11-18 22:38:56 +01:00
parent 4c26efe826
commit 10c84d75fc
4 changed files with 21 additions and 25 deletions

View File

@@ -68,8 +68,10 @@ Tensor& Tensor::operator=(Tensor&& other) noexcept {
}
Tensor::~Tensor() {
backend->deallocate(d_ptr);
d_ptr = nullptr;
if (backend && d_ptr) {
backend->deallocate(d_ptr);
d_ptr = nullptr;
}
}
size_t Tensor::numel() const {
@@ -80,21 +82,6 @@ size_t Tensor::size() const {
return total_size;
}
template <typename T>
const T* Tensor::data() const {
return static_cast<T*>(d_ptr);
}
template <typename T>
T* Tensor::data() {
return static_cast<T*>(d_ptr);
}
void Tensor::zero() {
backend->zero(*this);
}
template <typename T>
void Tensor::set_data(T *data) {
backend->copy_to_device(*this, data, total_size);
}