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
//! Concentration builder.

use crate::{
    err::Error,
    ord::{Name, Register},
};
use ndarray::Array1;

/// Loadable concentration structure.
pub type ConcBuilder = Vec<(String, f64)>;

impl Name for ConcBuilder {
    type Inst = Array1<f64>;

    #[inline]
    fn reg(self, reg: &Register) -> Result<Self::Inst, Error> {
        let mut cs = Array1::zeros(reg.total());

        for (name, c) in self {
            cs[reg.index(&name)] += c;
        }

        Ok(cs)
    }
}