mech_logic/
or.rs

1use crate::*;
2use mech_core::*;
3#[cfg(feature = "matrix")]
4use mech_core::matrix::Matrix;
5
6// Or ------------------------------------------------------------------------
7
8macro_rules! or_op {
9    ($lhs:expr, $rhs:expr, $out:expr) => {
10      unsafe {*$out = *$lhs || *$rhs;}
11      };}
12  
13macro_rules! or_vec_op {
14  ($lhs:expr, $rhs:expr, $out:expr) => {
15    unsafe {
16      for i in 0..(*$lhs).len() {
17        (&mut (*$out))[i] = (&(*$lhs))[i] || (&(*$rhs))[i];
18      }}};}
19    
20macro_rules! or_scalar_rhs_op {
21  ($lhs:expr, $rhs:expr, $out:expr) => {
22    unsafe {
23      for i in 0..(*$rhs).len() {
24        (&mut (*$out))[i] = (*$lhs) || (&(*$rhs))[i];
25      }}};}
26      
27
28macro_rules! or_scalar_lhs_op {
29  ($lhs:expr, $rhs:expr, $out:expr) => {
30    unsafe {
31      for i in 0..(*$lhs).len() {
32        (&mut (*$out))[i] = (&(*$lhs))[i] || (*$rhs);
33      }}};}
34
35macro_rules! or_mat_vec_op {
36  ($lhs:expr, $rhs:expr, $out:expr) => {
37    unsafe {
38      let mut out_deref = &mut (*$out);
39      let lhs_deref = &(*$lhs);
40      let rhs_deref = &(*$rhs);
41      for (mut col, lhs_col) in out_deref.column_iter_mut().zip(lhs_deref.column_iter()) {
42        for i in 0..col.len() {
43          col[i] = lhs_col[i] || rhs_deref[i];
44        }
45      }
46    }
47  };}   
48      
49macro_rules! or_vec_mat_op {
50  ($lhs:expr, $rhs:expr, $out:expr) => {
51      unsafe {
52        let mut out_deref = &mut (*$out);
53        let lhs_deref = &(*$lhs);
54        let rhs_deref = &(*$rhs);
55        for (mut col, rhs_col) in out_deref.column_iter_mut().zip(rhs_deref.column_iter()) {
56          for i in 0..col.len() {
57            col[i] = lhs_deref[i] || rhs_col[i];
58          }
59        }
60      }
61  };}
62  
63macro_rules! or_mat_row_op {
64  ($lhs:expr, $rhs:expr, $out:expr) => {
65      unsafe {
66      let mut out_deref = &mut (*$out);
67      let lhs_deref = &(*$lhs);
68      let rhs_deref = &(*$rhs);
69      for (mut row, lhs_row) in out_deref.row_iter_mut().zip(lhs_deref.row_iter()) {
70          for i in 0..row.len() {
71          row[i] = lhs_row[i] || rhs_deref[i];
72          }
73      }
74      }
75  };}
76
77macro_rules! or_row_mat_op {
78  ($lhs:expr, $rhs:expr, $out:expr) => {
79      unsafe {
80      let mut out_deref = &mut (*$out);
81      let lhs_deref = &(*$lhs);
82      let rhs_deref = &(*$rhs);
83      for (mut row, rhs_row) in out_deref.row_iter_mut().zip(rhs_deref.row_iter()) {
84          for i in 0..row.len() {
85          row[i] = lhs_deref[i] || rhs_row[i];
86          }
87      }
88      }
89  };}
90
91impl_logic_fxns!(Or);
92
93fn impl_or_fxn(lhs_value: Value, rhs_value: Value) -> MResult<Box<dyn MechFunction>> {
94  impl_binop_match_arms!(
95    Or,
96    register_fxn_descriptor_inner_logic,
97    (lhs_value, rhs_value),
98    Bool, bool, "bool";
99  )
100}
101
102impl_mech_binop_fxn!(LogicOr,impl_or_fxn,"logic/or");