Created
August 6, 2013 15:46
-
-
Save eltjpm/6165723 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
""" | |
>>> empty_bool() | |
False | |
>>> convert_bool(0) | |
False | |
>>> convert_bool(1) | |
True | |
>>> convert_bool(0.0) | |
False | |
>>> convert_bool(10.0) | |
True | |
""" | |
from numba import autojit | |
@autojit | |
def empty_bool(): | |
return bool() | |
@autojit | |
def convert_bool(x): | |
return bool(x) | |
if __name__ == '__main__': | |
import numba | |
numba.testing.testmod() |
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
""" | |
>>> empty_int() | |
0 | |
>>> convert_int(2.5) | |
2 | |
>>> convert_to_int('FF', 16) | |
255 | |
""" | |
from numba import autojit | |
@autojit | |
def empty_int(): | |
return int() | |
@autojit | |
def convert_int(x): | |
return int(x) | |
@autojit | |
def convert_to_int(s, base): | |
return int(s, base) | |
if __name__ == '__main__': | |
import numba | |
numba.testing.testmod() |
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
""" | |
>>> pow3(2,3,5) | |
3 | |
>>> pow3(3,3,5) | |
2 | |
>>> pow3_const() | |
3 | |
>>> pow2(2,3) | |
8 | |
>>> pow2(3,3) | |
27 | |
>>> pow2(3.0,3) | |
27.0 | |
>>> pow2(3,3.0) | |
27.0 | |
>>> pow2(3.0,3.0) | |
27.0 | |
>>> pow2(1.5, 2) | |
2.25 | |
>>> pow2(1.5, 1.5) == pow(1.5, 1.5) | |
True | |
>>> pow_op(3,3) | |
27 | |
>>> pow_op(3.0,3) | |
27.0 | |
>>> pow_op(3,3.0) | |
27.0 | |
>>> pow_op(3.0,3.0) | |
27.0 | |
>>> pow_op(1.5, 2) | |
2.25 | |
>>> pow_op(1.5, 1.5) == pow(1.5, 1.5) | |
True | |
>>> pow2_const() | |
8 | |
>>> c1, c2 = 1.2 + 4.1j, 0.6 + 0.5j | |
>>> pow2(c1, c2) == pow(c1, c2) | |
True | |
>>> d1, d2 = 4.2, 5.1 | |
>>> pow2(d1, d2) == pow(d1, d2) | |
True | |
""" | |
from numba import autojit | |
@autojit | |
def pow3(a,b,c): | |
return pow(a,b,c) | |
@autojit | |
def pow3_const(): | |
return pow(2,3,5) | |
@autojit | |
def pow2(a,b): | |
return pow(a,b) | |
@autojit | |
def pow_op(a,b): | |
return a**b | |
@autojit | |
def pow2_const(): | |
return pow(2,3) | |
if __name__ == '__main__': | |
import numba | |
numba.testing.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment