mech_stats/
lib.rs

1#![no_main]
2#![allow(warnings)]
3#[macro_use]
4extern crate mech_core;
5extern crate paste;
6
7use mech_core::*;
8
9#[cfg(feature = "vector3")]
10use nalgebra::Vector3;
11#[cfg(feature = "vectord")]
12use nalgebra::DVector;
13#[cfg(feature = "vector2")]
14use nalgebra::Vector2;
15#[cfg(feature = "vector4")]
16use nalgebra::Vector4;
17#[cfg(feature = "rowdvector")]
18use nalgebra::RowDVector;
19#[cfg(feature = "row_vectord")]
20use nalgebra::RowDVector;
21#[cfg(feature = "matrix1")]
22use nalgebra::Matrix1;
23#[cfg(feature = "matrix3")]
24use nalgebra::Matrix3;
25#[cfg(feature = "matrix4")]
26use nalgebra::Matrix4;
27#[cfg(feature = "row_vector3")]
28use nalgebra::RowVector3;
29#[cfg(feature = "row_vector4")]
30use nalgebra::RowVector4;
31#[cfg(feature = "row_vector2")]
32use nalgebra::RowVector2;
33#[cfg(feature = "matrixd")]
34use nalgebra::DMatrix;
35#[cfg(feature = "matrix2x3")]
36use nalgebra::Matrix2x3;
37#[cfg(feature = "matrix3x2")]
38use nalgebra::Matrix3x2;
39#[cfg(feature = "matrix2")]
40use nalgebra::Matrix2;
41
42use paste::paste;
43use std::ops::*;
44use std::fmt::Debug;
45
46#[cfg(feature = "sum")]
47pub mod sum_column;
48#[cfg(feature = "sum")]
49pub mod sum_row;
50
51#[cfg(feature = "sum")]
52pub use self::sum_column::*;
53#[cfg(feature = "sum")]
54pub use self::sum_row::*;
55
56#[macro_export]  
57macro_rules! impl_stats_unop {
58  ($struct_name:ident, $arg_type:ty, $out_type:ty, $op:ident) => {
59    #[derive(Debug)]
60    struct $struct_name<T> {
61      arg: Ref<$arg_type>,
62      out: Ref<$out_type>,
63    }
64    impl<T> MechFunctionImpl for $struct_name<T>
65    where
66      T: Copy + Debug + Clone + Sync + Send + 'static + 
67      Add<Output = T> + AddAssign +
68      Zero + One +
69      PartialEq + PartialOrd,
70      Ref<$out_type>: ToValue
71    {
72      fn solve(&self) {
73        let arg_ptr = self.arg.as_ptr();
74        let out_ptr = self.out.as_mut_ptr();
75        $op!(arg_ptr,out_ptr);
76      }
77      fn out(&self) -> Value { self.out.to_value() }
78      fn to_string(&self) -> String { format!("{:#?}", self) }
79    }
80    #[cfg(feature = "compiler")]
81    impl<T> MechFunctionCompiler for $struct_name<T> {
82      fn compile(&self, ctx: &mut CompileCtx) -> MResult<Register> {
83        todo!();
84      }
85    }};}
86