Arrays¶
Fixed-size bounded array circuits and traceable array utilities.
concrete_fhe_toolkit.arrays ¶
Fixed-size bounded array operations for Concrete FHE.
array_add ¶
array_add(array1: Union[ndarray, List[Any]], array2: Union[ndarray, List[Any]]) -> Any
Perform element-wise addition of two encrypted arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array1
|
Union[ndarray, List[Any]]
|
The first encrypted array. |
required |
array2
|
Union[ndarray, List[Any]]
|
The second encrypted array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The element-wise sum of the two arrays. |
Example
from concrete_fhe_toolkit import array_add
print(array_add([1, 2], [3, 4])) # [4, 6]
Source code in src/concrete_fhe_toolkit/arrays/arithmetic.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
array_multiply ¶
array_multiply(array1: Union[ndarray, List[Any]], array2: Union[ndarray, List[Any]]) -> Any
Perform element-wise multiplication of two encrypted arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array1
|
Union[ndarray, List[Any]]
|
The first encrypted array. |
required |
array2
|
Union[ndarray, List[Any]]
|
The second encrypted array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The element-wise product of the two arrays. |
Example
from concrete_fhe_toolkit import array_multiply
print(array_multiply([1, 2], [3, 4])) # [3, 8]
Source code in src/concrete_fhe_toolkit/arrays/arithmetic.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
array_scale ¶
array_scale(array: Union[ndarray, List[Any]], factor: int) -> Union[np.ndarray, List[Any]]
Multiply every element of an encrypted array by a scalar constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Union[ndarray, List[Any]]
|
The encrypted array or list of elements. |
required |
factor
|
int
|
The scalar constant to multiply by. |
required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, List[Any]]
|
Union[np.ndarray, List[Any]]: The scaled array. |
Example
from concrete_fhe_toolkit import array_scale
print(array_scale([1, 2, 3], factor=3)) # [3, 6, 9]
Source code in src/concrete_fhe_toolkit/arrays/arithmetic.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
array_sub ¶
array_sub(array1: Union[ndarray, List[Any]], array2: Union[ndarray, List[Any]]) -> Any
Perform element-wise subtraction of two encrypted arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array1
|
Union[ndarray, List[Any]]
|
The first encrypted array. |
required |
array2
|
Union[ndarray, List[Any]]
|
The second encrypted array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The element-wise difference between the two arrays. |
Example
from concrete_fhe_toolkit import array_sub
print(array_sub([5, 5], [2, 1])) # [3, 4]
Source code in src/concrete_fhe_toolkit/arrays/arithmetic.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
array_sum ¶
array_sum(elements: Union[ndarray, List[Any]]) -> Any
Calculate the sum of all elements in an encrypted array using a tournament reduction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
Union[ndarray, List[Any]]
|
The encrypted array or list of elements. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The computed encrypted sum of all elements in the array. |
Example
from concrete_fhe_toolkit import array_sum
print(array_sum([1, 2, 3, 4])) # 10
Source code in src/concrete_fhe_toolkit/arrays/arithmetic.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
array_all_equal ¶
array_all_equal(array1: Union[ndarray, List[Any]], array2: Union[ndarray, List[Any]]) -> Any
Check if two encrypted arrays are identical (returns 1 or 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array1
|
Union[ndarray, List[Any]]
|
The first encrypted array. |
required |
array2
|
Union[ndarray, List[Any]]
|
The second encrypted array. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
1 if all elements are equal, 0 otherwise. |
Example
from concrete_fhe_toolkit import array_all_equal
print(array_all_equal([1, 2], [1, 2])) # 1
Source code in src/concrete_fhe_toolkit/arrays/manipulation.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
array_concat ¶
array_concat(*arrays: Union[ndarray, List[Any]]) -> Union[np.ndarray, List[Any]]
Concatenate encrypted arrays along their public length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*arrays
|
Union[ndarray, List[Any]]
|
A variable number of arrays to concatenate. |
()
|
Returns:
| Type | Description |
|---|---|
Union[ndarray, List[Any]]
|
Union[np.ndarray, List[Any]]: The concatenated array. |
Example
from concrete_fhe_toolkit import array_concat
print(array_concat([1, 2], [3, 4])) # [1, 2, 3, 4]
Source code in src/concrete_fhe_toolkit/arrays/manipulation.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
array_cumsum ¶
array_cumsum(array: Union[ndarray, List[Any]]) -> Union[np.ndarray, List[Any]]
Return the running prefix sums of an encrypted array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Union[ndarray, List[Any]]
|
The encrypted array or list of elements. |
required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, List[Any]]
|
Union[np.ndarray, List[Any]]: The array of prefix sums. |
Example
from concrete_fhe_toolkit import array_cumsum
print(array_cumsum([1, 2, 3])) # [1, 3, 6]
Source code in src/concrete_fhe_toolkit/arrays/manipulation.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
array_reverse ¶
array_reverse(array: Union[ndarray, List[Any]]) -> Union[np.ndarray, List[Any]]
Return the array with its (public) element order reversed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Union[ndarray, List[Any]]
|
The encrypted array or list of elements. |
required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, List[Any]]
|
Union[np.ndarray, List[Any]]: The reversed array. |
Example
from concrete_fhe_toolkit import array_reverse
print(array_reverse([1, 2, 3])) # [3, 2, 1]
Source code in src/concrete_fhe_toolkit/arrays/manipulation.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
array_slice ¶
array_slice(array: Union[ndarray, List[Any]], begin_index: Any, end_index: Any) -> Any
Slice an encrypted array (return elements from begin_index to end_index - 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Union[ndarray, List[Any]]
|
The encrypted array or list of elements. |
required |
begin_index
|
Any
|
The starting index (inclusive). |
required |
end_index
|
Any
|
The ending index (exclusive). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The sliced array. |
Example
from concrete_fhe_toolkit import array_slice
print(array_slice([10, 20, 30, 40], 1, 3)) # [20, 30]
Source code in src/concrete_fhe_toolkit/arrays/manipulation.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
make_array_pad ¶
make_array_pad(size: int, target_size: int, min_value: int = -15, max_value: int = 15) -> Callable
Create a fixed-size array padding function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
target_size
|
int
|
The desired size of the array after padding. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that pads the input array with zeros. |
Example
from concrete_fhe_toolkit import make_array_pad
pad_fn = make_array_pad(size=2, target_size=4, min_value=0, max_value=10)
print(pad_fn([1, 2])) # [1, 2, 0, 0]
Source code in src/concrete_fhe_toolkit/arrays/manipulation.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
compile_array_pad ¶
compile_array_pad(size: int, target_size: int, min_value: int = -15, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a fixed-size array padding circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
target_size
|
int
|
The desired size of the array after padding. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled padding circuit. |
Example
from concrete_fhe_toolkit import compile_array_pad
circuit = compile_array_pad(size=2, target_size=4, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([1, 2])) # [1, 2, 0, 0]
Source code in src/concrete_fhe_toolkit/arrays/manipulation.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
compile_array_index ¶
compile_array_index(size: int, min_value: int = -15, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile an oblivious-read circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled oblivious-read circuit. |
Example
from concrete_fhe_toolkit import compile_array_index
circuit = compile_array_index(size=3, min_value=0, max_value=30)
print(circuit.encrypt_run_decrypt([10, 20, 30], 1)) # 20
Source code in src/concrete_fhe_toolkit/arrays/access.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
compile_array_set ¶
compile_array_set(size: int, min_value: int = -15, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile an FHE circuit for oblivious array writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled circuit for oblivious array writing. |
Example
from concrete_fhe_toolkit.arrays import compile_array_set
circuit = compile_array_set(size=5)
# circuit.encrypt_run_decrypt(arr, index, value)
Source code in src/concrete_fhe_toolkit/arrays/access.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
make_array_index ¶
make_array_index(size: int, min_value: int = -15, max_value: int = 15) -> Callable
Create an oblivious-read function for bounded encrypted arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that obliviously reads an element from the array at a given index. |
Example
from concrete_fhe_toolkit import make_array_index
index_fn = make_array_index(size=3, min_value=0, max_value=30)
print(index_fn([10, 20, 30], 1)) # 20
Source code in src/concrete_fhe_toolkit/arrays/access.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
make_array_set ¶
make_array_set(size: int, min_value: int = -15, max_value: int = 15) -> Callable
Create a function for oblivious array writing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that updates an element in the encrypted array obliviously. |
Example
from concrete_fhe_toolkit.arrays import make_array_set
array_set = make_array_set(size=5)
# new_arr = array_set(arr, index, value)
Source code in src/concrete_fhe_toolkit/arrays/access.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
compile_argmax ¶
compile_argmax(size: int, min_value: int = 0, max_value: int = 15, *, tie_break: TieBreak = 'first', configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile an argmax reduction circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
tie_break
|
TieBreak
|
Which index to return if multiple elements are equal to the maximum. |
'first'
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled argmax reduction circuit. |
Example
from concrete_fhe_toolkit import compile_argmax
circuit = compile_argmax(size=4, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([4, 1, 3, 2])) # 0
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
compile_argmin ¶
compile_argmin(size: int, min_value: int = 0, max_value: int = 15, *, tie_break: TieBreak = 'first', configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile an argmin reduction circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
tie_break
|
TieBreak
|
Which index to return if multiple elements are equal to the minimum. |
'first'
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled argmin reduction circuit. |
Example
from concrete_fhe_toolkit import compile_argmin
circuit = compile_argmin(size=4, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([4, 1, 3, 2])) # 1
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
compile_array_maximum ¶
compile_array_maximum(size: int, min_value: int = 0, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a maximum reduction circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled maximum reduction circuit. |
Example
from concrete_fhe_toolkit import compile_array_maximum
circuit = compile_array_maximum(size=4, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([4, 1, 3, 2])) # 4
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
compile_array_minimum ¶
compile_array_minimum(size: int, min_value: int = 0, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a minimum reduction circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled minimum reduction circuit. |
Example
from concrete_fhe_toolkit import compile_array_minimum
circuit = compile_array_minimum(size=4, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([4, 1, 3, 2])) # 1
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
make_argmax ¶
make_argmax(size: int, min_value: int = 0, max_value: int = 15, *, tie_break: TieBreak = 'first') -> UnaryArrayFunction
Create an argmax reduction with deterministic tie handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
tie_break
|
TieBreak
|
Which index to return if multiple elements are equal to the maximum. |
'first'
|
Returns:
| Name | Type | Description |
|---|---|---|
UnaryArrayFunction |
UnaryArrayFunction
|
A function that returns the index of the maximum value. |
Example
from concrete_fhe_toolkit import make_argmax
argmax_fn = make_argmax(size=4, min_value=0, max_value=10)
# Use `argmax_fn(array)` inside an FHE program compilation
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
make_argmin ¶
make_argmin(size: int, min_value: int = 0, max_value: int = 15, *, tie_break: TieBreak = 'first') -> UnaryArrayFunction
Create an argmin reduction with deterministic tie handling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
tie_break
|
TieBreak
|
Which index to return if multiple elements are equal to the minimum. |
'first'
|
Returns:
| Name | Type | Description |
|---|---|---|
UnaryArrayFunction |
UnaryArrayFunction
|
A function that returns the index of the minimum value. |
Example
from concrete_fhe_toolkit import make_argmin
argmin_fn = make_argmin(size=4, min_value=0, max_value=10)
# Use `argmin_fn(array)` inside an FHE program compilation
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
make_array_maximum ¶
make_array_maximum(size: int, min_value: int = 0, max_value: int = 15) -> UnaryArrayFunction
Create a tournament reduction that returns the maximum value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
UnaryArrayFunction |
UnaryArrayFunction
|
A function that returns the maximum value. |
Example
from concrete_fhe_toolkit import make_array_maximum
max_fn = make_array_maximum(size=4, min_value=0, max_value=10)
# Use `max_fn(array)` inside an FHE program compilation
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
make_array_minimum ¶
make_array_minimum(size: int, min_value: int = 0, max_value: int = 15) -> UnaryArrayFunction
Create a tournament reduction that returns the minimum value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
UnaryArrayFunction |
UnaryArrayFunction
|
A function that returns the minimum value. |
Example
from concrete_fhe_toolkit import make_array_minimum
min_fn = make_array_minimum(size=4, min_value=0, max_value=10)
# Use `min_fn(array)` inside an FHE program compilation
Source code in src/concrete_fhe_toolkit/arrays/extremes.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
compile_array_contains ¶
compile_array_contains(size: int, min_value: int = -15, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a membership-test circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled membership-test circuit. |
Example
from concrete_fhe_toolkit import compile_array_contains
circuit = compile_array_contains(size=3, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([1, 3, 5], 3)) # 1
Source code in src/concrete_fhe_toolkit/arrays/search.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
compile_array_count ¶
compile_array_count(size: int, min_value: int = -15, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a value-counting circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled counting circuit. |
Example
from concrete_fhe_toolkit import compile_array_count
circuit = compile_array_count(size=4, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([1, 2, 2, 3], 2)) # 2
Source code in src/concrete_fhe_toolkit/arrays/search.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
compile_array_index_of ¶
compile_array_index_of(size: int, min_value: int = -15, max_value: int = 15, *, missing_result: Optional[int] = None, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a first-index-of search circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
missing_result
|
Optional[int]
|
The value to return if the target is not found (default: size). |
None
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled search circuit. |
Example
from concrete_fhe_toolkit import compile_array_index_of
circuit = compile_array_index_of(size=3, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([10, 20, 30], 20)) # 1
Source code in src/concrete_fhe_toolkit/arrays/search.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
make_array_contains ¶
make_array_contains(size: int, min_value: int = -15, max_value: int = 15) -> Callable
Create a membership-test function for bounded encrypted arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that tests whether a value exists in the array. |
Example
from concrete_fhe_toolkit import make_array_contains
contains_fn = make_array_contains(size=3, min_value=0, max_value=10)
print(contains_fn([1, 3, 5], 3)) # 1
Source code in src/concrete_fhe_toolkit/arrays/search.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
make_array_count ¶
make_array_count(size: int, min_value: int = -15, max_value: int = 15) -> Callable
Create a value-counting function for bounded encrypted arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that counts occurrences of a value. |
Example
from concrete_fhe_toolkit import make_array_count
count_fn = make_array_count(size=4, min_value=0, max_value=10)
print(count_fn([1, 2, 2, 3], 2)) # 2
Source code in src/concrete_fhe_toolkit/arrays/search.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
make_array_index_of ¶
make_array_index_of(size: int, min_value: int = -15, max_value: int = 15, *, missing_result: Optional[int] = None) -> Callable
Create a first-index-of search function for bounded encrypted arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
-15
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
missing_result
|
Optional[int]
|
The value to return if the target is not found (default: size). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable
|
A function that returns the index of a specified value. |
Example
from concrete_fhe_toolkit import make_array_index_of
index_of_fn = make_array_index_of(size=3, min_value=0, max_value=10)
print(index_of_fn([10, 20, 30], 20)) # 1
Source code in src/concrete_fhe_toolkit/arrays/search.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
compile_compare_swap ¶
compile_compare_swap(min_value: int = 0, max_value: int = 15, *, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile an ascending compare-swap circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled compare-swap circuit. |
Example
from concrete_fhe_toolkit import compile_compare_swap
circuit = compile_compare_swap(min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt(5, 3)) # (3, 5)
Source code in src/concrete_fhe_toolkit/arrays/sorting.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
compile_sort ¶
compile_sort(size: int, min_value: int = 0, max_value: int = 15, *, descending: bool = False, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a fixed-size bitonic sorting circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
descending
|
bool
|
Whether to sort in descending order. |
False
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled sorting circuit. |
Example
from concrete_fhe_toolkit import compile_sort
circuit = compile_sort(size=4, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([4, 1, 3, 2])) # [1, 2, 3, 4]
Source code in src/concrete_fhe_toolkit/arrays/sorting.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
compile_top_k ¶
compile_top_k(size: int, k: int, min_value: int = 0, max_value: int = 15, *, largest: bool = True, configuration: Optional[Configuration] = None) -> fhe.Circuit
Compile a top-k reduction circuit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
k
|
int
|
The number of top elements to return. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
largest
|
bool
|
Whether to return the largest values (True) or smallest values (False). |
True
|
configuration
|
Optional[Configuration]
|
Optional FHE compiler configuration object. |
None
|
Returns:
| Type | Description |
|---|---|
Circuit
|
fhe.Circuit: The compiled top-k reduction circuit. |
Example
from concrete_fhe_toolkit import compile_top_k
circuit = compile_top_k(size=4, k=2, min_value=0, max_value=10)
print(circuit.encrypt_run_decrypt([4, 1, 3, 2])) # [4, 3]
Source code in src/concrete_fhe_toolkit/arrays/sorting.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
make_compare_swap ¶
make_compare_swap(min_value: int = 0, max_value: int = 15) -> BinaryScalarFunction
Create an ascending compare-swap function for bounded encrypted integers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
Returns:
| Name | Type | Description |
|---|---|---|
BinaryScalarFunction |
BinaryScalarFunction
|
A function that sorts two encrypted values. |
Example
from concrete_fhe_toolkit import make_compare_swap
swap = make_compare_swap(min_value=0, max_value=10)
# Use `swap(x, y)` inside an FHE program compilation
Source code in src/concrete_fhe_toolkit/arrays/sorting.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
make_sort ¶
make_sort(size: int, min_value: int = 0, max_value: int = 15, *, descending: bool = False) -> UnaryArrayFunction
Create a fixed-size bitonic sorting network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
descending
|
bool
|
Whether to sort in descending order instead of ascending. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
UnaryArrayFunction |
UnaryArrayFunction
|
A function that sorts the input array. |
Example
from concrete_fhe_toolkit import make_sort
sort_fn = make_sort(size=4, min_value=0, max_value=10)
# Use `sort_fn(array)` inside an FHE program compilation
Source code in src/concrete_fhe_toolkit/arrays/sorting.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
make_top_k ¶
make_top_k(size: int, k: int, min_value: int = 0, max_value: int = 15, *, largest: bool = True) -> UnaryArrayFunction
Create a reduction returning the k largest (or smallest) values in order.
Uses a sorting network (Bitonic Sort) and slices the top k elements, which is significantly more efficient in FHE than iterative greedy selection.
Note: Requires size to be a power of two (2, 4, 8...) due to the underlying sort.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
The fixed size of the input array, must be known at compile time. |
required |
k
|
int
|
The number of top elements to return. |
required |
min_value
|
int
|
The lower bound for the encrypted inputs, used to dimension the FHE circuit. |
0
|
max_value
|
int
|
The upper bound for the encrypted inputs, used to dimension the FHE circuit. |
15
|
largest
|
bool
|
Whether to return the largest values (True) or smallest values (False). |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
UnaryArrayFunction |
UnaryArrayFunction
|
A function that returns the top k values of the input array. |
Example
from concrete_fhe_toolkit import make_top_k
top_k_fn = make_top_k(size=4, k=2, min_value=0, max_value=10)
# Use `top_k_fn(array)` inside an FHE program compilation
Source code in src/concrete_fhe_toolkit/arrays/sorting.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |