<divclass="line"><aname="l00005"></a><spanclass="lineno"> 5</span> <spanclass="comment"> * This source code is licensed under the BSD+Patents license found in the</span></div>
<divclass="line"><aname="l00006"></a><spanclass="lineno"> 6</span> <spanclass="comment"> * LICENSE file in the root directory of this source tree.</span></div>
<divclass="line"><aname="l00009"></a><spanclass="lineno"> 9</span> <spanclass="comment">// Copyright 2004-present Facebook. All Rights Reserved.</span></div>
<divclass="line"><aname="l00010"></a><spanclass="lineno"> 10</span> <spanclass="comment">// -*- c++ -*-</span></div>
<divclass="line"><aname="l00024"></a><spanclass="lineno"> 24</span> <spanclass="comment">/** Product Quantizer. Implemented only for METRIC_L2 */</span></div>
<divclass="line"><aname="l00027"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a567cd512438f9e3404d9339a232d7695"> 27</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="l00028"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a83600e328893ce5f41fe459f5a3acf41"> 28</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="l00029"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#ac920fea11f02e8407d12cc99a09f5ea5"> 29</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="l00031"></a><spanclass="lineno"> 31</span> <spanclass="comment">// values derived from the above</span></div>
<divclass="line"><aname="l00032"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a467b451ca203544e42c250e4be65b983"> 32</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="l00033"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a13bf69a0dc7b4e45792d10f458e4a92d"> 33</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="l00034"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#aa61330eadb84772b71018b093773a5f9"> 34</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="l00035"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a0feee45e4151547b7a0444c14bad398f"> 35</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="l00036"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a1e4056fa3938ed8c9fe701e90d94ad95"> 36</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="l00042"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a3a41c6286095e731be744548d9535a35a4960d143d2aa49cf92028cf3470c47a0"> 42</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="l00049"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#af265acf5aa1bcda60898002287e6a3d6"> 49</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="l00051"></a><spanclass="lineno"> 51</span> <spanclass="comment"> /// if non-NULL, use this index for assignment (should be of size</span></div>
<divclass="line"><aname="l00052"></a><spanclass="lineno"> 52</span> <spanclass="comment"> /// d / M)</span></div>
<divclass="line"><aname="l00058"></a><spanclass="lineno"> 58</span> <spanclass="comment"> /// return the centroids associated with subvector m</span></div>
<divclass="line"><aname="l00059"></a><spanclass="lineno"><aclass="line"href="structfaiss_1_1ProductQuantizer.html#a4f0f33c011dffe633a1748a48a082c22"> 59</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="l00066"></a><spanclass="lineno"> 66</span> <spanclass="comment">// Train the product quantizer on a set of points. A clustering</span></div>
<divclass="line"><aname="l00067"></a><spanclass="lineno"> 67</span> <spanclass="comment">// can be set on input to define non-default clustering parameters</span></div>
<divclass="line"><aname="l00068"></a><spanclass="lineno"> 68</span> <spanclass="keywordtype">void</span> train (<spanclass="keywordtype">int</span> n, <spanclass="keyword">const</span><spanclass="keywordtype">float</span> *x);</div>
<divclass="line"><aname="l00070"></a><spanclass="lineno"> 70</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="l00071"></a><spanclass="lineno"> 71</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="l00072"></a><spanclass="lineno"> 72</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="l00076"></a><spanclass="lineno"> 76</span> <spanclass="comment"> /// compute derived values when d, M and nbits have been set</span></div>
<divclass="line"><aname="l00079"></a><spanclass="lineno"> 79</span> <spanclass="comment"> /// Define the centroids for subquantizer m</span></div>
<divclass="line"><aname="l00082"></a><spanclass="lineno"> 82</span> <spanclass="comment"> /// Quantize one vector with the product quantizer</span></div>
<divclass="line"><aname="l00085"></a><spanclass="lineno"> 85</span> <spanclass="comment"> /// same as compute_code for several vectors</span></div>
<divclass="line"><aname="l00090"></a><spanclass="lineno"> 90</span> <spanclass="comment"> /// decode a vector from a given code (or n vectors if third argument)</span></div>
<divclass="line"><aname="l00094"></a><spanclass="lineno"> 94</span> <spanclass="comment"> /// If we happen to have the distance tables precomputed, this is</span></div>
<divclass="line"><aname="l00095"></a><spanclass="lineno"> 95</span> <spanclass="comment"> /// more efficient to compute the codes.</span></div>
<divclass="line"><aname="l00100"></a><spanclass="lineno"> 100</span> <spanclass="comment"> /** Compute distance table for one vector.</span></div>
<divclass="line"><aname="l00102"></a><spanclass="lineno"> 102</span> <spanclass="comment"> * The distance table for x = [x_0 x_1 .. x_(M-1)] is a M * ksub</span></div>
<divclass="line"><aname="l00103"></a><spanclass="lineno"> 103</span> <spanclass="comment"> * matrix that contains</span></div>
<divclass="line"><aname="l00108"></a><spanclass="lineno"> 108</span> <spanclass="comment"> * where c_(m, j) is the centroid no j of sub-quantizer m.</span></div>
<divclass="line"><aname="l00120"></a><spanclass="lineno"> 120</span> <spanclass="comment"> /** compute distance table for several vectors</span></div>
<divclass="line"><aname="l00121"></a><spanclass="lineno"> 121</span> <spanclass="comment"> * @param nx nb of input vectors</span></div>
<divclass="line"><aname="l00138"></a><spanclass="lineno"> 138</span> <spanclass="comment"> * @param ncodes nb of nb vectors</span></div>
<divclass="line"><aname="l00139"></a><spanclass="lineno"> 139</span> <spanclass="comment"> * @param res heap array to store results (nh == nx)</span></div>
<divclass="line"><aname="l00149"></a><spanclass="lineno"> 149</span> <spanclass="comment"> /** same as search, but with inner product similarity */</span></div>
<divclass="line"><aname="l00161"></a><spanclass="lineno"> 161</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#l00179">ProductQuantizer.cpp:179</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#l00045">ProductQuantizer.h:45</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#l00029">ProductQuantizer.h:29</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#l00339">ProductQuantizer.cpp:339</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#l00033">ProductQuantizer.h:33</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#l00044">ProductQuantizer.h:44</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#l00166">ProductQuantizer.cpp:166</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#l00032">ProductQuantizer.h:32</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#l00035">ProductQuantizer.h:35</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#l00312">ProductQuantizer.cpp:312</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#l00042">ProductQuantizer.h:42</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#l00049">ProductQuantizer.h:49</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#l00028">ProductQuantizer.h:28</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#l00059">ProductQuantizer.h:59</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#l00027">ProductQuantizer.h:27</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#l00036">ProductQuantizer.h:36</a></div></div>