import cos_module import numpy as np import pylab print cos_module.cos_func(0.0) print cos_module.cos_func(1.0) print cos_module.cos_func(np.pi / 2) print cos_module.cos_func(np.pi) to_cos = {"zero": 0.0, "one": 1.0, "half_pi": np.pi / 2, "pi": np.pi} print cos_module.cos_func_dict(to_cos) x = np.arange(0, 2 * np.pi, 0.1) y = cos_module.cos_func_np(x) pylab.plot(x, y) pylab.show()
def main(): print("calling Python extension cos_module", cos_module.cos_func(1.0)) print("Callign C swig module: ", cswig.cos_func(0.0)) print("Calling C++11 swig module: ", cppfact.factorial(8))
#!/usr/bin/env python # -*- coding: utf-8 -*- import cos_module dir(cos_module) print(cos_module.cos_func(1.0)) print(cos_module.cos_func(0.0)) print(cos_module.cos_func(3.14159265359)) try: print(cos_module.cos_func('foo')) except TypeError as te: print(f"'foo' {te}")
from cos_module import cos_func print 'cos_func(100):', cos_func(100)
import cos_module print cos_module.cos_func(0.0)
import cos_module print(dir(cos_module)) print(cos_module.cos_func(1.0))
import cos_module # cos_module? # http://stackoverflow.com/questions/21058333/compute-rolling-maximum-drawdown-of-pandas-series print dir(cos_module) # ['__doc__', '__file__', '__name__', '__package__', 'cos_func'] print cos_module.cos_func(1.0) # Out[4]: 0.5403023058681398 print cos_module.cos_func(0.0) # Out[5]: 1.0 print cos_module.cos_func(3.14159265359) # print cos_module.cos_func('foo') # Out[6]: -1.0 import cy_rolling_dd_custom_mv print dir(cy_rolling_dd_custom_mv) import tushare as ts import numpy as np df = ts.get_hist_data('601198') print df.close.values abc = cy_rolling_dd_custom_mv.cy_rolling_dd_custom_mv(df.close.values, 5) print np.array(abc)
import cos_module print 'cos(1) =', cos_module.cos_func(1.0) print 'cos(0) =', cos_module.cos_func(0.0) print 'cos(pi) =', cos_module.cos_func(3.14159265359)
# cos_module.so contains the compiled extension, which can be load in the IPython interpreter # # more at: https://scipy-lectures.github.io/advanced/interfacing_with_c/interfacing_with_c.html import cos_module if __name__ == '__main__': print cos_module print dir(cos_module) print cos_module.cos_func(1.0) print cos_module.cos_func(0.0) print cos_module.cos_func(3.1415926535) print cos_module.cos_func('foo')