Skip to content

Commit

Permalink
Merge pull request #83 from mbeyeler/mb/cython
Browse files Browse the repository at this point in the history
[MRG] Cython implementation of Nanduri et al. (2012)
  • Loading branch information
arokem committed Mar 27, 2018
2 parents 2787cef + 75d3883 commit 7333062
Show file tree
Hide file tree
Showing 10 changed files with 899 additions and 88 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ before_install:

install:
- travis_wait
- python setup.py install --record installed_files.txt
- pip install -r requirements.txt
- pip install -e .

script:
- flake8 --ignore E501 `find . -name \*.py | grep -v setup.py | grep -v version.py | grep -v __init__.py | grep -v /doc/ | grep -v /scripts/`
Expand All @@ -56,4 +57,4 @@ after_success:
after failure:
- ls -alh
- ulimit -a
- free -m
- free -m
40 changes: 25 additions & 15 deletions examples/notebooks/0.0-example-usage.ipynb

Large diffs are not rendered by default.

167 changes: 167 additions & 0 deletions examples/notebooks/compare-nanduri-naive-cython.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mbeyeler/anaconda3/lib/python3.5/site-packages/skvideo/__init__.py:356: UserWarning: avconv/avprobe not found in path: \n",
" warnings.warn(\"avconv/avprobe not found in path: \" + str(path), UserWarning)\n",
"2017-10-31 22:03:23,168 [pulse2percept] [INFO] Welcome to pulse2percept\n"
]
}
],
"source": [
"import numpy as np\n",
"import pulse2percept as p2p"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"tsample = 0.005 / 1000\n",
"stim = p2p.stimuli.PulseTrain(tsample, freq=20, amp=50, pulse_dur=0.45 / 1000, dur=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"old_model = p2p.retina.Nanduri2012(tsample=tsample)\n",
"new_model = p2p.retina.NanduriCython(tsample=tsample)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"layers = ['OFL']\n",
"use_jit = True\n",
"in_arr = np.array([1, 1], dtype=np.float).reshape((2, 1))"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"old_out = old_model.model_cascade(in_arr, [stim.data], layers, use_jit)\n",
"new_out = new_model.model_cascade(in_arr, [stim.data], layers, use_jit)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.allclose(old_out.data, new_out.data)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%load_ext line_profiler"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mbeyeler/anaconda3/lib/python3.5/site-packages/line_profiler.py:294: UserWarning: Could not extract a code object for the object <class 'pulse2percept.retina.Nanduri2012'>\n",
" profile = LineProfiler(*funcs)\n"
]
}
],
"source": [
"%lprun -f p2p.retina.Nanduri2012 old_model.model_cascade(in_arr, [stim.data], layers, use_jit)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"585 ms ± 7.93 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
"source": [
"%timeit new_model.model_cascade(in_arr, [stim.data], layers, use_jit)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 7333062

Please sign in to comment.