[add] in-place operation for Tensor
Context
Some Tensor member functions are in-place and mutate the object (e.g setDataType()
), others are out-of-place and create a new object (e.g copyTranspose()
or add()
)
Most of this methods could benefit from having two versions: out-of-place and in-place.
Moreover, which member function is in place or not is not clear. It does not appear in parameters nor in the syntax. This informations only come from the non-complete documentation.
On the path to consistent syntax, I suggest to use the trailing underscore syntax for in-place member function transformations. Similar to PyTorch, this syntax is known to many users and is very visual.
Hense, we would have:
Tensor abs() const;
Tensor& abs_();
Tensor sqrt() const;
Tensor& sqrt_();
Tensor clip(float min = std::numeric_limits<float>::lowest(),
float max = std::numeric_limits<float>::max()) const;
Tensor& clip_(float min = std::numeric_limits<float>::lowest(),
float max = std::numeric_limits<float>::max());
as an example