← 返回首页
> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.nvidia.com/cuvs/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/cuvs/_mcp/server. # Binary _Source header: `cuvs/preprocessing/quantize/binary.hpp`_ ## Binary quantizer utilities ### preprocessing::quantize::binary::bit_threshold quantizer algorithms. The mean and sampling_median thresholds are calculated separately for each dimension. ```cpp enum class bit_threshold { zero, mean, sampling_median }; ``` **Values** | Name | Value | | --- | --- | | `zero` | `` | | `mean` | `` | | `sampling_median` | `` | ### preprocessing::quantize::binary::params quantizer parameters. ```cpp struct params { bit_threshold threshold; float sampling_ratio; }; ``` **Fields** | Name | Type | Description | | --- | --- | --- | | `threshold` | [`bit_threshold`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-bit-threshold) | Threshold method for binarization. | | `sampling_ratio` | `float` | Specifies the sampling ratio. | ### preprocessing::quantize::binary::quantizer Store the threshold vector for quantization. In the binary::transform function, a bit is set if the corresponding element in the dataset vector is greater than the corresponding element in the threshold vector. ```cpp template struct quantizer { raft::device_vector threshold; }; ``` **Fields** | Name | Type | Description | | --- | --- | --- | | `threshold` | `raft::device_vector` | Threshold vector used for binarization. | ### preprocessing::quantize::binary::quantizer::quantizer Construct a quantizer with an empty threshold vector. ```cpp quantizer(raft::resources const& res); ``` **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | | `raft::resources const&` | | **Returns** `void` ### preprocessing::quantize::binary::train Initializes a binary quantizer to be used later for quantizing the dataset. ```cpp quantizer train(raft::resources const& res, const params params, raft::device_matrix_view dataset); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `params` | in | [`const params`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-params) | configure binary quantizer, e.g. threshold | | `dataset` | in | `raft::device_matrix_view` | a row-major matrix view on device | **Returns** [`quantizer`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) **Additional overload:** `preprocessing::quantize::binary::train` Initializes a binary quantizer to be used later for quantizing the dataset. ```cpp quantizer train(raft::resources const& res, const params params, raft::host_matrix_view dataset); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `params` | in | [`const params`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-params) | configure binary quantizer, e.g. threshold | | `dataset` | in | `raft::host_matrix_view` | a row-major matrix view on host | **Returns** [`quantizer`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) ### preprocessing::quantize::binary::transform Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp void transform(raft::resources const& res, const quantizer& quantizer, raft::device_matrix_view dataset, raft::device_matrix_view out); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `quantizer` | in | [`const quantizer&`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | a binary quantizer | | `dataset` | in | `raft::device_matrix_view` | a row-major matrix view on device | | `out` | out | `raft::device_matrix_view` | a row-major matrix view on device | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::transform` Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp void transform(raft::resources const& res, const quantizer& quantizer, raft::host_matrix_view dataset, raft::host_matrix_view out); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `quantizer` | in | [`const quantizer&`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | a binary quantizer | | `dataset` | in | `raft::host_matrix_view` | a row-major matrix view on host | | `out` | out | `raft::host_matrix_view` | a row-major matrix view on host | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::train` Initializes a binary quantizer to be used later for quantizing the dataset. ```cpp quantizer train(raft::resources const& res, const params params, raft::device_matrix_view dataset); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `params` | in | [`const params`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-params) | configure binary quantizer, e.g. threshold | | `dataset` | in | `raft::device_matrix_view` | a row-major matrix view on device | **Returns** [`quantizer`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) **Additional overload:** `preprocessing::quantize::binary::train` Initializes a binary quantizer to be used later for quantizing the dataset. ```cpp quantizer train(raft::resources const& res, const params params, raft::host_matrix_view dataset); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `params` | in | [`const params`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-params) | configure binary quantizer, e.g. threshold | | `dataset` | in | `raft::host_matrix_view` | a row-major matrix view on host | **Returns** [`quantizer`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) **Additional overload:** `preprocessing::quantize::binary::transform` Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp void transform(raft::resources const& res, const quantizer& quantizer, raft::device_matrix_view dataset, raft::device_matrix_view out); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `quantizer` | in | [`const quantizer&`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | a binary quantizer | | `dataset` | in | `raft::device_matrix_view` | a row-major matrix view on device | | `out` | out | `raft::device_matrix_view` | a row-major matrix view on device | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::transform` Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp void transform(raft::resources const& res, const quantizer& quantizer, raft::host_matrix_view dataset, raft::host_matrix_view out); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `quantizer` | in | [`const quantizer&`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | a binary quantizer | | `dataset` | in | `raft::host_matrix_view` | a row-major matrix view on host | | `out` | out | `raft::host_matrix_view` | a row-major matrix view on host | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::train` Initializes a binary quantizer to be used later for quantizing the dataset. ```cpp quantizer train(raft::resources const& res, const params params, raft::device_matrix_view dataset); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `params` | in | [`const params`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-params) | configure binary quantizer, e.g. threshold | | `dataset` | in | `raft::device_matrix_view` | a row-major matrix view on device | **Returns** [`quantizer`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) **Additional overload:** `preprocessing::quantize::binary::train` Initializes a binary quantizer to be used later for quantizing the dataset. ```cpp quantizer train(raft::resources const& res, const params params, raft::host_matrix_view dataset); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `params` | in | [`const params`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-params) | configure binary quantizer, e.g. threshold | | `dataset` | in | `raft::host_matrix_view` | a row-major matrix view on host | **Returns** [`quantizer`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) **Additional overload:** `preprocessing::quantize::binary::transform` Applies binary quantization transform to given dataset. ```cpp void transform(raft::resources const& res, const quantizer& quantizer, raft::device_matrix_view dataset, raft::device_matrix_view out); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `quantizer` | in | [`const quantizer&`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | a binary quantizer | | `dataset` | in | `raft::device_matrix_view` | a row-major matrix view on device | | `out` | out | `raft::device_matrix_view` | a row-major matrix view on device | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::transform` Applies binary quantization transform to given dataset. ```cpp void transform(raft::resources const& res, const quantizer& quantizer, raft::host_matrix_view dataset, raft::host_matrix_view out); ``` Usage example: **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `res` | in | `raft::resources const&` | raft resource | | `quantizer` | in | [`const quantizer&`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | a binary quantizer | | `dataset` | in | `raft::host_matrix_view` | a row-major matrix view on host | | `out` | out | `raft::host_matrix_view` | a row-major matrix view on host | **Returns** `void` ### preprocessing::quantize::binary::[[deprecated [deprecated] Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp [[deprecated("please create and specify a quantizer")]] void transform( raft::resources const& res, raft::device_matrix_view dataset, raft::device_matrix_view out); ``` **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `arg1` | | [`"please create and specify a quantizer"`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::[[deprecated` [deprecated] Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp [[deprecated("please create and specify a quantizer")]] void transform( raft::resources const& res, raft::host_matrix_view dataset, raft::host_matrix_view out); ``` **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `arg1` | | [`"please create and specify a quantizer"`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::[[deprecated` [deprecated] Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp [[deprecated("please create and specify a quantizer")]] void transform( raft::resources const& res, raft::device_matrix_view dataset, raft::device_matrix_view out); ``` **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `arg1` | | [`"please create and specify a quantizer"`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::[[deprecated` [deprecated] Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp [[deprecated("please create and specify a quantizer")]] void transform( raft::resources const& res, raft::host_matrix_view dataset, raft::host_matrix_view out); ``` **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `arg1` | | [`"please create and specify a quantizer"`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::[[deprecated` [deprecated] Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp [[deprecated("please create and specify a quantizer")]] void transform( raft::resources const& res, raft::device_matrix_view dataset, raft::device_matrix_view out); ``` **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `arg1` | | [`"please create and specify a quantizer"`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | | **Returns** `void` **Additional overload:** `preprocessing::quantize::binary::[[deprecated` [deprecated] Applies binary quantization transform to given dataset. If a dataset element is positive, set the corresponding bit to 1. ```cpp [[deprecated("please create and specify a quantizer")]] void transform( raft::resources const& res, raft::host_matrix_view dataset, raft::host_matrix_view out); ``` **Parameters** | Name | Direction | Type | Description | | --- | --- | --- | --- | | `arg1` | | [`"please create and specify a quantizer"`](/api-reference/cpp-api-preprocessing-quantize-binary#preprocessing-quantize-binary-quantizer) | | **Returns** `void`