Skip to content

Commit

Permalink
Integrate C++ objects with NumPy arrays via Python buffer protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Jun 14, 2017
1 parent f49e537 commit 48e3925
Show file tree
Hide file tree
Showing 16 changed files with 1,283 additions and 98 deletions.
3 changes: 2 additions & 1 deletion doc/conf.py
Expand Up @@ -44,7 +44,8 @@
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'IPython.sphinxext.ipython_console_highlighting',
'IPython.sphinxext.ipython_directive']
'IPython.sphinxext.ipython_directive',
'nbsphinx']
#'breathe']

#if (os.environ.get('READTHEDOCS')=="True") is False:
Expand Down
3 changes: 2 additions & 1 deletion doc/conf.py.in
Expand Up @@ -44,7 +44,8 @@ extensions = ['sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'IPython.sphinxext.ipython_console_highlighting',
'IPython.sphinxext.ipython_directive']
'IPython.sphinxext.ipython_directive',
'nbsphinx']
#'breathe']

#if (os.environ.get('READTHEDOCS')=="True") is False:
Expand Down
1 change: 1 addition & 0 deletions doc/environment.yml
Expand Up @@ -10,6 +10,7 @@ dependencies:
- python==3.5
- sphinx_rtd_theme==0.1.9
- gsl
- nbsphinx
- pip:
- numpy
- matplotlib
Expand Down
16 changes: 8 additions & 8 deletions doc/examples/DataMatrix.rst
@@ -1,3 +1,5 @@
.. _datamatrix:

Representing samples from a population in matrix form
====================================================================================

Expand Down Expand Up @@ -30,6 +32,7 @@ The following example is a tour of the API:

import fwdpy11 as fp11
import fwdpy11.wright_fisher as wf
import fwdpy11.model_params
import fwdpy11.sampling
import numpy as np
import pickle
Expand Down Expand Up @@ -89,17 +92,13 @@ The following example is a tour of the API:

print(type(dm))

#Get the neutral genotypes out as a numpy array
n = dm.neutral()
#Get the neutral genotypes out as a 2d 2d numpy array
n = np.ndarray(dm.ndim_neutral(),buffer=dm.neutral,dtype=np.int8)
print(type(n))
print(n.dtype)

#n is a 1d array, and we want a 2d array
#with rows as individuals and columns
#as sites
n = np.reshape(n,(dm.nrow,dm.ncol_neutral()))
print(n.ndim)
#This must be pop.N = 1,000:
print(dm.nrow)
print(n.shape[0])

#finally, the DataMatrix is picklable
#As always with fwdpy11 types,
Expand All @@ -117,4 +116,5 @@ The output of the above code is:
<class 'fwdpy11.sampling.DataMatrix'>
<class 'numpy.ndarray'>
int8
2
1000
1 change: 1 addition & 0 deletions doc/examples/pickling.rst
Expand Up @@ -36,6 +36,7 @@ In order to pickle a file, you must also use the latest pickling protocol.
import fwdpy11 as fp11
import fwdpy11.wright_fisher as wf
import fwdpy11.ezparams
import fwdpy11.model_params
import numpy as np
import pickle

Expand Down
1 change: 1 addition & 0 deletions doc/examples/processingpops.rst
Expand Up @@ -19,6 +19,7 @@ First, we'll quickly simulate a single deme for `N` generations:
import fwdpy11.fitness
import fwdpy11.model_params
import fwdpy11.ezparams
import fwdpy11.wright_fisher
import numpy as np

rng = fwdpy11.GSLrng(42)
Expand Down
7 changes: 7 additions & 0 deletions doc/index.rst
Expand Up @@ -45,6 +45,13 @@ Welcome to fwdpy11's documentation!
examples/qtrait
examples/processingpops

.. toctree::
:caption: Maximizing performance
:maxdepth: 1

performance/processingpops_np
performance/UsingCython.ipynb

.. toctree::
:caption: Advanced topics and examples
:maxdepth: 1
Expand Down

0 comments on commit 48e3925

Please sign in to comment.