Skip to main content

Bf16

Struct Bf16 

Source
pub struct Bf16(pub bf16);
Expand description

A bfloat16 scalar in tenferro’s scalar contract.

The representation is bf16, and the wrapper carries no extra state.

§Examples

use tenferro_bf16_proof::Bf16;

let value = Bf16::from_f32(1.5);
assert_eq!(value.to_f32(), 1.5);
assert_eq!(value.narrow(), half::bf16::from_f32(1.5));

Tuple Fields§

§0: bf16

Implementations§

Source§

impl Bf16

Source

pub const fn of(value: bf16) -> Self

Wrap a bfloat16 value.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!(Bf16::of(half::bf16::from_f32(2.0)).to_f32(), 2.0);
Source

pub const fn narrow(self) -> bf16

The stored bfloat16 value.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!(Bf16::from_f32(1.0).narrow(), half::bf16::from_f32(1.0));
Source

pub fn from_f64(value: f64) -> Self

Round an f64 to bfloat16, which is the only way a stored value is produced.

§Examples
use tenferro_bf16_proof::Bf16;

// The spacing of bfloat16 on [1, 2) is 2^-8, so 1.001 is nearer to 1.0 than to the next
// representable value above it.
let stored = Bf16::from_f64(1.001);
assert_eq!(stored.to_f32(), 1.0);
Source

pub fn from_f32(value: f32) -> Self

Round an f32 to bfloat16.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!(Bf16::from_f32(0.5).to_f32(), 0.5);
Source

pub fn to_f32(self) -> f32

Widen the stored value to f32, which is exact.

§Examples
use tenferro_bf16_proof::Bf16;

let stored = Bf16::from_f64(1.0 + 2f64.powi(-10));
assert_eq!(stored.to_f32(), 1.0);
Source

pub fn to_f64(self) -> f64

Widen the stored value to f64, which is exact.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!(Bf16::from_f32(2.5).to_f64(), 2.5);
Source

pub const fn zero() -> Self

Additive identity.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!(Bf16::zero().to_f32(), 0.0);
Source

pub fn one() -> Self

Multiplicative identity.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!(Bf16::one().to_f32(), 1.0);

Trait Implementations§

Source§

impl Add for Bf16

Source§

fn add(self, rhs: Self) -> Self

Add in f32 and round the sum once.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!((Bf16::from_f32(1.0) + Bf16::from_f32(2.0)).to_f32(), 3.0);
Source§

type Output = Bf16

The resulting type after applying the + operator.
Source§

impl BinaryScalarOp<Bf16> for Bf16Add

Source§

fn apply(lhs: Bf16, rhs: Bf16) -> Bf16

Apply the operation. Read more
Source§

impl BinaryScalarOp<Bf16> for Bf16Sub

Source§

fn apply(lhs: Bf16, rhs: Bf16) -> Bf16

Apply the operation. Read more
Source§

impl BinaryScalarOp<Bf16> for Bf16Mul

Source§

fn apply(lhs: Bf16, rhs: Bf16) -> Bf16

Apply the operation. Read more
Source§

impl Clone for Bf16

Source§

fn clone(&self) -> Bf16

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Bf16

Source§

impl Debug for Bf16

Source§

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

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

impl Default for Bf16

Source§

fn default() -> Bf16

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

impl Mul for Bf16

Source§

fn mul(self, rhs: Self) -> Self

Multiply in f32 and round the product once.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!((Bf16::from_f32(3.0) * Bf16::from_f32(4.0)).to_f32(), 12.0);
Source§

type Output = Bf16

The resulting type after applying the * operator.
Source§

impl Neg for Bf16

Source§

fn neg(self) -> Self

Negate, which flips the sign bit and needs no rounding.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!((-Bf16::from_f32(2.0)).to_f32(), -2.0);
Source§

type Output = Bf16

The resulting type after applying the - operator.
Source§

impl PartialEq for Bf16

Source§

fn eq(&self, other: &Bf16) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Scalar for Bf16

Source§

const DOMAIN: ScalarDomain = tenferro_tensor_core::ScalarDomain::Field

Algebra of this scalar’s ordinary arithmetic.
Source§

impl ScalarArithmetic for Bf16

Source§

fn scalar_zero() -> Self

Additive identity. Read more
Source§

fn scalar_one() -> Self

Multiplicative identity. Read more
Source§

fn scalar_add(self, rhs: Self) -> Self

Sum under this scalar’s own semantics. Read more
Source§

fn scalar_sub(self, rhs: Self) -> Self

Difference under this scalar’s own semantics. Read more
Source§

fn scalar_mul(self, rhs: Self) -> Self

Product under this scalar’s own semantics. Read more
Source§

impl StructuralPartialEq for Bf16

Source§

impl Sub for Bf16

Source§

fn sub(self, rhs: Self) -> Self

Subtract in f32 and round the difference once.

§Examples
use tenferro_bf16_proof::Bf16;

assert_eq!((Bf16::from_f32(3.0) - Bf16::from_f32(2.0)).to_f32(), 1.0);
Source§

type Output = Bf16

The resulting type after applying the - operator.

Auto Trait Implementations§

§

impl Freeze for Bf16

§

impl RefUnwindSafe for Bf16

§

impl Send for Bf16

§

impl Sync for Bf16

§

impl Unpin for Bf16

§

impl UnsafeUnpin for Bf16

§

impl UnwindSafe for Bf16

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
§

impl<T> Boilerplate for T
where T: Copy + Send + Sync + Debug + PartialEq + 'static,

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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.