Vector

Struct Vector 

Source
pub struct Vector<T> {
    pub vec: Vec<T>,
    pub norm: Option<T>,
}
Expand description

Generic n-vectors used to represent a basis

§Examples

use svp::{Vector, nvec};

// Build an integer vector
let u = Vector{ vec: vec![0i64; 3], norm: None};
let v = Vector{ vec: vec![0, 1, 0], norm: None};

// Shorthand notation
let u = nvec![0i64; 3];
let v = nvec![0, 1, 0];

Vector multiplication corresponds to the scalar product

use svp::{Vector, nvec};

let u = nvec![1, 0, 0];
let v = nvec![0, 1, 0];

assert_eq!(&u * &v, 0);

It can be useful to keep track of the squared norm

use svp::{Vector, nvec};

// Build an integer vector
let mut u = nvec![1, 0, 0];

// Compute the squared norm (inner product)
u.norm = Some(&u * &u);

assert_eq!(u.norm.unwrap(), 1);

As a special case, big integers can be used for arbitrary precision

use rug::Integer;
use svp::{Vector, nvec};

// Big Integers with gmp
let p = "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f";
let u = nvec![Integer::from_str_radix(p, 16).unwrap(); 3];

let v = nvec![Integer::new(), Integer::from(1), Integer::new()];
assert_eq!(&v * &v, Integer::from(1));

Fields§

§vec: Vec<T>§norm: Option<T>

Trait Implementations§

Source§

impl<T: Clone> Clone for Vector<T>

Source§

fn clone(&self) -> Vector<T>

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<T: Debug> Debug for Vector<T>

Source§

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

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

impl GaussReduce<Integer> for Vector<Integer>

Source§

fn reduce(&mut self, v: &Vector<Integer>) -> bool

GaussReduce with respect to v

Source§

impl GaussReduce<i64> for Vector<i64>

Source§

fn reduce(&mut self, v: &Vector<i64>) -> bool

GaussReduce with respect to v

Source§

impl Mul<&Vector<Float>> for &Lattice<Integer>

Right multiply basis matrix by a vector with arbitrary precision

Source§

type Output = Vector<Integer>

The resulting vector type of the matrix product

Source§

fn mul(self, _rhs: &Vector<Float>) -> Vector<Integer>

Compute the matrix product with v

Source§

impl Mul<&Vector<Float>> for &Vector<Integer>

Source§

type Output = Float

The resulting scalar type of the inner product

Source§

fn mul(self, _rhs: &Vector<Float>) -> Float

Compute the inner product of two arbitrary precision n-vectors

Source§

impl Mul<&Vector<Integer>> for &Lattice<Integer>

Right multiply basis matrix by a vector with arbitrary precision

Source§

type Output = Vector<Integer>

The resulting vector type of the matrix product

Source§

fn mul(self, _rhs: &Vector<Integer>) -> Vector<Integer>

Compute the matrix product with v

Source§

impl Mul<&Vector<f64>> for &Lattice<i64>

Right multiply basis matrix by a vector

Source§

type Output = Vector<i64>

The resulting vector type of the matrix product

Source§

fn mul(self, _rhs: &Vector<f64>) -> Vector<i64>

Compute the matrix product with v

Source§

impl Mul<&Vector<f64>> for &Vector<i64>

Source§

type Output = f64

The resulting scalar type of the inner product

Source§

fn mul(self, _rhs: &Vector<f64>) -> f64

Compute the (truncated) inner product of two n-vectors

Source§

impl Mul<&Vector<i64>> for &Lattice<i64>

Right multiply basis matrix by a vector

Source§

type Output = Vector<i64>

The resulting vector type of the matrix product

Source§

fn mul(self, _rhs: &Vector<i64>) -> Vector<i64>

Compute the matrix product with v

Source§

impl Mul for &Vector<Float>

Source§

type Output = Float

The resulting scalar type of the inner product

Source§

fn mul(self, _rhs: &Vector<Float>) -> Float

Compute the inner product of two arbitrary precision n-vectors

Source§

impl Mul for &Vector<Integer>

Source§

type Output = Integer

The resulting scalar type of the inner product

Source§

fn mul(self, _rhs: &Vector<Integer>) -> Integer

Compute the inner product of two arbitrary precision n-vectors

Source§

impl Mul for &Vector<f64>

Source§

type Output = f64

The resulting scalar type of the inner product

Source§

fn mul(self, _rhs: &Vector<f64>) -> f64

Compute the inner product of two n-vectors

Source§

impl Mul for &Vector<i64>

Source§

type Output = i64

The resulting scalar type of the inner product

Source§

fn mul(self, _rhs: &Vector<i64>) -> i64

Compute the inner product of two n-vectors

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for Vector<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector<T>
where T: 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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.