pub struct Quantity<T, U>(/* private fields */);
Expand description
Physical quantity with compile-time checked unit.
Implementations§
Source§impl<T: Copy, U> Quantity<Array1<T>, U>
impl<T: Copy, U> Quantity<Array1<T>, U>
Sourcepub fn from_vec(v: Vec<Quantity<T, U>>) -> Self
pub fn from_vec(v: Vec<Quantity<T, U>>) -> Self
Create a one-dimensional array from a vector of scalar quantities.
Sourcepub fn linspace(start: Quantity<T, U>, end: Quantity<T, U>, n: usize) -> Self
pub fn linspace(start: Quantity<T, U>, end: Quantity<T, U>, n: usize) -> Self
Create a one-dimensional array with n evenly spaced elements from start
to end
(inclusive).
§Example
let x = Length::linspace(1.0 * METER, 3.0 * METER, 5);
assert_relative_eq!(x, &(arr1(&[1.0, 1.5, 2.0, 2.5, 3.0]) * METER));
Source§impl<U> Quantity<Array1<f64>, U>
impl<U> Quantity<Array1<f64>, U>
Sourcepub fn logspace(
start: Quantity<f64, U>,
end: Quantity<f64, U>,
n: usize,
) -> Self
pub fn logspace( start: Quantity<f64, U>, end: Quantity<f64, U>, n: usize, ) -> Self
Create a one-dimensional array with n logarithmically spaced elements from start
to end
(inclusive).
§Example
let x = Length::logspace(1.0 * METER, 16.0 * METER, 5);
assert_relative_eq!(x, &(arr1(&[1.0, 2.0, 4.0, 8.0, 16.0]) * METER));
Source§impl<T, U, D: Dimension> Quantity<Array<T, D>, U>
impl<T, U, D: Dimension> Quantity<Array<T, D>, U>
Sourcepub fn zeros<Sh: ShapeBuilder<Dim = D>>(shape: Sh) -> Self
pub fn zeros<Sh: ShapeBuilder<Dim = D>>(shape: Sh) -> Self
Create an array with all elements set to 0.
Sourcepub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
pub fn from_shape_fn<Sh, F>(shape: Sh, f: F) -> Self
Create an array with values created by the function f.
Source§impl<T, S: Data<Elem = T>, U, D: Dimension> Quantity<ArrayBase<S, D>, U>
impl<T, S: Data<Elem = T>, U, D: Dimension> Quantity<ArrayBase<S, D>, U>
Sourcepub fn sum(&self) -> Quantity<T, U>
pub fn sum(&self) -> Quantity<T, U>
Return the sum of all elements in the array.
§Example
let x = arr1(&[1.5, 2.5]) * BAR;
assert_relative_eq!(x.sum(), &(4.0 * BAR));
Sourcepub fn to_owned(&self) -> Quantity<Array<T, D>, U>where
T: Clone,
pub fn to_owned(&self) -> Quantity<Array<T, D>, U>where
T: Clone,
Return an uniquely owned copy of the array.
Sourcepub fn mapv<F, T2, U2>(&self, f: F) -> Quantity<Array<T2, D>, U2>
pub fn mapv<F, T2, U2>(&self, f: F) -> Quantity<Array<T2, D>, U2>
Call f by value on each element and create a new array with the new values.
Sourcepub fn index_axis(
&self,
axis: Axis,
index: usize,
) -> Quantity<ArrayView<'_, T, D::Smaller>, U>where
D: RemoveAxis,
pub fn index_axis(
&self,
axis: Axis,
index: usize,
) -> Quantity<ArrayView<'_, T, D::Smaller>, U>where
D: RemoveAxis,
Returns a view restricted to index along the axis, with the axis removed.
Sourcepub fn lanes_mut(&mut self, axis: Axis) -> LanesMut<'_, T, D::Smaller>where
S: DataMut,
pub fn lanes_mut(&mut self, axis: Axis) -> LanesMut<'_, T, D::Smaller>where
S: DataMut,
Return a producer and iterable that traverses over all 1D lanes pointing in the direction of axis.
Sourcepub fn insert_axis(self, axis: Axis) -> Quantity<ArrayBase<S, D::Larger>, U>
pub fn insert_axis(self, axis: Axis) -> Quantity<ArrayBase<S, D::Larger>, U>
Insert new array axis at axis and return the result.
Source§impl<U> Quantity<f64, U>
impl<U> Quantity<f64, U>
Sourcepub fn powi<E: Integer>(self) -> Quantity<f64, Prod<U, E>>where
U: Mul<E>,
pub fn powi<E: Integer>(self) -> Quantity<f64, Prod<U, E>>where
U: Mul<E>,
Calculate the integer power of self.
§Example
let x = 3.0 * METER;
assert_relative_eq!(x.powi::<P2>(), 9.0 * METER * METER);
Sourcepub fn sqrt(self) -> Quantity<f64, Quot<U, P2>>
pub fn sqrt(self) -> Quantity<f64, Quot<U, P2>>
Calculate the square root of self.
§Example
let x = 9.0 * METER * METER;
assert_relative_eq!(x.sqrt(), 3.0 * METER);
Source§impl<T, U> Quantity<T, U>
impl<T, U> Quantity<T, U>
Source§impl<U> Quantity<f64, U>
impl<U> Quantity<f64, U>
Sourcepub fn signum(self) -> f64
pub fn signum(self) -> f64
Returns a number that represents the sign of self
.
1.0
if the number is positive,+0.0
orINFINITY
-1.0
if the number is negative,-0.0
orNEG_INFINITY
NAN
if the number isNAN
Sourcepub fn is_sign_negative(&self) -> bool
pub fn is_sign_negative(&self) -> bool
Returns true
if self
has a negative sign, including -0.0
, NaN
s with
negative sign bit and negative infinity.
Sourcepub fn is_sign_positive(&self) -> bool
pub fn is_sign_positive(&self) -> bool
Returns true
if self
has a positive sign, including +0.0
, NaN
s with
positive sign bit and positive infinity.
Source§impl<T> Quantity<T, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, ATerm>>>>>>>>
impl<T> Quantity<T, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, TArr<Z0, ATerm>>>>>>>>
Sourcepub fn into_value(self) -> T
pub fn into_value(self) -> T
Return the value of a dimensionless quantity.
Source§impl<T, U> Quantity<T, U>
impl<T, U> Quantity<T, U>
pub fn new(value: T) -> Self
Sourcepub fn convert_to<T2>(&self, unit: Quantity<T2, U>) -> Quot<&T, T2>
pub fn convert_to<T2>(&self, unit: Quantity<T2, U>) -> Quot<&T, T2>
Convert a quantity into the given unit and return it as a float or array.
Sourcepub fn convert_into<T2>(self, unit: Quantity<T2, U>) -> Quot<T, T2>where
T: Div<T2>,
pub fn convert_into<T2>(self, unit: Quantity<T2, U>) -> Quot<T, T2>where
T: Div<T2>,
Convert a quantity into the given unit and return it as a float or array.
Trait Implementations§
Source§impl<T: AbsDiffEq, U> AbsDiffEq for Quantity<T, U>
impl<T: AbsDiffEq, U> AbsDiffEq for Quantity<T, U>
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.Source§impl<'a, T1, T2, U> AddAssign<&'a Quantity<T2, U>> for Quantity<T1, U>
impl<'a, T1, T2, U> AddAssign<&'a Quantity<T2, U>> for Quantity<T1, U>
Source§fn add_assign(&mut self, rhs: &'a Quantity<T2, U>)
fn add_assign(&mut self, rhs: &'a Quantity<T2, U>)
+=
operation. Read moreSource§impl<T1, T2, U> AddAssign<Quantity<T2, U>> for Quantity<T1, U>where
T1: AddAssign<T2>,
impl<T1, T2, U> AddAssign<Quantity<T2, U>> for Quantity<T1, U>where
T1: AddAssign<T2>,
Source§fn add_assign(&mut self, rhs: Quantity<T2, U>)
fn add_assign(&mut self, rhs: Quantity<T2, U>)
+=
operation. Read moreSource§impl<Inner: Debug, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer> Debug for Quantity<Inner, SIUnit<T, L, M, I, THETA, N, J>>
impl<Inner: Debug, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer> Debug for Quantity<Inner, SIUnit<T, L, M, I, THETA, N, J>>
Source§impl<U: Neg, S: DataOwned<Elem = f64> + DataMut, D: Dimension> Div<Quantity<f64, U>> for ArrayBase<S, D>
impl<U: Neg, S: DataOwned<Elem = f64> + DataMut, D: Dimension> Div<Quantity<f64, U>> for ArrayBase<S, D>
Source§impl<U, T1, T2> DivAssign<T2> for Quantity<T1, U>where
T1: DivAssign<T2>,
impl<U, T1, T2> DivAssign<T2> for Quantity<T1, U>where
T1: DivAssign<T2>,
Source§fn div_assign(&mut self, other: T2)
fn div_assign(&mut self, other: T2)
/=
operation. Read moreSource§impl<D, F, T: DualStruct<D, F>, U> DualStruct<D, F> for Quantity<T, U>
impl<D, F, T: DualStruct<D, F>, U> DualStruct<D, F> for Quantity<T, U>
Source§impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer, D: Dimension> FromPyObject<'py> for Quantity<Array<f64, D>, SIUnit<T, L, M, I, THETA, N, J>>where
Self: PrintUnit,
impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer, D: Dimension> FromPyObject<'py> for Quantity<Array<f64, D>, SIUnit<T, L, M, I, THETA, N, J>>where
Self: PrintUnit,
Source§impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer> FromPyObject<'py> for Quantity<f64, SIUnit<T, L, M, I, THETA, N, J>>where
Self: PrintUnit,
impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer> FromPyObject<'py> for Quantity<f64, SIUnit<T, L, M, I, THETA, N, J>>where
Self: PrintUnit,
Source§impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer, D: Dimension> IntoPyObject<'py> for Quantity<Array<f64, D>, SIUnit<T, L, M, I, THETA, N, J>>
impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer, D: Dimension> IntoPyObject<'py> for Quantity<Array<f64, D>, SIUnit<T, L, M, I, THETA, N, J>>
Source§impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer> IntoPyObject<'py> for Quantity<f64, SIUnit<T, L, M, I, THETA, N, J>>
impl<'py, T: Integer, L: Integer, M: Integer, I: Integer, THETA: Integer, N: Integer, J: Integer> IntoPyObject<'py> for Quantity<f64, SIUnit<T, L, M, I, THETA, N, J>>
Source§impl<U, S: DataOwned<Elem = f64> + DataMut, D: Dimension> Mul<Quantity<f64, U>> for ArrayBase<S, D>
impl<U, S: DataOwned<Elem = f64> + DataMut, D: Dimension> Mul<Quantity<f64, U>> for ArrayBase<S, D>
Source§impl<U, T1, T2> MulAssign<T2> for Quantity<T1, U>where
T1: MulAssign<T2>,
impl<U, T1, T2> MulAssign<T2> for Quantity<T1, U>where
T1: MulAssign<T2>,
Source§fn mul_assign(&mut self, other: T2)
fn mul_assign(&mut self, other: T2)
*=
operation. Read moreSource§impl<T: PartialOrd, U> PartialOrd for Quantity<T, U>
impl<T: PartialOrd, U> PartialOrd for Quantity<T, U>
Source§impl<T: RelativeEq, U> RelativeEq for Quantity<T, U>
impl<T: RelativeEq, U> RelativeEq for Quantity<T, U>
Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
Source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq
.Source§impl<'a, T1, T2, U> SubAssign<&'a Quantity<T2, U>> for Quantity<T1, U>
impl<'a, T1, T2, U> SubAssign<&'a Quantity<T2, U>> for Quantity<T1, U>
Source§fn sub_assign(&mut self, rhs: &'a Quantity<T2, U>)
fn sub_assign(&mut self, rhs: &'a Quantity<T2, U>)
-=
operation. Read moreSource§impl<T1, T2, U> SubAssign<Quantity<T2, U>> for Quantity<T1, U>where
T1: SubAssign<T2>,
impl<T1, T2, U> SubAssign<Quantity<T2, U>> for Quantity<T1, U>where
T1: SubAssign<T2>,
Source§fn sub_assign(&mut self, rhs: Quantity<T2, U>)
fn sub_assign(&mut self, rhs: Quantity<T2, U>)
-=
operation. Read moreimpl<T: Copy, U: Copy> Copy for Quantity<T, U>
Auto Trait Implementations§
impl<T, U> Freeze for Quantity<T, U>where
T: Freeze,
impl<T, U> RefUnwindSafe for Quantity<T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for Quantity<T, U>
impl<T, U> Sync for Quantity<T, U>
impl<T, U> Unpin for Quantity<T, U>
impl<T, U> UnwindSafe for Quantity<T, U>where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
Source§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self
into an owned Python object, dropping type information.Source§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.