python
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
python [2015/01/01 13:45] – donghee | python [2018/07/18 14:10] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 57: | Line 57: | ||
Dockerfile | Dockerfile | ||
+ | < | ||
FROM debian:sid | FROM debian:sid | ||
MAINTAINER Donghee Park < | MAINTAINER Donghee Park < | ||
Line 74: | Line 74: | ||
# | # | ||
+ | </ | ||
Makefile | Makefile | ||
+ | < | ||
cython helloworld.pyx | cython helloworld.pyx | ||
gcc -g -O2 -fpic `python-config --cflags` -c helloworld.c -o helloworld.o | gcc -g -O2 -fpic `python-config --cflags` -c helloworld.c -o helloworld.o | ||
gcc -shared -o helloworld.so helloworld.o `python-config --libs` | gcc -shared -o helloworld.so helloworld.o `python-config --libs` | ||
- | # | + | </ |
mycode.c | mycode.c | ||
- | ``` | + | < |
#include < | #include < | ||
Line 93: | Line 95: | ||
return a+b; | return a+b; | ||
} | } | ||
- | ``` | + | </ |
mycode.h | mycode.h | ||
- | ``` | + | < |
#ifndef __MYCODE_H__ | #ifndef __MYCODE_H__ | ||
#define __MYCODE_H__ | #define __MYCODE_H__ | ||
extern int myfunc (int, int); | extern int myfunc (int, int); | ||
#endif __MYCODE_H__ | #endif __MYCODE_H__ | ||
- | ``` | + | </ |
mycodecpy.pyx | mycodecpy.pyx | ||
- | ``` | + | < |
cdef extern from " | cdef extern from " | ||
cdef int myfunc (int, int) | cdef int myfunc (int, int) | ||
Line 112: | Line 114: | ||
def callCfunc (): | def callCfunc (): | ||
print myfunc (1,2) | print myfunc (1,2) | ||
- | ``` | + | </ |
+ | < | ||
cython mycodecpy.pyx | cython mycodecpy.pyx | ||
gcc -g -O2 -fpic -c mycode.c -o mycode.o | gcc -g -O2 -fpic -c mycode.c -o mycode.o | ||
gcc -g -O2 -fpic -c mycodecpy.c -o mycodecpy `python-config --cflags` | gcc -g -O2 -fpic -c mycodecpy.c -o mycodecpy `python-config --cflags` | ||
gcc -shared -o mycodecpy.so mycode.o mycodecpy.o `python-config --libs` | gcc -shared -o mycodecpy.so mycode.o mycodecpy.o `python-config --libs` | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | ===== xdress install ===== | ||
+ | llvm 3.4.2 in macos x 10.9 | ||
+ | |||
+ | < | ||
+ | wget http:// | ||
+ | #wget http:// | ||
+ | |||
+ | tar xvfz clang+llvm-3.4.2-x86_64-apple-darwin10.9.xz | ||
+ | mv clang+llvm-3.4.2-x86_64-apple-darwin10.9 llvm-3.4.2-build | ||
+ | |||
+ | export LLVM_CONFIG=llvm-3.4.2-build/ | ||
+ | |||
+ | git clone git:// | ||
+ | |||
+ | cd xdress | ||
+ | |||
+ | python setup.py build_ext --inplace | ||
+ | sudo python setup.py install | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | xdress --debug -p clang | ||
+ | </ | ||
---- | ---- | ||
- | xdress 사용하기. | + | ===== xdress 사용하기 |
c++ class ' | c++ class ' | ||
Line 129: | Line 157: | ||
jehsrc/ | jehsrc/ | ||
- | ``` | + | < |
#if !defined(HOOVER) | #if !defined(HOOVER) | ||
#define HOOVER | #define HOOVER | ||
Line 139: | Line 167: | ||
};}; | };}; | ||
#endif | #endif | ||
- | ``` | + | </ |
---- | ---- | ||
jehsrc/ | jehsrc/ | ||
- | ``` | + | |
+ | < | ||
#include " | #include " | ||
double hoover:: | double hoover:: | ||
int i = 1; | int i = 1; | ||
double val = a; | double val = a; | ||
- | while (i < n){val *= a;}; | + | while (i < n){val *= a; i++;}; |
return val; | return val; | ||
}; | }; | ||
- | ``` | + | </ |
Line 157: | Line 186: | ||
jeh_xdressrc.py | jeh_xdressrc.py | ||
- | ``` | + | |
+ | < | ||
package = ' | package = ' | ||
packagedir = ' | packagedir = ' | ||
Line 163: | Line 193: | ||
classes = [(' | classes = [(' | ||
- | ``` | + | </ |
- | xdress --rc jeh_xdressrc.py | + | jeh_setup.py |
- | python3 | + | <code> |
+ | import os | ||
+ | from distutils.core import setup | ||
+ | from distutils.extension import Extension | ||
+ | from Cython.Distutils import build_ext | ||
+ | import numpy as np | ||
+ | |||
+ | cwd = os.getcwd() | ||
+ | incdirs = [cwd, os.path.join(cwd, | ||
+ | |||
+ | ext_modules = [ | ||
+ | Extension(" | ||
+ | include_dirs=incdirs, | ||
+ | ] | ||
+ | |||
+ | setup( | ||
+ | name = ' | ||
+ | cmdclass = {' | ||
+ | ext_modules = ext_modules, | ||
+ | packages = [' | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | Makefile | ||
+ | |||
+ | < | ||
+ | all: | ||
+ | xdress --rc jeh_xdressrc.py | ||
+ | python jeh_setup.py build > /dev/null 2>&1 | ||
+ | clean: | ||
+ | rm -rf build | ||
+ | rm -rf jehbuild | ||
+ | | ||
+ | </ | ||
---- | ---- | ||
Hoover Example | Hoover Example | ||
- | ``` | + | < |
from jedgar.hoover import A | from jedgar.hoover import A | ||
Line 178: | Line 241: | ||
a.a = 10 | a.a = 10 | ||
a.power(42) | a.power(42) | ||
- | ``` | + | </ |
python.1420119937.txt.gz · Last modified: 2018/07/18 14:09 (external edit)