Skip to content

Commit bec658a

Browse files
ultajainAtul Jain
andauthored
Added is and isNot operators in DelitePy (#168)
Signed-off-by: Atul Jain <atul.jain@nimbleedgehq.ai> Co-authored-by: Atul Jain <atul.jain@nimbleedgehq.ai>
1 parent ffb8169 commit bec658a

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

coreruntime/nimblenet/task_manager/operators/include/compare_operators.hpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,50 @@ class NotEqualOp {
153153
}
154154
};
155155

156+
/**
157+
* @brief Identity comparison operator
158+
*
159+
* Checks if two operands refer to the same object.
160+
* If both operands are None, returns true.
161+
*/
162+
class IsOp {
163+
public:
164+
/**
165+
* @brief Performs identity comparison between two operands
166+
*
167+
* @param v1 First operand
168+
* @param v2 Second operand
169+
* @return Boolean result of v1 is v2
170+
*/
171+
static OpReturnType operate(OpReturnType v1, OpReturnType v2) {
172+
bool isIdentical = (v1 == v2);
173+
bool bothNone = (v1->is_none() && v2->is_none());
174+
return OpReturnType(new SingleVariable<bool>(isIdentical || bothNone));
175+
}
176+
};
177+
178+
/**
179+
* @brief Identity negation comparison operator
180+
*
181+
* Checks if two operands do not refer to the same object.
182+
* If both operands are None, returns false.
183+
*/
184+
class IsNotOp {
185+
public:
186+
/**
187+
* @brief Performs negated identity comparison between two operands
188+
*
189+
* @param v1 First operand
190+
* @param v2 Second operand
191+
* @return Boolean result of v1 is not v2
192+
*/
193+
static OpReturnType operate(OpReturnType v1, OpReturnType v2) {
194+
bool isDifferent = (v1 != v2);
195+
bool bothNone = (v1->is_none() && v2->is_none());
196+
return OpReturnType(new SingleVariable<bool>(isDifferent && !bothNone));
197+
}
198+
};
199+
156200
/**
157201
* @brief Main class for comparison operations
158202
*
@@ -225,6 +269,28 @@ class CompareOperators {
225269
static OpReturnType notIn(OpReturnType v1, OpReturnType v2) {
226270
return OpReturnType(new SingleVariable<bool>(v2->notIn(v1)));
227271
}
272+
273+
/**
274+
* @brief Tests if the two operands refer to the same object.
275+
*
276+
* @param v1 First operand
277+
* @param v2 Second operand
278+
* @return Boolean result of v1 is v2
279+
*/
280+
static OpReturnType is(OpReturnType v1, OpReturnType v2) {
281+
return IsOp::operate(v1, v2);
282+
}
283+
284+
/**
285+
* @brief Tests if the two operands do not refer to the same object.
286+
*
287+
* @param v1 First operand
288+
* @param v2 Second operand
289+
* @return Boolean result of v1 is not v2
290+
*/
291+
static OpReturnType isNot(OpReturnType v1, OpReturnType v2) {
292+
return IsNotOp::operate(v1, v2);
293+
}
228294
};
229295

230296
/**

coreruntime/nimblenet/task_manager/operators/src/compare_operators.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ std::map<std::string, CompareFuncPtr> CompareOperators::_compareOpMap = {
1515
{"In", CompareOperators::in},
1616
{"NotEq", CompareOperators::operate<NotEqualOp>},
1717
{"NotIn", CompareOperators::notIn},
18+
{"Is", CompareOperators::is},
19+
{"IsNot", CompareOperators::isNot},
1820
};
1921

2022
CompareFuncPtr CompareOperators::get_operator(const std::string& opType) {

0 commit comments

Comments
 (0)