quantize.rst 6.79 KB
Newer Older
1
.. ops/quantize.rst:
2 3 4 5 6 7 8 9 10 11 12 13

########
Quantize
########

.. code-block:: cpp

   Quantize // Maps real input to quantized output

Description
===========

14 15 16 17 18
Produces a tensor of element type ``type`` and the same shape as ``input`` 
where the value of each coordinate :math:`i` of ``output`` is the corresponding coordinate of 
``input`` divided by ``scale`` rounded as specified by ``round_mode`` plus ``offset``.
The coordinate :math:`j` of ``scale`` and ``offset`` is the coordinate of ``output`` 
projected onto ``axes``.
19 20 21 22

Inputs
------

23 24 25 26 27 28 29 30 31
+-----------------+-------------------------+------------------------------------------+
| Name            | Element Type            | Shape                                    |
+=================+=========================+==========================================+
| ``input``       | Any real type           | Any                                      |
+-----------------+-------------------------+------------------------------------------+
| ``scale``       | Same as ``input``       | ``input`` shape projected onto ``axes``  |
+-----------------+-------------------------+------------------------------------------+
| ``offset``      | Same as ``output``      | ``input`` shape projected onto ``axes``  |
+-----------------+-------------------------+------------------------------------------+
32 33 34 35 36 37 38

Attributes
----------

+-------------------------------+----------------------------------------------------------------+
| Name                          | Description                                                    |
+===============================+================================================================+
39
| ``type``                      | ``output`` element type; any quantized type                    |
40 41 42
+-------------------------------+----------------------------------------------------------------+
| ``axes``                      | Axis positions on which ``scale`` and ``offset`` are specified |
+-------------------------------+----------------------------------------------------------------+
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 82 83
| ``round_mode``                | *ROUND_NEAREST_TOWARD_INFINITY:*                               |
|                               | round to nearest integer                                       |
|                               | in case of two equidistant integers round away from zero e.g.  |
|                               | 2.5 -> 3                                                       |
|                               | -3.5 -> -4                                                     |
|                               |                                                                |
|                               | *ROUND_NEAREST_TOWARD_ZERO:*                                   |
|                               | round to nearest integer                                       |
|                               | in case of two equidistant integers round toward zero e.g.     |
|                               | 2.5 -> 2                                                       |
|                               | -3.5 to -3                                                     |
|                               |                                                                |
|                               | *ROUND_NEAREST_UPWARD:*                                        |
|                               | round to nearest integer                                       |
|                               | in case of two equidistant integers round up e.g.              |
|                               | 2.5 to 3                                                       |
|                               | -3.5 to -3                                                     |
|                               |                                                                |
|                               | *ROUND_NEAREST_DOWNWARD:*                                      |
|                               | round to nearest integer                                       |
|                               | in case of two equidistant integers round down e.g.            |
|                               | 2.5 to 2                                                       |
|                               | -3.5 to -4                                                     |
|                               |                                                                |
|                               | *ROUND_NEAREST_TOWARD_EVEN:*                                   |
|                               | round to nearest integer                                       |
|                               | in case of two equidistant integers round to even e.g.         |
|                               | 2.5 to 2                                                       |
|                               | -3.5 to -4                                                     |
|                               |                                                                |
|                               | *ROUND_TOWARD_INFINITY:*                                       |
|                               | round to nearest integer away from zero                        |
|                               |                                                                |
|                               | *ROUND_TOWARD_ZERO:*                                           |
|                               | round to nearest integer toward zero                           |
|                               |                                                                |
|                               | *ROUND_UP:*                                                    |
|                               | round to nearest integer toward infinity (ceiling)             |
|                               |                                                                |
|                               | *ROUND_DOWN:*                                                  |
|                               | round to nearest integer toward negative infinity (floor)      |
84 85 86 87 88 89 90 91
+-------------------------------+----------------------------------------------------------------+

Outputs
-------

+-----------------+-------------------------+---------------------------------------+
| Name            | Element Type            | Shape                                 |
+=================+=========================+=======================================+
92
| ``output``      | ``type``                | Same as ``input``                     |
93 94 95 96 97 98 99
+-----------------+-------------------------+---------------------------------------+

Mathematical Definition
=======================

.. math::
  
100
   \mathtt{output}_{i,j} = \mathtt{round}\left(\frac{\mathtt{input}_{i,j}}{\mathtt{scale}_{j}}\right) + \mathtt{offset}_{j}    
101 102 103 104 105 106 107

C++ Interface
=============

.. doxygenclass:: ngraph::op::Quantize
   :project: ngraph
   :members: