[llvm-branch-commits] [llvm] [IR2Vec] Add out-of-place arithmetic operators to Embedding class (PR #145118)
S. VenkataKeerthy via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jul 1 11:54:36 PDT 2025
================
@@ -71,20 +71,43 @@ inline bool fromJSON(const llvm::json::Value &E, Embedding &Out,
// Embedding
//===----------------------------------------------------------------------===//
+Embedding Embedding::operator+(const Embedding &RHS) const {
+ assert(this->size() == RHS.size() && "Vectors must have the same dimension");
+ Embedding Result(*this);
+ std::transform(this->begin(), this->end(), RHS.begin(), Result.begin(),
+ std::plus<double>());
+ return Result;
+}
+
Embedding &Embedding::operator+=(const Embedding &RHS) {
assert(this->size() == RHS.size() && "Vectors must have the same dimension");
----------------
svkeerthy wrote:
Implemented <operator> in terms of <operator>= as it would avoid copies in <operator>=.
https://github.com/llvm/llvm-project/pull/145118
More information about the llvm-branch-commits
mailing list