finitediff/
pert.rs

1// Copyright 2018-2024 argmin developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8/// Perturbation Vector for the accelerated computation of the Jacobian.
9#[derive(Clone, Default)]
10pub struct PerturbationVector {
11    /// x indices
12    pub x_idx: Vec<usize>,
13    /// corresponding function indices
14    pub r_idx: Vec<Vec<usize>>,
15}
16
17impl PerturbationVector {
18    /// Create a new empty `PerturbationVector`
19    pub fn new() -> Self {
20        PerturbationVector {
21            x_idx: vec![],
22            r_idx: vec![],
23        }
24    }
25
26    /// Add an index `x_idx` and the corresponding function indices `r_idx`
27    pub fn add(mut self, x_idx: usize, r_idx: Vec<usize>) -> Self {
28        self.x_idx.push(x_idx);
29        self.r_idx.push(r_idx);
30        self
31    }
32}
33
34/// A collection of `PerturbationVector`s
35pub type PerturbationVectors = Vec<PerturbationVector>;