import sample print(sample.gcd(35,42)) print(sample.in_mandel(0,0,500)) print(sample.in_mandel(2.0,1.0,500)) print(sample.divide(42,8)) print(sample.avg([1,2,3])) p1 = sample.Point(1,2) p2 = sample.Point(4,5) print(sample.distance(p1,p2))
#!/usr/bin/env python # coding: utf-8 # setup.py from distutils.core import setup, Extension setup(name='sample', ext_modules=[ Extension('sample', ['pysample.c'], include_dirs=['/some/dir'], define_macros=[('FOO', '1')], undef_macros=['BAR'], library_dirs=['/usr/local/lib'], libraries=['sample']) ]) import sample sample.gcd(35, 42) sample.in_mandel(0, 0, 500) sample.in_mandel(2.0, 1.0, 500) sample.divide(42, 8)
#!usr/bin/env python # -*- coding:utf-8 -*- import sample print('gcd:', sample.gcd(35, 42)) print('in_mandel:', sample.in_mandel(0, 0, 500)) print('in_mandel:', sample.in_mandel(2.0, 1.0, 500)) print('divide:', sample.divide(42, 8)) print('avg:', sample.avg([1, 2, 3])) p1 = sample.Point(1, 2) p2 = sample.Point(4, 5) print('distance:', sample.distance(p1, p2))
import sample import array print(sample.gcd(42, 10)) print(sample.in_mandel(0, 0, 400)) print(sample.divide(42, 10)) a = array.array('d', [1, 2, 3]) print(sample.avg(a)) p1 = sample.Point(2, 3) p2 = sample.Point(4, 5) print(p1, p2) print(sample.distance(p1, p2))
def test_capi_basics() -> None: assert 7 == sample.gcd(35, 42) assert 1 == sample.in_mandel(0., 0., 500) assert 0 == sample.in_mandel(2., 1., 500) assert (5, 2) == sample.divide(42, 8)
quot = _divide(x,y,rem) return quot,rem.value #call Point struct class Point(ctypes.Structure): _fields_ = [('x',ctypes.c_double), ('y',ctypes.c_double)] distince = _mod.distince distince.argtypes = (ctypes.POINTER(Point),ctypes.POINTER(Point)) distince.restypes = ctypes.c_double if __name__ == '__main__': print ('call c func begin') result = sample.gcd(35,42) print ('call gcd fun :result =',result) print ("-----------") in_result = sample.in_mandel(0,0,500) print ('call in_mandel :in_result = ',in_result) print ('---------') remainder,result = sample.divide(42,8) print('call divide,remainder = %d,reslut = %d' %(remainder,result)) print ('--------') p1 = sample.Point(1,2) p2 = sample.Point(4,5) dresult = sample.distince(p1,p2) print ("point distince result = ", dresult)
import sample print("sample.gcd(35,42) is ", sample.gcd(35,42)) print("sample.in_mandel(0,0,500) is", sample.in_mandel(0,0,500)) print("sample.divide(23,5) is", sample.divide(23,5))
ext_modules = [ Extension('sample', ['sample.pyx'], libraries=['sample'], library_dirs=['.'])] setup( name = 'Sample extension module', cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules ) import sample sample.gcd(42,10) sample.in_mandel(1,1,400) sample.in_mandel(0,0,400) sample.divide(42,10) import array a = array.array('d',[1,2,3]) sample.avg(a) p1 = sample.Point(2,3) p2 = sample.Point(4,5) p1 p2