From f1d5616778533899e04909eb1fa438d094b91824 Mon Sep 17 00:00:00 2001 From: Olivier BICHLER <olivier.bichler@cea.fr> Date: Sun, 10 Dec 2023 11:40:18 +0100 Subject: [PATCH] Clarified resize() behavior --- include/aidge/data/Tensor.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp index 6c256746d..6c51af6ab 100644 --- a/include/aidge/data/Tensor.hpp +++ b/include/aidge/data/Tensor.hpp @@ -446,9 +446,15 @@ class Tensor : public Data, constexpr std::size_t sizeM1() const { return mSizeM1; } /** - * @brief Change the shape of the Tensor object according to the given argument. - * @tparam DIM new dimensions. - * @param dims + * @brief Change the dimensions of the Tensor object according to the given argument. + * If the overall size is not changed (meaning we actually only performed a + * reshape), data is garanteed to remain valid. + * Otherwise, no garantee is provided regarding the validy of previous data + * (unlike std::vector). If the new overall size is larger than the previous + * one, all previous data is invalided. Otherwise, previous data may or may + * not remain valid, depending on the backend implementation. + * @tparam DIM Number of dimensions. + * @param dims New dimensions */ template <std::array<DimSize_t, 1>::size_type DIM> // deducing std::array size_type and declaring DIM accordingly void resize(const std::array<DimSize_t, DIM> &dims) { @@ -457,6 +463,16 @@ class Tensor : public Data, computeSize(); } + /** + * @brief Change the dimensions of the Tensor object according to the given argument. + * If the overall size is not changed (meaning we actually only performed a + * reshape), data is garanteed to remain valid. + * Otherwise, no garantee is provided regarding the validy of previous data + * (unlike std::vector). If the new overall size is larger than the previous + * one, all previous data is invalided. Otherwise, previous data may or may + * not remain valid, depending on the backend implementation. + * @param dims New dimensions + */ void resize(const std::vector<DimSize_t> &dims) { mDims = dims; computeSize(); -- GitLab