Skip to main content

RationalVector

Struct RationalVector 

Source
pub struct RationalVector<const D: usize> { /* private fields */ }
Available on crate feature exact only.
Expand description

Exact rational vector with compile-time dimension D.

Construction validates that every denominator is non-zero and canonicalizes every entry to lowest terms with a positive denominator. Solutions returned by RationalMatrix::solve and crate::Matrix::solve_exact also use this type, making any later conversion to Vector explicit through ExactF64Conversion. Use try_to_f64 when every component must remain exact, or to_rounded_f64 to opt into round-to-nearest, ties-to-even. Both conversions reject results that cannot be rounded to finite binary64 values.

Implementations§

Source§

impl<const D: usize> RationalVector<D>

Source

pub fn try_new(data: [BigRational; D]) -> Result<Self, LaError>

Try to create an exact vector from rational storage.

Raw, non-reduced values and negative denominators are accepted and stored canonically. A raw zero denominator is rejected.

§Examples
use la_stack::prelude::*;

let rhs = RationalVector::<2>::try_new([
    BigRational::new(1.into(), 2.into()),
    BigRational::from_integer(3.into()),
])?;
assert_eq!(rhs.try_to_f64()?.into_array(), [0.5, 3.0]);
§Errors

Returns LaError::NonFinite at the first vector entry whose raw rational denominator is zero.

Source

pub fn try_from_fn( make_entry: impl FnMut(usize) -> BigRational, ) -> Result<Self, LaError>

Try to create an exact vector by evaluating a function at every index.

The function is evaluated once per entry in increasing index order. All entries are generated before validation and canonicalization, as in try_new.

§Examples
use la_stack::prelude::*;

let numerators = [1, 2, 3];
let rhs = RationalVector::<3>::try_from_fn(|index| {
    BigRational::new(numerators[index].into(), 2.into())
})?;
assert_eq!(rhs.try_to_f64()?.into_array(), [0.5, 1.0, 1.5]);
§Errors

Returns LaError::NonFinite at the first generated entry whose raw rational denominator is zero.

Source

pub fn zero() -> Self

Return the all-zero exact vector.

Source

pub const fn as_array(&self) -> &[BigRational; D]

Borrow the exact backing array.

Source

pub fn into_array(self) -> [BigRational; D]

Consume the vector and return its exact backing array.

Source

pub fn get(&self, index: usize) -> Option<&BigRational>

Borrow one entry, returning None for an out-of-bounds index.

Trait Implementations§

Source§

impl<const D: usize> Clone for RationalVector<D>

Source§

fn clone(&self) -> RationalVector<D>

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<const D: usize> Debug for RationalVector<D>

Source§

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

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

impl<const D: usize> Eq for RationalVector<D>

Source§

impl<const D: usize> ExactF64Conversion for RationalVector<D>

Source§

type Output = Vector<D>

Finite binary64 output produced by the conversion.
Source§

fn try_to_f64(&self) -> Result<Self::Output, LaError>

Convert only when every exact value already has an exact finite binary64 representation. Read more
Source§

fn to_rounded_f64(&self) -> Result<Self::Output, LaError>

Round the exact value to finite binary64 output. Read more
Source§

impl<const D: usize> PartialEq for RationalVector<D>

Source§

fn eq(&self, other: &RationalVector<D>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<const D: usize> StructuralPartialEq for RationalVector<D>

Auto Trait Implementations§

§

impl<const D: usize> Freeze for RationalVector<D>
where [Ratio<BigInt>; D]: Freeze,

§

impl<const D: usize> RefUnwindSafe for RationalVector<D>

§

impl<const D: usize> Send for RationalVector<D>
where [Ratio<BigInt>; D]: Send,

§

impl<const D: usize> Sync for RationalVector<D>
where [Ratio<BigInt>; D]: Sync,

§

impl<const D: usize> Unpin for RationalVector<D>
where [Ratio<BigInt>; D]: Unpin,

§

impl<const D: usize> UnsafeUnpin for RationalVector<D>

§

impl<const D: usize> UnwindSafe for RationalVector<D>
where [Ratio<BigInt>; D]: 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.