From ef381497693ef4da68c0a3169cd588c2d2546ba6 Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Wed, 10 Apr 2024 16:11:13 +0200 Subject: [PATCH] Improved specifications --- include/aidge/backend/cpu/data/TensorImpl.hpp | 2 ++ include/aidge/data/Tensor.hpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/aidge/backend/cpu/data/TensorImpl.hpp b/include/aidge/backend/cpu/data/TensorImpl.hpp index 922acacb0..7cd8c6726 100644 --- a/include/aidge/backend/cpu/data/TensorImpl.hpp +++ b/include/aidge/backend/cpu/data/TensorImpl.hpp @@ -23,6 +23,8 @@ namespace Aidge { template <class T> class TensorImpl_cpu : public TensorImpl { + static_assert(std::is_trivially_copyable<T>::value, "TensorImpl type should be trivially copyable"); + private: /// Pointer to the data and its capacity future_std::span<T> mData; diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp index 2503c01b3..cdd2aba1b 100644 --- a/include/aidge/data/Tensor.hpp +++ b/include/aidge/data/Tensor.hpp @@ -527,6 +527,7 @@ public: template <typename expectedType> const expectedType& get(std::size_t idx) const { AIDGE_ASSERT(NativeType<expectedType>::type == mDataType, "wrong data type"); + AIDGE_ASSERT(mImpl->hostPtr() != nullptr, "get() can only be used for backends providing a valid host pointer"); AIDGE_ASSERT(idx < mSize, "idx out of range"); return *reinterpret_cast<expectedType *>(mImpl->hostPtr(mImplOffset + idx)); } @@ -539,6 +540,7 @@ public: template <typename expectedType> void set(std::size_t idx, expectedType value){ AIDGE_ASSERT(NativeType<expectedType>::type == mDataType, "wrong data type"); + AIDGE_ASSERT(mImpl->hostPtr() != nullptr, "get() can only be used for backends providing a valid host pointer"); AIDGE_ASSERT(idx < mSize, "idx out of range"); expectedType* dataPtr = static_cast<expectedType*>(mImpl->hostPtr(mImplOffset + idx)); *dataPtr = value; -- GitLab