Skip to content

Commit

Permalink
Update Python example in README to reflect latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
svkeerthy committed Jan 9, 2024
1 parent 3d886e6 commit dd3e025
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit dd3e025

Please sign in to comment.