Skip to main content

SimpleMovingAverage

Struct SimpleMovingAverage 

Source
pub struct SimpleMovingAverage<const N: usize> { /* private fields */ }
Expand description

固定窓の単純移動平均 (SMA)。

リングバッファで最新N個の観測値を保持。

Implementations§

Source§

impl<const N: usize> SimpleMovingAverage<N>

Source

pub const fn new() -> Self

新しいSMAを作成。

Source

pub fn observe(&mut self, value: f64)

観測値を追加。

§Panics

N == 0 の場合 (幅 0 の移動平均は定義できない) 型引数の前提違反なので Result にせず panic する SimpleMovingAverage::<0>::new() 自体は成功し、 最初の observe で panic する 契約は tests/panic_contract.rs が pin する

Source

pub fn value(&self) -> f64

現在の平均値。

Source

pub const fn len(&self) -> usize

有効な要素数。

Source

pub const fn is_empty(&self) -> bool

空かどうか。

Source

pub const fn is_full(&self) -> bool

ウィンドウが満杯かどうか。

Source

pub const fn reset(&mut self)

リセット。

Trait Implementations§

Source§

impl<const N: usize> Default for SimpleMovingAverage<N>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<const N: usize> Freeze for SimpleMovingAverage<N>
where [f64; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for SimpleMovingAverage<N>
where [f64; N]: RefUnwindSafe,

§

impl<const N: usize> Send for SimpleMovingAverage<N>
where [f64; N]: Send,

§

impl<const N: usize> Sync for SimpleMovingAverage<N>
where [f64; N]: Sync,

§

impl<const N: usize> Unpin for SimpleMovingAverage<N>
where [f64; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for SimpleMovingAverage<N>
where [f64; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for SimpleMovingAverage<N>
where [f64; N]: 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> 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, 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.