<?xml version='1.0' encoding='utf-8'?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns="http://purl.org/rss/1.0/">

<channel rdf:about="http://uellue.de/blog/">
  <title>Uellue's Blog</title>
  <link>http://uellue.de/blog/</link>
  <description>A dummy weblog to show how Beta-Blogger works</description>
  <items>
    <rdf:Seq>
    <rdf:li resource="http://uellue.de/blog/single.php?date=1347379140" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1345568280" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1337798820" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1336634040" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1334578560" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1320156360" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1315165500" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1311844200" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1311705240" />
<rdf:li resource="http://uellue.de/blog/single.php?date=1311705240" />
    </rdf:Seq>
  </items>
</channel>

  <item rdf:about="http://uellue.de/blog/single.php?date=1347379140">
    <title>PhotoRec just saved my day</title>
    <link>http://uellue.de/blog/single.php?date=1347379140</link>
    <dc:date>2012-09-11T17:59:00+02:00</dc:date>
    <description><![CDATA[The file system on my SD card got thrashed and I couldn't get my pictures the normal way anymore. <a href="http://www.cgsecurity.org/wiki/PhotoRec">PhotoRec</a>, a tool of the <code>testdisk</code> package, could get everything back! Including previously deleted pictures...
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1345568280">
    <title>Python attribute caching with low overhead</title>
    <link>http://uellue.de/blog/single.php?date=1345568280</link>
    <dc:date>2012-08-21T18:58:00+02:00</dc:date>
    <description><![CDATA[<p>For my work I need to do various lengthy numerical calculations on large datasets with results that do not change. The program is interactive, which means I do not know in advance which calculations on which data I need to perform. The results of the calculations depend completely on the dataset, there are no additional parameters. One can implement such a thing with a cache and corresponding code that checks if the result is in the cache before doing the calculation. I developed a generic technique to cache the results in such a way that no function call is necessary at all if the result is cached. It works by dynamically generating and deleting object attributes. If the attribute is set, it is used. If it is not set, a corresponding function to calculate the attribute is called and the attribute is set. If the data changes, all designated attributes are unset and will be recalculated when they are accessed next time.</p>

<p>A class for lists demonstrates how it works:</p>
<pre>
<code>
#!/usr/bin/env python3
# works similarly with python 2.x, except different syntax in some points

# -*- coding: utf-8 -*-

class CachedList(object):
    # List of attributes that can be cached.
    # Use keys of a hash to quickly look up if an attribute is managed.
    # Leading underscores do not work due to the way attributes 
    # with two underscores are handled.
    # A method that calculates the result has to be defined for each of these attributes. 
    # It has the same name as the attribute plus a leading underscore: average -> _average(), ...
    _managed_attributes = {'average': 1, 'sum': 1, 'len': 1, 'exc': 1}
    def __init__(self, l):
        # copy the list
        self._list = list(l)
        self._exception_cache = {}
        
    # This method is called automatically if an undefined attribute is accessed.
    # If the attribute already exists, this method will not be called.
    def __getattr__(self, attr):
        # Avoid recalculating attributes that raised an exception.
        # Instead raise the cached exception.
        # Some of my calculations fail with an exception after a very long calculation,
        # so it makes sense to cache the exception.
        exception = self._exception_cache.get(attr)
        if exception is not None:
            raise exception
        if attr in self._managed_attributes:
            # Try to get and call a method that "makes" the entry
            f = getattr(self, '_'+attr)
            try:
                # Just some tracing code for the example
                print("calculate {0}".format(attr))
                result = f()
                setattr(self, attr, result)
            except Exception as e:
                # "remember" the exception
                self._exception_cache[attr] = e
                raise
        else:
            raise AttributeError('{0} object has no attribute {1}'.format(type(self), attr))
        # result has been set if this point is reached
        return result
    
    def append(self, x):
        self._list.append(x)
        self._invalidate_cache()
        
    def _invalidate_cache(self):
        # just some tracing
        print("empty cache")
        self._exception_cache = {}
        for a in self._managed_attributes.keys():
            try:
                delattr(self, a)
            except AttributeError:
                pass
            
            
    def _average(self):
        # Cached attributes can be used just like normal attributes
        return self.sum/self.len
        
    def _sum(self):
        return sum(self._list)
        
    def _len(self):
        return len(self._list)
        
    def _exc(self):
        raise Exception("Exception!")
    
# now test the code!    

l = range(10000000)
cl = CachedList(l)
# attribute is calculated and set
print(cl.average)
# attribute is used
print(cl.average)
# cache is cleared
cl.append(100000000)
# attribute is recalculated
print(cl.average)
# exceptions are also cached
try:
    print(cl.exc)
except Exception as e:
    print(e)
    pass

try:
    print(cl.exc)
except Exception as e:
    print(e)
    pass
</code>
</pre>

<pre>
<kbd>user@host:~$ ./propertycache.py</kbd>
<samp>
calculate average
calculate sum
calculate len
4999999.5
4999999.5
empty cache
calculate average
calculate sum
calculate len
5000008.9999991
calculate exc
Exception!
Exception!
</samp>
</pre>
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1337798820">
    <title>Why is the air in airplanes so dry?</title>
    <link>http://uellue.de/blog/single.php?date=1337798820</link>
    <dc:date>2012-05-23T20:47:00+02:00</dc:date>
    <description><![CDATA[<p>If you ever traveled a long distance by plane, you may have noticed that the air is extremely dry: The eyes start burning, the skin is dry and you get thirsty. But why is the air not moistened so that the passengers are more comfortable?</p>

<p>There are actually two reasons. First, the air at the altitudes where the plane is flying is extremely <a href="http://www.atoptics.co.uk/highsky/htrop.htm">cold</a> (say, -60 °C and below) and consequently dry. It contains practically no water. This air is compressed by the turbines and used as <a href="http://en.wikipedia.org/wiki/Environmental_control_system">cabin air</a>. Any water in the air would come from people breathing or would have to be added. Such a "moisturizing" system costs money, takes up space and has weight, so an airline would have to think if the added cost is worth it.</p>

<p>Second, airplanes are usually made of high-strength aluminum alloys that can corrode in contact with water. They also have a lot of electrical cables running all over. And they fly at high altitude where it is very, very cold. So at least some parts of the hull are cold, too. This means that moisture from the air inside the plane could condense to liquid water on cold parts and cause trouble. Dry cabin air can reliably prevent that: If the <a href="http://www.decatur.de/javascript/dew/index.html">dew point</a> (resp. frost point in that case) of the cabin air is below the freezing point of water, there can be no liquid water condensing. Only frost can form, i.e. water vapor turns directly into ice, which does not cause corrosion problems. And a frost point of roughly 0 °C corresponds to a relative humidity of 25 % at 20 °C. If the humidity in the cabin is desired to be above 25 %, one would have to take special measures: Corrosion-resistant materials or a completely sealed <a href="http://en.wikipedia.org/wiki/Vapor_barrier">vapor barrier</a> on top of the cabin's thermal insulation. Such a barrier would prevent the moisture from reaching colder parts. But it would make the insulation more complex and add weight...</p
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1336634040">
    <title>Libreoffice WTF</title>
    <link>http://uellue.de/blog/single.php?date=1336634040</link>
    <dc:date>2012-05-10T09:14:00+02:00</dc:date>
    <description><![CDATA[<p><a href="http://www.libreoffice.org/">Libreoffice</a> bugged out on me big time (3.5.3.2 350m1(Build:2)). A presentation that I created at my work computer has mangled figures if I open it on my home computer. On exactly the same version of libreoffice! Things breaking when I open a file with a different version or when I have to export as .ppt I can tolerate. But incompatibility between different installations of the same version is beyond my comprehension and strains my patience. Maybe I should give <a href="http://en.wikipedia.org/wiki/Beamer_%28LaTeX%29">LaTeX Beamer</a> another look.</p>

<p>Does MS Powerpoint still do this kind of stuff?</p>
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1334578560">
    <title>Currency backed by gold?</title>
    <link>http://uellue.de/blog/single.php?date=1334578560</link>
    <dc:date>2012-04-16T14:16:00+02:00</dc:date>
    <description><![CDATA[<p>In these economically volatile times with the 2009 financial crisis and the European debt crisis, some people argue that a gold-based currency would be desirable because gold is a "real value", as opposed to pieces of paper with elaborate imprints on them or numbers in a database. But how is gold a value more real than paper money or bank accounts? As such, a piece of gold seems rather useless to me. It can serve as paperweight, blunt weapon or door stopper. I admit that you can make pretty, shiny things out of it, but, lets say, martensitic stainless steel in the shape of a knife is more useful in the daily life. Should we have a currency backed by martensitic stainless steel?</p>

<p>The value of gold, just like paper money, is based on the fact that other people want to have it and that they are willing to trade their work force or posessions for it. The demand for it has always been higher than the production capacity, and mining gold is an expensive and slow process in itself. It is therefore quite suitable as a currency in a primitive society: It's supply is self-limiting and keeps the value of gold at a more or less constant level that is related to it's mining cost. A rising gold price makes gold mining more profitable and increases supply, while a falling gold price discourages mining.</p>

<p>But on the long run and in a growing global economy, a gold-based currency could be fatal for the following reasons:</p>
<ul>
<li>Gold mining and refining is bad for the environment.</li>
<li>Mining gold that is then stored in some safe and "sitting around" wastes all the expenses that went into mining and refining it, because the gold is not doing anything useful. The gold should be used as jewellery or for high-tech products.</li>
<li>The mining cost of gold is not constant. It could decrease because new technology is developed that decreases the minig cost, or new deposits or production methods are discovered. It could increase if existing deposits are exhausted. Both could disrupt the value of gold.</li>
<li>The production of gold cannot be increased quickly, which could lead to a deflation if the world economy outgrows the gold production.</li>
<li>The value of the gold currency would not be under control of central banks, but under the control of mining companies. They would in fact be the new central banks.</li>
<li>Gold is not distributed evenly around the world. It could create a similar dependency like for fossile fuels.</li>
<li>Gold is at the moment and will be in the future subject to speculation. It's value is more volatile than good currencies like US-Dollar or Euro. The value of such currencies is under tight control of powerful and highly developed central banks that stabilize them proactively.</li>
</ul>

<p>There is a good reason for which gold was abandoned as a currency or base of a currency. Gold is not a real value. Real values are the house that you live in, the food that you eat, the tools that you use, the things that you know, and most importantly, the people who you love and who love you. All these don't make a good currency, but definitely a good investment.</p>
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1320156360">
    <title>What is Greece doing?</title>
    <link>http://uellue.de/blog/single.php?date=1320156360</link>
    <dc:date>2011-11-01T15:06:00+01:00</dc:date>
    <description><![CDATA[<p>Just now the Greek prime minister Georgios Papandreou <a href="http://www.huffingtonpost.co.uk/2011/11/01/ftse-100-plunges-on-news-of-greek-bail-out_n_1068948.html">announced</a> that he wants to conduct a referendum if Greece is going to accept the EU financial aid. This came as a surprise to everybody, as just last week the European countries came to a first agreement on the financial aids after a long struggle. The markets are not so fond of Papandreou's move and indices are plummeting as I am writing this. Respecting the will of your population is not a bad thing in itself, but a referendum in such a heated environment with street protests all over in Greece resembles tossing a coin instead of making a rational decision. Papandreou's government will have to inform it's citizens about the implications of their decision, and I hope people will think and decide carefully. My feeling is that the Greek government wants to dodge the responsibility for their bad decisions in the past and later blame the population for whatever decision they take in the referendum.</p>

<p>The options, as I see it, are harsh austerity measures on all fronts in case Greece accepts the aid and stays in the euro zone, or the revival of the drachm and bankruptcy. Both options are at first viable ways out of the situation, and I'll try to analyse what could happen in either case, maybe identifying a preferable solution.</p>

<h3>Staying in the zone</h3>
<p>Four things will be necessary to get out of debt: A debt cut as an incentive to pay back the debt at least partially instead of going bankrupt right away, reducing government spending, increasing government income and improving the efficiency of the Greek economy in order to keep an acceptable standard of living for the population. The debt cut is already agreed on, but the remaining three steps are politically problematic. The main hindrance is a deep-rooted culture of corruption, tax evasion and clientele politics in Greece: Decisions are not made based on what would be better for the country, but what would be better for the decision maker and his friends. Once such a system is fully established, it is hard to remove because the network of corruption includes judges, prosecutors and high government officials who would be the first in line to fight corruption and tax evasion. They will be preoccupied with saving themselves instead of fighting the rot in their own ranks.</p>

<p>The only way here is to fight the corruption from top to bottom. This means that Papandreou will first have to fight corruption in his own government, which may sever him from a lot of important figures that support him. Does he have enough people around him who are loyal to Greece? If not, there's no hope and Papandreou will fall soon.</p>

<p>Fighting corruption, reducing government spending and increasing government income have to be backed up with stimulating the Greek economy in order to fight unemployment and keep an acceptable standard of living for the population. Only the private sector can create income from which to draw taxes and pay salaries to workers. Greece has to attract foreign capital, support export-oriented industries to fight the foreign trade deficit, educate people and train them for jobs that are needed, and also invest into infrastructure &mdash; which is difficult if you up to your neck in debt. Again, improving government efficiency is a key factor because slow and unreliable bureaucracy hand in hand with corruption repel investors and make life hard for domestic companies.</p>

<h3>Leaving the zone</h3>
<p>It would mean that foreign investors can pretty much kiss their money goodbye. Probably (I'm just guessing here) the foreign debts will be converted to drachm at a rate dictated by the Greek government, and the expected gradual depreciation of the drachm with respect to dollar and euro will devalue the debts. This step would therefore be strongly against the interest of any country or institution that lent money to Greece or Greek companies. For me it is still a question how the debts of Greek companies, as opposed to government debts, would be handled.</p>

<p>The diminishing buying power of the drachm can be a chance for Greece: The country becomes more attractive for investors because of lower levels of income, and export-oriented industries and tourism are bolstered by a weak drachm. Problem here is the EU membership, which pretty much forbids tariffs for trade within the EU. It means that the price of many goods in drachm will increase as the exchange rate of the drachm drops relative to the euro. Similar things have happened in north America, where international trade has increased the price of corn in Mexico, hurting the Mexican population.</p>

<p>On top of that, Greece still as a foreign trade deficit, which means that the effect of increased price of imported foreign goods outweighs the benefit for the own export-oriented industries. And, again, it is the private sector that ultimately creates value in an economy, and a strong private sector needs an efficient and reliable administration as well as good infrastructure and educated workers.</p>

<p>The reduced international debts will only provide a short-term relief if the deficit remains: Taking new foreign debts will be much more expensive, and "printing drachms" just lets the value of the drachm spiral down into a deep inflation.</p>

<h3>Conclusion</h3>

<p>In summary, reintroducing the drachm is not going to solve any problems. Such a step may be beneficial in some situations, but in case of Greece with it's foreign trade deficit and continuing accumulation of debts it only makes the situation worse. The way out of the crisis is the same in any case: Fighting corruption and tax evasion, making the administration more efficient, and stimulating the economy. Money for military and "presents" to diverse interest groups should be diverted into education and infrastructure. And Greece has to become a reliable partner for foreign investors and other EU countries to ensure support during this time of crisis.</p>

<p>Papandreou's move is therefore clearly in his own interest by putting the responsibility for any kind of measures to the voters and not to him and his government. He also seeks to win time, probably trying to save him and his buddies from the bloodbath in the awaiting fight against corruption and tax evasion. But at the same time he's gambling with his country's future, as leaving the euro zone is definitely not a good option for Greece. Instead, he is hurting the relations to other EU countries and also private investors, destroying any trust into the willingness of the current administration to take the necessary measures.</p>

<p>The debts to Greece are lost at least partially in any case, and a debt cut along with financial aid and political pressure to solve the domestic problems are probably the best way to recover at least some of the loans to Greece and Greek companies. The damage to other EU countries and companies could be severe on the short run if Greece reintroduces the drachm because of writing off the debts of Greece, but the strong economic position of other EU countries would soon allow them to recover. If other countries like Italy, Portugal, Spain or Ireland however follow the path of Greece it would severely weaken the EU. I believe that sticking together and helping out each other is in the interest of all European countries.</p>
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1315165500">
    <title>Numpy makes your python math 10x faster</title>
    <link>http://uellue.de/blog/single.php?date=1315165500</link>
    <dc:date>2011-09-04T21:45:00+02:00</dc:date>
    <description><![CDATA[<p>As an exercise in parallel number crunching with python and <a href="http://numpy.scipy.org/">numpy</a>, I wrote a <a href="http://shootout.alioth.debian.org/u64q/program.php?test=mandelbrot&amp;lang=python3&amp;id=6">program</a> for the <a href="http://shootout.alioth.debian.org/">computer language benchmark game</a>. It is more than 10x faster than the python <a href="http://shootout.alioth.debian.org/u64q/benchmark.php?test=mandelbrot&amp;lang=python3">runner-up</a> without numpy and plays already in the league of compiled languages. The speedup comes solely from the high-level vector math functions of numpy.</p>
<p>As a remark: The program was disqualified from the competition but is shown anyway. I don't exactly understand why. Well, I also don't really feel like asking the admin Isaac Gouy, as he seems to be a bit <a href="http://article.gmane.org/gmane.comp.python.numeric.general/45910/match=">tense</a> about the subject.</p>
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1311844200">
    <title>Two-column float gets stuck with revtex</title>
    <link>http://uellue.de/blog/single.php?date=1311844200</link>
    <dc:date>2011-07-28T11:10:00+02:00</dc:date>
    <description><![CDATA[When preparing a manuscript with revtex (<code>documentclass[aip,apl,amsmath,amssymb,reprint]{revtex4-1}</code>), I ran into a problem: A two-column float with the <code>figure*</code> environment got stuck and ended up at the end of the document. The solution was trivial: Remove all placing hints for the float, instead of <code>\begin{figure*}[h]</code> use just <code>\begin{figure*}</code>!
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1311705240">
    <title>C and C++ vs. interpreted languages like Python</title>
    <link>http://uellue.de/blog/single.php?date=1311705240</link>
    <dc:date>2011-07-26T20:34:00+02:00</dc:date>
    <description><![CDATA[<p>Check out these articles!</p>

<ul>
<li>A Guide to Undefined Behavior in C and C++, <a href="http://blog.regehr.org/archives/213">Part 1</a>, <a href="http://blog.regehr.org/archives/226">Part 2</a>, <a href="http://blog.regehr.org/archives/232">Part 3</a></li>
<li>What Every C Programmer Should Know About Undefined Behavior,  <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">Part 1</a>, <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html">Part 2</a>, <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html">Part 3</a></li>
</ul>

<p>A high-level summary: The C and C++ standards are defined in such a way that the result of many operations is undefined if it would require additional checks to make it defined on all platforms. This includes dereferencing invalid pointers, signed integer overflows and shifting beyond bit boundaries. The compiler has lots of room to rearrange or drop code which consequently leads to a fast program. On the down side, it can lead to unexpected and unsafe behavior in many cases. Informing the user about all cases where the code could possibly be unsafe would be either too noisy with tons of false positives or contain too many false negatives.</p>

<p>It seem that such errors are kind of unavoidable in large codebases because only geniuses can figure out what exactly is going on and the bytecode that optimizing compilers generate has little resemblance of the corresponding source code because of loop unrolling, inlining and so on.</p>

<p>A language like <a href="http://python.org">Python</a> looks to me like a very good solution: The programming language has many high-level functions and libraries with completely defined behavior, and the average programmer does not have to worry about undefined behavior. These high-level functions are implemented as highly efficient and thoroughly tested C routines. The interpreter will then, in an ideal case, spend a significant amount of time in these optimized functions (say, for example, multiplying <a href="http://numpy.scipy.org/">numpy</a> matrices) which reduces the overhead from permanent bounds checking and so on. For the interpreted language it is critical that moving parts of the code to C is easy, for example by allowing calls to libraries (example: <a href="http://docs.python.org/library/ctypes.html">ctypes</a>) or implementing subroutines in C (<a href="http://docs.python.org/extending/extending.html">example</a>). C is in those cases only used to speed up the performance bottlenecks or access existing routines.</p>
]]></description>
  </item>
    <item rdf:about="http://uellue.de/blog/single.php?date=1311705240">
    <title>C and C++ vs. interpreted languages like Python</title>
    <link>http://uellue.de/blog/single.php?date=1311705240</link>
    <dc:date>2011-07-26T20:34:00+02:00</dc:date>
    <description><![CDATA[<p>Check out these articles!</p>

<ul>
<li>A Guide to Undefined Behavior in C and C++, <a href="http://blog.regehr.org/archives/213">Part 1</a>, <a href="http://blog.regehr.org/archives/226">Part 2</a>, <a href="http://blog.regehr.org/archives/232">Part 3</a></li>
<li>What Every C Programmer Should Know About Undefined Behavior,  <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html">Part 1</a>, <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html">Part 2</a>, <a href="http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html">Part 3</a></li>
</ul>

<p>A high-level summary: The C and C++ standards are defined in such a way that the result of many operations is undefined if it would require additional checks to make it defined on all platforms. This includes dereferencing invalid pointers, signed integer overflows and shifting beyond bit boundaries. The compiler has lots of room to rearrange or drop code which consequently leads to a fast program. On the down side, it can lead to unexpected and unsafe behavior in many cases. Informing the user about all cases where the code could possibly be unsafe would be either too noisy with tons of false positives or contain too many false negatives.</p>

<p>It seem that such errors are kind of unavoidable in large codebases because only geniuses can figure out what exactly is going on and the bytecode that optimizing compilers generate has little resemblance of the corresponding source code because of loop unrolling, inlining and so on.</p>

<p>A language like <a href="http://python.org">Python</a> looks to me like a very good solution: The programming language has many high-level functions and libraries with completely defined behavior, and the average programmer does not have to worry about undefined behavior. These high-level functions are implemented as highly efficient and thoroughly tested C routines. The interpreter will then, in an ideal case, spend a significant amount of time in these optimized functions (say, for example, multiplying <a href="http://numpy.scipy.org/">numpy</a> matrices) which reduces the overhead from permanent bounds checking and so on. For the interpreted language it is critical that moving parts of the code to C is easy, for example by allowing calls to libraries (example: <a href="http://docs.python.org/library/ctypes.html">ctypes</a>) or implementing subroutines in C (<a href="http://docs.python.org/extending/extending.html">example</a>). C is in those cases only used to speed up the performance bottlenecks or access existing routines.</p>
]]></description>
  </item>
  </rdf:RDF>
