> For the complete documentation index, see [llms.txt](https://docs.zama.org/concrete-ml/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/concrete-ml/0.4/developer-guide/api/concrete.ml.quantization.quantized_ops.md).

# concrete.ml.quantization.quantized\_ops

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L0)

## module `concrete.ml.quantization.quantized_ops`

Quantized versions of the ONNX operators for post training quantization.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L16)

### class `QuantizedSigmoid`

Quantized sigmoid op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L22)

### class `QuantizedHardSigmoid`

Quantized HardSigmoid op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L28)

### class `QuantizedRelu`

Quantized Relu op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L34)

### class `QuantizedPRelu`

Quantized PRelu op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L40)

### class `QuantizedLeakyRelu`

Quantized LeakyRelu op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L46)

### class `QuantizedHardSwish`

Quantized Hardswish op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L52)

### class `QuantizedElu`

Quantized Elu op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L58)

### class `QuantizedSelu`

Quantized Selu op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L64)

### class `QuantizedCelu`

Quantized Celu op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L70)

### class `QuantizedClip`

Quantized clip op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L76)

### class `QuantizedRound`

Quantized round op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L82)

### class `QuantizedPow`

Quantized pow op.

Only works for a float constant power. This operation will be fused to a (potentially larger) TLU.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L91)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L110)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Power raising can be fused and computed in float when a single integer tensor generates both the operands. For example in the formula: f(x) = x \*\* (x + 1) where x is an integer tensor.

**Returns:**

* **`bool`**: Can fuse

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L124)

### class `QuantizedGemm`

Quantized Gemm op.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L129)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L257)

#### method `can_fuse`

```python
can_fuse()
```

Determine if this op can be fused.

Gemm operation can not be fused since it must be performed over integer tensors and it combines different values of the input tensors.

**Returns:**

* **`bool`**: False, this operation can not be fused as it adds different encrypted integers

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L154)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L270)

### class `QuantizedMatMul`

Quantized MatMul op.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L129)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L257)

#### method `can_fuse`

```python
can_fuse()
```

Determine if this op can be fused.

Gemm operation can not be fused since it must be performed over integer tensors and it combines different values of the input tensors.

**Returns:**

* **`bool`**: False, this operation can not be fused as it adds different encrypted integers

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L154)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L276)

### class `QuantizedAdd`

Quantized Addition operator.

Can add either two variables (both encrypted) or a variable and a constant

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L371)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Add operation can be computed in float and fused if it operates over inputs produced by a single integer tensor. For example the expression x + x \* 1.75, where x is an encrypted tensor, can be computed with a single TLU.

**Returns:**

* **`bool`**: Whether the number of integer input tensors allows computing this op as a TLU

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L285)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L385)

### class `QuantizedTanh`

Quantized Tanh op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L391)

### class `QuantizedSoftplus`

Quantized Softplus op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L397)

### class `QuantizedExp`

Quantized Exp op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L403)

### class `QuantizedLog`

Quantized Log op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L409)

### class `QuantizedAbs`

Quantized Abs op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L415)

### class `QuantizedIdentity`

Quantized Identity op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L420)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L426)

### class `QuantizedReshape`

Quantized Reshape op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L432)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

Reshape the input integer encrypted tensor.

**Args:**

* **`q_inputs`**: an encrypted integer tensor at index 0 and one constant shape at index 1
* **`attrs`**: additional optional reshape options

**Returns:**

* **`result`** (QuantizedArray): reshaped encrypted integer tensor

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L465)

### class `QuantizedConv`

Quantized Conv op.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L470)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

Construct the quantized convolution operator and retrieve parameters.

**Args:**

* **`n_bits_output`**: number of bits for the quantization of the outputs of this operator
* **`int_input_names`**: names of integer tensors that are taken as input for this operation
* **`constant_inputs`**: the weights and activations
* **`input_quant_opts`**: options for the input quantizer
* **`attrs`**: convolution options
* **`dilations`** (Tuple\[int]): dilation of the kernel, default 1 on all dimensions.
* **`group`** (int): number of convolution groups, default 1
* **`kernel_shape`** (Tuple\[int]): shape of the kernel. Should have 2 elements for 2d conv
* **`pads`** (Tuple\[int]): padding in ONNX format (begin, end) on each axis
* **`strides`** (Tuple\[int]): stride of the convolution on each axis

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L649)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Conv operation can not be fused since it must be performed over integer tensors and it combines different elements of the input tensors.

**Returns:**

* **`bool`**: False, this operation can not be fused as it adds different encrypted integers

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L534)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

Compute the quantized convolution between two quantized tensors.

Allows an optional quantized bias.

**Args:**

