Advertisement
Guest User

Untitled

a guest
Mar 1st, 2020
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using BitPacking;
  8.  
  9. namespace Edgy
  10. {
  11.  
  12.     public class FloatQuantizer
  13.     {
  14.  
  15.         public float Delta
  16.         {
  17.             get => this.delta;
  18.         }
  19.  
  20.         public float MaxIntegerValue
  21.         {
  22.             get => this.maxIntegerValue;
  23.         }
  24.  
  25.         public int BitsRequired
  26.         {
  27.             get => this.bitsRequired;
  28.         }
  29.  
  30.         private float min;
  31.         private float max;
  32.         private float resolution;
  33.         private bool checkBounds;
  34.  
  35.         private float delta;
  36.         private int maxIntegerValue;
  37.         private int bitsRequired;
  38.  
  39.         public FloatQuantizer(float min, float max, float resolution, bool checkBounds = false)
  40.         {
  41.             this.min = min;
  42.             this.max = max;
  43.             this.resolution = resolution;
  44.             this.checkBounds = checkBounds;
  45.  
  46.             BitsHelper.CalculateDataForQuantizing(this.min, this.max, this.resolution, out this.delta, out this.maxIntegerValue, out this.bitsRequired);
  47.         }
  48.  
  49.         public float DequantizeUIntValue(uint value)
  50.         {
  51.             return (value / this.MaxIntegerValue * this.Delta + this.min);
  52.         }
  53.  
  54.         public void Read(IBitReaderStream bitReaderStream, out float value)
  55.         {
  56.             value = this.DequantizeUIntValue(bitReaderStream.ReadBits(this.BitsRequired));
  57.         }
  58.  
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement