<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RoBlog</title>
	<atom:link href="http://robpatro.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://robpatro.com/blog</link>
	<description>Thoughts and musings on science and life</description>
	<lastBuildDate>Thu, 08 Mar 2012 04:29:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Macports, Git and HTTPS</title>
		<link>http://robpatro.com/blog/?p=78</link>
		<comments>http://robpatro.com/blog/?p=78#comments</comments>
		<pubDate>Tue, 17 May 2011 13:02:46 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=78</guid>
		<description><![CDATA[My university recently started providing Git hosting over Smart HTTPS.  Previously, they only provided subversion hosting.  I&#8217;ve used git for around 2 years now, so this is great news for me, and I asked them to create a repository for &#8230; <a href="http://robpatro.com/blog/?p=78">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My university recently started providing Git hosting over Smart HTTPS.  Previously, they only provided subversion hosting.  I&#8217;ve used git for around 2 years now, so this is great news for me, and I asked them to create a repository for my latest project.  I try to clone the (empty) repository and . . . failure!  It seems as though git failed to authenticate with the server, even though I provided valid credentials and had the appropriate certificates installed.  This failure occurs on my MacBook Pro, so I quickly logged into one of the university machines and tried.  Much to my surprise it everything works from their machines.</p>
<p>So I spent some time hunting down the differences.  The most substantial difference was the version of curl and OpenSSL being used.  Mine were much newer.  After a few hours of searching online, I came to the conclusion that OpenSSL was at fault here.  On a hunch, I resolved my issue by reinstalling curl, but this time with [+gnutls] instead of openssl (the default).  So if you&#8217;re having issues dealing with Smart HTTPS hosted repositories using a new version of git (particularly if you are on OSX), then give this solution a try.  Hopefully it will save you some time, as I couldn&#8217;t find this solution anywhere else.</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=78</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ugly Scala corner case</title>
		<link>http://robpatro.com/blog/?p=73</link>
		<comments>http://robpatro.com/blog/?p=73#comments</comments>
		<pubDate>Mon, 14 Mar 2011 13:26:29 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=73</guid>
		<description><![CDATA[Eww. I ran into this little wart in the Scala language this morning.  Thank goodness that StackOverflow had an answer, or the frustration might have continued a while longer.   Basically, the wart deals with tuple unwrapping (or matching if &#8230; <a href="http://robpatro.com/blog/?p=73">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Eww.  I ran into <a href="http://stackoverflow.com/questions/2727612/scalas-tuple-unwrapping-nuance">this</a> little wart in the Scala language this morning.  Thank goodness that StackOverflow had an answer, or the frustration might have continued a while longer.   Basically, the wart deals with tuple unwrapping (or matching if you prefer that terminology).  Say that I have some very simple function f that looks like:</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> f <span style="color: #000080;">:</span> <span style="color: #F78811;">&#40;</span>Int, Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> <a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">return</span></a> <span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span>,<span style="color: #F78811;">2</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#125;</span></div></div>
<p>now, in some other piece of code, I want to call f and assign the result to a tuple.</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> <span style="color: #F78811;">&#40;</span>Res1, Res2<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> f</div></div>
<p>but wait; Scala complains about this code!  You&#8217;ll get the following:</p>
<blockquote><p>error: not found: value Res1<br />
error: not found: value Res2</p></blockquote>
<p>But why?  The source of the error is that Res1 and Res2 begin with capital letters.  Thus, when Scala tries to assign the tuple elements by means of pattern matching, it assumes that Res1 and Res2 are previously defined constants, not new values (despite the val annotation in front of them).  It&#8217;s fairly easy to correct this; just write</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> <span style="color: #F78811;">&#40;</span>res1, res2<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> f</div></div>
<p>and you&#8217;ll get the expected behavior.  However, this seems to me to be a little bit of a wart in the language.  Scala is, in my opinion, a beautiful and incredibly expressive language.  However, little things like this often remind me that there  are still a lot of improvements to be made, and often the little things count.</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=73</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python Hatchlings part 0</title>
		<link>http://robpatro.com/blog/?p=68</link>
		<comments>http://robpatro.com/blog/?p=68#comments</comments>
		<pubDate>Tue, 30 Nov 2010 02:29:10 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=68</guid>
		<description><![CDATA[So my labmate recently wrote a very nice blog post comparing some different solutions for speeding up Python code. The solutions he explored are either replacement interpreters, (restricted) python -> vm bytecode compilers, or (restricted) python -> C++ compilers. Some &#8230; <a href="http://robpatro.com/blog/?p=68">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So my <a href="http://www.dailyfungus.com">labmate</a> recently wrote a very nice <a href="http://geetduggal.wordpress.com/2010/11/25/speed-up-your-python-unladen-vs-shedskin-vs-pypy-vs-c/">blog post</a> comparing some different solutions for speeding up Python code.  The solutions he explored are either replacement interpreters, (restricted) python -> vm bytecode compilers, or (restricted) python -> C++ compilers.  Some of these solutions look very promising.  However, they are not all mature yet, and most only support a subset of the current language.  I recently had a need to speed up some multithreaded python code that I had written, and in the process, I learned a bit about improving the performance of Python itself (i.e. not replacing the interpreter/bytecode compiler).</p>
<p>In particular, there are two changes that significantly sped up my code; converting <strong>while</strong> loops to <strong>for</strong> loops, and replacing list comprehensions with conditional guards with filter statements.  So the first of these improvements is rather obvious in retrospect, as a for loop can be unrolled somewhat, whereas the condition guard on the while loop must be re-evaluated by the interpreter for every loop iteration.  However, what was not obvious at first was how to convert my while loop to a for loop.  The loop in question traverses the edges in a tree from an internal node until it reaches the root.  My initial code looked something like this:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> pathToRoot<span style="color: black;">&#40;</span>G<span style="color: #66cc66;">,</span> n<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; path <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>n<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>G.<span style="color: black;">predecessors</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; pred <span style="color: #66cc66;">=</span> G..<span style="color: black;">predecessors</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; path.<span style="color: black;">append</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; n <span style="color: #66cc66;">=</span> pred<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> path</div></div>
<p>Simple enough, right?  So how do we turn this into a for loop?  The solution upon which I settled was to make an initial pass over the tree and to label each node with its depth.  Therefore, for an arbitrary node n, n['depth'] holds the number of predecessors I must traverse to reach the root.  This allows the above code to be written as:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">def</span> pathToRoot<span style="color: black;">&#40;</span>G<span style="color: #66cc66;">,</span> n<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; path <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span>n<span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; ndepth <span style="color: #66cc66;">=</span> n<span style="color: black;">&#91;</span><span style="color: #483d8b;">'depth'</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span>ndepth<span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; &nbsp; &nbsp; pred <span style="color: #66cc66;">=</span> G..<span style="color: black;">predecessors</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; path.<span style="color: black;">append</span><span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; n <span style="color: #66cc66;">=</span> pred<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">return</span> path</div></div>
<p>It&#8217;s a very minor change, but it led to a significant speedup in my program.</p>
<p>The other change I made was even more simple, but likewise, it yielded improved performance.  This was simply to replace a list comprehension with a filter statement.  So initially, the list comprehension looked pretty much like a filter itself</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">result <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span> x <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">input</span> <span style="color: #ff7700;font-weight:bold;">if</span> fun<span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span> <span style="color: black;">&#93;</span></div></div>
<p>This simply becomes</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">result <span style="color: #66cc66;">=</span> <span style="color: #008000;">filter</span><span style="color: black;">&#40;</span> fun<span style="color: #66cc66;">,</span> <span style="color: #008000;">input</span> <span style="color: black;">&#41;</span></div></div>
<p>Unlike the previous example, there&#8217;s no real though required here.  However, I was surprised to discover than the filter statement was significantly faster than the list comprehension.  For some (obviously misguided) reason, I thought they would both lead to the same bytecode; they do not.  Anyway, these are two very simple Python performance tricks that are easy to implement and can lead to significantly improved performance.  If I stumble upon other such tricks in the future, I&#8217;ll be sure to drop them here.</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=68</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Closures and Currying and Partials . . . oh my!</title>
		<link>http://robpatro.com/blog/?p=53</link>
		<comments>http://robpatro.com/blog/?p=53#comments</comments>
		<pubDate>Wed, 27 Oct 2010 01:53:35 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=53</guid>
		<description><![CDATA[So we were having a discussion in the lab the other day about some of the more functional features of the Python language (and of course, I made sure to give Scala some love as well).  In particular, we were &#8230; <a href="http://robpatro.com/blog/?p=53">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So we were having a discussion in the lab the other day about some of the more functional features of the Python language (and of course, I made sure to give Scala some love as well).  In particular, we were discussing some code where I&#8217;d made use of Python&#8217;s <a href="http://docs.python.org/library/functools.html#functools.partial" target="_self">partials</a>.  My lab mate made a comment to the effect of &#8220;this seems related to closures.&#8221;</p>
<p>Indeed, there are three functional programming concepts that came to the top of my head which are all <em>related</em>, but these relationships, and indeed  the tools themselves are often overlooked in most programming courses which do not  focus on the functional style.  These three concepts are:</p>
<ol>
<li>Closures</li>
<li>Currying</li>
<li>Partials</li>
</ol>
<p><span style="font-size: medium;"><span style="line-height: 24px;">Now, the wikipedia article on <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)" target="_self">closures</a> is pretty good, but alas, it has no scala example!  But before we get to the example, what is a closure?  Well, consider first a &#8220;normal&#8221; function.</span></span></p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> plus<span style="color: #F78811;">&#40;</span> x <span style="color: #000080;">:</span> Int, y <span style="color: #000080;">:</span> Int <span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> x + y <span style="color: #F78811;">&#125;</span></div></div>
<p><span style="font-size: medium;"><span style="line-height: 24px;">Scala functions don&#8217;t get too much simpler than this.  The <strong>plus</strong> function takes two Ints and returns their sum.  What I want to draw your attention to here are the variables <em>x</em> and <em>y</em>.  These variables, as we are used to, are explicitly declared in an argument list.  When we call the plus function, we pass in two Ints, which the compiler takes as <em>x</em> and <em>y, </em>and we say that the values we pass in are <strong>bound</strong> to the variables <em>x </em>and <em>y</em>.  So, what if I defined the following function</span></span></p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> plus<span style="color: #F78811;">&#40;</span> x <span style="color: #000080;">:</span> Int, y <span style="color: #000080;">:</span> Int <span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> x + y + z <span style="color: #F78811;">&#125;</span></div></div>
<p>Uh ohh; what is this <em>z</em> you might ask? It&#8217;s not defined in the body of the function; it&#8217;s not passed in as a variable, so what is it?  Well, in the context of closures, <em>z</em> is a <em>free</em> variable.  That is, given just the context I&#8217;ve shown you above it is unbound (and also undefined).  However, what if I showed you the following piece of code</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> plusZ <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> z <span style="color: #000080;">=</span> <span style="color: #F78811;">3</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> plus<span style="color: #F78811;">&#40;</span> x <span style="color: #000080;">:</span> Int, y <span style="color: #000080;">:</span> Int <span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> x + y + z <span style="color: #F78811;">&#125;</span><br />
plus<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span>, <span style="color: #F78811;">2</span><span style="color: #F78811;">&#41;</span><br />
<span style="color: #F78811;">&#125;</span></div></div>
<p>Ok, so this function is not very useful, but this is a pedagogical example. So, what&#8217;s the behavior of this function? In particular, what happens when I call &#8220;plusZ&#8221;? Take a wild guess . . . it returns 6. That <em>free</em> variable, z, in the <em>plus</em> function was <em>bound</em> to 3 in the enclosing lexical scope of the <em>plusZ</em> function. Essentially, a closure is this process; where <em>free</em> variables within functions are bound to values. The term comes from the proper terminology of referring to the <em>free</em> variables in the function; the function is said to be &#8220;closed over&#8221; its <em>free</em> variables. &#8220;Regular&#8221; functions, are just those with no free variables. The variables of which they make use are explicit arguments, and are, by construction, bound within the scope of the function.</p>
<p>Next, lets look at currying. The syntax for currying varies from language to language as does the syntax support. In Scala, a curried function may look something like this</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> plus<span style="color: #F78811;">&#40;</span>x <span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>y <span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> x + y <span style="color: #F78811;">&#125;</span></div></div>
<p>Again, this is our good old <strong>plus</strong> example. Our normal <strong>plus</strong> function has the type (x:Int, y:Int)Int, or more readably, (Int, Int) =&gt; Int. We say <strong>plus</strong> is a function which takes two Ints as arguments and returns an Int. What&#8217;s the type of our curried <strong>plus</strong> function though? Well, it&#8217;s (Int)(Int)Int, or, again more readably, (Int) =&gt; (Int) =&gt; Int. That is, the new <strong>plus</strong> is a function which takes a single Int, and it returns another function which itself takes a single Int and returns an Int. Calling this new <strong>plus</strong> function as follows:</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">plus<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">3</span>, <span style="color: #F78811;">4</span><span style="color: #F78811;">&#41;</span></div></div>
<p>results in the error &#8220;error: too many arguments for method plus: (x: Int)(y: Int)Int&#8221;. Rather, the proper way to call this function is</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">plus<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">3</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">4</span><span style="color: #F78811;">&#41;</span></div></div>
<p>This yields the expected result of &#8220;7.&#8221; However, the error we received before is rather telling. As we can see by the signature, the curried version of plus does not take two arguments (thus the error). What the second (successful) call really means is call the function plus with the argument 3 (i.e. plus(3) ), then apply the result of this function call ( remember the call plus(3) itself returns a function) to the argument 4. This can be extended to any number of arguments where:</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> func<span style="color: #F78811;">&#40;</span>x<span style="color: #000080;">_</span><span style="color: #F78811;">&#123;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>x<span style="color: #000080;">_</span><span style="color: #F78811;">&#123;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span> . . . <span style="color: #F78811;">&#40;</span>x<span style="color: #000080;">_</span><span style="color: #F78811;">&#123;</span>k<span style="color: #F78811;">&#125;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> evaluate function <span style="color: #F78811;">&#125;</span></div></div>
<p>Is a function which takes a single argument, and returns a function (let&#8217;s call it <em>func_1</em>, even though it doesn&#8217;t really have a name) which itself takes <img src='http://s.wordpress.com/latex.php?latex=k-1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k-1' title='k-1' class='latex' /> arguments. However, <em>func_1</em>, in turn, takes a single argument and returns a function <em>func_2</em> which takes <img src='http://s.wordpress.com/latex.php?latex=k-2&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k-2' title='k-2' class='latex' /> arguments. In a similar fashion, each <em>func_<img src='http://s.wordpress.com/latex.php?latex=d&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d' title='d' class='latex' /></em> takes a single argument and returns a function taking <img src='http://s.wordpress.com/latex.php?latex=d-1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='d-1' title='d-1' class='latex' /> arguments, until we get to <em>func_<img src='http://s.wordpress.com/latex.php?latex=k-1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k-1' title='k-1' class='latex' /></em>; a function which takes a single argument and returns the result of whatever expression is evaluated in &#8220;evaluate function&#8221;. Currying takes a function of <img src='http://s.wordpress.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> arguments, and returns a chain of <img src='http://s.wordpress.com/latex.php?latex=k&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> function applications, where each function takes a single argument. Perhaps now it&#8217;s becoming clear the relation between bound and free variables, closures and currying. Each function application in the chain of curried functions is essentially binding one of the free variables used in the function body&#8217;s expression. Ok, time for a test; what if, given the curried definition of plus above, I wrote something like</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> p9 <span style="color: #000080;">=</span> plus<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">9</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">_</span><br />
p9<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span></div></div>
<p>What&#8217;s the result of the &#8220;p9(1)&#8221; expression? If you guessed 10, then you&#8217;re correct! Essentially, <strong>p9</strong> is the result of a partial function application to the curried function. In the partially applied function, exists in a scope where the previously free variable &#8220;x&#8221;, has now been bound to 9. In fact, we could have achieved the same thing by writing the much more cumbersome (and much less intuitive) code:</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> p9 <span style="color: #000080;">=</span> <span style="color: #F78811;">&#40;</span>y<span style="color: #000080;">:</span>Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=&amp;</span>gt<span style="color: #000080;">;</span> <span style="color: #F78811;">9</span> + y</div></div>
<p>Here, we&#8217;re assigning p9 directly as a function which takes a single integer, &#8220;y&#8221; and returns the sum of 9 and y. This is equivalent to binding the value 9 to the variable &#8220;x&#8221; in our curried function.</p>
<p>After all of this discussion, we come full circle, back to the notion of a partial, or &#8220;partially applied function.&#8221; All we mean by a partial is function, where some subset of the free variables are captured in a closure. When we partially apply a set of arguments to a function, we get back some function where some set of the free variables of the function are bound to those arguments, and the rest of the free variables will (presumably) be passed in at another point. Again, scala has some fairly nice syntax for this, let&#8217;s take our old friend, the original <em>plus</em> function, and look at partially applying each of its two arguments.</p>
<div class="codecolorer-container scala default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="scala codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">def</span></a> plus<span style="color: #F78811;">&#40;</span>x <span style="color: #000080;">:</span> Int, y <span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span> x + y <span style="color: #F78811;">&#125;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> p9first <span style="color: #000080;">=</span> plus<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">9</span>, <span style="color: #000080;">_</span> <span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> res0 <span style="color: #000080;">=</span> p9first<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span><br />
<br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> p9second <span style="color: #000080;">=</span> plus<span style="color: #F78811;">&#40;</span><span style="color: #000080;">_</span> <span style="color: #000080;">:</span> Int, <span style="color: #F78811;">9</span><span style="color: #F78811;">&#41;</span><br />
<a href="http://scala-lang.org"><span style="color: #0000ff; font-weight: bold;">val</span></a> res1 <span style="color: #000080;">=</span> p9second<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span></div></div>
<p>At the end of this little exercise, both res0 and res1 have the same value, 10. However, in the first case, <em>p9first</em> the free variable &#8220;x&#8221; is bound to the value 9 and the function call p9first(1) is interpreted as binding y to 1 and evaluating 9 + 1; thus returning 10. In the second case, <em>p9second</em> the free variable &#8220;y&#8221; is bound to the value 9, and the function call p9second(1) is interpreted as binding x to 1 and evaluating 9 + 1; thus returning 10. Now, the commutativity of plus ensures that these results were the same, but if we had instead considered the function <em>minus</em> (defined in the natural way), then the analogs <em>m9first</em> and <em>m9second</em> would have returned different results; namely 8 and -8 respectively.</p>
<p>Alright, enough with these examples. We&#8217;ve begun to explore the wonderful world of closures, currying and partially applied functions, and I hope that I&#8217;ve given you at least some idea about how these concepts are related (at least conceptually if not in terms of implementation). Though the concepts are distinct, they share a certain flavor and overlap in many meaningful ways. Together, closures, currying and partials provide a <strong>very powerful</strong> set of functional programming tools that you should remember next time you are faced with a programming problem where they apply . . . that is, assuming that you are programming in a language as awesome as scala which offers access to such functional constructs.</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=53</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Numpy from source</title>
		<link>http://robpatro.com/blog/?p=47</link>
		<comments>http://robpatro.com/blog/?p=47#comments</comments>
		<pubDate>Thu, 21 Oct 2010 13:13:51 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=47</guid>
		<description><![CDATA[This post should act as a note to future Rob, as well as a hint to anyone else that runs into this problem after building and installing numpy. &#62; ImportError: path_to_python/site-packages/numpy/linalg/lapack_lite.so: &#62; undefined symbol: zgesdd_ I was motivated to build &#8230; <a href="http://robpatro.com/blog/?p=47">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This post should act as a note to future Rob, as well as a hint to anyone else that runs into this problem after building and installing numpy.</p>
<p><span style="color: #3366ff;">&gt; ImportError:  path_to_python/</span><em><span style="color: #3366ff;">site-packages/numpy/linalg/lapack_lite.so:<br />
&gt; </span></em><em><span style="color: #33cccc;"><span style="color: #3366ff;">undefined symbol: zgesdd</span><span style="color: #3366ff;">_</span></span></em></p>
<p>I was motivated to build my own version of Numpy because I use a newer version of Python than the one that is provided on some of the machines I use in the lab.  I&#8217;ve built up my entire python ecosystem from source; and thus far, everything had worked out smoothly.  The real problem with this numpy error, is that it can happen for so many reasons, none of which was the reason it was occurring for me.</p>
<p>First, make sure that the build script is looking for BLAS and LAPACK in the right place.  If you download the actual numpy sources, this is fairly simple.  Just copy site.cfg.example to site.cfg in the top-level directory, and then make sure that the include and library path variables include the proper paths.  Now, the crux of the problem, which took me a few hours to resolve, is that blas and lapack must be built as shared libraries.  Numpy assumes this is the case and will look to link them at runtime.  I had previously built BLAS and LAPACK as static libraries, so numpy could not find them, and  hence failed with the error stated above.  Simply re-downloading lapack, altering the makefile to build shared libraries, and then installing them solved the problem.  Obviously, it&#8217;s always easiest if you have admin privileges on a machine and can handle these things with a decent package manger.  However, if you have to build sources by hand and run into this problem, I hope this note helps you out and saves you some time!</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=47</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing With Scala</title>
		<link>http://robpatro.com/blog/?p=42</link>
		<comments>http://robpatro.com/blog/?p=42#comments</comments>
		<pubDate>Mon, 18 Oct 2010 01:17:38 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=42</guid>
		<description><![CDATA[I&#8217;ve recently been exploring the Scala language. I used it mainly as a scripting language and in conjunction with Python and C++ in a recent research project. Now, I&#8217;m starting a more substantial (at least from a coding perspective) project, &#8230; <a href="http://robpatro.com/blog/?p=42">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently been exploring the <a href="http://scala-lang.org">Scala</a> language.  I used it mainly as a scripting language and in conjunction with Python and C++ in a recent research project.  Now, I&#8217;m starting a more substantial (at least from a coding perspective) project, and I&#8217;m faced with the tough decision of what language I should use to write the code.  My standard fall-backs are Python and C++.  Don&#8217;t get me wrong, they&#8217;re great languages, both in isolation and when combined.  However, for a long time, I&#8217;ve been looking for a language with the expressiveness of a high level scripting language, but without the excessive performance penalty.</p>
<p>So far, Scala fits the bill better than anything else I&#8217;ve seen.  It&#8217;s a statically typed language which compiles down to JVM bytecode.  Scala attempts to combine the object-oriented and functional programming paradigms in a single language in the most natural way.  It has a type system that is among the most powerful I&#8217;ve yet seen, and a type inference systems which relieves the user of the burden and verbosity of explicitly annotating the types of most variables.</p>
<p>The power of the type system and the built in functional constructs <em>really</em> make Scala an expressive language.  Moreover, the JVM bytecode it produces seems very good.  In particular, there seems to be little to no <a href="http://shootout.alioth.debian.org/u64q/scala.php">penalty</a> (in terms of performance and resource utilization) over Java.  This can probably be chalked up to a combination of the JVM&#8217;s awesome performance tuning abilities and the adeptness of the Scala development team at producing efficient JVM bytecode.</p>
<p>Finally, being a JVM language, Scala capable of using Java libraries directly.  This means that vast wealth of libraries written in Java are available to a Scala user immediately; in real life projects, this is a <em>huge</em> plus.  Anyway, as you can probably tell from the tone of this post, I&#8217;m pretty excited about Scala, and the more I explore it, the more I find to like.  I&#8217;m seriously considering attacking my new research project in Scala, and you&#8217;ll likely be hearing much more about my experience with the language on this blog in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=42</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Releasing a fun project</title>
		<link>http://robpatro.com/blog/?p=14</link>
		<comments>http://robpatro.com/blog/?p=14#comments</comments>
		<pubDate>Fri, 13 Aug 2010 20:05:33 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=14</guid>
		<description><![CDATA[So I finally got around to releasing some code I wrote a few months ago. It&#8217;s basically an implementation of &#8220;Implicit Fairing of Arbitrary Meshes using Diffusion and Curvature Flow&#8221; by Desbrun et al. However, the interesting part about this &#8230; <a href="http://robpatro.com/blog/?p=14">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I finally got around to <a href="http://github.com/rob-p/mcflow">releasing</a> some code I wrote a few months ago.  It&#8217;s basically an implementation of <a href="http://portal.acm.org/citation.cfm?id=311576">&#8220;Implicit Fairing of Arbitrary Meshes using Diffusion and Curvature Flow&#8221; </a> by <a href="http://www.cs.caltech.edu/~mathieu/">Desbrun</a> et al.  However, the interesting part about this implementation is that it uses a <em>very</em> efficient method to solve the linear system required by this approach.  One of the main ideas put forth in this paper is to replace the common approach to mesh fairing, which relies on integration via the forward Euler method, with an approach which relies on integration via an unconditionally stable backward Euler method.</p>
<p>Imagine we have a set of vectors <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbf%7Bx%7D_%7Bi%7D%2C%20i%20%5Cin%20%5C%7B0%2C1%2C2%5C%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbf{x}_{i}, i \in \{0,1,2\}' title='\mathbf{x}_{i}, i \in \{0,1,2\}' class='latex' /> of length <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />; representing the <img src='http://s.wordpress.com/latex.php?latex=x&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='x' title='x' class='latex' />, ﻿<img src='http://s.wordpress.com/latex.php?latex=y&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='y' title='y' class='latex' />, and <img src='http://s.wordpress.com/latex.php?latex=z&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='z' title='z' class='latex' /> coordinates of our mesh.  The standard approach to smoothing our mesh using some differential operator matrix <img src='http://s.wordpress.com/latex.php?latex=%5Cmathcal%7BL%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathcal{L}' title='\mathcal{L}' class='latex' /> (e.g. some formulation of the Laplacian) is to apply the following formula:</p>
<table border="0">
<tr>
<td>﻿<img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%20%20%5Cmathbf%7Bx%7D_%7Bi%7D%5E%7Bn%2B1%7D%20%3D%20%28%5Cmathbf%7BI%7D%2B%5Clambda%20dt%20%5Cmathcal%7BL%7D%29%20%5Cmathbf%7Bx%7D_%7Bi%7D%5E%7Bn%7D%2C%20i%20%5Cin%20%5C%7B1%2C2%2C3%5C%7D%20%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\displaystyle  \mathbf{x}_{i}^{n+1} = (\mathbf{I}+\lambda dt \mathcal{L}) \mathbf{x}_{i}^{n}, i \in \{1,2,3\}  ' title='\displaystyle  \mathbf{x}_{i}^{n+1} = (\mathbf{I}+\lambda dt \mathcal{L}) \mathbf{x}_{i}^{n}, i \in \{1,2,3\}  ' class='latex' /></td>
<td>(1)</td>
</tr>
</table>
<p>This tells us how we obtain the coordinates of the vertices at timestep <img src='http://s.wordpress.com/latex.php?latex=n%2B1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n+1' title='n+1' class='latex' /> from the positions of the vertices at timestep <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />.  The main problem with this approach is that to ensure stability, we must choose a sufficiently small <img src='http://s.wordpress.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda' title='\lambda' class='latex' />.  However, the value of <img src='http://s.wordpress.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda' title='\lambda' class='latex' /> directly affects the amount of smoothing performed in every iteration.  Thus, the smaller we need to make <img src='http://s.wordpress.com/latex.php?latex=%5Clambda&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\lambda' title='\lambda' class='latex' /> for the sake of stability, the greater the number of smoothing iterations we must perform to obtain the desired amount of smoothing.</p>
<p>Desbrun et al. get around this problem by replacing equation (1) by the following equation:</p>
<table border="0">
<tr>
<td>﻿<img src='http://s.wordpress.com/latex.php?latex=%5Cdisplaystyle%20%20%28%5Cmathbf%7BI%7D-%5Clambda%20dt%20%5Cmathcal%7BL%7D%29%5Cmathbf%7Bx%7D_%7Bi%7D%5E%7Bn%2B1%7D%3D%5Cmathbf%7Bx%7D_%7Bi%7D%5E%7Bn%7D%2C%20i%20%5Cin%20%5C%7B1%2C2%2C3%5C%7D%20%20&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\displaystyle  (\mathbf{I}-\lambda dt \mathcal{L})\mathbf{x}_{i}^{n+1}=\mathbf{x}_{i}^{n}, i \in \{1,2,3\}  ' title='\displaystyle  (\mathbf{I}-\lambda dt \mathcal{L})\mathbf{x}_{i}^{n+1}=\mathbf{x}_{i}^{n}, i \in \{1,2,3\}  ' class='latex' /></td>
<td>(2)</td>
</tr>
</table>
<p>This should look familiar; if we set <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbf%7BA%7D%20%3D%20%5Cmathbf%7BI%7D-%5Clambda%20dt%20%5Cmathcal%7BL%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbf{A} = \mathbf{I}-\lambda dt \mathcal{L}' title='\mathbf{A} = \mathbf{I}-\lambda dt \mathcal{L}' class='latex' />, <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbf%7Bx%7D%20%3D%20%5Cmathbf%7Bx%7D_%7Bi%7D%5E%7Bn%2B1%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbf{x} = \mathbf{x}_{i}^{n+1}' title='\mathbf{x} = \mathbf{x}_{i}^{n+1}' class='latex' />, and <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbf%7Bb%7D%20%3D%20%5Cmathbf%7Bx%7D_%7Bi%7D%5E%7Bn%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbf{b} = \mathbf{x}_{i}^{n}' title='\mathbf{b} = \mathbf{x}_{i}^{n}' class='latex' />, then we can see that, just like in our introduction to linear algebra course, we want to solve <img src='http://s.wordpress.com/latex.php?latex=%5Cmathbf%7BA%7D%5Cmathbf%7Bx%7D%20%3D%20%5Cmathbf%7Bb%7D&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\mathbf{A}\mathbf{x} = \mathbf{b}' title='\mathbf{A}\mathbf{x} = \mathbf{b}' class='latex' />.  Intuitively, equation (1) says we take the vertex positions at the current timestep <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />, and apply the smoothing process to obtain the vertex positions at the next timestep <img src='http://s.wordpress.com/latex.php?latex=n%2B1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n+1' title='n+1' class='latex' />.  Equation (2), on the other hand, asks, what must the vertex positions at the next timestep <img src='http://s.wordpress.com/latex.php?latex=n%2B1&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n+1' title='n+1' class='latex' /> be such that by applying the &#8220;inverse&#8221; of the smoothing process (i.e. <img src='http://s.wordpress.com/latex.php?latex=%28%5Cmathbf%7BI%7D-%5Clambda%20dt%20%5Cmathcal%7BL%7D%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(\mathbf{I}-\lambda dt \mathcal{L})' title='(\mathbf{I}-\lambda dt \mathcal{L})' class='latex' /> instead of <img src='http://s.wordpress.com/latex.php?latex=%28%5Cmathbf%7BI%7D%2B%5Clambda%20dt%20%5Cmathcal%7BL%7D%29&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='(\mathbf{I}+\lambda dt \mathcal{L})' title='(\mathbf{I}+\lambda dt \mathcal{L})' class='latex' />) to these positions we obtain the vertex positions at the current timestep <img src='http://s.wordpress.com/latex.php?latex=n&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />.</p>
<p>Now, instead of simply applying the smoothing operator as in equation (1), we have to solve a linear system of equations.  There are many ways we can tackle this problem; each with certain benefits and detriments.  However, a particularly practical and fast approach is to solve the system iteratively.  In fact, this is what Desbrun et al. suggest in the paper, where they solve (2) using a PBCG solver.  However, <a href="http://graphics.uni-bielefeld.de/people/botsch.php">Botsch</a> et al. in <a href="http://graphics.uni-bielefeld.de/publications/papers/disclaimer.php?dlurl=ima05.pdf">&#8220;Efficient Linear System Solvers for Mesh Processing&#8221;</a> show us that for many problems, direct solvers can be much more efficient than iterative solvers.  In particular, in situations where a set of linear systems with the same non-zero structure need to be solved, approaches which reuse the factorization can be <em>much</em> faster.</p>
<p>Luckily, our problem presents one of these situations.  Since the non-zero structure of the matrix is the same for each smoothing iteration, a symbolic factorization of the necessary matrix can be performed only once, and reused for for all subsequent iterations.  My direct solver implementation of the smoothing algorithm makes use of the symbolic Cholesky factorization of the differential operator matrix.  This means that for all but the first iteration, only the numeric factorization and back substitution need to be performed to solve the linear system.  My code provides implementations of implicit smoothing using both an iterative Precomputed Bi-Conjugate Gradient (PBCG) solver as well as a direct solver making using the Cholesky factorization of operator matrix.  Compare them yourself to see the speed difference!  If I have time in the future, I&#8217;d like to add an implementation which solves the linear system iteratively on the GPU.  There are a number of nice libraries out there which provide PBCG implementations for GPUs, and it would certainly be interesting to see how an implementation using one of these solvers would compare against either of the CPU based approaches.</p>
<p>Let me know if you find my code useful or cool; or if you find any crazy bugs still lingering in there.  I have more fun stuff to release in the future, but it requires some preparation first and I&#8217;m short on free time right now.  Hopefully, however, I&#8217;ll find enough to post again soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=14</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world . . . again!</title>
		<link>http://robpatro.com/blog/?p=1</link>
		<comments>http://robpatro.com/blog/?p=1#comments</comments>
		<pubDate>Thu, 22 Jul 2010 21:28:56 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://robpatro.com/blog/?p=1</guid>
		<description><![CDATA[So, there are a lot of new things going on in my graduate career right now, and this is also leading to a renewal of my efforts to accomplish other things I&#8217;ve previously wanted to do. I&#8217;m going to give &#8230; <a href="http://robpatro.com/blog/?p=1">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, there are a lot of new things going on in my graduate career right now, and this is also leading to a renewal of my efforts to accomplish other things I&#8217;ve previously wanted to do.  I&#8217;m going to give the whole blogging thing another try.  I think it can be a worthwhile way to explore (even if I&#8217;m the only participant) interesting issues pertaining to my research and perhaps other various topics as well.  I&#8217;m going to make an honest and concerted effort to update this thing on a reasonably frequent basis; even if that means some of the posts will be tiny.  I believe that one of the most effective ways to form a new habit is to force yourself to perform an activity frequently, until it becomes almost second nature.</p>
<p>Anyway, that&#8217;s all for now.  By the way, for future reference, I&#8217;ve installed a LaTeX module for the blog so that you can include math with &#91latex&#93 . . . &#91/latex&#93 tags.</p>
]]></content:encoded>
			<wfw:commentRss>http://robpatro.com/blog/?feed=rss2&#038;p=1</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

