From dd3e0250053c0ba7edc6b4b347c0032661316c28 Mon Sep 17 00:00:00 2001 From: "S. VenkataKeerthy" <31350914+svkeerthy@users.noreply.github.com> Date: Sat, 6 Jan 2024 15:47:58 +0530 Subject: [PATCH] Update Python example in README to reflect latest changes --- README.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 15ca3015d..c5e7284b2 100644 --- a/README.md +++ b/README.md @@ -217,16 +217,22 @@ for (auto val : pgmVec) ```python import ir2vec +# IR2Vec Python APIs can be used in two ways. As shown below. initObj = ir2vec.initEmbedding("/path/to/file.ll", "fa", "p") progVector1 = ir2vec.getProgramVector(initObj) functionVectorMap1 = ir2vec.getFunctionVectors(initObj) -instructionVectorsMap1 = ir2vec.getInstructionVectors(initObj) +instructionVectorsList1 = ir2vec.getInstructionVectors(initObj) progVector2 = initObj.getProgramVector() functionVectorMap2 = initObj.getFunctionVectors() -instructionVectorMap2 = initObj.getInstructionVectors() +instructionVectorsList2 = initObj.getInstructionVectors() -for fun, funcObj in functionVectorMap.items(): +# Both the approaches would result in same outcomes +tolerance = 1e-6 +for val1, val2 in zip(progVector1, progVector2): + assert (abs(progVector1 - progVector2) <= tolerance) + +for fun, funcObj in functionVectorMap1.items(): assert fun == funcObj["demangledName"] functionOutput1 = ir2vec.getFunctionVectors( @@ -238,15 +244,8 @@ for fun, funcObj in functionVectorMap.items(): funcObj["actualName"] ) - assert( - functionOutput1[fun]["vector"] == pytest.approx( - functionOutput2[fun]["vector"], abs=ABS_ACCURACY - ) - ) - - assert( - funcObj["vector"] == pytest.approx(functionOutput1[fun]["vector"], abs=ABS_ACCURACY) - ) + for val1, val2 in zip(functionOutput1[fun]["vector"], functionOutput2[fun]["vector"]): + assert (abs(progVector1 - progVector2) <= tolerance) ``` ## Binaries, Libraries and Wheels - Artifacts