├── .gitignore ├── .gitmodules ├── .travis.yml ├── LICENSE.txt ├── MANIFEST.in ├── README.rst ├── doc ├── Makefile ├── release │ ├── 0.15.0-notes.rst │ ├── 0.16.0-notes.rst │ └── 0.17.0-notes.rst ├── source │ ├── _static │ │ ├── scipy_fallback.css │ │ └── scipyshiny_small.png │ ├── _templates │ │ ├── autosummary │ │ │ └── class.rst │ │ ├── indexsidebar.html │ │ └── layout.html │ ├── api_reference.rst │ ├── conf.py │ ├── index.rst │ ├── release.0.15.0.rst │ ├── release.0.16.0.rst │ ├── release.0.17.0.rst │ ├── release.rst │ └── tutorial.rst ├── tutorial.txt └── tutorial_original.html ├── examples ├── array3d.py ├── binary_search.py ├── cast_copy_transpose.py ├── dict_sort.py ├── fibonacci.py ├── functional.py ├── increment_example.py ├── md5_speed.py ├── object.py ├── print_example.py ├── py_none.py ├── ramp.c ├── ramp.py ├── ramp2.py ├── support_code_example.py ├── swig2_example.py ├── swig2_ext.h ├── swig2_ext.i ├── tuple_return.py ├── vq.py ├── vtk_example.py ├── wx_example.py └── wx_speed.py ├── runtests.py ├── setup.py ├── tox.ini └── weave ├── __init__.py ├── _dumb_shelve.py ├── _dumbdbm_patched.py ├── accelerate_tools.py ├── ast_tools.py ├── base_info.py ├── base_spec.py ├── blitz └── blitz │ ├── Makefile.am │ ├── Makefile.in │ ├── README │ ├── applics.h │ ├── array-impl.h │ ├── array-old.h │ ├── array.h │ ├── array │ ├── Makefile.am │ ├── Makefile.in │ ├── asexpr.h │ ├── bops.cc │ ├── cartesian.h │ ├── cgsolve.h │ ├── complex.cc │ ├── convolve.cc │ ├── convolve.h │ ├── cycle.cc │ ├── domain.h │ ├── et.h │ ├── eval.cc │ ├── expr.h │ ├── fastiter.h │ ├── funcs.h │ ├── functorExpr.h │ ├── geometry.h │ ├── indirect.h │ ├── interlace.cc │ ├── io.cc │ ├── iter.h │ ├── map.h │ ├── methods.cc │ ├── misc.cc │ ├── multi.h │ ├── newbops.cc │ ├── newet-macros.h │ ├── newet.h │ ├── ops.cc │ ├── ops.h │ ├── reduce.cc │ ├── reduce.h │ ├── resize.cc │ ├── shape.h │ ├── slice.h │ ├── slicing.cc │ ├── stencil-et.h │ ├── stencil.cc │ ├── stencil.h │ ├── stencilops.h │ ├── stencils.cc │ ├── stencils.h │ ├── storage.h │ ├── uops.cc │ ├── where.h │ └── zip.h │ ├── bench.cc │ ├── bench.h │ ├── benchext.cc │ ├── benchext.h │ ├── blitz.h │ ├── bzconfig.h │ ├── bzdebug.h │ ├── compiler.h │ ├── config.h.in │ ├── etbase.h │ ├── extremum.h │ ├── funcs.h │ ├── generate │ ├── Makefile.am │ ├── Makefile.in │ ├── arroperands.h │ ├── arroptuple.h │ ├── bzfstream.h │ ├── genarrbops.cpp │ ├── genarruops.cpp │ ├── genmatbops.cpp │ ├── genmathfunc.cpp │ ├── genmatuops.cpp │ ├── genpromote.cpp │ ├── genvecbfn.cpp │ ├── genvecbops.cpp │ ├── genvecuops.cpp │ ├── genvecwhere.cpp │ ├── operands.h │ ├── operands2.h │ ├── optuple.h │ └── optuple2.h │ ├── gnu │ └── bzconfig.h │ ├── indexexpr.h │ ├── limits-hack.h │ ├── listinit.h │ ├── matbops.h │ ├── matdiag.h │ ├── matexpr.h │ ├── matgen.h │ ├── mathf2.h │ ├── mathfunc.h │ ├── matltri.h │ ├── matref.h │ ├── matrix.cc │ ├── matrix.h │ ├── matsymm.h │ ├── mattoep.h │ ├── matuops.h │ ├── matutri.h │ ├── memblock.cc │ ├── memblock.h │ ├── meta │ ├── Makefile.am │ ├── Makefile.in │ ├── dot.h │ ├── matassign.h │ ├── matmat.h │ ├── matvec.h │ ├── metaprog.h │ ├── product.h │ ├── sum.h │ └── vecassign.h │ ├── minmax.h │ ├── mstruct.h │ ├── numinquire.h │ ├── numtrait.h │ ├── ops.h │ ├── prettyprint.h │ ├── promote-old.h │ ├── promote.h │ ├── rand-dunif.h │ ├── rand-normal.h │ ├── rand-tt800.h │ ├── rand-uniform.h │ ├── random.h │ ├── randref.h │ ├── range.h │ ├── reduce.h │ ├── shapecheck.h │ ├── tau.h │ ├── timer.h │ ├── tiny.h │ ├── tinymat.h │ ├── tinymatexpr.h │ ├── tinymatio.cc │ ├── tinyvec-et.h │ ├── tinyvec.cc │ ├── tinyvec.h │ ├── tinyvecio.cc │ ├── tinyveciter.h │ ├── traversal.cc │ ├── traversal.h │ ├── tuning.h │ ├── tvcross.h │ ├── tvecglobs.h │ ├── update.h │ ├── vecaccum.cc │ ├── vecall.cc │ ├── vecany.cc │ ├── vecbfn.cc │ ├── vecbops.cc │ ├── veccount.cc │ ├── vecdelta.cc │ ├── vecdot.cc │ ├── vecexpr.h │ ├── vecexprwrap.h │ ├── vecglobs.cc │ ├── vecglobs.h │ ├── vecio.cc │ ├── veciter.h │ ├── vecmax.cc │ ├── vecmin.cc │ ├── vecnorm.cc │ ├── vecnorm1.cc │ ├── vecpick.cc │ ├── vecpick.h │ ├── vecpickio.cc │ ├── vecpickiter.h │ ├── vecsum.cc │ ├── vector-et.h │ ├── vector.cc │ ├── vector.h │ ├── vecuops.cc │ ├── vecwhere.cc │ ├── vecwhere.h │ ├── wrap-climits.h │ ├── zero.cc │ └── zero.h ├── blitz_spec.py ├── blitz_tools.py ├── build_tools.py ├── bytecodecompiler.py ├── c_spec.py ├── catalog.py ├── common_info.py ├── converters.py ├── cpp_namespace_spec.py ├── ext_tools.py ├── inline_tools.py ├── numpy_scalar_spec.py ├── platform_info.py ├── scxx ├── README.txt ├── dict.h ├── list.h ├── notes.txt ├── number.h ├── object.h ├── sequence.h ├── str.h ├── tuple.h └── weave_imp.cpp ├── setup.py ├── size_check.py ├── slice_handler.py ├── standard_array_spec.py ├── swig2_spec.py ├── swigptr.py ├── swigptr2.py ├── tests ├── scxx_timings.py ├── test_ast_tools.py ├── test_blitz_tools.py ├── test_build_tools.py ├── test_c_spec.py ├── test_catalog.py ├── test_ext_tools.py ├── test_inline_tools.py ├── test_numpy_scalar_spec.py ├── test_scxx_dict.py ├── test_scxx_object.py ├── test_scxx_sequence.py ├── test_size_check.py ├── test_slice_handler.py ├── test_standard_array_spec.py └── weave_test_utils.py └── vtk_spec.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Editor temporary/working/backup files # 2 | ######################################### 3 | .#* 4 | [#]*# 5 | *~ 6 | *$ 7 | *.bak 8 | *.kdev4 9 | *.org 10 | .project 11 | .pydevproject 12 | *.rej 13 | .settings/ 14 | .*.sw[nop] 15 | .sw[nop] 16 | *.tmp 17 | *.vim 18 | tags 19 | 20 | # Compiled source # 21 | ################### 22 | *.a 23 | *.com 24 | *.class 25 | *.dll 26 | *.exe 27 | *.l[ao] 28 | *.o 29 | *.py[ocd] 30 | *.so 31 | _configtest.c 32 | 33 | # Packages # 34 | ############ 35 | # it's better to unpack these files and commit the raw source 36 | # git has its own built in compression methods 37 | *.7z 38 | *.bz2 39 | *.bzip2 40 | *.dmg 41 | *.gz 42 | *.iso 43 | *.jar 44 | *.rar 45 | *.tar 46 | *.tbz2 47 | *.tgz 48 | *.zip 49 | 50 | # Python files # 51 | ################ 52 | # setup.py working directory 53 | build 54 | # sphinx build directory 55 | doc/_build 56 | # cython files 57 | cythonize.dat 58 | # setup.py dist directory 59 | dist 60 | # Egg metadata 61 | *.egg-info 62 | # tox testing tool 63 | .tox 64 | # The shelf plugin uses this dir 65 | ./.shelf 66 | MANIFEST 67 | # distutils configuration 68 | site.cfg 69 | # other temporary files 70 | .deps 71 | .libs 72 | 73 | # Paver generated files # 74 | ######################### 75 | /release 76 | 77 | # Logs and databases # 78 | ###################### 79 | *.log 80 | *.sql 81 | *.sqlite 82 | 83 | # Patches # 84 | ########### 85 | *.patch 86 | *.diff 87 | 88 | # OS generated files # 89 | ###################### 90 | .directory 91 | .fseventsd 92 | .DS_Store* 93 | .gdb_history 94 | .VolumeIcon.icns 95 | ehthumbs.db 96 | Icon? 97 | Thumbs.db 98 | 99 | # Documentation generated files # 100 | ################################# 101 | doc/frontpage/build 102 | doc/source/generated 103 | 104 | # Things specific to this project # 105 | ################################### 106 | weave/__config__.py 107 | weave/version.py 108 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scipy/weave/c0f6df08eaabc21d0c08b45317fc9b61d6fbd9ef/.gitmodules -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # After changing this file, check it on: 2 | # http://lint.travis-ci.org/ 3 | language: python 4 | sudo: false 5 | matrix: 6 | include: 7 | - python: 3.7 8 | env: 9 | - TESTMODE=full 10 | - COVERAGE=--coverage 11 | - python: 3.6 12 | env: 13 | - TESTMODE=fast 14 | addons: 15 | apt: 16 | packages: 17 | - libatlas-dev 18 | - libatlas-base-dev 19 | - liblapack-dev 20 | - ccache 21 | cache: 22 | directories: 23 | - $HOME/.ccache 24 | before_install: 25 | - export PATH=/usr/lib/ccache:$PATH 26 | - uname -a 27 | - free -m 28 | - df -h 29 | - ulimit -a 30 | - mkdir builds 31 | - pushd builds 32 | - travis_retry pip install numpy 33 | - travis_retry pip install nose argparse 34 | - travis_retry pip install coverage 35 | - python -V 36 | - popd 37 | script: 38 | - python $OPTIMIZE runtests.py -g -m $TESTMODE $COVERAGE 39 | notifications: 40 | # Perhaps we should have status emails sent to the mailing list, but 41 | # let's wait to see what people think before turning that on. 42 | email: false 43 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include MANIFEST.in 2 | include *.txt 3 | # Top-level build scripts 4 | include setup.py 5 | # All source files 6 | recursive-include weave * 7 | # All documentation 8 | recursive-include doc * 9 | # Add build and testing tools 10 | include tox.ini 11 | # Exclude what we don't want to include 12 | prune doc/build 13 | prune doc/source/generated 14 | prune */__pycache__ 15 | global-exclude *.pyc *~ *.bak *.swp *.pyo 16 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ``scipy-weave`` provides tools for including C/C++ code within Python code. 2 | Inlining C/C++ code within Python generally results in speedups of 1.5x to 30x 3 | over algorithms written in pure Python. 4 | 5 | ``scipy-weave`` is the stand-alone version of the removed SciPy submodule 6 | ``scipy.weave``. It is provided for users that need versions of SciPy from 7 | which the ``weave`` submodule has been removed but have existing code that 8 | still depends on ``scipy.weave``. **For new code, users are recommended to use 9 | Cython.** 10 | 11 | Note that the Python 3.x support is new as of version 0.19.0 (Nov 2022), and is 12 | *experimental*. It is not tested on all Python 3.x versions. 13 | For Python 2.6-2.7, use versions 0.17.0 or 0.18.0 14 | 15 | To install ``scipy-weave``, use of pip is recommended:: 16 | 17 | pip install scipy-weave 18 | 19 | Note that the import name for ``scipy-weave`` is ``weave``. To run the tests:: 20 | 21 | python -c "import weave; weave.test('full')" 22 | -------------------------------------------------------------------------------- /doc/release/0.15.0-notes.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Weave 0.15.0 Release Notes 3 | ========================== 4 | 5 | Weave provides tools for including C/C++ code within Python code. Inlining 6 | C/C++ code within Python generally results in speedups of 1.5x to 30x over 7 | algorithms written in pure Python. 8 | 9 | Weave is the stand-alone version of the deprecated Scipy submodule scipy.weave. 10 | It is Python 2.x only, and is provided for users that need new versions of 11 | Scipy (from which the weave submodule may be removed) but have existing code 12 | that still depends on scipy.weave. For new code, users are recommended to use 13 | Cython. 14 | 15 | Weave 0.15.0 is the first release of Weave as a standalone package. It is 16 | numbered 0.15.0, because it was split from Scipy after the 0.14.0 release of 17 | that package. No new functionality is included in this release compared to 18 | Scipy 0.14.0, only changes needed to make Weave a standalone package. 19 | 20 | This release requires Python 2.6 or 2.7. 21 | -------------------------------------------------------------------------------- /doc/release/0.16.0-notes.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Weave 0.16.0 Release Notes 3 | ========================== 4 | 5 | Weave provides tools for including C/C++ code within Python code. Inlining 6 | C/C++ code within Python generally results in speedups of 1.5x to 30x over 7 | algorithms written in pure Python. 8 | 9 | Weave is the stand-alone version of the deprecated Scipy submodule scipy.weave. 10 | It is Python 2.x only, and is provided for users that need new versions of 11 | Scipy (from which the weave submodule may be removed) but have existing code 12 | that still depends on scipy.weave. For new code, users are recommended to use 13 | Cython. 14 | 15 | Weave 0.16.0 is a maintenance release that accounts for changes in SciPy since 16 | the Weave 0.15.0 release. 17 | 18 | This release requires Python 2.6 or 2.7. 19 | -------------------------------------------------------------------------------- /doc/release/0.17.0-notes.rst: -------------------------------------------------------------------------------- 1 | ========================== 2 | Weave 0.17.0 Release Notes 3 | ========================== 4 | 5 | Weave provides tools for including C/C++ code within Python code. Inlining 6 | C/C++ code within Python generally results in speedups of 1.5x to 30x over 7 | algorithms written in pure Python. 8 | 9 | Weave is the stand-alone version of the now-removed SciPy submodule ``scipy.weave``. 10 | It is Python 2.x only, and is provided for users that need new versions of 11 | SciPy but have existing code that still depends on ``scipy.weave``. For new code, 12 | users are recommended to use Cython. 13 | 14 | Weave 0.17.0 is a maintenance release that fixes compatibility with NumPy 15 | 1.16.x. 16 | 17 | This release requires Python 2.6 or 2.7. 18 | -------------------------------------------------------------------------------- /doc/source/_static/scipy_fallback.css: -------------------------------------------------------------------------------- 1 | @import "default.css"; 2 | 3 | /** 4 | * Spacing fixes 5 | */ 6 | 7 | div.body p, div.body dd, div.body li { 8 | line-height: 125%; 9 | } 10 | 11 | ul.simple { 12 | margin-top: 0; 13 | margin-bottom: 0; 14 | padding-top: 0; 15 | padding-bottom: 0; 16 | } 17 | 18 | /* spacing around blockquoted fields in parameters/attributes/returns */ 19 | td.field-body > blockquote { 20 | margin-top: 0.1em; 21 | margin-bottom: 0.5em; 22 | } 23 | 24 | /* spacing around example code */ 25 | div.highlight > pre { 26 | padding: 2px 5px 2px 5px; 27 | } 28 | 29 | /* spacing in see also definition lists */ 30 | dl.last > dd { 31 | margin-top: 1px; 32 | margin-bottom: 5px; 33 | margin-left: 30px; 34 | } 35 | 36 | /* hide overflowing content in the sidebar */ 37 | div.sphinxsidebarwrapper p.topless { 38 | overflow: hidden; 39 | } 40 | 41 | /** 42 | * Hide dummy toctrees 43 | */ 44 | 45 | ul { 46 | padding-top: 0; 47 | padding-bottom: 0; 48 | margin-top: 0; 49 | margin-bottom: 0; 50 | } 51 | ul li { 52 | padding-top: 0; 53 | padding-bottom: 0; 54 | margin-top: 0; 55 | margin-bottom: 0; 56 | } 57 | ul li a.reference { 58 | padding-top: 0; 59 | padding-bottom: 0; 60 | margin-top: 0; 61 | margin-bottom: 0; 62 | } 63 | 64 | /** 65 | * Make high-level subsections easier to distinguish from top-level ones 66 | */ 67 | div.body h3 { 68 | background-color: transparent; 69 | } 70 | 71 | div.body h4 { 72 | border: none; 73 | background-color: transparent; 74 | } 75 | 76 | /** 77 | * Scipy colors 78 | */ 79 | 80 | body { 81 | background-color: rgb(100,135,220); 82 | } 83 | 84 | div.document { 85 | background-color: rgb(230,230,230); 86 | } 87 | 88 | div.sphinxsidebar { 89 | background-color: rgb(230,230,230); 90 | overflow: hidden; 91 | } 92 | 93 | div.related { 94 | background-color: rgb(100,135,220); 95 | } 96 | 97 | div.sphinxsidebar h3 { 98 | color: rgb(0,102,204); 99 | } 100 | 101 | div.sphinxsidebar h3 a { 102 | color: rgb(0,102,204); 103 | } 104 | 105 | div.sphinxsidebar h4 { 106 | color: rgb(0,82,194); 107 | } 108 | 109 | div.sphinxsidebar p { 110 | color: black; 111 | } 112 | 113 | div.sphinxsidebar a { 114 | color: #355f7c; 115 | } 116 | 117 | div.sphinxsidebar ul.want-points { 118 | list-style: disc; 119 | } 120 | 121 | .field-list th { 122 | color: rgb(0,102,204); 123 | white-space: nowrap; 124 | } 125 | 126 | /** 127 | * Extra admonitions 128 | */ 129 | 130 | div.tip { 131 | background-color: #ffffe4; 132 | border: 1px solid #ee6; 133 | } 134 | 135 | div.plot-output { 136 | clear-after: both; 137 | } 138 | 139 | div.plot-output .figure { 140 | float: left; 141 | text-align: center; 142 | margin-bottom: 0; 143 | padding-bottom: 0; 144 | } 145 | 146 | div.plot-output .caption { 147 | margin-top: 2; 148 | padding-top: 0; 149 | } 150 | 151 | div.plot-output:after { 152 | content: ""; 153 | display: block; 154 | height: 0; 155 | clear: both; 156 | } 157 | 158 | 159 | /* 160 | div.admonition-example { 161 | background-color: #e4ffe4; 162 | border: 1px solid #ccc; 163 | }*/ 164 | 165 | 166 | /** 167 | * Styling for field lists 168 | */ 169 | 170 | table.field-list th { 171 | border-left: 1px solid #aaa !important; 172 | padding-left: 5px; 173 | } 174 | 175 | table.field-list { 176 | border-collapse: separate; 177 | border-spacing: 10px; 178 | } 179 | 180 | /** 181 | * Styling for footnotes 182 | */ 183 | 184 | table.footnote td, table.footnote th { 185 | border: none; 186 | } 187 | -------------------------------------------------------------------------------- /doc/source/_static/scipyshiny_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scipy/weave/c0f6df08eaabc21d0c08b45317fc9b61d6fbd9ef/doc/source/_static/scipyshiny_small.png -------------------------------------------------------------------------------- /doc/source/_templates/autosummary/class.rst: -------------------------------------------------------------------------------- 1 | {% extends "!autosummary/class.rst" %} 2 | 3 | {% block methods %} 4 | {% if methods %} 5 | .. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages. 6 | .. autosummary:: 7 | :toctree: 8 | {% for item in all_methods %} 9 | {%- if not item.startswith('_') or item in ['__call__'] %} 10 | {{ name }}.{{ item }} 11 | {%- endif -%} 12 | {%- endfor %} 13 | {% endif %} 14 | {% endblock %} 15 | 16 | {% block attributes %} 17 | {% if attributes %} 18 | .. HACK -- the point here is that we don't want this to appear in the output, but the autosummary should still generate the pages. 19 | .. autosummary:: 20 | :toctree: 21 | {% for item in all_attributes %} 22 | {%- if not item.startswith('_') %} 23 | {{ name }}.{{ item }} 24 | {%- endif -%} 25 | {%- endfor %} 26 | {% endif %} 27 | {% endblock %} 28 | -------------------------------------------------------------------------------- /doc/source/_templates/indexsidebar.html: -------------------------------------------------------------------------------- 1 |

