diff --git a/include/aidge/data/Tensor.hpp b/include/aidge/data/Tensor.hpp index aab6f375765e87c8978d08fddfbcfc76f9a6990c..681e8ca618795a85a1e3a55a413dbfd74d5b0ea2 100644 --- a/include/aidge/data/Tensor.hpp +++ b/include/aidge/data/Tensor.hpp @@ -15,7 +15,7 @@ #include <cstring> #include <set> #include <memory> -#include <numeric> +#include <numeric> // std::accumulate #include <string> #include <vector> @@ -327,11 +327,11 @@ class Tensor : public Data, /** * @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 + * 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 + * 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 @@ -343,11 +343,11 @@ class Tensor : public Data, /** * @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 + * 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 + * 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 */ @@ -424,7 +424,7 @@ class Tensor : public Data, return std::string("?"); // To make Clang happy }; - if (dims().empty()) { return "{}"; } + if (dims().empty()) { return ptrToString(mDataType, mImpl->hostPtr(), 0); } std::string res; std::size_t dim = 0; std::size_t counter = 0; @@ -546,22 +546,22 @@ class Tensor : public Data, /** * Copy-cast data from a Tensor. * @param src Source tensor to copy-cast from. - * @param movedSrc shared_ptr to an indermediate Tensor that will - * contain the moved data if a device change should occur AND a type + * @param movedSrc shared_ptr to an indermediate Tensor that will + * contain the moved data if a device change should occur AND a type * conversion is necessary (otherwise it remains unused). - * Any data already present will be overwritten. No new memory allocation - * will occur if movedSrc has already been allocated with the right + * Any data already present will be overwritten. No new memory allocation + * will occur if movedSrc has already been allocated with the right * type/size/device. - * If required, memory is always allocated on current (destination) + * If required, memory is always allocated on current (destination) * Tensor's device. */ void copyCastFrom(const Tensor& src, std::shared_ptr<Tensor>& movedSrc); /** * Copy-cast data from a Tensor. - * In case of both a device change AND a data type conversion, an + * In case of both a device change AND a data type conversion, an * intermediate buffer on will be allocated and deallocated each time. - * If required, buffer's memory is always allocated on current (destination) + * If required, buffer's memory is always allocated on current (destination) * Tensor's device. * @param src Source tensor to copy-cast from. */ @@ -579,7 +579,7 @@ class Tensor : public Data, * The backend stays the same. * @param fallback A shared_ptr to Tensor ready to be overwritten if necessary. * The shared_ptr does not need to be initialized. No new memory allocation - * will occur if fallback has already been allocated with the right + * will occur if fallback has already been allocated with the right * type/size/device. * @param dt The desired data type. * @return Reference to either itself or to fallback. @@ -594,7 +594,7 @@ class Tensor : public Data, * The data type stays the same. * @param fallback A shared_ptr to Tensor ready to be overwritten if necessary. * The shared_ptr does not need to be initialized. No new memory allocation - * will occur if fallback has already been allocated with the right + * will occur if fallback has already been allocated with the right * type/size/device. * @param backend The desired backend. * @param device The desired device. @@ -607,11 +607,11 @@ class Tensor : public Data, * Return a reference to a Tensor on desired data type and backend/device: * - itself, if already with the right characteristics; * - the provided Tensor, overwritten with the copy-casted data. - * If required, fallback is always allocated on desired (destination) + * If required, fallback is always allocated on desired (destination) * device. * @param fallback A shared_ptr to Tensor ready to be overwritten if necessary. * The shared_ptr does not need to be initialized. No new memory allocation - * will occur if fallback has already been allocated with the right + * will occur if fallback has already been allocated with the right * type/size/device. * @param dt The desired data type. * @param backend The desired backend. @@ -628,11 +628,11 @@ class Tensor : public Data, * (data type, backend/device) as targetReqs Tensor: * - itself, if already with the right characteristics; * - the provided Tensor, overwritten with the copy-casted data. - * If required, fallback is always allocated on current (destination) + * If required, fallback is always allocated on current (destination) * Tensor's device. * @param fallback A shared_ptr to Tensor ready to be overwritten if necessary. * The shared_ptr does not need to be initialized. No new memory allocation - * will occur if fallback has already been allocated with the right + * will occur if fallback has already been allocated with the right * type/size/device. * @param targetReqs Tensor with the desired target characteristics. * @return Reference to either itself or to fallback. @@ -644,15 +644,8 @@ class Tensor : public Data, private: ///\bug not protected against overflow - std::size_t computeSize() { - if (mDims.empty()) { - mSize = DimSize_t(0); - } - else { - mSize = std::accumulate(mDims.begin(), mDims.end(), DimSize_t(1), std::multiplies<DimSize_t>()); - } - - return mSize; + void computeSize() { + mSize = std::accumulate(mDims.begin(), mDims.end(), DimSize_t(1), std::multiplies<DimSize_t>()); } }; } // namespace Aidge