This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Function to calculate Euclidean distance of two N-Dim Vectors on C64X

I need compute Euclidean distance between X and Y on C64X, i.e. D = sum{i=1,2,…,N}((Xi-Yi)^2), where N=2000.  Does TI provide such function in its libraries? If not, may I get some advices how to implement it in term of minimum MIPS consumption?

 

Many thanks

Darleen

  •  

    Darleen,

    As far as I know, Euclidean distance is not present in any of the libraries.

    Optimization of this function for C64x depends on the data-type of the vectors X and Y, whether they are chars or shorts or integers.

    As it is a fairly simple function, the compiler should be able to do a good job with the following C code.

    for(i=0;i<N;i++)

    {

        z = x[i] - y[i];

       acc += z*z;

    }

    Also, Euclidean distance requires a sqrt at the end of accumulation. As it is outside the loop, you can use the default sqrt() function.

    Please let me know if you need any clarification.

    Regards

    Senthil

  • The above logic can also be implemented using some optimized kernels provided with the std libraries (http://processors.wiki.ti.com/index.php?title=Software_libraries). For ex, the IMGLIB documentation includes the function: IMG_sub_16s that can be used to implement the first step that calculates the diff. The second step can be implemented by using the function DSP_vecsumsq from the DSPLIB. The SQRT function is provided in the IQMath lib

  • Senthil,

    Thank you for confirming that Euclidean distance is not present in any of the libraries and your suggestion.

     

     

  • Thanks for the advice. Eulidean distance is a simple and basic function, I am surprised it is not included in any of TI libraries. I wish that TI would consider to have similar functions like ippsNormDiff_L2 of Intel IPP libraries in the future release.

  •  

    Dunling,

    We have other distance measures like Manhattan distance and Bhattacharya distance in VLIB.

    I would take your request for Euclidean distance and implement it for the next VLIB release positively.

    Regards

    Senthil