Filters

View as Markdown

Python module: cuvs.neighbors.filters

no_filter

1def no_filter()

Create a default pre-filter which filters nothing.

from_bitmap

1def from_bitmap(bitmap)

Create a pre-filter from an array with type of uint32.

Parameters

NameTypeDescription
bitmapnumpy.ndarrayAn array with type of uint32 where each bit in the array corresponds to if a sample and query pair is greenlit (not filtered) or filtered. The array is row-major, meaning the bits are ordered by rows first. Each bit in a uint32 element represents a different sample-query pair.

- Bit value of 1: The sample-query pair is greenlit (allowed).
- Bit value of 0: The sample-query pair is filtered.

Returns

NameTypeDescription
filtercuvs.neighbors.filters.PrefilterAn instance of Prefilter that can be used to filter neighbors based on the given bitmap.
resourcescuvs.common.Resources, optional

Examples

1>>> import cupy as cp
2>>> import numpy as np
3>>> from cuvs.neighbors import filters
4>>>
5>>> n_samples = 50000
6>>> n_queries = 1000
7>>>
8>>> n_bitmap = np.ceil(n_samples * n_queries / 32).astype(int)
9>>> bitmap = cp.random.randint(1, 100, size=(n_bitmap,), dtype=cp.uint32)
10>>> prefilter = filters.from_bitmap(bitmap)

from_bitset

1def from_bitset(bitset)

Create a pre-filter from an array with type of uint32.

Parameters

NameTypeDescription
bitsetnumpy.ndarrayAn array with type of uint32 where each bit in the array corresponds to if a sample is greenlit (not filtered) or filtered. Each bit in a uint32 element represents a different sample of the dataset.

- Bit value of 1: The sample is greenlit (allowed).
- Bit value of 0: The sample pair is filtered.

Returns

NameTypeDescription
filtercuvs.neighbors.filters.PrefilterAn instance of Prefilter that can be used to filter neighbors based on the given bitset.
resourcescuvs.common.Resources, optional

Examples

1>>> import cupy as cp
2>>> import numpy as np
3>>> from cuvs.neighbors import filters
4>>>
5>>> n_samples = 50000
6>>> n_queries = 1000
7>>>
8>>> n_bitset = np.ceil(n_samples / 32).astype(int)
9>>> bitset = cp.random.randint(1, 100, size=(n_bitset,), dtype=cp.uint32)
10>>> prefilter = filters.from_bitset(bitset)

Prefilter

1cdef class Prefilter

Constructor

1def __init__(self, cuvsFilter prefilter, parent=None)