Resources

2 | 6 | -------------------------------------------------------------------------------- /doc/source/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {% block sidebarsearch %} 4 | {%- if sourcename %} 5 | 12 | {%- endif %} 13 | {{ super() }} 14 | {% endblock %} 15 | -------------------------------------------------------------------------------- /doc/source/api_reference.rst: -------------------------------------------------------------------------------- 1 | ************* 2 | API reference 3 | ************* 4 | 5 | .. warning:: 6 | 7 | This documentation is work-in-progress; incomplete and unorganized. 8 | 9 | .. automodule:: weave 10 | :members: 11 | 12 | 13 | .. autosummary:: 14 | :toctree: generated/ 15 | 16 | inline 17 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | Weave 2 | ===== 3 | 4 | :Release: |release| 5 | :Date: |today| 6 | 7 | Weave provides tools for including C/C++ code within Python code. Inlining 8 | C/C++ code within Python generally results in speedups of 1.5x to 30x over 9 | algorithms written in pure Python. 10 | 11 | Weave is the stand-alone version of the deprecated Scipy submodule 12 | ``scipy.weave``. It is Python 2.x only, and is provided for users that need 13 | new versions of Scipy (from which the ``weave`` submodule may be removed) but 14 | have existing code that still depends on ``scipy.weave``. For new code, users 15 | are recommended to use Cython. 16 | 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | 21 | release 22 | tutorial 23 | api_reference 24 | -------------------------------------------------------------------------------- /doc/source/release.0.15.0.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../release/0.15.0-notes.rst 2 | -------------------------------------------------------------------------------- /doc/source/release.0.16.0.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../release/0.16.0-notes.rst 2 | -------------------------------------------------------------------------------- /doc/source/release.0.17.0.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../release/0.17.0-notes.rst 2 | -------------------------------------------------------------------------------- /doc/source/release.rst: -------------------------------------------------------------------------------- 1 | ************* 2 | Release Notes 3 | ************* 4 | 5 | .. toctree:: 6 | :maxdepth: 1 7 | 8 | release.0.15.0 9 | release.0.16.0 10 | release.0.17.0 11 | -------------------------------------------------------------------------------- /examples/array3d.py: -------------------------------------------------------------------------------- 1 | """ A simple example to show how to access a 3D numpy array. One 2 | example shows how to access the numpy array using blitz type 3 | converters and the other shows how it can be done without using blitz 4 | by accessing the numpy array data directly. 5 | 6 | """ 7 | 8 | 9 | import weave 10 | from weave import converters 11 | import numpy 12 | 13 | 14 | def create_array(): 15 | """Creates a simple 3D numpy array with unique values at each 16 | location in the matrix. 17 | 18 | """ 19 | rows, cols, depth = 2, 3, 4 20 | arr = numpy.zeros((rows, cols, depth), 'i') 21 | count = 0 22 | for i in range(rows): 23 | for j in range(cols): 24 | for k in range(depth): 25 | arr[i,j,k] = count 26 | count += 1 27 | return arr 28 | 29 | 30 | def pure_inline(arr): 31 | """Prints the given 3D array by accessing the raw numpy data and 32 | without using blitz converters. 33 | 34 | Notice the following: 35 | 1. '\\n' to escape generating a newline in the C++ code. 36 | 2. rows, cols = Narr[0], Narr[1]. 37 | 3. Array access using arr[(i*cols + j)*depth + k]. 38 | 39 | """ 40 | 41 | code = """ 42 | int rows = Narr[0]; 43 | int cols = Narr[1]; 44 | int depth = Narr[2]; 45 | for (int i=0; i < rows; i++) 46 | { 47 | for (int j=0; j < cols; j++) 48 | { 49 | printf("img[%3d][%3d]=", i, j); 50 | for (int k=0; k< depth; ++k) 51 | { 52 | printf(" %3d", arr[(i*cols + j)*depth + k]); 53 | } 54 | printf("\\n"); 55 | } 56 | } 57 | """ 58 | 59 | weave.inline(code, ['arr']) 60 | 61 | 62 | def blitz_inline(arr): 63 | """Prints the given 3D array by using blitz converters which 64 | provides a numpy-like syntax for accessing the numpy data. 65 | 66 | Notice the following: 67 | 1. '\\n' to escape generating a newline in the C++ code. 68 | 2. rows, cols = Narr[0], Narr[1]. 69 | 3. Array access using arr(i, j, k). 70 | 71 | """ 72 | 73 | code = """ 74 | int rows = Narr[0]; 75 | int cols = Narr[1]; 76 | int depth = Narr[2]; 77 | for (int i=0; i < rows; i++) 78 | { 79 | for (int j=0; j < cols; j++) 80 | { 81 | printf("img[%3d][%3d]=", i, j); 82 | for (int k=0; k< depth; ++k) 83 | { 84 | printf(" %3d", arr(i, j, k)); 85 | } 86 | printf("\\n"); 87 | } 88 | } 89 | """ 90 | 91 | weave.inline(code, ['arr'], type_converters=converters.blitz) 92 | 93 | 94 | def main(): 95 | arr = create_array() 96 | print("numpy:") 97 | print(arr) 98 | 99 | print("Pure Inline:") 100 | pure_inline(arr) 101 | 102 | print("Blitz Inline:") 103 | blitz_inline(arr) 104 | 105 | 106 | if __name__ == '__main__': 107 | main() 108 | -------------------------------------------------------------------------------- /examples/functional.py: -------------------------------------------------------------------------------- 1 | # C:\home\eric\wrk\weave\examples>python functional.py 2 | # desired: [2, 3, 4] 3 | # actual: [2, 3, 4] 4 | # actual2: [2, 3, 4] 5 | # python speed: 0.039999961853 6 | # SCXX speed: 0.0599999427795 7 | # speed up: 0.666666666667 8 | # c speed: 0.0200001001358 9 | # speed up: 1.99998807913 10 | 11 | 12 | import sys 13 | sys.path.insert(0,'..') 14 | import inline_tools 15 | from types import * 16 | 17 | 18 | def c_list_map(func,seq): 19 | """ Uses CXX C code to implement a simple map-like function. 20 | It does not provide any error checking. 21 | """ 22 | assert(type(func) in [FunctionType,MethodType,type(len)]) 23 | code = """ 24 | #line 22 "functional.py" 25 | py::tuple args(1); 26 | int N = seq.len(); 27 | py::list result(N); 28 | for(int i = 0; i < N;i++) 29 | { 30 | args[0] = seq[i]; 31 | result[i] = func.call(args); 32 | } 33 | return_val = result; 34 | """ 35 | return inline_tools.inline(code,['func','seq']) 36 | 37 | 38 | def c_list_map2(func,seq): 39 | """ Uses Python API more than CXX to implement a simple map-like function. 40 | It does not provide any error checking. 41 | """ 42 | assert(type(func) in [FunctionType,MethodType,type(len)]) 43 | code = """ 44 | #line 40 "functional.py" 45 | py::tuple args(1); 46 | PyObject* py_args = (PyObject*)args; 47 | py::list result(seq.len()); 48 | PyObject* py_result = (PyObject*)result; 49 | PyObject* item = NULL; 50 | PyObject* this_result = NULL; 51 | int N = seq.len(); 52 | for(int i = 0; i < N;i++) 53 | { 54 | item = PyList_GET_ITEM(py_seq,i); 55 | Py_INCREF(item); 56 | PyTuple_SetItem(py_args,0,item); 57 | this_result = PyEval_CallObject(py_func,py_args); 58 | PyList_SetItem(py_result,i,this_result); 59 | } 60 | return_val = result; 61 | """ 62 | return inline_tools.inline(code,['func','seq']) 63 | 64 | 65 | def main(): 66 | seq = ['aa','bbb','cccc'] 67 | print('desired:', list(map(len,seq))) 68 | print('actual:', c_list_map(len,seq)) 69 | print('actual2:', c_list_map2(len,seq)) 70 | 71 | 72 | def time_it(m,n): 73 | import time 74 | seq = ['aadasdf'] * n 75 | t1 = time.time() 76 | for i in range(m): 77 | result = list(map(len,seq)) 78 | t2 = time.time() 79 | py = t2 - t1 80 | print('python speed:', py) 81 | 82 | #load cache 83 | result = c_list_map(len,seq) 84 | t1 = time.time() 85 | for i in range(m): 86 | result = c_list_map(len,seq) 87 | t2 = time.time() 88 | c = t2-t1 89 | print('SCXX speed:', c) 90 | print('speed up:', py / c) 91 | 92 | #load cache 93 | result = c_list_map2(len,seq) 94 | t1 = time.time() 95 | for i in range(m): 96 | result = c_list_map2(len,seq) 97 | t2 = time.time() 98 | c = t2-t1 99 | print('c speed:', c) 100 | print('speed up:', py / c) 101 | 102 | if __name__ == "__main__": 103 | main() 104 | time_it(100,1000) 105 | -------------------------------------------------------------------------------- /examples/increment_example.py: -------------------------------------------------------------------------------- 1 | # examples/increment_example.py 2 | 3 | # from weave import ext_tools 4 | 5 | # use the following so that development version is used. 6 | 7 | 8 | import sys 9 | sys.path.insert(0,'..') 10 | import weave.ext_tools as ext_tools 11 | 12 | 13 | def build_increment_ext(): 14 | """ Build a simple extension with functions that increment numbers. 15 | The extension will be built in the local directory. 16 | """ 17 | mod = ext_tools.ext_module('increment_ext') 18 | 19 | # Effectively a type declaration for 'a' in the following functions. 20 | a = 1 21 | 22 | ext_code = "return_val = PyLong_FromLong(a+1);" 23 | func = ext_tools.ext_function('increment',ext_code,['a']) 24 | mod.add_function(func) 25 | 26 | ext_code = "return_val = PyLong_FromLong(a+2);" 27 | func = ext_tools.ext_function('increment_by_2',ext_code,['a']) 28 | mod.add_function(func) 29 | 30 | mod.compile() 31 | 32 | if __name__ == "__main__": 33 | try: 34 | import increment_ext 35 | except ImportError: 36 | build_increment_ext() 37 | import increment_ext 38 | a = 1 39 | print('a, a+1:', a, increment_ext.increment(a)) 40 | print('a, a+2:', a, increment_ext.increment_by_2(a)) 41 | -------------------------------------------------------------------------------- /examples/md5_speed.py: -------------------------------------------------------------------------------- 1 | """ 2 | Storing actual strings instead of their md5 value appears to 3 | be about 10 times faster. 4 | 5 | >>> md5_speed.run(200,50000) 6 | md5 build(len,sec): 50000 0.870999932289 7 | md5 retrv(len,sec): 50000 0.680999994278 8 | std build(len,sec): 50000 0.259999990463 9 | std retrv(len,sec): 50000 0.0599999427795 10 | 11 | This test actually takes several minutes to generate the random 12 | keys used to populate the dictionaries. Here is a smaller run, 13 | but with longer keys. 14 | 15 | >>> md5_speed.run(1000,4000) 16 | md5 build(len,sec,per): 4000 0.129999995232 3.24999988079e-005 17 | md5 retrv(len,sec,per): 4000 0.129999995232 3.24999988079e-005 18 | std build(len,sec,per): 4000 0.0500000715256 1.25000178814e-005 19 | std retrv(len,sec,per): 4000 0.00999999046326 2.49999761581e-006 20 | 21 | Results are similar, though not statistically to good because of 22 | the short times used and the available clock resolution. 23 | 24 | Still, I think it is safe to say that, for speed, it is better 25 | to store entire strings instead of using md5 versions of 26 | their strings. Yeah, the expected result, but it never hurts 27 | to check... 28 | 29 | """ 30 | 31 | 32 | import random 33 | import md5 34 | import time 35 | import io 36 | 37 | 38 | def speed(n,m): 39 | s = 'a'*n 40 | t1 = time.time() 41 | for i in range(m): 42 | q = md5.new(s).digest() 43 | t2 = time.time() 44 | print((t2 - t1) / m) 45 | 46 | #speed(50,1e6) 47 | 48 | 49 | def generate_random(avg_length,count): 50 | all_str = [] 51 | alphabet = 'abcdefghijklmnopqrstuvwxyz' 52 | lo,hi = [30,avg_length*2+30] 53 | for i in range(count): 54 | new_str = io.StringIO() 55 | l = random.randrange(lo,hi) 56 | for i in range(l): 57 | new_str.write(random.choice(alphabet)) 58 | all_str.append(new_str.getvalue()) 59 | return all_str 60 | 61 | 62 | def md5_dict(lst): 63 | catalog = {} 64 | t1 = time.time() 65 | for s in lst: 66 | key = md5.new(s).digest() 67 | catalog[key] = None 68 | t2 = time.time() 69 | print('md5 build(len,sec,per):', len(lst), t2 - t1, (t2-t1)/len(lst)) 70 | 71 | t1 = time.time() 72 | for s in lst: 73 | key = md5.new(s).digest() 74 | val = catalog[key] 75 | t2 = time.time() 76 | print('md5 retrv(len,sec,per):', len(lst), t2 - t1, (t2-t1)/len(lst)) 77 | 78 | 79 | def std_dict(lst): 80 | catalog = {} 81 | t1 = time.time() 82 | for s in lst: 83 | catalog[s] = None 84 | t2 = time.time() 85 | print('std build(len,sec,per):', len(lst), t2 - t1, (t2-t1)/len(lst)) 86 | 87 | t1 = time.time() 88 | for s in lst: 89 | val = catalog[s] 90 | t2 = time.time() 91 | print('std retrv(len,sec,per):', len(lst), t2 - t1, (t2-t1)/len(lst)) 92 | 93 | 94 | def run(m=200,n=10): 95 | lst = generate_random(m,n) 96 | md5_dict(lst) 97 | std_dict(lst) 98 | 99 | run(2000,100) 100 | -------------------------------------------------------------------------------- /examples/object.py: -------------------------------------------------------------------------------- 1 | """ Attribute and method access on Python objects from C++. 2 | 3 | Note: std::cout type operations currently crash python... 4 | Not sure what is up with this... 5 | """ 6 | 7 | 8 | import weave 9 | 10 | #---------------------------------------------------------------------------- 11 | # get/set attribute and call methods example 12 | #---------------------------------------------------------------------------- 13 | 14 | 15 | class Foo(object): 16 | def __init__(self): 17 | self.val = 1 18 | 19 | def inc(self,amount): 20 | self.val += amount 21 | return self.val 22 | obj = Foo() 23 | code = """ 24 | py::tuple result(3); 25 | 26 | int i = obj.attr("val"); 27 | result[0] = i; 28 | 29 | py::tuple args(1); 30 | args[0] = 2; 31 | i = obj.mcall("inc",args); 32 | result[1] = i; 33 | 34 | obj.set_attr("val",5); 35 | i = obj.attr("val"); 36 | result[2] = i; 37 | 38 | return_val = result; 39 | """ 40 | 41 | print('initial, inc(2), set(5)/get:', weave.inline(code,['obj'])) 42 | 43 | #---------------------------------------------------------------------------- 44 | # indexing of values. 45 | #---------------------------------------------------------------------------- 46 | from collections import UserList 47 | obj = UserList([1,[1,2],"hello"]) 48 | code = """ 49 | int i; 50 | // find obj length and access each of its items 51 | //std::cout << "UserList items: "; 52 | //for(i = 0; i < obj.length(); i++) 53 | // std::cout << obj[i].str() << " "; 54 | //std::cout << std::endl; 55 | // assign new values to each of its items 56 | for(i = 0; i < obj.length(); i++) 57 | obj[i] = "goodbye"; 58 | """ 59 | weave.inline(code,['obj']) 60 | print("obj with new values:", obj) 61 | -------------------------------------------------------------------------------- /examples/print_example.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import sys 4 | sys.path.insert(0,'..') 5 | import inline_tools 6 | 7 | import time 8 | 9 | 10 | def print_compare(n): 11 | print('Printing %d integers:' % n) 12 | t1 = time.time() 13 | for i in range(n): 14 | print(i, end=' ') 15 | t2 = time.time() 16 | py = (t2-t1) 17 | 18 | # get it in cache 19 | inline_tools.inline('printf("%d",i);',['i']) 20 | t1 = time.time() 21 | for i in range(n): 22 | inline_tools.inline('printf("%d",i);',['i']) 23 | t2 = time.time() 24 | print(' speed in python:', py) 25 | print(' speed in c:',(t2 - t1)) 26 | print(' speed up: %3.2f' % (py/(t2-t1))) 27 | 28 | 29 | def cout_example(lst): 30 | # get it in cache 31 | i = lst[0] 32 | inline_tools.inline('std::cout << i << std::endl;',['i']) 33 | t1 = time.time() 34 | for i in lst: 35 | inline_tools.inline('std::cout << i << std::endl;',['i']) 36 | t2 = time.time() 37 | 38 | if __name__ == "__main__": 39 | n = 3000 40 | print_compare(n) 41 | print("calling cout with integers:") 42 | cout_example([1,2,3]) 43 | print("calling cout with strings:") 44 | cout_example(['a','bb', 'ccc']) 45 | -------------------------------------------------------------------------------- /examples/py_none.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | # This tests the amount of overhead added for inline() function calls. 4 | # It isn't a "real world" test, but is somewhat informative. 5 | # C:\home\ej\wrk\weave\examples>python py_none.py 6 | # python: 0.0199999809265 7 | # inline: 0.160000085831 8 | # speed up: 0.124999813736 (this is about a factor of 8 slower) 9 | 10 | import time 11 | import sys 12 | sys.path.insert(0,'..') 13 | from inline_tools import inline 14 | 15 | 16 | def py_func(): 17 | return None 18 | 19 | n = 10000 20 | t1 = time.time() 21 | for i in range(n): 22 | py_func() 23 | t2 = time.time() 24 | py_time = t2 - t1 25 | print('python:', py_time) 26 | 27 | inline("",[]) 28 | t1 = time.time() 29 | for i in range(n): 30 | inline("",[]) 31 | t2 = time.time() 32 | print('inline:', (t2-t1)) 33 | print('speed up:', py_time/(t2-t1)) 34 | print('or (more likely) slow down:', (t2-t1)/py_time) 35 | -------------------------------------------------------------------------------- /examples/ramp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void Ramp(double* result, int size, double start, double end) 5 | { 6 | double step = (end-start)/(size-1); 7 | double val = start; 8 | int i; 9 | for (i = 0; i < size; i++) 10 | { 11 | *result++ = val; 12 | val += step; 13 | } 14 | } 15 | 16 | void main() 17 | { 18 | double array[10000]; 19 | int i; 20 | clock_t t1, t2; 21 | float seconds; 22 | t1 = clock(); 23 | for (i = 0; i < 10000; i++) 24 | Ramp(array, 10000, 0.0, 1.0); 25 | t2 = clock(); 26 | seconds = (float)(t2-t1)/CLOCKS_PER_SEC; 27 | printf("c version (seconds): %f\n", seconds); 28 | printf("array[500]: %f\n", array[500]); 29 | } -------------------------------------------------------------------------------- /examples/ramp2.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | # 4 | # C:\home\eric\wrk\weave\examples>python ramp2.py 5 | # python (seconds): 2.94499993324 6 | # arr[500]: 0.0500050005001 7 | # 8 | # compiled numeric (seconds, speed up): 3.47500002384 42.3740994682 9 | # arr[500]: 0.0500050005001 10 | 11 | import time 12 | from weave import ext_tools 13 | from numpy import * 14 | 15 | 16 | def Ramp(result, size, start, end): 17 | step = (end-start)/(size-1) 18 | for i in range(size): 19 | result[i] = start + step*i 20 | 21 | 22 | def build_ramp_ext(): 23 | mod = ext_tools.ext_module('ramp_ext') 24 | 25 | # type declarations 26 | result = array([0],float64) 27 | start,end = 0.,0. 28 | code = """ 29 | const int size = Nresult[0]; 30 | const double step = (end-start)/(size-1); 31 | double val = start; 32 | for (int i = 0; i < size; i++) 33 | { 34 | result[i] = val; 35 | val += step; 36 | } 37 | """ 38 | func = ext_tools.ext_function('Ramp',code,['result','start','end']) 39 | mod.add_function(func) 40 | mod.compile(compiler='gcc') 41 | 42 | 43 | def main(): 44 | arr = [0]*10000 45 | t1 = time.time() 46 | for i in range(200): 47 | Ramp(arr, 10000, 0.0, 1.0) 48 | t2 = time.time() 49 | py_time = t2 - t1 50 | print('python (seconds):', py_time) 51 | print('arr[500]:', arr[500]) 52 | print() 53 | 54 | try: 55 | import ramp_ext 56 | except: 57 | build_ramp_ext() 58 | import ramp_ext 59 | arr = array([0]*10000,float64) 60 | for i in range(10000): 61 | ramp_ext.Ramp(arr, 0.0, 1.0) 62 | t2 = time.time() 63 | c_time = (t2 - t1) 64 | print('compiled numeric (seconds, speed up):', c_time, (py_time*10000/200.) / c_time) 65 | print('arr[500]:', arr[500]) 66 | 67 | if __name__ == '__main__': 68 | main() 69 | -------------------------------------------------------------------------------- /examples/support_code_example.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import sys 4 | sys.path.insert(0,'..') 5 | import inline_tools 6 | 7 | 8 | support_code = """ 9 | PyObject* length(std::string a) 10 | { 11 | int l = a.length(); 12 | return PyLong_FromLong(l); 13 | } 14 | """ 15 | a = 'some string' 16 | val = inline_tools.inline("return_val = length(a);",['a'], 17 | support_code=support_code) 18 | print(val) 19 | -------------------------------------------------------------------------------- /examples/swig2_example.py: -------------------------------------------------------------------------------- 1 | """Simple example to show how to use weave.inline on SWIG2 wrapped 2 | objects. SWIG2 refers to SWIG versions >= 1.3. 3 | 4 | To run this example you must build the trivial SWIG2 extension called 5 | swig2_ext. To do this you need to do something like this:: 6 | 7 | $ swig -c++ -python -I. -o swig2_ext_wrap.cxx swig2_ext.i 8 | 9 | $ g++ -Wall -O2 -I/usr/include/python2.3 -fPIC -I. -c \ 10 | -o swig2_ext_wrap.os swig2_ext_wrap.cxx 11 | 12 | $ g++ -shared -o _swig2_ext.so swig2_ext_wrap.os \ 13 | -L/usr/lib/python2.3/config 14 | 15 | The files swig2_ext.i and swig2_ext.h are included in the same 16 | directory that contains this file. 17 | 18 | Note that weave's SWIG2 support works fine whether SWIG_COBJECT_TYPES 19 | are used or not. 20 | 21 | Author: Prabhu Ramachandran 22 | Copyright (c) 2004, Prabhu Ramachandran 23 | License: BSD Style. 24 | 25 | """ 26 | 27 | 28 | # Import our SWIG2 wrapped library 29 | import swig2_ext 30 | 31 | import weave 32 | from weave import swig2_spec, converters 33 | 34 | # SWIG2 support is not enabled by default. We do this by adding the 35 | # swig2 converter to the default list of converters. 36 | converters.default.insert(0, swig2_spec.swig2_converter()) 37 | 38 | 39 | def test(): 40 | """Instantiate the SWIG wrapped object and then call its method 41 | from C++ using weave.inline 42 | 43 | """ 44 | a = swig2_ext.A() 45 | b = swig2_ext.foo() # This will be an APtr instance. 46 | b.thisown = 1 # Prevent memory leaks. 47 | code = """a->f(); 48 | b->f(); 49 | """ 50 | weave.inline(code, ['a', 'b'], include_dirs=['.'], 51 | headers=['"swig2_ext.h"'], verbose=1) 52 | 53 | 54 | if __name__ == "__main__": 55 | test() 56 | -------------------------------------------------------------------------------- /examples/swig2_ext.h: -------------------------------------------------------------------------------- 1 | #include 2 | class A { 3 | public: 4 | void f() {std::cout << "A::f()\n";} 5 | }; 6 | 7 | A* foo() 8 | { 9 | A* a = new A; 10 | return a; 11 | } 12 | -------------------------------------------------------------------------------- /examples/swig2_ext.i: -------------------------------------------------------------------------------- 1 | %module swig2_ext 2 | %{ 3 | #include "swig2_ext.h" 4 | %} 5 | 6 | %include "swig2_ext.h" 7 | -------------------------------------------------------------------------------- /examples/tuple_return.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import sys 4 | sys.path.insert(0,'..') 5 | import inline_tools 6 | 7 | 8 | def multi_return(): 9 | return 1, '2nd' 10 | 11 | 12 | def c_multi_return(): 13 | 14 | code = """ 15 | py::tuple results(2); 16 | results[0] = 1; 17 | results[1] = "2nd"; 18 | return_val = results; 19 | """ 20 | return inline_tools.inline(code,[]) 21 | 22 | 23 | def compare(m): 24 | import time 25 | t1 = time.time() 26 | for i in range(m): 27 | py_result = multi_return() 28 | t2 = time.time() 29 | py = t2 - t1 30 | print('python speed:', py) 31 | 32 | #load cache 33 | result = c_multi_return() 34 | t1 = time.time() 35 | for i in range(m): 36 | c_result = c_multi_return() 37 | t2 = time.time() 38 | c = t2-t1 39 | print('c speed:', c) 40 | print('speed up:', py / c) 41 | print('or slow down (more likely:', c / py) 42 | print('python result:', py_result) 43 | print('c result:', c_result) 44 | 45 | if __name__ == "__main__": 46 | compare(10000) 47 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # 'Tox' is a tool for automating sdist/build/test cycles against 2 | # multiple Python versions: 3 | # http://pypi.python.org/pypi/tox 4 | # http://tox.testrun.org/ 5 | 6 | # Running the command 'tox' while in the root of the weave source 7 | # directory will: 8 | # - Create a weave source distribution (setup.py sdist) 9 | # - Then for every supported version of Python: 10 | # - Create a virtualenv in {homedir}/.tox/weave/py$VERSION and 11 | # install dependencies. (These virtualenvs are cached across 12 | # runs unless you use --recreate.) 13 | # - Use pip to install the weave sdist into the virtualenv 14 | # - Run the weave tests 15 | # To run against a specific subset of Python versions, use: 16 | # tox -e py27 17 | 18 | # Extra arguments will be passed to runtests.py. To run the full testsuite: 19 | # tox full 20 | # To run with extra verbosity: 21 | # tox -- -v 22 | 23 | # Tox assumes that you have appropriate Python interpreters already 24 | # installed and that they can be run as 'python2.6', 'python2.7', etc. 25 | 26 | [tox] 27 | toxworkdir = {homedir}/.tox/weave/ 28 | envlist = py26,py27,py34 29 | 30 | [testenv] 31 | deps= 32 | nose 33 | numpy 34 | changedir={envdir} 35 | commands=python {toxinidir}/runtests.py -n -m full {posargs:} 36 | 37 | [pep8] 38 | max_line_length=79 39 | statistics = True 40 | ignore = E121,E122,E123,E125,E126,E127,E128,E226,E231,E265,E501,E712,W291,W293,W391 41 | -------------------------------------------------------------------------------- /weave/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | C/C++ integration for Python 3 | 4 | Main functions are:: 5 | 6 | inline -- a function for including C/C++ code within Python 7 | blitz -- a function for compiling Numeric expressions to C++ 8 | ext_tools -- a module that helps construct C/C++ extension modules. 9 | accelerate -- a module that inline accelerates Python functions 10 | 11 | 12 | .. note:: On Linux one needs to have the Python development headers installed 13 | in order to be able to compile things with the `weave` module. 14 | Since this is a runtime dependency these headers (typically in a 15 | pythonX.Y-dev package) are not always installed when installing 16 | weave. 17 | 18 | """ 19 | 20 | 21 | import sys 22 | 23 | from weave.version import version as __version__ 24 | 25 | from .blitz_tools import blitz, BlitzWarning 26 | from .inline_tools import inline 27 | from . import ext_tools 28 | from .ext_tools import ext_module, ext_function 29 | try: 30 | from .accelerate_tools import accelerate 31 | except: 32 | pass 33 | 34 | 35 | from numpy.testing import Tester 36 | test = Tester().test 37 | -------------------------------------------------------------------------------- /weave/_dumb_shelve.py: -------------------------------------------------------------------------------- 1 | from shelve import Shelf 2 | import collections 3 | try: 4 | import zlib 5 | except ImportError: 6 | zlib = None 7 | 8 | class ZlibMapping(collections.MutableMapping): 9 | """Mapping adapter that applies zlib compression. 10 | """ 11 | 12 | def __init__(self, dict): 13 | self.dict = dict 14 | if hasattr(dict, 'close'): 15 | self.close = dict.close 16 | if hasattr(dict, 'sync'): 17 | self.sync = dict.sync 18 | if hasattr(dict, 'keys'): 19 | self.keys = dict.keys 20 | 21 | def __iter__(self): 22 | return iter(self.dict) 23 | 24 | def __len__(self): 25 | return len(self.dict) 26 | 27 | def __contains__(self, key): 28 | return key in self.dict 29 | 30 | def __getitem__(self, key): 31 | return zlib.decompress(self.dict[key]) 32 | 33 | def __setitem__(self, key, value): 34 | self.dict[key] = zlib.compress(value) 35 | 36 | def __delitem__(self, key): 37 | del self.dict[key] 38 | 39 | 40 | def open(filename, flag='c'): 41 | """Open a persistent dictionary for reading and writing. 42 | 43 | The filename parameter is the base filename for the underlying 44 | database. As a side-effect, an extension may be added to the 45 | filename and more than one file may be created. The optional flag 46 | parameter has the same interpretation as the flag parameter of 47 | dbm.open(). 48 | """ 49 | writeback = False 50 | 51 | from . import _dumbdbm_patched 52 | d = _dumbdbm_patched.open(filename, flag) 53 | return Shelf(ZlibMapping(d) if zlib is not None else d) 54 | -------------------------------------------------------------------------------- /weave/blitz/blitz/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Written by Patrick Guio 3 | # 4 | 5 | SUBDIRS = generate meta array 6 | 7 | blitzdir = $(includedir)/blitz 8 | generatedir = ./generate 9 | 10 | genheaders = matbops.h mathfunc.h matuops.h promote-old.h vecbops.cc vecuops.cc vecwhere.cc 11 | 12 | blitz_HEADERS = applics.h array-impl.h array-old.h array.h bench.cc bench.h \ 13 | benchext.cc benchext.h blitz.h bzconfig.h bzdebug.h compiler.h \ 14 | etbase.h extremum.h funcs.h indexexpr.h limits-hack.h listinit.h \ 15 | matdiag.h matexpr.h matgen.h mathf2.h matltri.h matref.h matrix.cc \ 16 | matrix.h matsymm.h mattoep.h matutri.h memblock.cc memblock.h \ 17 | minmax.h mstruct.h numinquire.h numtrait.h ops.h prettyprint.h \ 18 | promote.h rand-dunif.h rand-mt.h rand-normal.h rand-tt800.h rand-uniform.h \ 19 | random.h randref.h range.h reduce.h shapecheck.h tau.h timer.h tiny.h \ 20 | tinymat.h tinymatexpr.h tinymatio.cc tinyvec-et.h tinyvec.cc tinyvec.h \ 21 | tinyvecio.cc tinyveciter.h traversal.cc traversal.h tuning.h tvcross.h \ 22 | tvecglobs.h update.h vecaccum.cc vecall.cc vecany.cc vecbfn.cc \ 23 | veccount.cc vecdelta.cc vecdot.cc vecexpr.h vecexprwrap.h vecglobs.cc \ 24 | vecglobs.h vecio.cc veciter.h vecmax.cc vecmin.cc vecnorm.cc vecnorm1.cc \ 25 | vecpick.cc vecpick.h vecpickio.cc vecpickiter.h vecsum.cc vector-et.h \ 26 | vector.cc vector.h vecwhere.h wrap-climits.h zero.cc zero.h $(genheaders) 27 | 28 | EXTRA_HEADERS = apple/bzconfig.h intel/bzconfig.h ibm/bzconfig.h \ 29 | compaq/bzconfig.h hp/bzconfig.h sgi/bzconfig.h gnu/bzconfig.h \ 30 | pgi/bzconfig.h pathscale/bzconfig.h kai/bzconfig.h fujitsu/bzconfig.h 31 | 32 | nobase_blitz_HEADERS = $(COMPILER_SPECIFIC_HEADER) 33 | 34 | DISTCLEANFILES = apple/bzconfig.h intel/bzconfig.h ibm/bzconfig.h \ 35 | compaq/bzconfig.h hp/bzconfig.h sgi/bzconfig.h gnu/bzconfig.h \ 36 | pgi/bzconfig.h pathscale/bzconfig.h kai/bzconfig.h fujitsu/bzconfig.h 37 | 38 | clean-local: 39 | -rm -rf config.h 40 | -------------------------------------------------------------------------------- /weave/blitz/blitz/README: -------------------------------------------------------------------------------- 1 | Blitz header file notes 2 | 3 | 1) Some matrix headers are included in this release, but only because 4 | the Benchmark class needs them. Their design is not yet stable, 5 | and they are untested, so use them at your own peril. 6 | 7 | 2) A compiler-specific header file with configuration settings is included 8 | from the master header file . The compiler-specific 9 | header file is selected on the basis of preprocessor symbols. Since some 10 | C++ compilers (notably the IBM XL compiler for Darwin and for AIX systems) 11 | do not define a unique preprocessor symbol, we have added a -D option in 12 | the autoconf macro AC_CXX_FLAGS_PRESET (see file m4/ac_cxx_flags_preset.m4). 13 | Thus, we use the option -D__APPLE with xlc++ and -D__IBM with xlC. 14 | Please note that any user code must also be compiled with the same -D option 15 | in order to be compiled successfully with one of these compilers. 16 | 17 | -------------------------------------------------------------------------------- /weave/blitz/blitz/array-old.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * blitz/array-old.h Maximal include version of Array 3 | * Note: see for the class def. 4 | * 5 | * $Id: array-old.h 1414 2005-11-01 22:04:59Z cookedm $ 6 | * 7 | * Copyright (C) 1997-2001 Todd Veldhuizen 8 | * 9 | * This code was relicensed under the modified BSD license for use in SciPy 10 | * by Todd Veldhuizen (see LICENSE.txt in the weave directory). 11 | * 12 | * 13 | * Suggestions: blitz-dev@oonumerics.org 14 | * Bugs: blitz-bugs@oonumerics.org 15 | * 16 | * For more information, please see the Blitz++ Home Page: 17 | * http://oonumerics.org/blitz/ 18 | * 19 | ***************************************************************************/ 20 | 21 | #ifndef BZ_ARRAY_OLD_H 22 | #define BZ_ARRAY_OLD_H 23 | 24 | /* 25 | * used to include most of the Blitz++ library 26 | * functionality, totally ~ 120000 lines of source code. This 27 | * made for extremely slow compile times; processing #include 28 | * took gcc about 25 seconds on a 500 MHz pentium box. 29 | * 30 | * Much of this compile time was due to the old vector expression templates 31 | * implementation. Since this is not really needed for the Array 32 | * class, the headers were redesigned so that: 33 | * 34 | * #include is the old-style include, pulls in most 35 | * of Blitz++ including vector e.t. 36 | * #include pulls in much less of the library, and 37 | * in particular excludes the vector e.t. code 38 | * 39 | * With , one gets TinyVector expressions automatically. 40 | * With , one must now also include 41 | * to get TinyVector expressions. 42 | * 43 | * The implementation of Array has been moved to . 44 | */ 45 | 46 | #include 47 | #include 48 | 49 | #endif // BZ_ARRAY_OLD_H 50 | 51 | -------------------------------------------------------------------------------- /weave/blitz/blitz/array.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * blitz/array.h Minimal include version of Array 3 | * 4 | * $Id: array.h 1414 2005-11-01 22:04:59Z cookedm $ 5 | * 6 | * Copyright (C) 1997-2000 Todd Veldhuizen 7 | * 8 | * This code was relicensed under the modified BSD license for use in SciPy 9 | * by Todd Veldhuizen (see LICENSE.txt in the weave directory). 10 | * 11 | * 12 | * Suggestions: blitz-dev@oonumerics.org 13 | * Bugs: blitz-bugs@oonumerics.org 14 | * 15 | * For more information, please see the Blitz++ Home Page: 16 | * http://oonumerics.org/blitz/ 17 | * 18 | ***************************************************************************/ 19 | 20 | #ifndef BZ_ARRAY_ONLY_H 21 | #define BZ_ARRAY_ONLY_H 22 | 23 | // See comments in for an explanation of the new 24 | // headers arrangement. 25 | 26 | #include 27 | 28 | #endif // BZ_ARRAY_ONLY_H 29 | 30 | -------------------------------------------------------------------------------- /weave/blitz/blitz/array/Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # Written by Patrick Guio 3 | # 4 | 5 | arraydir = $(includedir)/blitz/array 6 | generatedir = ../generate 7 | 8 | genheaders = bops.cc uops.cc 9 | 10 | array_HEADERS = asexpr.h cartesian.h cgsolve.h complex.cc \ 11 | convolve.cc convolve.h cycle.cc domain.h et.h eval.cc expr.h fastiter.h \ 12 | funcs.h functorExpr.h geometry.h indirect.h interlace.cc io.cc iter.h map.h \ 13 | methods.cc misc.cc multi.h newet-macros.h \ 14 | newet.h ops.cc ops.h reduce.cc reduce.h resize.cc shape.h slice.h slicing.cc \ 15 | stencil-et.h stencilops.h stencils.cc stencils.h storage.h where.h zip.h \ 16 | $(genheaders) 17 | 18 | $(genheaders): 19 | cd $(generatedir) ; $(MAKE) generate-headers 20 | 21 | -------------------------------------------------------------------------------- /weave/blitz/blitz/array/asexpr.h: -------------------------------------------------------------------------------- 1 | // -*- C++ -*- 2 | /*************************************************************************** 3 | * blitz/array/asexpr.h Declaration of the asExpr helper functions 4 | * 5 | * Copyright (C) 1997-2001 Todd Veldhuizen 6 | * 7 | * This code was relicensed under the modified BSD license for use in SciPy 8 | * by Todd Veldhuizen (see LICENSE.txt in the weave directory). 9 | * 10 | * 11 | * Suggestions: blitz-dev@oonumerics.org 12 | * Bugs: blitz-bugs@oonumerics.org 13 | * 14 | * For more information, please see the Blitz++ Home Page: 15 | * http://oonumerics.org/blitz/ 16 | * 17 | ***************************************************************************/ 18 | #ifndef BZ_ARRAYASEXPR_H 19 | #define BZ_ARRAYASEXPR_H 20 | 21 | #ifndef BZ_ARRAY_H 22 | #error must be included via 23 | #endif 24 | 25 | BZ_NAMESPACE(blitz) 26 | 27 | // The traits class asExpr converts arbitrary things to 28 | // expression templatable operands. 29 | 30 | // Default to scalar. 31 | 32 | template 33 | struct asExpr { 34 | typedef _bz_ArrayExprConstant T_expr; 35 | static T_expr getExpr(const T& x) { return T_expr(x); } 36 | }; 37 | 38 | // Already an expression template term 39 | 40 | template 41 | struct asExpr<_bz_ArrayExpr > { 42 | typedef _bz_ArrayExpr T_expr; 43 | static const T_expr& getExpr(const T_expr& x) { return x; } 44 | }; 45 | 46 | // An array operand 47 | 48 | template 49 | struct asExpr > { 50 | typedef FastArrayIterator T_expr; 51 | static T_expr getExpr(const Array& x) { return x.beginFast(); } 52 | }; 53 | 54 | // Index placeholder 55 | 56 | template 57 | struct asExpr > { 58 | typedef IndexPlaceholder T_expr; 59 | static T_expr getExpr(T_expr x) { return x; } 60 | }; 61 | 62 | #ifdef BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS 63 | 64 | // A traits class that provides the return type of a binary operation. 65 | 66 | template