chandra/core/operations/
and.rs

1use std::marker::PhantomData;
2
3use crate::core::{
4    operation::{Operation, OperationWrapper}, processor::cpu::DifferentiatedCPUContext
5};
6
7
8pub fn and<LEFT: Operation<bool>, RIGHT: Operation<bool>>(
9    left: LEFT,
10    right: RIGHT,
11) -> OperationWrapper<bool, And<LEFT, RIGHT>> {
12    OperationWrapper(
13        And {
14            left: left,
15            right: right,
16        },
17        PhantomData,
18    )
19}
20
21#[derive(Clone, Debug)]
22pub struct And<LEFT: Operation<bool>, RIGHT: Operation<bool>> {
23    pub left: LEFT,
24    pub right: RIGHT,
25}
26
27impl<LEFT: Operation<bool>, RIGHT: Operation<bool>> Operation<bool> for And<LEFT, RIGHT> {
28    fn evaluate(&self, context: &mut DifferentiatedCPUContext) -> bool {
29        self.left.evaluate(context) && self.right.evaluate(context)
30    }
31}
32
33//impl<R: Computable, LEFT: Differentiable<R>, RIGHT: Differentiable<R>> Differentiable<bool> for And<R, LEFT, RIGHT> {
34//    type Diff = Self;
35//
36//    fn auto_diff_for<R1: Computable>(&self, _var: super::var::Variable<R1>) -> Self::Diff {
37//        return self.clone()
38//    }
39//    fn contains_var<R1: Computable>(&self, var: super::var::Variable<R1>) -> bool {
40//        self.left.contains_var(var.clone()) || self.right.contains_var(var)
41//    }
42//}