Skip to content
Snippets Groups Projects

[Fix] Producer clone and Tensor copy

Merged Maxence Naud requested to merge fix_207-producer-clone into dev
2 files
+ 129
2
Compare changes
  • Side-by-side
  • Inline
Files
2
  • 4cd0fd80
    Upd: Tensor operators and fmt display · 4cd0fd80
    Maxence Naud authored
    - add compound assignment operator (+=, -=, *=, /=) with Tensor and arithmetic values
    - add operator(+, -, *, /) with arithmetic values
    - add friend symetric operator (+, -, *) with arithmetic values
    - add fmt parsing function
@@ -23,6 +23,8 @@
#include <type_traits> // std::is_arithmetic
#include <vector>
#include <fmt/core.h>
#include "aidge/backend/TensorImpl.hpp"
#include "aidge/data/Data.hpp"
#include "aidge/utils/ArrayHelpers.hpp"
@@ -272,6 +274,17 @@ class Tensor : public Data,
* @return Tensor
*/
Tensor operator+(const Tensor& other) const;
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
Tensor operator+(T val) const { return *this + Tensor(val); }
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
friend Tensor operator+(T val, const Tensor& other) { return other + val; }
Tensor& operator+=(const Tensor& other);
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
Tensor& operator+=(T val) {return *this += Tensor(val); }
/**
* @brief Element-wise subtraction operation for two ``Tensor``s.
@@ -283,6 +296,17 @@ class Tensor : public Data,
* @return Tensor
*/
Tensor operator-(const Tensor& other) const;
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
inline Tensor operator-(T val) const { return *this - Tensor(val); }
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
friend inline Tensor operator-(T val, const Tensor& other) { return other - val; }
Tensor& operator-=(const Tensor& other);
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
inline Tensor& operator-=(T val) {return *this -= Tensor(val); }
/**
* @brief Element-wise multiplication operation for two ``Tensor``s.
@@ -294,6 +318,17 @@ class Tensor : public Data,
* @return Tensor
*/
Tensor operator*(const Tensor& other) const;
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
inline Tensor operator*(T val) const { return *this * Tensor(val); }
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
friend inline Tensor operator*(T val, const Tensor& other) { return other * val; }
Tensor& operator*=(const Tensor& other);
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
inline Tensor& operator*=(T val) {return *this *= Tensor(val); }
/**
* @brief Element-wise division operation for two ``Tensor``s.
@@ -305,6 +340,14 @@ class Tensor : public Data,
* @return Tensor
*/
Tensor operator/(const Tensor& other) const;
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
inline Tensor operator/(T val) const { return *this / Tensor(val); }
Tensor& operator/=(const Tensor& other);
template<typename T,
typename VT = std::enable_if_t<std::is_arithmetic<T>::value, std::decay_t<T>>>
inline Tensor& operator/=(T val) {return *this /= Tensor(val); }
/**
* @brief Element-wise sqrt operation for Tensor.
@@ -927,4 +970,17 @@ private:
};
} // namespace Aidge
template<>
struct fmt::formatter<Aidge::Tensor> {
template<typename ParseContext>
inline constexpr auto parse(ParseContext& ctx) {
return ctx.begin();
}
template<typename FormatContext>
inline auto format(Aidge::Tensor const& t, FormatContext& ctx) const {
return fmt::format_to(ctx.out(), "{}", t.toString());
}
};
#endif /* AIDGE_CORE_DATA_TENSOR_H_ */
Loading