[llvm] [IR2Vec] Exposing Embedding as an ADT wrapped around std::vector<double> (PR #143197)

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 9 13:45:47 PDT 2025


================
@@ -53,16 +53,70 @@ class raw_ostream;
 enum class IR2VecKind { Symbolic };
 
 namespace ir2vec {
-using Embedding = std::vector<double>;
+/// Embedding is a ADT that wraps std::vector<double>. It provides
+/// additional functionality for arithmetic and comparison operations.
+/// It is meant to be used *like* std::vector<double> but is more restrictive
+/// in the sense that it does not allow the user to change the size of the
+/// embedding vector. The dimension of the embedding is fixed at the time of
+/// construction of Embedding object. But the elements can be modified in-place.
+struct Embedding {
+private:
+  std::vector<double> Data;
+
+public:
+  Embedding() = default;
+  Embedding(const std::vector<double> &V) : Data(V) {}
+  Embedding(std::vector<double> &&V) : Data(std::move(V)) {}
+  Embedding(std::initializer_list<double> IL) : Data(IL) {}
+  Embedding(size_t Size, double InitialValue) : Data(Size, InitialValue) {}
----------------
mtrofin wrote:

Nit: `InitialValue = 0`?

https://github.com/llvm/llvm-project/pull/143197


More information about the llvm-commits mailing list