<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to compute pairwise Euclidean distances using IPP? in Intel® Integrated Performance Primitives</title>
    <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859570#M7596</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;It is possible to apply one of ippsLogGauss_IdVar_* function (ippsr library). The formula slightly differs (for val==0 you get the negative Euclidean square distance.&lt;/P&gt;
&lt;P&gt;32f, 16s to 32s and 16s to 32f data types are supported.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier" size="2"&gt;&lt;FONT face="Times New Roman" size="3"&gt;Data step in these functions is in data elements, not in bytes&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier" size="2"&gt;&lt;FONT face="Times New Roman" size="3"&gt;Alexander&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2008 08:04:25 GMT</pubDate>
    <dc:creator>Intel_C_Intel</dc:creator>
    <dc:date>2008-02-01T08:04:25Z</dc:date>
    <item>
      <title>How to compute pairwise Euclidean distances using IPP?</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859569#M7595</link>
      <description>I want to compute the pairwise squared Euclidean distances between all the rows of an NxD matrix and store these distances in an NxN matrix. In plain C++ code, that would look something like this:
&lt;BR /&gt;
&lt;BR /&gt;for(int i = 0; i smaller than n; i++) {
&lt;BR /&gt;
&lt;BR /&gt;for(int j = i + 1; j smaller than n; j++) {
&lt;BR /&gt;
&lt;BR /&gt;double val = 0.0;
&lt;BR /&gt;
&lt;BR /&gt;for(int k = 0; k 
&lt;BR /&gt;val += pow((float) *(data + (i * (data_step / sizeof(Ipp32f))) + k) - (float) *(data + (j * (data_step / sizeof(Ipp32f))) + k), (float) 2.0);
&lt;BR /&gt;
&lt;BR /&gt;}		
&lt;BR /&gt;
&lt;BR /&gt;*(P + (i * (P_step / sizeof(Ipp32f))) + j) = *(P + (j * (P_step / sizeof(Ipp32f))) + i) = (Ipp32f) val;
&lt;BR /&gt;
&lt;BR /&gt;}
&lt;BR /&gt;
&lt;BR /&gt;}
&lt;BR /&gt;
&lt;BR /&gt;Herein, the data is my NxD matrix with stride data_step, and P is the NxN matrix in which I store the squared Euclidean distances.
&lt;BR /&gt;
&lt;BR /&gt;I've been trying to think about a smart way to do this with IPP (e.g., by using d(A,B) = sum(A.^2) + sum(B.^2) - 2*sum(A.*B)), but they all involve the implementation of loops. Does anyone have a suggestion how I can do this computation efficiently using IPP?</description>
      <pubDate>Fri, 25 Jan 2008 22:31:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859569#M7595</guid>
      <dc:creator>minne</dc:creator>
      <dc:date>2008-01-25T22:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute pairwise Euclidean distances using IPP?</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859570#M7596</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;It is possible to apply one of ippsLogGauss_IdVar_* function (ippsr library). The formula slightly differs (for val==0 you get the negative Euclidean square distance.&lt;/P&gt;
&lt;P&gt;32f, 16s to 32s and 16s to 32f data types are supported.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier" size="2"&gt;&lt;FONT face="Times New Roman" size="3"&gt;Data step in these functions is in data elements, not in bytes&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier" size="2"&gt;&lt;FONT face="Times New Roman" size="3"&gt;Alexander&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2008 08:04:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859570#M7596</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2008-02-01T08:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute pairwise Euclidean distances using IPP?</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859571#M7597</link>
      <description>Thanks, but that only allows me to compute one row of the pairwise distance matrix at a time right? I've tried that, but it doesn't really make things any faster (since you don't have the advantage of processing a large chunk of data at a time)...</description>
      <pubDate>Fri, 01 Feb 2008 20:46:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859571#M7597</guid>
      <dc:creator>minne</dc:creator>
      <dc:date>2008-02-01T20:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute pairwise Euclidean distances using IPP?</title>
      <link>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859572#M7598</link>
      <description>The best I came up with until now is the following (assuming you have an NxD dataset called data):
&lt;BR /&gt;
&lt;BR /&gt;=========================
&lt;BR /&gt;Ipp64f* dataSqr = ippsMalloc_64f (n * d);
&lt;BR /&gt;	Ipp64f* dataSqrSums = ippsMalloc_64f (n);
&lt;BR /&gt;	ippsSqr_64f (data, dataSqr, n * d);
&lt;BR /&gt;	ippsSumRow_64f_D2 (dataSqr, d, d, dataSqrSums, n);
&lt;BR /&gt;	ippmMul_mt_64f (data, d * sizeof(Ipp64f), sizeof(Ipp64f), d, n, data, d * sizeof(Ipp64f), sizeof(Ipp64f), d, n, P, n * sizeof(Ipp64f), sizeof(Ipp64f));
&lt;BR /&gt;	ippsMulC_64f_I ((Ipp64f) -2.0, P, n * n);
&lt;BR /&gt;	for(int i = 0; i smaller than n; i++) {
&lt;BR /&gt;		for(int j = 0; j smaller than n; j++) {
&lt;BR /&gt;			*(P + i * n + j) += *(dataSqrSums + i) + *(dataSqrSums + j);
&lt;BR /&gt;		}
&lt;BR /&gt;	}
&lt;BR /&gt;	ippsFree(dataSqr);
&lt;BR /&gt;	ippsFree(dataSqrSums);
&lt;BR /&gt;==========================
&lt;BR /&gt;
&lt;BR /&gt;However, it has three disadvantages:
&lt;BR /&gt; * It uses ippm, which I think is mainly optimized for small matrices (in my case, N=5000 and D=[1,10])
&lt;BR /&gt; * I still need a loop to add the L2-norms of the data vectors
&lt;BR /&gt; * I don't exploit the fact that the pairwise distance matrix is symmetric (I compute everything twice)
&lt;BR /&gt;
&lt;BR /&gt;Any ideas anyone?</description>
      <pubDate>Sun, 03 Feb 2008 02:37:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Integrated-Performance/How-to-compute-pairwise-Euclidean-distances-using-IPP/m-p/859572#M7598</guid>
      <dc:creator>minne</dc:creator>
      <dc:date>2008-02-03T02:37:32Z</dc:date>
    </item>
  </channel>
</rss>

