<divclass="line"><aname="l00006"></a><spanclass="lineno"> 6</span> <spanclass="comment"> * This source code is licensed under the CC-by-NC license found in the</span></div>
<divclass="line"><aname="l00007"></a><spanclass="lineno"> 7</span> <spanclass="comment"> * LICENSE file in the root directory of this source tree.</span></div>
<divclass="line"><aname="l00010"></a><spanclass="lineno"> 10</span> <spanclass="comment">// Copyright 2004-present Facebook. All Rights Reserved.</span></div>
<divclass="line"><aname="l00011"></a><spanclass="lineno"> 11</span> <spanclass="comment">// -*- c++ -*-</span></div>
<divclass="line"><aname="l00025"></a><spanclass="lineno"> 25</span> <spanclass="comment">/** Product Quantizer. Implemented only for METRIC_L2 */</span></div>
<divclass="line"><aname="l00028"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a567cd512438f9e3404d9339a232d7695"> 28</a></span> <spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a567cd512438f9e3404d9339a232d7695">d</a>; <spanclass="comment">///< size of the input vectors</span></div>
<divclass="line"><aname="l00029"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a83600e328893ce5f41fe459f5a3acf41"> 29</a></span> <spanclass="comment"></span><spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a83600e328893ce5f41fe459f5a3acf41">M</a>; <spanclass="comment">///< number of subquantizers</span></div>
<divclass="line"><aname="l00030"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#ac920fea11f02e8407d12cc99a09f5ea5"> 30</a></span> <spanclass="comment"></span><spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#ac920fea11f02e8407d12cc99a09f5ea5">nbits</a>; <spanclass="comment">///< number of bits per quantization index</span></div>
<divclass="line"><aname="l00032"></a><spanclass="lineno"> 32</span> <spanclass="comment">// values derived from the above</span></div>
<divclass="line"><aname="l00033"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a467b451ca203544e42c250e4be65b983"> 33</a></span> <spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a467b451ca203544e42c250e4be65b983">dsub</a>; <spanclass="comment">///< dimensionality of each subvector</span></div>
<divclass="line"><aname="l00034"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a13bf69a0dc7b4e45792d10f458e4a92d"> 34</a></span> <spanclass="comment"></span><spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a13bf69a0dc7b4e45792d10f458e4a92d">byte_per_idx</a>; <spanclass="comment">///< nb bytes per code component (1 or 2)</span></div>
<divclass="line"><aname="l00035"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#aa61330eadb84772b71018b093773a5f9"> 35</a></span> <spanclass="comment"></span><spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#aa61330eadb84772b71018b093773a5f9">code_size</a>; <spanclass="comment">///< byte per indexed vector</span></div>
<divclass="line"><aname="l00036"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a0feee45e4151547b7a0444c14bad398f"> 36</a></span> <spanclass="comment"></span><spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a0feee45e4151547b7a0444c14bad398f">ksub</a>; <spanclass="comment">///< number of centroids for each subquantizer</span></div>
<divclass="line"><aname="l00037"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a1e4056fa3938ed8c9fe701e90d94ad95"> 37</a></span> <spanclass="comment"></span><spanclass="keywordtype">bool</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a1e4056fa3938ed8c9fe701e90d94ad95">verbose</a>; <spanclass="comment">///< verbose during training?</span></div>
<divclass="line"><aname="l00043"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a3a41c6286095e731be744548d9535a35a4960d143d2aa49cf92028cf3470c47a0"> 43</a></span> <aclass="code"href="structfaiss_1_1ProductQuantizer.html#a3a41c6286095e731be744548d9535a35a4960d143d2aa49cf92028cf3470c47a0">Train_hot_start</a>, <spanclass="comment">///< the centroids are already initialized</span></div>
<divclass="line"><aname="l00050"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#af265acf5aa1bcda60898002287e6a3d6"> 50</a></span> <aclass="code"href="structfaiss_1_1ClusteringParameters.html">ClusteringParameters</a><aclass="code"href="structfaiss_1_1ProductQuantizer.html#af265acf5aa1bcda60898002287e6a3d6">cp</a>; <spanclass="comment">///< parameters used during clustering</span></div>
<divclass="line"><aname="l00055"></a><spanclass="lineno"> 55</span> <spanclass="comment"> /// return the centroids associated with subvector m</span></div>
<divclass="line"><aname="l00056"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a4f0f33c011dffe633a1748a48a082c22"> 56</a></span> <spanclass="comment"></span><spanclass="keywordtype">float</span> * <aclass="code"href="structfaiss_1_1ProductQuantizer.html#a4f0f33c011dffe633a1748a48a082c22">get_centroids</a> (<spanclass="keywordtype">size_t</span> m, <spanclass="keywordtype">size_t</span> i) {</div>
<divclass="line"><aname="l00063"></a><spanclass="lineno"> 63</span> <spanclass="comment">// Train the product quantizer on a set of points. A clustering</span></div>
<divclass="line"><aname="l00064"></a><spanclass="lineno"> 64</span> <spanclass="comment">// can be set on input to define non-default clustering parameters</span></div>
<divclass="line"><aname="l00065"></a><spanclass="lineno"> 65</span> <spanclass="keywordtype">void</span> train (<spanclass="keywordtype">int</span> n, <spanclass="keyword">const</span><spanclass="keywordtype">float</span> *x);</div>
<divclass="line"><aname="l00067"></a><spanclass="lineno"> 67</span>  ProductQuantizer(<spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a567cd512438f9e3404d9339a232d7695">d</a>, <spanclass="comment">/* dimensionality of the input vectors */</span></div>
<divclass="line"><aname="l00068"></a><spanclass="lineno"> 68</span> <spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#a83600e328893ce5f41fe459f5a3acf41">M</a>, <spanclass="comment">/* number of subquantizers */</span></div>
<divclass="line"><aname="l00069"></a><spanclass="lineno"> 69</span> <spanclass="keywordtype">size_t</span><aclass="code"href="structfaiss_1_1ProductQuantizer.html#ac920fea11f02e8407d12cc99a09f5ea5">nbits</a>); <spanclass="comment">/* number of bit per subvector index */</span></div>
<divclass="line"><aname="l00073"></a><spanclass="lineno"> 73</span> <spanclass="comment"> /// compute derived values when d, M and nbits have been set</span></div>
<divclass="line"><aname="l00076"></a><spanclass="lineno"> 76</span> <spanclass="comment"> /// Define the centroids for subquantizer m</span></div>
<divclass="line"><aname="l00079"></a><spanclass="lineno"> 79</span> <spanclass="comment"> /// Quantize one vector with the product quantizer</span></div>
<divclass="line"><aname="l00082"></a><spanclass="lineno"> 82</span> <spanclass="comment"> /// same as compute_code for several vectors</span></div>
<divclass="line"><aname="l00087"></a><spanclass="lineno"> 87</span> <spanclass="comment"> /// decode a vector from a given code (or n vectors if third argument)</span></div>
<divclass="line"><aname="l00091"></a><spanclass="lineno"> 91</span> <spanclass="comment"> /// If we happen to have the distance tables precomputed, this is</span></div>
<divclass="line"><aname="l00092"></a><spanclass="lineno"> 92</span> <spanclass="comment"> /// more efficient to compute the codes.</span></div>
<divclass="line"><aname="l00099"></a><spanclass="lineno"> 99</span> <spanclass="comment"> * The distance table for x = [x_0 x_1 .. x_(M-1)] is a M * ksub</span></div>
<divclass="line"><aname="l00100"></a><spanclass="lineno"> 100</span> <spanclass="comment"> * matrix that contains</span></div>
<divclass="line"><aname="l00105"></a><spanclass="lineno"> 105</span> <spanclass="comment"> * where c_(m, j) is the centroid no j of sub-quantizer m.</span></div>
<divclass="line"><aname="l00117"></a><spanclass="lineno"> 117</span> <spanclass="comment"> /** compute distance table for several vectors</span></div>
<divclass="line"><aname="l00118"></a><spanclass="lineno"> 118</span> <spanclass="comment"> * @param nx nb of input vectors</span></div>
<divclass="line"><aname="l00135"></a><spanclass="lineno"> 135</span> <spanclass="comment"> * @param ncodes nb of nb vectors</span></div>
<divclass="line"><aname="l00136"></a><spanclass="lineno"> 136</span> <spanclass="comment"> * @param res heap array to store results (nh == nx)</span></div>
<divclass="line"><aname="l00146"></a><spanclass="lineno"> 146</span> <spanclass="comment"> /** same as search, but with inner product similarity */</span></div>
<divclass="line"><aname="l00158"></a><spanclass="lineno"> 158</span> <spanclass="comment">// intitialize the SDC table from the centroids</span></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_ad291f113c6d44a634ddc1972f9a3c775"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#ad291f113c6d44a634ddc1972f9a3c775">faiss::ProductQuantizer::set_params</a></div><divclass="ttdeci">void set_params(const float *centroids, int m)</div><divclass="ttdoc">Define the centroids for subquantizer m. </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8cpp_source.html#l00180">ProductQuantizer.cpp:180</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a3a41c6286095e731be744548d9535a35a6b330bc2cfa02a402d002d657f214931"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a3a41c6286095e731be744548d9535a35a6b330bc2cfa02a402d002d657f214931">faiss::ProductQuantizer::Train_hypercube_pca</a></div><divclass="ttdoc">intialize centroids with nbits-D hypercube </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00046">ProductQuantizer.h:46</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_ac920fea11f02e8407d12cc99a09f5ea5"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#ac920fea11f02e8407d12cc99a09f5ea5">faiss::ProductQuantizer::nbits</a></div><divclass="ttdeci">size_t nbits</div><divclass="ttdoc">number of bits per quantization index </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00030">ProductQuantizer.h:30</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a7afbf9d96276f021981e99f064254208"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a7afbf9d96276f021981e99f064254208">faiss::ProductQuantizer::decode</a></div><divclass="ttdeci">void decode(const uint8_t *code, float *x) const </div><divclass="ttdoc">decode a vector from a given code (or n vectors if third argument) </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8cpp_source.html#l00338">ProductQuantizer.cpp:338</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a13bf69a0dc7b4e45792d10f458e4a92d"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a13bf69a0dc7b4e45792d10f458e4a92d">faiss::ProductQuantizer::byte_per_idx</a></div><divclass="ttdeci">size_t byte_per_idx</div><divclass="ttdoc">nb bytes per code component (1 or 2) </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00034">ProductQuantizer.h:34</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a3a41c6286095e731be744548d9535a35ac8040c8792a014a2ea7188583575013e"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a3a41c6286095e731be744548d9535a35ac8040c8792a014a2ea7188583575013e">faiss::ProductQuantizer::Train_hypercube</a></div><divclass="ttdoc">intialize centroids with nbits-D hypercube </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00045">ProductQuantizer.h:45</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_ab3067f333b26811537a8519fb08292ce"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#ab3067f333b26811537a8519fb08292ce">faiss::ProductQuantizer::set_derived_values</a></div><divclass="ttdeci">void set_derived_values()</div><divclass="ttdoc">compute derived values when d, M and nbits have been set </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8cpp_source.html#l00167">ProductQuantizer.cpp:167</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a467b451ca203544e42c250e4be65b983"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a467b451ca203544e42c250e4be65b983">faiss::ProductQuantizer::dsub</a></div><divclass="ttdeci">size_t dsub</div><divclass="ttdoc">dimensionality of each subvector </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00033">ProductQuantizer.h:33</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_aa61330eadb84772b71018b093773a5f9"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#aa61330eadb84772b71018b093773a5f9">faiss::ProductQuantizer::code_size</a></div><divclass="ttdeci">size_t code_size</div><divclass="ttdoc">byte per indexed vector </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00035">ProductQuantizer.h:35</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a0feee45e4151547b7a0444c14bad398f"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a0feee45e4151547b7a0444c14bad398f">faiss::ProductQuantizer::ksub</a></div><divclass="ttdeci">size_t ksub</div><divclass="ttdoc">number of centroids for each subquantizer </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00036">ProductQuantizer.h:36</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a08b130e3a21f2699a4e3bbec121fb838"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a08b130e3a21f2699a4e3bbec121fb838">faiss::ProductQuantizer::compute_code</a></div><divclass="ttdeci">void compute_code(const float *x, uint8_t *code) const </div><divclass="ttdoc">Quantize one vector with the product quantizer. </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8cpp_source.html#l00311">ProductQuantizer.cpp:311</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a3a41c6286095e731be744548d9535a35a4960d143d2aa49cf92028cf3470c47a0"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a3a41c6286095e731be744548d9535a35a4960d143d2aa49cf92028cf3470c47a0">faiss::ProductQuantizer::Train_hot_start</a></div><divclass="ttdoc">the centroids are already initialized </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00043">ProductQuantizer.h:43</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_af265acf5aa1bcda60898002287e6a3d6"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#af265acf5aa1bcda60898002287e6a3d6">faiss::ProductQuantizer::cp</a></div><divclass="ttdeci">ClusteringParameters cp</div><divclass="ttdoc">parameters used during clustering </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00050">ProductQuantizer.h:50</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a83600e328893ce5f41fe459f5a3acf41"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a83600e328893ce5f41fe459f5a3acf41">faiss::ProductQuantizer::M</a></div><divclass="ttdeci">size_t M</div><divclass="ttdoc">number of subquantizers </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00029">ProductQuantizer.h:29</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a4f0f33c011dffe633a1748a48a082c22"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a4f0f33c011dffe633a1748a48a082c22">faiss::ProductQuantizer::get_centroids</a></div><divclass="ttdeci">float * get_centroids(size_t m, size_t i)</div><divclass="ttdoc">return the centroids associated with subvector m </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00056">ProductQuantizer.h:56</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a567cd512438f9e3404d9339a232d7695"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a567cd512438f9e3404d9339a232d7695">faiss::ProductQuantizer::d</a></div><divclass="ttdeci">size_t d</div><divclass="ttdoc">size of the input vectors </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00028">ProductQuantizer.h:28</a></div></div>
<divclass="ttc"id="structfaiss_1_1ProductQuantizer_html_a1e4056fa3938ed8c9fe701e90d94ad95"><divclass="ttname"><ahref="structfaiss_1_1ProductQuantizer.html#a1e4056fa3938ed8c9fe701e90d94ad95">faiss::ProductQuantizer::verbose</a></div><divclass="ttdeci">bool verbose</div><divclass="ttdoc">verbose during training? </div><divclass="ttdef"><b>Definition:</b><ahref="ProductQuantizer_8h_source.html#l00037">ProductQuantizer.h:37</a></div></div>