* **`q_inputs`**: input tuple, contains
* **`x`** (numpy.ndarray): input data. Shape is N x C x H x W for 2d
* **`w`** (numpy.ndarray): weights tensor. Shape is (O x I x Kh x Kw) for 2d
* **`b`** (numpy.ndarray, Optional): bias tensor, Shape is (O,)
* **`attrs`**: convolution options handled in constructor

**Returns:**

* **`res`** (QuantizedArray): result of the quantized integer convolution

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L662)

### class `QuantizedAvgPool`

Quantized Average Pooling op.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L668)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L754)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Avg Pooling operation can not be fused since it must be performed over integer tensors and it combines different elements of the input tensors.

**Returns:**

* **`bool`**: False, this operation can not be fused as it adds different encrypted integers

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L717)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L766)

### class `QuantizedPad`

Quantized Padding op.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L771)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L793)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Pad operation can not be fused since it must be performed over integer tensors.

**Returns:**

* **`bool`**: False, this operation can not be fused as it is manipulates integer tensors

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L804)

### class `QuantizedWhere`

Where operator on quantized arrays.

Supports only constants for the results produced on the True/False branches.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L813)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L836)

### class `QuantizedCast`

Cast the input to the required data type.

In FHE we only support a limited number of output types. Booleans are cast to integers.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L845)

### class `QuantizedGreater`

Comparison operator >.

Only supports comparison with a constant.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L854)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L869)

### class `QuantizedGreaterOrEqual`

Comparison operator >=.

Only supports comparison with a constant.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L878)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L893)

### class `QuantizedLess`

Comparison operator <.

Only supports comparison with a constant.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L902)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L917)

### class `QuantizedLessOrEqual`

Comparison operator <=.

Only supports comparison with a constant.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L926)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L941)

### class `QuantizedOr`

Or operator ||.

This operation is not really working as a quantized operation. It just works when things got fused, as in e.g. Act(x) = x || (x + 42))

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L950)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L969)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Or can be fused and computed in float when a single integer tensor generates both the operands. For example in the formula: f(x) = x || (x + 1) where x is an integer tensor.

**Returns:**

* **`bool`**: Can fuse

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L982)

### class `QuantizedDiv`

Div operator /.

This operation is not really working as a quantized operation. It just works when things got fused, as in e.g. Act(x) = 1000 / (x + 42))

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L991)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1010)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Div can be fused and computed in float when a single integer tensor generates both the operands. For example in the formula: f(x) = x / (x + 1) where x is an integer tensor.

**Returns:**

* **`bool`**: Can fuse

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1023)

### class `QuantizedMul`

Multiplication operator.

Only multiplies an encrypted tensor with a float constant for now. This operation will be fused to a (potentially larger) TLU.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1032)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: QuantizationOptions = None,
    **attrs
) → None
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1051)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Multiplication can be fused and computed in float when a single integer tensor generates both the operands. For example in the formula: f(x) = x \* (x + 1) where x is an integer tensor.

**Returns:**

* **`bool`**: Can fuse

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1064)

### class `QuantizedSub`

Subtraction operator.

This works the same as addition on both encrypted - encrypted and on encrypted - constant.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L371)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Add operation can be computed in float and fused if it operates over inputs produced by a single integer tensor. For example the expression x + x \* 1.75, where x is an encrypted tensor, can be computed with a single TLU.

**Returns:**

* **`bool`**: Whether the number of integer input tensors allows computing this op as a TLU

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L285)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1074)

### class `QuantizedBatchNormalization`

Quantized Batch normalization with encrypted input and in-the-clear normalization params.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1080)

### class `QuantizedFlatten`

Quantized flatten for encrypted inputs.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1124)

#### method `can_fuse`

```python
can_fuse() → bool
```

Determine if this op can be fused.

Flatten operation can not be fused since it must be performed over integer tensors.

**Returns:**

* **`bool`**: False, this operation can not be fused as it is manipulates integer tensors.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1086)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

Flatten the input integer encrypted tensor.

**Args:**

* **`q_inputs`**: an encrypted integer tensor at index 0
* **`attrs`**: contains axis attribute

**Returns:**

* **`result`** (QuantizedArray): reshaped encrypted integer tensor

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1136)

### class `QuantizedReduceSum`

ReduceSum with encrypted input.

