hnswlib
hnswlib copied to clipboard
I want to know how many distance calculations are needed to complete a query with fixed parameters
Hi, I want to know how many distance calculations are needed to complete a query with fixed parameters. How can I get this value? Do I need to change the source code? Another question is how to run the corresponding. cpp file in vs2019?
-
You can add something to count the number of times the distance computation function is called https://github.com/nmslib/hnswlib/blob/3c6a84fb54a2a92dc4b7dc3e13dbae3d99892444/hnswlib/hnswlib.h#L52-L53
-
You can goole how cmake is used together with visual studio
Thanks for your reply, for the first problem, I have another question, now I only run the code in python. I modified the code in hnswlib/hnswlib/hnswlib.h and added a variable for counting. How can the counting result be displayed in the running result of python?
- You can add something to count the number of times the distance computation function is called https://github.com/nmslib/hnswlib/blob/3c6a84fb54a2a92dc4b7dc3e13dbae3d99892444/hnswlib/hnswlib.h#L52-L53
- You can goole how cmake is used together with visual studio Thanks for your reply, for the first problem, I have another question, now I only run the code in python. I modified the code in hnswlib/hnswlib/hnswlib.h and added a variable for counting. How can the counting result be displayed in the running result of python?
The easisst way is to print the result to stdout or a file.他Or you can refer to the python binding code
@qxzhou1010 You can also change line https://github.com/nmslib/hnswlib/blob/master/hnswlib/hnswalg.h#L556
From searchBaseLayerST<false> to searchBaseLayerST<true>. It will start collecting the number of calculations (metric_distance_computations, metric_hops fields) until you manually reset them.
To access the from python you would need to add a method to bindings. That is pretty straighforward, you can just copy the get_M method https://github.com/nmslib/hnswlib/blob/master/python_bindings/bindings.cpp#L402 .
To build and install the bindings you can run from the root repository:
pip3 install pybind11 numpy setuptools
cd python_bindings
python3 setup.py install
@qxzhou1010 You can also change line https://github.com/nmslib/hnswlib/blob/master/hnswlib/hnswalg.h#L556 From
searchBaseLayerST<false>tosearchBaseLayerST<true>. It will start collecting the number of calculations (metric_distance_computations,metric_hopsfields) until you manually reset them. To access the from python you would need to add a method to bindings. That is pretty straighforward, you can just copy theget_Mmethod https://github.com/nmslib/hnswlib/blob/master/python_bindings/bindings.cpp#L402 . To build and install the bindings you can run from the root repository:pip3 install pybind11 numpy setuptools cd python_bindings python3 setup.py install
Could you give a demo, as some of the code has been updated?