Once you have a Method instance, you can apply it to data in several ways depending on whether you want to preserve the original data, create a new vector, or modify data in-place.
1. Generate a new vector (over)
Use .over(inputs) to iterate a method over a Sequence and return a new Vec containing the results. The output length is guaranteed to match the input length.
2. Call a method on a Sequence (call)
If you have a Sequence object, you can pass a mutable reference to your method using .call(&mut method). This is useful when working with YATA's Sequence abstraction.
3. In-place modification (apply)
If the Method's Input and Output types are the same, you can use .apply(&mut sequence) to modify the values within the sequence directly.
4. One-shot execution (new_over and new_apply)
If you don't want to manage the lifecycle of the Method instance manually, use these static methods:
Method::new_over(params, inputs): Creates a new instance and returns a Vec of results.Method::new_apply(params, &mut sequence): Creates a new instance and applies it to the sequence in-place.
use yata::methods::SMA;
use yata::prelude::*;
let s: Vec<_> = vec![1., 2., 3., 4., 5.];
let mut ma = SMA::new(2, &s[0]).unwrap();
// 1. Get a new vector
let result = ma.over(s.clone());
// 2. Apply in-place (if Input == Output)
let mut s_mut = vec![1., 2., 3., 4., 5.];
let mut ma_inplace = SMA::new(2, &s_mut[0]).unwrap();
s_mut.apply(&mut ma_inplace);