This operator is currently an experimental feature.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1147)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: Optional[QuantizationOptions] = None,
    **attrs
) → None
```

Construct the quantized ReduceSum operator and retrieve parameters.

**Args:**

* **`n_bits_output`** (int): Number of bits for the operator's quantization of outputs.
* **`int_input_names`** (Optional\[Set\[str]]): Names of input integer tensors. Default to None.
* **`constant_inputs`** (Optional\[Dict]): Input constant tensor.
* **`axes`** (Optional\[numpy.ndarray]): Array of integers along which to reduce. The default is to reduce over all the dimensions of the input tensor if 'noop\_with\_empty\_axes' is false, else act as an Identity op when 'noop\_with\_empty\_axes' is true. Accepted range is \[-r, r-1] where r = rank(data). Default to None.
* **`input_quant_opts`** (Optional\[QuantizationOptions]): Options for the input quantizer. Default to None.
* **`attrs`** (dict): RecuseSum options.
* **`keepdims`** (int): Keep the reduced dimension or not, 1 means keeping the input dimension, 0 will reduce it along the given axis. Default to 1.
* **`noop_with_empty_axes`** (int): Defines behavior if 'axes' is empty or set to None. Default behavior with 0 is to reduce all axes. When axes is empty and this attribute is set to true 1, input tensor will not be reduced, and the output tensor would be equivalent to input tensor. Default to 0.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1190)

#### method `calibrate`

```python
calibrate(*inputs: ndarray) → ndarray
```

Create corresponding QuantizedArray for the output of the activation function.

**Args:**

* **`*inputs (numpy.ndarray)`**: Calibration sample inputs.

**Returns:**

* **`numpy.ndarray`**: the output values for the provided calibration samples.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1359)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

Sum the encrypted tensor's values over axis 1.

**Args:**

* **`q_inputs`** (QuantizedArray): An encrypted integer tensor at index 0.
* **`attrs`** (Dict): Contains axis attribute.

**Returns:**

* **`(QuantizedArray)`**: The sum of all values along axis 1 as an encrypted integer tensor.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1231)

#### method `tree_sum`

```python
tree_sum(input_qarray, is_calibration=False)
```

Large sum without overflow (only MSB remains).

**Args:**

* **`input_qarray`**: Enctyped integer tensor.
* **`is_calibration`**: Whether we are calibrating the tree sum. If so, it will create all the quantizers for the downscaling.

**Returns:**

* **`(numpy.ndarray)`**: The MSB (based on the precision self.n\_bits) of the integers sum.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1417)

### class `QuantizedErf`

Quantized erf op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1423)

### class `QuantizedNot`

Quantized Not op.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1429)

### class `QuantizedBrevitasQuant`

Brevitas uniform quantization with encrypted input.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1434)

#### method `__init__`

```python
__init__(
    n_bits_output: int,
    int_input_names: Set[str] = None,
    constant_inputs: Optional[Dict[str, Any], Dict[int, Any]] = None,
    input_quant_opts: Optional[QuantizationOptions] = None,
    **attrs
) → None
```

Construct the Brevitas quantization operator.

**Args:**

* **`n_bits_output`** (int): Number of bits for the operator's quantization of outputs. Not used, will be overridden by the bit\_width in ONNX
* **`int_input_names`** (Optional\[Set\[str]]): Names of input integer tensors. Default to None.
* **`constant_inputs`** (Optional\[Dict]): Input constant tensor.
* **`scale`** (float): Quantizer scale
* **`zero_point`** (float): Quantizer zero-point
* **`bit_width`** (int): Number of bits of the integer representation
* **`input_quant_opts`** (Optional\[QuantizationOptions]): Options for the input quantizer. Default to None. attrs (dict):
* **`rounding_mode`** (str): Rounding mode (default and only accepted option is "ROUND")
* **`signed`** (int): Whether this op quantizes to signed integers (default 1),
* **`narrow`** (int): Whether this op quantizes to a narrow range of integers e.g. \[-2**n\_bits-1 .. 2**n\_bits-1] (default 0),

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1496)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

Quantize values.

**Args:**

* **`q_inputs`**: an encrypted integer tensor at index 0 and one constant shape at index 1
* **`attrs`**: additional optional reshape options

**Returns:**

* **`result`** (QuantizedArray): reshaped encrypted integer tensor

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1556)

### class `QuantizedTranspose`

Transpose operator for quantized inputs.

This operator performs quantization, transposes the encrypted data, then dequantizes again.

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/0.4.x/src/concrete/ml/quantization/quantized_ops.py#L1566)

#### method `q_impl`

```python
q_impl(*q_inputs: QuantizedArray, **attrs) → QuantizedArray
```

Reshape the input integer encrypted tensor.

**Args:**

* **`q_inputs`**: an encrypted integer tensor at index 0 and one constant shape at index 1
* **`attrs`**: additional optional reshape options

**Returns:**

* **`result`** (QuantizedArray): reshaped encrypted integer tensor


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/concrete-ml/0.4/developer-guide/api/concrete.ml.quantization.quantized_ops.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
