nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: OceanParcels/parcels
Pull request #424 (2018-08-24 13:28:06)

Adding support for power ('**') operator in JIT mode


Patch:
diff --git a/parcels/codegenerator.py b/parcels/codegenerator.py
index e1d786be..533bc47a 100644
--- a/parcels/codegenerator.py
+++ b/parcels/codegenerator.py
@@ -538,7 +538,10 @@ class KernelGenerator(ast.NodeVisitor):
         self.visit(node.left)
         self.visit(node.op)
         self.visit(node.right)
-        node.ccode = "(%s %s %s)" % (node.left.ccode, node.op.ccode, node.right.ccode)
+        if node.op.ccode == 'pow':  # catching '**' pow statements
+            node.ccode = "pow(%s, %s)" % (node.left.ccode, node.right.ccode)
+        else:
+            node.ccode = "(%s %s %s)" % (node.left.ccode, node.op.ccode, node.right.ccode)
         node.s_print = True
 
     def visit_Add(self, node):
@@ -562,6 +565,9 @@ class KernelGenerator(ast.NodeVisitor):
     def visit_Mod(self, node):
         node.ccode = "%"
 
+    def visit_Pow(self, node):
+        node.ccode = "pow"
+
     def visit_Num(self, node):
         node.ccode = str(node.n)
 


Test patch:
diff --git a/tests/test_kernel_language.py b/tests/test_kernel_language.py
index c202840c..476efccf 100644
--- a/tests/test_kernel_language.py
+++ b/tests/test_kernel_language.py
@@ -53,6 +53,7 @@ def test_expression_int(fieldset, mode, name, expr, result, npart=10):
     ('Sub', '6. - 2.', 4),
     ('Mul', '3. * 5.', 15),
     ('Div', '24. / 4.', 6),
+    ('Pow', '2 ** 3', 8),
 ])
 def test_expression_float(fieldset, mode, name, expr, result, npart=10):
     """ Test basic arithmetic expressions """