forked from jakevdp/jakevdp.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index7.html
733 lines (671 loc) · 24.4 KB
/
index7.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="author" content="Jake VanderPlas">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<title>Home | Pythonic Perambulations</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<link rel="alternate" type="application/atom+xml" title="Pythonic Perambulations blog atom feed" href="/feeds/all.atom.xml" />
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="/theme/css/icons.css"/>
<style>.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #60a0b0; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #007020; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #007020 } /* Comment.Preproc */
.highlight .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
.highlight .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #808080 } /* Generic.Output */
.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0040D0 } /* Generic.Traceback */
.highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #007020 } /* Keyword.Pseudo */
.highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #902000 } /* Keyword.Type */
.highlight .m { color: #40a070 } /* Literal.Number */
.highlight .s { color: #4070a0 } /* Literal.String */
.highlight .na { color: #4070a0 } /* Name.Attribute */
.highlight .nb { color: #007020 } /* Name.Builtin */
.highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
.highlight .no { color: #60add5 } /* Name.Constant */
.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
.highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #007020 } /* Name.Exception */
.highlight .nf { color: #06287e } /* Name.Function */
.highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #bb60d5 } /* Name.Variable */
.highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #40a070 } /* Literal.Number.Float */
.highlight .mh { color: #40a070 } /* Literal.Number.Hex */
.highlight .mi { color: #40a070 } /* Literal.Number.Integer */
.highlight .mo { color: #40a070 } /* Literal.Number.Oct */
.highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
.highlight .sc { color: #4070a0 } /* Literal.String.Char */
.highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #4070a0 } /* Literal.String.Double */
.highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
.highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
.highlight .sx { color: #c65d09 } /* Literal.String.Other */
.highlight .sr { color: #235388 } /* Literal.String.Regex */
.highlight .s1 { color: #4070a0 } /* Literal.String.Single */
.highlight .ss { color: #517918 } /* Literal.String.Symbol */
.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
.highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
.highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
.highlight .il { color: #40a070 } /* Literal.Number.Integer.Long */</style>
<style>body {
margin: 0;
padding: 0;
font: 15px 'Source Sans Pro', sans-serif;
line-height: 1.6em;
color: #222;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
}
a {
color: #007EE5;
text-decoration: none;
}
a:hover {
color: #007EE5;
text-decoration: none;
}
header.main-header {
background: none repeat scroll 0% 0% #205F29;
margin-bottom: 0px;
}
header.main-header a {
color: #fff;
}
header.main-header .container {
max-width: 1000px;
}
header.main-header .container nav a:hover {
background-color: #5C881C;
}
article {
margin: 0;
}
article header.about {
margin-bottom: 0px;
padding-bottom: 0px;
}
article header {
margin-bottom: 20px;
padding-bottom: 20px;
}
article header h1 {
margin-bottom: 2px;
font-weight: 700;
color: #000;
}
article header time {
color: #9E9E9E;
font-size: 0.85em;
float: right;
}
article header time.left {
color: #9E9E9E;
font-size: 0.85em;
float: left;
}
article div.social-links ul {
padding: 0px;
}
article div.social-links li {
display: inline;
font-size: 20px;
}
article div.social-links li a {
color: #000;
padding: 10px;
}
article div.social-links li a:hover {
color: #666;
text-decoration: none;
}
article p {
font-size: 16px;
margin-bottom: 20px;
line-height: 1.6em;
}
article p.note {
background: #f5f5f5;
border: 1px solid #ddd;
padding: 0.533em 0.733em;
}
article p.update {
background-color: #FEEFB3;
border: 1px solid #e6e68a;
padding: 0.533em 0.733em;
}
article p.alert {
background-color: #ffe2e2;
border: 1px solid #ffb2b2;
padding: 0.533em 0.733em;
}
article ul,
article ol {
margin-top: 0px;
margin-bottom: 25px;
}
article li {
font-size: 16px;
line-height: 1.6em;
}
article a:hover {
text-decoration: underline;
}
article blockquote {
border-left: 2px solid #c7c7cc;
color: #666;
margin: 30px 0;
padding: 0 0 0 25px;
}
article img {
max-width: 100%;
}
article code {
color: #333;
background-color: #EEE;
border-radius: 0;
font-size: 13px;
}
article .meta {
font-size: 11px;
}
article .meta a:hover {
text-decoration: none;
}
article .meta div {
margin-bottom: 20px;
display: block;
}
article .meta a.tag {
margin: 0 10px 10px 0;
padding: 1px 12px;
display: inline-block;
font-size: 14px;
color: rgba(0, 0, 0, 0.8);
background: rgba(0, 0, 0, 0.05);
}
article .meta a.tag:hover {
background: rgba(0, 0, 0, 0.15);
}
article .meta a.read_more,
article .meta a.comments_btn {
font-size: 14px;
font-weight: 800;
padding: 10px 20px;
color: #205F29;
background: #FFF;
border: 1px solid #205F29;
}
article .meta a.read_more:hover,
article .meta a.comments_btn:hover {
color: #FFF;
background: #5C881C;
}
.index {
max-width: 700px;
}
.index article header h2 {
font-size: 36px;
margin-bottom: 2px;
font-weight: 700;
}
.index article header h2 a {
color: #000;
}
.index article header h2 a:hover {
color: #007EE5;
text-decoration: none;
}
.index .separator {
padding: 40px 0 0 0;
margin: 0 0 40px 0;
height: 10px;
border-bottom: solid 1px #CCC;
}
.index .pagination {
display: block;
margin-bottom: 100px;
}
.index .pagination .left {
text-align: right;
}
.index .pagination .right {
text-align: left;
}
.index .pagination a {
display: inline-block;
border: 2px solid #5C881C;
margin: 0 5px;
padding: 8px 20px;
font-weight: bold;
color: #5C881C;
}
.index .pagination a:hover {
color: #FFF;
background: #5C881C;
}
.post {
max-width: 700px;
}
.post h2:before {
content: "# ";
font-weight: bold;
color: #DDD;
}
.post h3:before {
content: "## ";
font-weight: bold;
color: #DDD;
}
.post h4:before {
content: "### ";
font-weight: bold;
color: #DDD;
}
.post article .meta {
margin: 50px 0 100px;
}
.list {
max-width: 700px;
}
.list ul.double-list {
margin: 0 auto 60px;
padding: 0;
list-style-type: none;
}
.list ul.double-list li {
padding: 5px 0;
}
.list ul.double-list li h2 {
font-size: 1em;
display: inline;
font-weight: normal;
}
.list ul.double-list li span {
font-family: sans-serif;
text-transform: uppercase;
text-align: right;
float: right;
padding-top: 3px;
font-size: 12px;
color: #999;
}
.full-width-content {
padding-top: 10px;
padding-left: 0px;
padding-right: 0px;
margin-left: -20px;
margin-right: -20px;
}
.col-xs-1,
.col-sm-1,
.col-md-1,
.col-lg-1,
.col-xs-2,
.col-sm-2,
.col-md-2,
.col-lg-2,
.col-xs-3,
.col-sm-3,
.col-md-3,
.col-lg-3,
.col-xs-4,
.col-sm-4,
.col-md-4,
.col-lg-4,
.col-xs-5,
.col-sm-5,
.col-md-5,
.col-lg-5,
.col-xs-6,
.col-sm-6,
.col-md-6,
.col-lg-6,
.col-xs-7,
.col-sm-7,
.col-md-7,
.col-lg-7,
.col-xs-8,
.col-sm-8,
.col-md-8,
.col-lg-8,
.col-xs-9,
.col-sm-9,
.col-md-9,
.col-lg-9,
.col-xs-10,
.col-sm-10,
.col-md-10,
.col-lg-10,
.col-xs-11,
.col-sm-11,
.col-md-11,
.col-lg-11,
.col-xs-12,
.col-sm-12,
.col-md-12,
.col-lg-12 {
padding-right: 0px;
padding-left: 0px;
}</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript"></script>
<script type="text/javascript">
init_mathjax = function() {
if (window.MathJax) {
// MathJax loaded
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
},
displayAlign: 'left', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}}
}
});
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
}
init_mathjax();
</script>
</head>
<body>
<header class="navbar navbar-inverse bs-docs-nav">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#theNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/" title="Home" class="title">Pythonic Perambulations</a>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation" id="theNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="/pages/about.html" title="About">About</a></li>
<li><a href="/archives.html" title="Archive">Archive</a></li>
<li><a class="nodec icon-rss" href="/feeds/all.atom.xml" title="jakevdp.github.io RSS feed" rel="me"></a></li>
</ul>
</nav>
</div>
</header>
<div id="wrap">
<div class="container index">
<article>
<header>
<h2><a href="http://jakevdp.github.io/blog/2012/09/12/dynamic-programming-in-python/">Dynamic Programming in Python: Bayesian Blocks</a></h2>
<time datetime="" title="2012-09-12T19:02:00-07:00" pubdate>Wed 12 September 2012</time>
</header>
<div class="article_content">
<p>Of all the programming styles I have learned,
<a href="http://en.wikipedia.org/wiki/Dynamic_programming">dynamic programming</a>
is perhaps the most beautiful. It can take problems that, at first glance,
look ugly and intractable, and solve the problem with clean, concise code.
Where a simplistic algorithm might accomplish something by brute force,
dynamic programming steps back, breaks the task into a smaller set of
sequential parts, and then proceeds in the most efficient way possible.</p>
<h3>Bayesian Blocks</h3>
<p>I'll go through an example here where the ideas of dynamic programming
are vital to some very cool data analysis resuts.
This post draws heavily from a recent
<a href="http://adsabs.harvard.edu/abs/2012arXiv1207.5578S">paper</a> by Jeff Scargle
and collaborators (this is the Scargle of <em>Lomb-Scargle Periodogram</em>
fame), as well as some conversations I had with Jeff at
<a href="http://www.astro.caltech.edu/ai12/">Astroinformatics 2012</a>.
The paper discusses
a framework called <em>Bayesian Blocks</em>, which is essentially a method of
creating histograms with bin sizes that adapt to the data (there's a bit
more to it than that: here we'll focus on histograms for simplicity).</p>
</div>
<div class="meta">
<div>
<a href="http://jakevdp.github.io/blog/2012/09/12/dynamic-programming-in-python/" class="read_more">Read more →</a>
</div>
<div>
<a href="http://jakevdp.github.io/tag/tutorial.html" class="tag">tutorial</a>
</div>
</div>
</article>
<div class="separator"></div>
<article>
<header>
<h2><a href="http://jakevdp.github.io/blog/2012/09/05/quantum-python/">Quantum Python: Animating the Schrodinger Equation</a></h2>
<time datetime="" title="2012-09-05T20:12:00-07:00" pubdate>Wed 05 September 2012</time>
</header>
<div class="article_content">
<p><em>Update: a reader contributed some improvements to the Python code presented
below. Please see the
<a href="https://github.com/jakevdp/pySchrodinger">pySchrodinger</a> github repository
for updated code</em></p>
<p>In a <a href="/blog/2012/08/18/matplotlib-animation-tutorial/">previous post</a>
I explored the new animation capabilities of the latest
<a href="http://matplotlib.sourceforge.net">matplotlib</a> release.
It got me wondering whether it would be possible to simulate more complicated
physical systems in real time in python. Quantum Mechanics was the first
thing that came to mind. It turns out that by mixing a bit of Physics
knowledge with a bit of computing knowledge, it's quite straightforward
to simulate and animate a simple quantum mechanical system with python.</p>
<h2>The Schrodinger Equation</h2>
<p>The dynamics of a one-dimensional quantum system are governed by the
time-dependent Schrodinger equation:</p>
<p>$$
i\hbar\frac{\partial \psi}{\partial t}
= \frac{-\hbar^2}{2m} \frac{\partial^2 \psi}{\partial x^2} + V \psi
$$</p>
</div>
<div class="meta">
<div>
<a href="http://jakevdp.github.io/blog/2012/09/05/quantum-python/" class="read_more">Read more →</a>
</div>
<div>
<a href="http://jakevdp.github.io/tag/matplotlib.html" class="tag">matplotlib</a>
<a href="http://jakevdp.github.io/tag/animation.html" class="tag">animation</a>
<a href="http://jakevdp.github.io/tag/simulation.html" class="tag">simulation</a>
</div>
</div>
</article>
<div class="separator"></div>
<article>
<header>
<h2><a href="http://jakevdp.github.io/blog/2012/08/24/numba-vs-cython/">Numba vs Cython</a></h2>
<time datetime="" title="2012-08-24T10:41:00-07:00" pubdate>Fri 24 August 2012</time>
</header>
<div class="article_content">
<p><em>For a more up-to-date comparison of Numba and Cython, see the</em>
<a href="http://jakevdp.github.io/blog/2013/06/15/numba-vs-cython-take-2/"><em>newer post</em></a>
<em>on this subject.</em></p>
<p>Often I'll tell people that I use python for computational analysis, and they
look at me inquisitively. "Isn't python pretty slow?" They have a point.
Python is an interpreted language, and as such cannot natively perform
many operations as quickly as a compiled language such as C or Fortran.
There is also the issue of the oft-misunderstood and much-maligned
<a href="http://wiki.python.org/moin/GlobalInterpreterLock">GIL</a>,
which calls into question python's ability to allow true parallel computing.</p>
<p>Many solutions have been proposed: <a href="http://pypy.org/">PyPy</a> is a much faster
version of the core python language;
<a href="http://code.google.com/p/numexpr/">numexpr</a> provides optimized performance
on certain classes of operations from within python;
<a href="http://www.scipy.org/Weave/">weave</a> allows inline inclusion of compiled
C/C++ code;
<a href="http://www.cython.org/">cython</a> provides extra markup that allows python
and/or python-like code to be compiled into C for fast operations. But
a naysayer might point out: many of these "python" solutions in practice
are not really python at all, but clever hacks into Fortran or C.</p>
</div>
<div class="meta">
<div>
<a href="http://jakevdp.github.io/blog/2012/08/24/numba-vs-cython/" class="read_more">Read more →</a>
</div>
<div>
<a href="http://jakevdp.github.io/tag/numba.html" class="tag">numba</a>
<a href="http://jakevdp.github.io/tag/cython.html" class="tag">cython</a>
<a href="http://jakevdp.github.io/tag/benchmarks.html" class="tag">benchmarks</a>
</div>
</div>
</article>
<div class="separator"></div>
<article>
<header>
<h2><a href="http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/">Matplotlib Animation Tutorial</a></h2>
<time datetime="" title="2012-08-18T08:01:00-07:00" pubdate>Sat 18 August 2012</time>
</header>
<div class="article_content">
<p><a href="http://matplotlib.sourceforge.net">Matplotlib</a> version 1.1 added some tools
for creating
<a href="http://matplotlib.sourceforge.net/api/animation_api.html">animations</a>
which are really slick. You can find some good example animations on
the matplotlib
<a href="http://matplotlib.sourceforge.net/examples/animation/index.html">examples</a>
page. I thought I'd share here some of the things I've learned when playing
around with these tools.</p>
<h3>Basic Animation</h3>
<p>The animation tools center around the <code>matplotlib.animation.Animation</code> base
class, which provides a framework around which the animation functionality
is built. The main interfaces are <code>TimedAnimation</code> and <code>FuncAnimation</code>,
which you can read more about in the
<a href="http://matplotlib.sourceforge.net/api/animation_api.html">documentation</a>.
Here I'll explore using the <code>FuncAnimation</code> tool, which I have found
to be the most useful.</p>
</div>
<div class="meta">
<div>
<a href="http://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/" class="read_more">Read more →</a>
</div>
<div>
<a href="http://jakevdp.github.io/tag/matplotlib.html" class="tag">matplotlib</a>
<a href="http://jakevdp.github.io/tag/animation.html" class="tag">animation</a>
<a href="http://jakevdp.github.io/tag/tutorial.html" class="tag">tutorial</a>
<a href="http://jakevdp.github.io/tag/simulation.html" class="tag">simulation</a>
</div>
</div>
</article>
<div class="separator"></div>
<article>
<header>
<h2><a href="http://jakevdp.github.io/blog/2012/08/16/memoryview-benchmarks-2/">Memoryview Benchmarks 2</a></h2>
<time datetime="" title="2012-08-16T14:19:00-07:00" pubdate>Thu 16 August 2012</time>
</header>
<div class="article_content">
<p>In the <a href="/blog/2012/08/08/memoryview-benchmarks/">previous post</a>, I explored
how cython typed memoryviews can be used to speed up repeated array
operations. It became clear that typed memoryviews are superior to
the ndarray syntax for slicing, and as fast as raw pointers for single
element access. In the comments, Mathieu brought up an interesting
question: is the ndarray syntax as good as typed memoryviews if you're
not doing slicing?</p>
<p>The answer turns out to be yes, <em>unless</em> the compiler tries to inline your
function.</p>
</div>
<div class="meta">
<div>
<a href="http://jakevdp.github.io/blog/2012/08/16/memoryview-benchmarks-2/" class="read_more">Read more →</a>
</div>
<div>
<a href="http://jakevdp.github.io/tag/numpy.html" class="tag">numpy</a>
<a href="http://jakevdp.github.io/tag/cython.html" class="tag">cython</a>
<a href="http://jakevdp.github.io/tag/benchmarks.html" class="tag">benchmarks</a>
<a href="http://jakevdp.github.io/tag/memoryviews.html" class="tag">memoryviews</a>
</div>
</div>
</article>
<div class="separator"></div>
<article>
<header>
<h2><a href="http://jakevdp.github.io/blog/2012/08/08/memoryview-benchmarks/">Memoryview Benchmarks</a></h2>
<time datetime="" title="2012-08-08T18:50:00-07:00" pubdate>Wed 08 August 2012</time>
</header>
<div class="article_content">
<p>There was recently a <a href="https://groups.google.com/forum/?fromgroups#!topic/cython-users/8uuxjB_wbBQ[1-25]" title="cython-users archive">thread</a>
on cython-users which caught my eye. It has to do with
<a href="http://docs.cython.org/src/userguide/memoryviews.html">memoryviews</a>, a new
way of working with memory buffers in cython.</p>
<p>I've been thinking recently about how to do fast
and flexible memory buffer access in cython. I contributed the
<a href="http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.BallTree.html">BallTree</a>
implementation for nearest neighbors searching in
<a href="http://www.scikit-learn.org">scikit-learn</a>, and have been actively thinking
about how to make it faster and more flexible, including adding the ability
to specify distance metrics other than euclidean and minkowski.</p>
<p>In order to accomplish this, I'd like to have a set of distance metric
functions which take two vectors and compute a distance. There would
be many functions with similar call signatures which could then be
plugged into a code that would iterate over a set of vectors and
compute the appropriate distances.</p>
</div>
<div class="meta">
<div>
<a href="http://jakevdp.github.io/blog/2012/08/08/memoryview-benchmarks/" class="read_more">Read more →</a>
</div>
<div>
<a href="http://jakevdp.github.io/tag/benchmarks.html" class="tag">benchmarks</a>
<a href="http://jakevdp.github.io/tag/numpy.html" class="tag">numpy</a>
<a href="http://jakevdp.github.io/tag/cython.html" class="tag">cython</a>
</div>
</div>
</article>
<div class="separator"></div>
<nav class="pagination row">
<div class="col-xs-6 left">
</div>
<div class="col-xs-6 right">
<a class="next" href="http://jakevdp.github.io/index6.html">Future →</a>
</div>
</nav>
</div>
</div>
</div>
<!--
<footer>
<p>
© 2012-2017 Jake VanderPlas, license <a href="https://github.com/jakevdp/jakevdp.github.io-source/blob/master/LICENSE"> </a>
unless otherwise noted.
Generated by <a href= "http://docs.getpelican.com/">Pelican</a>.
</p>
</footer>
-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-34061646-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-34061646-1');
ga('send', 'pageview');
</script>
</body>
</html>