rust_poly/poly/
indexing.rs

1use super::{Complex, Poly, RealScalar};
2
3impl<T: RealScalar> Poly<T> {
4    /// Index from the end, useful for porting algorithm that use the descending convention
5    pub(crate) fn coeffs_descending(&self, idx: usize) -> &Complex<T> {
6        &self.0[self.len_raw() - idx - 1]
7    }
8
9    pub(crate) fn coeffs_descending_mut(&mut self, idx: usize) -> &mut Complex<T> {
10        let n = self.len_raw();
11        &mut self.0[n - idx - 1]
12    }
13}
14
15impl<T: RealScalar> Poly<T> {
16    /// Return a slice containing the coefficients in ascending order of degree
17    ///
18    /// This is an alias for [`Poly::as_slice`] for API consistency.
19    #[inline]
20    #[must_use]
21    pub fn coeffs(&self) -> &[Complex<T>] {
22        self.as_slice()
23    }
24
25    /// Return a mutable slice containing the coefficient in ascending order of degree
26    ///
27    /// This is an alias for [`Poly::as_mut_slice()`] for API consistency.
28    #[inline]
29    pub fn coeffs_mut(&mut self) -> &mut [Complex<T>] {
30        self.as_mut_slice()
31    }
32}