Quantized

Struct Quantized 

Source
pub struct Quantized<Q: Quantize>(/* private fields */);
Expand description

Contains a quantized value.

use numquant::{Quantized, IntRange};
let q = Quantized::<IntRange<u8, 0xff, 0, 1000>>::from_f64(500.0);
let v = q.to_f64();
approx::assert_abs_diff_eq!(v, 500.0, epsilon = 2.0);

Implementations§

Source§

impl<Q: Quantize> Quantized<Q>
where Q::Type: Into<f64>,

Source

pub fn set(&mut self, value: f64)

Source§

impl<Q: Quantize> Quantized<Q>
where Q::Type: Into<f64> + Copy,

Source

pub fn from_raw(v: Q::Type) -> Self

Source

pub fn raw(&self) -> Q::Type

Source

pub fn from_f64(v: f64) -> Self
where Self: Sized,

Create an instance from an f64.

Source

pub fn to_f64(&self) -> f64

Dequantize the stored value into an f64.

Source

pub fn from_f32(v: f32) -> Self
where Self: Sized,

Create an instance from an f32.

Source

pub fn to_f32(&self) -> f32

Dequantize the stored value into an f32.

Trait Implementations§

Source§

impl<Q: Quantize> Clone for Quantized<Q>
where Q::Type: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Q: Quantize> Debug for Quantized<Q>
where Q::Type: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Q: Quantize> Default for Quantized<Q>
where Q::Type: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Q> Freeze for Quantized<Q>
where <Q as Quantize>::Type: Freeze,

§

impl<Q> RefUnwindSafe for Quantized<Q>

§

impl<Q> Send for Quantized<Q>
where <Q as Quantize>::Type: Send, Q: Send,

§

impl<Q> Sync for Quantized<Q>
where <Q as Quantize>::Type: Sync, Q: Sync,

§

impl<Q> Unpin for Quantized<Q>
where <Q as Quantize>::Type: Unpin, Q: Unpin,

§

impl<Q> UnwindSafe for Quantized<Q>
where <Q as Quantize>::Type: UnwindSafe, Q: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.