[Yt-svn] commit/yt-doc: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Mar 4 11:40:35 PST 2011
2 new changesets in yt-doc:
http://bitbucket.org/yt_analysis/yt-doc/changeset/10b316fcec6c/
changeset: r32:10b316fcec6c
user: MatthewTurk
date: 2011-03-04 19:38:49
summary: Adding a complete example for external code.
affected #: 6 files (2.8 KB)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/advanced/_static/axes.c Fri Mar 04 13:38:49 2011 -0500
@@ -0,0 +1,15 @@
+#include "axes.h"
+
+void calculate_axes(ParticleCollection *part,
+ double *ax1, double *ax2, double *ax3)
+{
+ int i;
+ for (i = 0; i < part->npart; i++) {
+ if (ax1[0] > part->xpos[i]) ax1[0] = part->xpos[i];
+ if (ax2[0] > part->ypos[i]) ax2[0] = part->ypos[i];
+ if (ax3[0] > part->zpos[i]) ax3[0] = part->zpos[i];
+ if (ax1[1] < part->xpos[i]) ax1[1] = part->xpos[i];
+ if (ax2[1] < part->ypos[i]) ax2[1] = part->ypos[i];
+ if (ax3[1] < part->zpos[i]) ax3[1] = part->zpos[i];
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/advanced/_static/axes.h Fri Mar 04 13:38:49 2011 -0500
@@ -0,0 +1,10 @@
+typedef struct structParticleCollection {
+ long npart;
+ double *xpos;
+ double *ypos;
+ double *zpos;
+} ParticleCollection;
+
+void calculate_axes(ParticleCollection *part,
+ double *ax1, double *ax2, double *ax3);
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/advanced/_static/axes_calculator.pyx Fri Mar 04 13:38:49 2011 -0500
@@ -0,0 +1,37 @@
+import numpy as np
+cimport numpy as np
+cimport cython
+from stdlib cimport malloc, free
+
+cdef extern from "axes.h":
+ ctypedef struct ParticleCollection:
+ long npart
+ double *xpos
+ double *ypos
+ double *zpos
+
+ void calculate_axes(ParticleCollection *part,
+ double *ax1, double *ax2, double *ax3)
+
+def examine_axes(np.ndarray[np.float64_t, ndim=1] xpos,
+ np.ndarray[np.float64_t, ndim=1] ypos,
+ np.ndarray[np.float64_t, ndim=1] zpos):
+ cdef double ax1[3], ax2[3], ax3[3]
+ cdef ParticleCollection particles
+ cdef int i
+
+ particles.npart = len(xpos)
+ particles.xpos = <double *> xpos.data
+ particles.ypos = <double *> ypos.data
+ particles.zpos = <double *> zpos.data
+
+ for i in range(particles.npart):
+ particles.xpos[i] = xpos[i]
+ particles.ypos[i] = ypos[i]
+ particles.zpos[i] = zpos[i]
+
+ calculate_axes(&particles, ax1, ax2, ax3)
+
+ return ( (ax1[0], ax1[1], ax1[2]),
+ (ax2[0], ax2[1], ax2[2]),
+ (ax3[0], ax3[1], ax3[2]) )
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/advanced/_static/axes_calculator_setup.py.txt Fri Mar 04 13:38:49 2011 -0500
@@ -0,0 +1,25 @@
+NAME = "axes_calculator"
+EXT_SOURCES = ["axes.c"]
+EXT_LIBRARIES = []
+EXT_LIBRARY_DIRS = []
+EXT_INCLUDE_DIRS = []
+DEFINES = []
+
+from distutils.core import setup
+from distutils.extension import Extension
+from Cython.Distutils import build_ext
+
+ext_modules = [Extension(NAME,
+ [NAME+".pyx"] + EXT_SOURCES,
+ libraries = EXT_LIBRARIES,
+ library_dirs = EXT_LIBRARY_DIRS,
+ include_dirs = EXT_INCLUDE_DIRS,
+ define_macros = DEFINES)
+]
+
+setup(
+ name = NAME,
+ cmdclass = {'build_ext': build_ext},
+ ext_modules = ext_modules
+)
+
--- a/source/advanced/external_analysis.rst Fri Mar 04 03:07:24 2011 -0500
+++ b/source/advanced/external_analysis.rst Fri Mar 04 13:38:49 2011 -0500
@@ -77,7 +77,7 @@
Our Example Code
++++++++++++++++
-Here is the ``.h`` file in our imaginary code, which we will then wrap:
+Here is the ``axes.h`` file in our imaginary code, which we will then wrap:
.. code-block:: c
@@ -108,7 +108,7 @@
To get started, we'll need to create two files:
-.. code-block::
+.. code-block:: bash
axes_calculator.pyx
axes_calculator_setup.py
@@ -126,7 +126,7 @@
NAME = "axes_calculator"
EXT_SOURCES = []
- EXT_LIBRARIES = ["axes_calculator", "m"]
+ EXT_LIBRARIES = ["axes_utils", "m"]
EXT_LIBRARY_DIRS = ["/home/rincewind/axes_calculator/"]
EXT_INCLUDE_DIRS = []
DEFINES = []
@@ -136,7 +136,7 @@
from Cython.Distutils import build_ext
ext_modules = [Extension(NAME,
- [NAME+".pyx"] + ADDITIONAL_SOURCES,
+ [NAME+".pyx"] + EXT_SOURCES,
libraries = EXT_LIBRARIES,
library_dirs = EXT_LIBRARY_DIRS,
include_dirs = EXT_INCLUDE_DIRS,
@@ -212,7 +212,7 @@
import numpy as np
cimport numpy as np
cimport cython
- from stdlib import malloc, free
+ from stdlib cimport malloc, free
These lines simply import and "Cython import" some common routines. For more
information about what is already available, see the Cython documentation. For
@@ -274,7 +274,7 @@
particles.ypos[i] = ypos[i]
particles.zpos[i] = zpos[i]
- calculate_axes(particles, ax1, ax2, ax3)
+ calculate_axes(&particles, ax1, ax2, ax3)
free(particles.xpos)
free(particles.ypos)
@@ -309,9 +309,9 @@
.. code-block:: cython
- def examine_axes(np.ndarray[np.float64_t, dim=1] xpos,
- np.ndarray[np.float64_t, dim=1] ypos,
- np.ndarray[np.float64_t, dim=1] zpos):
+ def examine_axes(np.ndarray[np.float64_t, ndim=1] xpos,
+ np.ndarray[np.float64_t, ndim=1] ypos,
+ np.ndarray[np.float64_t, ndim=1] zpos):
cdef double ax1[3], ax2[3], ax3[3]
cdef ParticleCollection particles
cdef int i
@@ -326,7 +326,7 @@
particles.ypos[i] = ypos[i]
particles.zpos[i] = zpos[i]
- calculate_axes(particles, ax1, ax2, ax3)
+ calculate_axes(&particles, ax1, ax2, ax3)
free(particles.xpos)
free(particles.ypos)
@@ -343,9 +343,9 @@
.. code-block:: cython
- def examine_axes(np.ndarray[np.float64_t, dim=1] xpos,
- np.ndarray[np.float64_t, dim=1] ypos,
- np.ndarray[np.float64_t, dim=1] zpos):
+ def examine_axes(np.ndarray[np.float64_t, ndim=1] xpos,
+ np.ndarray[np.float64_t, ndim=1] ypos,
+ np.ndarray[np.float64_t, ndim=1] zpos):
cdef double ax1[3], ax2[3], ax3[3]
cdef ParticleCollection particles
cdef int i
@@ -360,7 +360,7 @@
particles.ypos[i] = ypos[i]
particles.zpos[i] = zpos[i]
- calculate_axes(particles, ax1, ax2, ax3)
+ calculate_axes(&particles, ax1, ax2, ax3)
return ( (ax1[0], ax1[1], ax1[2]),
(ax2[0], ax2[1], ax2[2]),
@@ -373,6 +373,15 @@
was pretty easy! Let us know if you run into any problems, or if you are
interested in distributing your code with yt.
+A complete set of files is available with this documentation. These are
+slightly different, so that the whole thing will simply compile, but they
+provide a useful example.
+
+ * `axes.c <../_static/axes.c>`_
+ * `axes.h <../_static/axes.h>`_
+ * `axes_calculator.pyx <../_static/axes_calculator.pyx>`_
+ * `axes_calculator_setup.py <../_static/axes_calculator_setup.py.txt>`_
+
Exporting Data from yt
----------------------
--- a/source/conf.py Fri Mar 04 03:07:24 2011 -0500
+++ b/source/conf.py Fri Mar 04 13:38:49 2011 -0500
@@ -138,7 +138,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+html_static_path = ['_static', 'advanced/_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
http://bitbucket.org/yt_analysis/yt-doc/changeset/730e69398699/
changeset: r33:730e69398699
user: MatthewTurk
date: 2011-03-04 20:40:30
summary: Moving around the axes_calculator_setup.py.txt file to avoid problems on the
server side.
affected #: 3 files (603 bytes)
--- a/source/advanced/_static/axes_calculator_setup.py.txt Fri Mar 04 13:38:49 2011 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-NAME = "axes_calculator"
-EXT_SOURCES = ["axes.c"]
-EXT_LIBRARIES = []
-EXT_LIBRARY_DIRS = []
-EXT_INCLUDE_DIRS = []
-DEFINES = []
-
-from distutils.core import setup
-from distutils.extension import Extension
-from Cython.Distutils import build_ext
-
-ext_modules = [Extension(NAME,
- [NAME+".pyx"] + EXT_SOURCES,
- libraries = EXT_LIBRARIES,
- library_dirs = EXT_LIBRARY_DIRS,
- include_dirs = EXT_INCLUDE_DIRS,
- define_macros = DEFINES)
-]
-
-setup(
- name = NAME,
- cmdclass = {'build_ext': build_ext},
- ext_modules = ext_modules
-)
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source/advanced/_static/axes_calculator_setup.txt Fri Mar 04 14:40:30 2011 -0500
@@ -0,0 +1,25 @@
+NAME = "axes_calculator"
+EXT_SOURCES = ["axes.c"]
+EXT_LIBRARIES = []
+EXT_LIBRARY_DIRS = []
+EXT_INCLUDE_DIRS = []
+DEFINES = []
+
+from distutils.core import setup
+from distutils.extension import Extension
+from Cython.Distutils import build_ext
+
+ext_modules = [Extension(NAME,
+ [NAME+".pyx"] + EXT_SOURCES,
+ libraries = EXT_LIBRARIES,
+ library_dirs = EXT_LIBRARY_DIRS,
+ include_dirs = EXT_INCLUDE_DIRS,
+ define_macros = DEFINES)
+]
+
+setup(
+ name = NAME,
+ cmdclass = {'build_ext': build_ext},
+ ext_modules = ext_modules
+)
+
--- a/source/advanced/external_analysis.rst Fri Mar 04 13:38:49 2011 -0500
+++ b/source/advanced/external_analysis.rst Fri Mar 04 14:40:30 2011 -0500
@@ -380,7 +380,7 @@
* `axes.c <../_static/axes.c>`_
* `axes.h <../_static/axes.h>`_
* `axes_calculator.pyx <../_static/axes_calculator.pyx>`_
- * `axes_calculator_setup.py <../_static/axes_calculator_setup.py.txt>`_
+ * `axes_calculator_setup.py <../_static/axes_calculator_setup.txt>`_
Exporting Data from yt
----------------------
Repository URL: https://bitbucket.org/yt_analysis/yt-doc/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list