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