# Crate caffe2op_lengthsreduce

## Structs

• | A templated class that implements | SparseLengths[Sum,WeightedSum,Mean]. | | typename T, // output type | class InputTypes, // supported input types, such as TensorTypes | bool USE_WEIGHT = false, // Whether it is SparseLengthsWeightedSum | bool USE_MEAN = false, // Whether this is SparseLengthsMean | bool USE_POSITIONAL_WEIGHT = false | // USE_WEIGHT = true and USE_POSITIONAL_WEIGHT = true | // -> SparseLengthsPositionalWeightedSum
• | This operator applies 8Bit row-wise | quantization to input tensor and returns | quantized tensor. | | Row wise quantization of input tensor | is the following process. | | We take tensor of size | | (m_1, m_2,…,m_n), n >= 2, reshape | it into matrix of size | | (m_1, m_2 x… x m_n) and apply row-wise | quantization. | | After this, we compute scale_i= (min_i | - max_i) / 255 and bias_i = min_i for i-th | row r_i of reshaped matrix, where min_i | and max_i – minimum and maximum elements | of i-th row, and quantize each element | r_{ij} as 0 <= round(r_ij - bias_i) / | scale_i) < 256. | | Instead of input tensor we obtain uint8 | tensor and auxiliary information as | scale and bias to restore input tensor | (with losses). |
• | Given uint8 tensor, quantized using | 8bit row-wise quantization, and auxiliary | scales and biases, this operator restores | float tensor in the following way. | | We take input 8bits tensor of size | | (m_1, m_2, …, m_n), n >= 2, reshape | it into matrix of size | | (m_1, m_2 x… x m_n). | | We compute element r_{ij} of output | matrix as | | r_{ij} * s_i + b_i | | and after this we reshape this output | matrix into output tensor of size | | (m_1, m_2, …, m_n). |

## Enums

• |note there is something weird here because we |may or may not have a Weights input therefore |check how we use Input(N) where N is integer for |correct usage (see c++ if this is confusing)
• |there is weirdness with MaybeWeights it is |possible Data is 0, MaybeWeights is 1, Indices |is 2, etc or it is possible Data is 0, Indices |is 1, etc check the c++ code
• | static_assert( !(with_weights && | is_mean), “Cannot have with_weights | and is_mean a the same time”); |
• |note there is something weird here because we |may or may not have a Weights input therefore |check how we use Input(N) where N is integer for |correct usage (see c++ if this is confusing)
• |note there is something weird here because we |may or may not have a Weights input therefore |check how we use Input(N) where N is integer for |correct usage (see c++ if this is confusing)
• |note there is something weird here because we |may or may not have a Weights input therefore |check how we use Input(N) where N is integer for |correct usage (see c++ if this is confusing)