1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use nalgebra::{DVector, Dynamic, Matrix, VecStorage};
use crate::Float;
pub type Result<F> = Matrix<F, Dynamic, Dynamic, VecStorage<F, Dynamic, Dynamic>>;
pub trait Ext<F: Float> {
fn new(nrows: usize, ncols: usize) -> Self;
fn initial_values(&self) -> Vec<F>;
fn set_state(&mut self, i: usize, x: Vec<F>);
fn state(&self, i: usize) -> Vec<F>;
fn result(&self, i: usize) -> Vec<F>;
}
impl<F: Float> Ext<F> for Result<F> {
fn new(nrows: usize, ncols: usize) -> Self {
let nrows = Dynamic::new(nrows);
let ncols = Dynamic::new(ncols);
Matrix::zeros_generic(nrows, ncols)
}
fn initial_values(&self) -> Vec<F> {
self.state(0)
}
fn set_state(&mut self, i: usize, x: Vec<F>) {
let x = DVector::from(x);
self.set_column(i, &x);
}
fn state(&self, i: usize) -> Vec<F> {
self.column(i).into_iter().copied().collect()
}
fn result(&self, i: usize) -> Vec<F> {
self.row(i).into_iter().copied().collect()
}
}