mech_stats/
lib.rs

1extern crate nalgebra as na;
2extern crate mech_core;
3
4use na::*;
5use num_traits::*;
6use std::ops::*;
7use std::fmt::Debug;
8use mech_core::matrix::Matrix;
9use paste::paste;
10
11pub mod sum_column;
12pub mod sum_row;
13
14pub use self::sum_column::*;
15pub use self::sum_row::*;
16
17#[macro_export]  
18macro_rules! impl_stats_urop {
19  ($struct_name:ident, $arg_type:ty, $out_type:ty, $op:ident) => {
20    #[derive(Debug)]
21    struct $struct_name<T> {
22      arg: Ref<$arg_type>,
23      out: Ref<$out_type>,
24    }
25    impl<T> MechFunction for $struct_name<T>
26    where
27      T: Copy + Debug + Clone + Sync + Send + 'static + 
28      Add<Output = T> + AddAssign +
29      Zero + One +
30      PartialEq + PartialOrd,
31      Ref<$out_type>: ToValue
32    {
33      fn solve(&self) {
34        let arg_ptr = self.arg.as_ptr();
35        let out_ptr = self.out.as_ptr();
36        $op!(arg_ptr,out_ptr);
37      }
38      fn out(&self) -> Value { self.out.to_value() }
39      fn to_string(&self) -> String { format!("{:#?}", self) }
40    }};}
41