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> MechFunctionFactory for $struct_name<T>
65 where
66 T: Copy + Debug + Clone + Sync + Send + 'static +
67 Add<Output = T> + AddAssign +
68 CompileConst + ConstElem + AsValueKind +
69 Zero + One +
70 PartialEq + PartialOrd,
71 Ref<$out_type>: ToValue
72 {
73 fn new(args: FunctionArgs) -> MResult<Box<dyn MechFunction>> {
74 match args {
75 FunctionArgs::Unary(out, arg) => {
76 let arg = unsafe{ arg.as_unchecked().clone() };
77 let out = unsafe{ out.as_unchecked().clone() };
78 Ok(Box::new($struct_name { arg, out }))
79 }
80 _ => Err(MechError{file: file!().to_string(), tokens: vec![], msg: "".to_string(), id: line!(), kind: MechErrorKind::None})
81 }
82 }
83 }
84 impl<T> MechFunctionImpl for $struct_name<T>
85 where
86 T: Copy + Debug + Clone + Sync + Send + 'static +
87 Add<Output = T> + AddAssign +
88 Zero + One +
89 PartialEq + PartialOrd,
90 Ref<$out_type>: ToValue
91 {
92 fn solve(&self) {
93 let arg_ptr = self.arg.as_ptr();
94 let out_ptr = self.out.as_mut_ptr();
95 $op!(arg_ptr,out_ptr);
96 }
97 fn out(&self) -> Value { self.out.to_value() }
98 fn to_string(&self) -> String { format!("{:#?}", self) }
99 }
100 #[cfg(feature = "compiler")]
101 impl<T> MechFunctionCompiler for $struct_name<T>
102 where
103 T: CompileConst + ConstElem + AsValueKind,
104 {
105 fn compile(&self, ctx: &mut CompileCtx) -> MResult<Register> {
106 let name = format!("{}<{}>", stringify!($struct_name), T::as_value_kind());
107 compile_unop!(name, self.out, self.arg, ctx, FeatureFlag::Custom(hash_str("stats/sum")) );
108 }
109 }};}
110
111#[macro_export]
112macro_rules! impls_stas {
113 ($name:ident, $arg_type:ty, $out_type:ty, $op:ident) => {
114 impl_stats_unop!($name, $arg_type, $out_type, $op);
115 register_fxn_descriptor!($name, u8, "u8", u16, "u16", u32, "u32", u64, "u64", u128, "u128", i8, "i8", i16, "i16", i32, "i32", i64, "i64", i128, "i128", F32, "f32", F64, "f64", C64, "complex", R64, "rational");
116 };
117}