Created
May 7, 2010 07:08
-
-
Save mikejs/393156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: lib/clyther/tests/test_integer_ops.py | |
=================================================================== | |
--- lib/clyther/tests/test_integer_ops.py (revision 71) | |
+++ lib/clyther/tests/test_integer_ops.py (working copy) | |
@@ -178,6 +178,22 @@ | |
_test_unary_minus.func(a, output) | |
self.failUnlessEqual(clout.item(), output[0]) | |
+ | |
+ def test_mod(self): | |
+ @clyther.task | |
+ def _test_mod(a, b, output): | |
+ output[0] = a % b | |
+ | |
+ a = randint32(a=1) | |
+ b = randint32(a=1) | |
+ | |
+ clout = clyther.DeviceBuffer([1], c_int32) | |
+ _test_mod(a, b, clout) | |
+ | |
+ output = [0] | |
+ _test_mod.func(a, b, output) | |
+ | |
+ self.failUnlessEqual(clout.item(), output[0]) | |
if __name__ == "__main__": | |
Index: lib/clyther/tests/test_float_ops.py | |
=================================================================== | |
--- lib/clyther/tests/test_float_ops.py (revision 71) | |
+++ lib/clyther/tests/test_float_ops.py (working copy) | |
@@ -100,6 +100,21 @@ | |
self.failUnlessAlmostEqual(clout.item(), output[0], 4) | |
+ def test_mod(self): | |
+ @clyther.task | |
+ def _test_mod(a, b, output): | |
+ output[0] = a % b | |
+ | |
+ a = random.uniform(1, 100) | |
+ b = random.uniform(1, 100) | |
+ | |
+ clout = clyther.DeviceBuffer([1], c_float) | |
+ _test_mod(a, b, clout) | |
+ | |
+ output = [0] | |
+ _test_mod.func(a, b, output) | |
+ | |
+ self.failUnlessAlmostEqual(clout.item(), output[0], 4) | |
if __name__ == "__main__": | |
Index: lib/clyther/api/ast/astgen.py | |
=================================================================== | |
--- lib/clyther/api/ast/astgen.py (revision 71) | |
+++ lib/clyther/api/ast/astgen.py (working copy) | |
@@ -24,7 +24,7 @@ | |
import pdb | |
from clyther.api.ast.node import RuntimeConst, TypeTree,RuntimeResolveType,\ | |
- CLCallFunc | |
+ CLCallFunc, CLMod | |
from clyther.api.ast.node import ResolveAttrType,ResolveReturnType | |
from clyther import __cl_builtins__, clmath | |
@@ -343,14 +343,9 @@ | |
left,ltype = self.dispatch( node.left ) | |
right,rtype = self.dispatch( node.right ) | |
- | |
- return CLCallFunc( ast.Const( math.fmod ), (left, right), (ltype,rtype), node.lineno ), TypeTree(ltype,rtype) | |
- | |
-# return ast.Mod((left, right), lineno) | |
+ | |
+ return CLMod(left, right, ltype, rtype, node.lineno), TypeTree(ltype, rtype) | |
- | |
- | |
- | |
def lookUp(self,name): | |
if name in self.scope.__local_variables__: | |
Index: lib/clyther/api/ast/codegen.py | |
=================================================================== | |
--- lib/clyther/api/ast/codegen.py (revision 71) | |
+++ lib/clyther/api/ast/codegen.py (working copy) | |
@@ -444,6 +444,26 @@ | |
# print "visitCLStructDef", node | |
self._print( str(node.string) ) | |
# return str(node.string) | |
- | |
+ | |
+ def visitCLMod(self, node): | |
+ left, right = node.left, node.right | |
+ ltype, rtype = node.ltype, node.rtype | |
+ | |
+ if hasattr(ltype, 'resolve'): | |
+ ltype = ltype.resolve() | |
+ | |
+ if hasattr(rtype, 'resolve'): | |
+ rtype = rtype.resolve() | |
+ | |
+ max = cltype.maxtype(ltype, rtype) | |
+ family = cltype.family(max)[1] | |
+ cdef = cltype.cdef(max) | |
+ | |
+ if family == 'int': | |
+ return "( (%s) %% (%s) )" % (self.dispatch(left), self.dispatch(right)) | |
+ elif family == 'float': | |
+ return "fmod( (%s)(%s), (%s)(%s) )" % (cdef, self.dispatch(left), | |
+ cdef, self.dispatch(right)) | |
+ | |
visitAssAttr ='{expr}.{attrname}' | |
\ No newline at end of file | |
Index: lib/clyther/api/ast/node.py | |
=================================================================== | |
--- lib/clyther/api/ast/node.py (revision 71) | |
+++ lib/clyther/api/ast/node.py (working copy) | |
@@ -445,6 +445,23 @@ | |
return [] | |
def __repr__(self): | |
- return "CLStructDef( %r )" %self.string | |
- | |
- | |
+ return "CLStructDef( %r )" %self.string | |
+ | |
+class CLMod(ast.Node): | |
+ def __init__(self, left, right, ltype, rtype, lineno): | |
+ self.left = left | |
+ self.right = right | |
+ self.ltype = ltype | |
+ self.rtype = rtype | |
+ self.lineno = lineno | |
+ | |
+ def getChildren(self): | |
+ yield left | |
+ yield right | |
+ | |
+ def getChildNodes(self): | |
+ yield left | |
+ yield right | |
+ | |
+ def __repr__(self): | |
+ return "CLMod( %r, %r )" % (self.left, self.right) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment