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