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

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 10 10:15:57 PDT 2025


================
@@ -32,89 +33,194 @@ class TestableEmbedder : public Embedder {
   void computeEmbeddings() const override {}
   void computeEmbeddings(const BasicBlock &BB) const override {}
   using Embedder::lookupVocab;
-  static void addVectors(Embedding &Dst, const Embedding &Src) {
-    Embedder::addVectors(Dst, Src);
-  }
-  static void addScaledVector(Embedding &Dst, const Embedding &Src,
-                              float Factor) {
-    Embedder::addScaledVector(Dst, Src, Factor);
-  }
 };
 
-TEST(IR2VecTest, CreateSymbolicEmbedder) {
-  Vocab V = {{"foo", {1.0, 2.0}}};
-
-  LLVMContext Ctx;
-  Module M("M", Ctx);
-  FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), false);
-  Function *F = Function::Create(FTy, Function::ExternalLinkage, "f", M);
+TEST(EmbeddingTest, ConstructorsAndAccessors) {
+  // Default constructor
+  Embedding E1;
+  EXPECT_TRUE(E1.empty());
+  EXPECT_EQ(E1.size(), 0u);
+
+  // Constructor with const std::vector<double>&
+  std::vector<double> Data = {1.0, 2.0, 3.0};
+  Embedding E2(Data);
+  EXPECT_FALSE(E2.empty());
+  EXPECT_EQ(E2.size(), 3u);
----------------
snehasish wrote:

This should be assert -- if this fails then we may access unintialized memory below when we check the elements. 

https://google.github.io/googletest/primer.html#assertions

Also you can use testing::SizeIs for a better error message.

Same for a few cases below.

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


More information about the llvm-commits mailing list