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