Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- using BitPacking;
- namespace Edgy
- {
- public class FloatQuantizer
- {
- public float Delta
- {
- get => this.delta;
- }
- public float MaxIntegerValue
- {
- get => this.maxIntegerValue;
- }
- public int BitsRequired
- {
- get => this.bitsRequired;
- }
- private float min;
- private float max;
- private float resolution;
- private bool checkBounds;
- private float delta;
- private int maxIntegerValue;
- private int bitsRequired;
- public FloatQuantizer(float min, float max, float resolution, bool checkBounds = false)
- {
- this.min = min;
- this.max = max;
- this.resolution = resolution;
- this.checkBounds = checkBounds;
- BitsHelper.CalculateDataForQuantizing(this.min, this.max, this.resolution, out this.delta, out this.maxIntegerValue, out this.bitsRequired);
- }
- public float DequantizeUIntValue(uint value)
- {
- return (value / this.MaxIntegerValue * this.Delta + this.min);
- }
- public void Read(IBitReaderStream bitReaderStream, out float value)
- {
- value = this.DequantizeUIntValue(bitReaderStream.ReadBits(this.BitsRequired));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement