1use crate::*;
2use mech_core::*;
3#[cfg(feature = "matrix")]
4use mech_core::matrix::Matrix;
5
6macro_rules! lte_scalar_lhs_op {
9 ($lhs:expr, $rhs:expr, $out:expr) => {
10 unsafe {
11 for i in 0..(&*$lhs).len() {
12 (&mut *$out)[i] = (&*$lhs)[i] <= *$rhs;
13 }
14 }
15 };
16}
17
18macro_rules! lte_scalar_rhs_op {
19 ($lhs:expr, $rhs:expr, $out:expr) => {
20 unsafe {
21 for i in 0..(&*$rhs).len() {
22 (&mut *$out)[i] = *$lhs <= (&*$rhs)[i];
23 }
24 }
25 };
26}
27
28macro_rules! lte_vec_op {
29 ($lhs:expr, $rhs:expr, $out:expr) => {
30 unsafe {
31 for i in 0..(&*$lhs).len() {
32 (&mut *$out)[i] = (&*$lhs)[i] <= (&*$rhs)[i];
33 }
34 }
35 };
36}
37
38macro_rules! lte_op {
39 ($lhs:expr, $rhs:expr, $out:expr) => {
40 unsafe {
41 (*$out) = (*$lhs) <= (*$rhs);
42 }};}
43
44macro_rules! lte_mat_vec_op {
45 ($lhs:expr, $rhs:expr, $out:expr) => {
46 unsafe {
47 let mut out_deref = &mut (*$out);
48 let lhs_deref = &(*$lhs);
49 let rhs_deref = &(*$rhs);
50 for (mut col, lhs_col) in out_deref.column_iter_mut().zip(lhs_deref.column_iter()) {
51 for i in 0..col.len() {
52 col[i] = lhs_col[i] <= rhs_deref[i];
53 }
54 }
55 }
56 };}
57
58macro_rules! lte_vec_mat_op {
59 ($lhs:expr, $rhs:expr, $out:expr) => {
60 unsafe {
61 let mut out_deref = &mut (*$out);
62 let lhs_deref = &(*$lhs);
63 let rhs_deref = &(*$rhs);
64 for (mut col, rhs_col) in out_deref.column_iter_mut().zip(rhs_deref.column_iter()) {
65 for i in 0..col.len() {
66 col[i] = lhs_deref[i] <= rhs_col[i];
67 }
68 }
69 }
70 };}
71
72macro_rules! lte_mat_row_op {
73 ($lhs:expr, $rhs:expr, $out:expr) => {
74 unsafe {
75 let mut out_deref = &mut (*$out);
76 let lhs_deref = &(*$lhs);
77 let rhs_deref = &(*$rhs);
78 for (mut row, lhs_row) in out_deref.row_iter_mut().zip(lhs_deref.row_iter()) {
79 for i in 0..row.len() {
80 row[i] = lhs_row[i] <= rhs_deref[i];
81 }
82 }
83 }
84 };}
85
86macro_rules! lte_row_mat_op {
87 ($lhs:expr, $rhs:expr, $out:expr) => {
88 unsafe {
89 let mut out_deref = &mut (*$out);
90 let lhs_deref = &(*$lhs);
91 let rhs_deref = &(*$rhs);
92 for (mut row, rhs_row) in out_deref.row_iter_mut().zip(rhs_deref.row_iter()) {
93 for i in 0..row.len() {
94 row[i] = lhs_deref[i] <= rhs_row[i];
95 }
96 }
97 }
98 };}
99
100impl_compare_fxns!(LTE);
101
102fn impl_lte_fxn(lhs_value: Value, rhs_value: Value) -> MResult<Box<dyn MechFunction>> {
103 impl_binop_match_arms!(
104 LTE,
105 register_fxn_descriptor_inner,
106 (lhs_value, rhs_value),
107 I8, bool, "i8";
108 I16, bool, "i16";
109 I32, bool, "i32";
110 I64, bool, "i64";
111 I128, bool, "i128";
112 U8, bool, "u8";
113 U16, bool, "u16";
114 U32, bool, "u32";
115 U64, bool, "u64";
116 U128, bool, "u128";
117 F32, bool, "f32";
118 F64, bool, "f64";
119 R64, bool, "rational";
120 C64, bool, "complex";
121 )
122}
123
124impl_mech_binop_fxn!(CompareLessThanEqual,impl_lte_fxn,"compare/lte");
125