<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Software Development on shocksolution.com</title><link>https://shocksolution.com/tags/software-development/</link><description>Recent content in Software Development on shocksolution.com</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 05 May 2021 20:37:05 +0000</lastBuildDate><atom:link href="https://shocksolution.com/tags/software-development/index.xml" rel="self" type="application/rss+xml"/><item><title>Multi-Page Blueprints for Confluence</title><link>https://shocksolution.com/posts/multi-page-blueprints-for-confluence/</link><pubDate>Wed, 05 May 2021 20:37:05 +0000</pubDate><guid>https://shocksolution.com/posts/multi-page-blueprints-for-confluence/</guid><description>&lt;p&gt;A free demo app is available in the Atlassian Marketplace which supports multi-page blueprints for Confluence. This app works around numerous bugs in the official Atlassian blueprint tutorials and a key Atlassian API bug.&lt;/p&gt;&#10;&lt;h2 id="background-on-confluence"&gt;Background on Confluence&lt;/h2&gt;&#10;&lt;p&gt;&lt;a href="https://%3Cwww.atlassian.com/software/confluence%3E"&gt;Confluence&lt;/a&gt; is one of the leading enterprise wiki products. Its built-in feature set is already very powerful, and it can be extended with &lt;a href="https://marketplace.atlassian.com/addons/app/confluence"&gt;applications available in the Atlassian Marketplace&lt;/a&gt;. You can also write your own applications for private, internal use. Atlassian provides the &lt;a href="https://bitbucket.org/atlassian/atlassian-connect-express/src/master/"&gt;atlassian-connect-express toolkit for building apps with Node.js&lt;/a&gt;, which reduces development time and effort. They also provide a number of &lt;a href="https://bitbucket.org/atlassianlabs/workspace/projects/ATL"&gt;sample projects for Jira and Confluence apps&lt;/a&gt; on Bitbucket. Unfortunately, many of these examples are obsolete or deprecated, and do not function correctly with the latest version of atlassian-connect-express or the latest release of Confluence and Jira.&lt;/p&gt;</description></item><item><title>Node.js: Connecting to MySQL on a socket with Sequelize</title><link>https://shocksolution.com/posts/node-js-connecting-to-mysql-on-a-socket-with-sequelize/</link><pubDate>Thu, 22 Apr 2021 18:54:25 +0000</pubDate><guid>https://shocksolution.com/posts/node-js-connecting-to-mysql-on-a-socket-with-sequelize/</guid><description>&lt;p&gt;According to its official description, &amp;ldquo;&lt;a href="https://sequelize.org/master/index.html"&gt;Sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server.&lt;/a&gt;&amp;rdquo; Sequelize is widely used in Node.js web applications to abstract the database layer. I recently found a &amp;ldquo;corner case&amp;rdquo; for Sequelize which is possible to accomplish, but is not well documented anywhere on the web. I need to use Sequelize to connect to a MySQL server via a UNIX socket. I&amp;rsquo;m developing some plugins for Confluence that use the &lt;a href="https://bitbucket.org/atlassian/atlassian-connect-express/src/master/"&gt;atlassian-connect-express&lt;/a&gt; toolkit, which has a datastore that wraps Sequelize. The way Atlassian has chosen to wrap Sequelize is rather unfortunate, probably because they are trying to maintain backwards compatibility with JugglingDB. Essentially, the Atlassian Connect Express only looks at the URL, and ignores any option passed to Sequelize. Therefore, you have to pass everything you need via the URL, and this is where it&amp;rsquo;s tricky. Here&amp;rsquo;s the form of the URL that you need to connect to MySQL via a UNIX socket with Sequelize:&lt;/p&gt;</description></item><item><title>Configuring Laravel/Lumen applications to connect to SQL database sockets</title><link>https://shocksolution.com/posts/configuring-laravel-lumen-applications-to-connect-to-sql-database-sockets/</link><pubDate>Mon, 14 May 2018 18:58:47 +0000</pubDate><guid>https://shocksolution.com/posts/configuring-laravel-lumen-applications-to-connect-to-sql-database-sockets/</guid><description>&lt;p&gt;The Laravel/Lumen framework documentation does not explain how to connect an application to a database using UNIX sockets instead of a TCP-based network connection. I recently had to configure the &lt;a href="https://polrproject.org/"&gt;Polr URL shortener&lt;/a&gt; (built on the &lt;a href="https://lumen.laravel.com/"&gt;Lumen microframework&lt;/a&gt; by &lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt;) to connect to Google Cloud SQL with a UNIX socket. Since all of Polr&amp;rsquo;s configuration takes place in the &lt;strong&gt;.env&lt;/strong&gt; file, and there is no environment variable that&amp;rsquo;s specific to database sockets, this took some research. I finally found the answer in an &lt;a href="https://stackoverflow.com/questions/29305502/php-artisan-migrate-with-mamp-and-unix-socket/39509268#39509268"&gt;obscure StackOverflow response&lt;/a&gt;. Previous TCP connection: [code] DB_HOST=some-server-name DB_PORT=3306 [/code] Socket-based SQL connection: [code] DB_HOST=localhost;unix_socket=/cloudsql/cloud-project-name:us-east1:sql-instance-name [/code] This approach will work with any UNIX socket; you just need to give it the absolute path to the socket.&lt;/p&gt;</description></item><item><title>Service account credentials with the Python client for the Google Drive API (v3)</title><link>https://shocksolution.com/posts/service-account-credentials-python-client-google-drive-api-v3/</link><pubDate>Mon, 23 Apr 2018 12:23:29 +0000</pubDate><guid>https://shocksolution.com/posts/service-account-credentials-python-client-google-drive-api-v3/</guid><description>&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; &lt;a href="https://github.com/cfinch/Shocksolution_Examples/blob/master/GoogleCloudPlatform/driveAPIexample.py"&gt;Get the full code for this post on Github&lt;/a&gt;. This article only contains important snippets of code that require explanation.&lt;/p&gt;&#10;&lt;p&gt;There are numerous ways to authenticate against the Google Drive API. If you have an application running on Google Compute Engine that needs to access Drive, a Service Account is probably the easiest way to do it. One use case is for an application to write reports or log files to Drive so that users can see them without logging into a server. Before you try this example, go through all of the steps in Google&amp;rsquo;s &lt;a href="https://developers.google.com/identity/protocols/OAuth2ServiceAccount"&gt;Using OAuth 2.0 for Server to Server Applications&lt;/a&gt; guide and save your service account&amp;rsquo;s private key locally in JSON format. Getting credentials from a service account file is easy:&lt;/p&gt;</description></item><item><title>"Exporting" a project from a Git repository</title><link>https://shocksolution.com/posts/exporting-a-project-from-a-git-repository/</link><pubDate>Fri, 24 Jan 2014 18:48:31 +0000</pubDate><guid>https://shocksolution.com/posts/exporting-a-project-from-a-git-repository/</guid><description>&lt;p&gt;What do you do when you want to distribute or release source code that is stored in a Git repository? Obviously, if your target audience is using Git, you can just compress the directory that contains the repository and distribute the copies, or give the users a way to clone your repository (such as &lt;a href="https://github.com/" title="GitHub"&gt;GitHub&lt;/a&gt;). However, your audience may not be Git users, or the hidden .git directory may be very large and you don&amp;rsquo;t want to distribute it. The solution is the &lt;strong&gt;git archive&lt;/strong&gt; command, which packs the files from a tree-ish into an achive (ZIP or TAR). By &amp;ldquo;tree-ish&amp;rdquo;, they mean that you can specify a branch, commit, HEAD, etc. &lt;code&gt;git archive&lt;/code&gt; is somewhat analagous to the &lt;code&gt;svn export&lt;/code&gt; command. I find the most useful form of this command to be: &lt;code&gt;cd example git archive --output ~/example.zip --format=zip --prefix=example/ HEAD&lt;/code&gt; Do not forget the trailing slash after the directory that you specify with the &lt;code&gt;--prefix&lt;/code&gt; flag! REFERENCE: &lt;a href="http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export"&gt;How to do a &amp;ldquo;git export&amp;rdquo; (like svn export)&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Collaborative Git workflow: Shared Repository on a File Server</title><link>https://shocksolution.com/posts/collaborative-git-workflow-shared-repository-on-a-file-server/</link><pubDate>Fri, 10 Jan 2014 20:55:26 +0000</pubDate><guid>https://shocksolution.com/posts/collaborative-git-workflow-shared-repository-on-a-file-server/</guid><description>&lt;p&gt;GitHub is a great tool for collaborating on projects. However, sometimes it is necessary to mimic the &amp;ldquo;GitHub workflow&amp;rdquo; using a shared repository on a local Linux server. The following example shows how I shared an example repository with multiple users.  We are also using the &lt;a href="http://nvie.com/posts/a-successful-git-branching-model/" title="Git%20Flow%20branching%20model"&gt;Git flow model for branching&lt;/a&gt;, aided by the handy &lt;a href="https://github.com/nvie/gitflow" title="Git%20Flow%20plugin"&gt;git flow plugin&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h2 id="on-my-workstation"&gt;On my workstation&lt;/h2&gt;&#10;&lt;p&gt;I started by creating a repo on my local workstation and setting it up to use the git flow plugin.&lt;/p&gt;</description></item><item><title>pickle, hickle and HDF5</title><link>https://shocksolution.com/posts/pickle-hickle-and-hdf5/</link><pubDate>Sun, 03 Feb 2013 19:33:57 +0000</pubDate><guid>https://shocksolution.com/posts/pickle-hickle-and-hdf5/</guid><description>&lt;p&gt;&lt;a href="http://%3C%3Cwww.thetelegraphic.com/&amp;amp;gt%3E;" title="Danny%20Price"&gt;Danny Price&lt;/a&gt; recently left a comment to let me know about a new Python package he&amp;rsquo;s developing called &lt;a href="https://github.com/telegraphic/hickle" title="hickle"&gt;hickle&lt;/a&gt;. The goal of &amp;ldquo;hickle&amp;rdquo; is to create a module that works like Python&amp;rsquo;s &lt;a href="http://docs.python.org/2/library/pickle.html" title="Pickle"&gt;pickle&lt;/a&gt; module but stores its data in the &lt;a href="http://%3C%3Cwww.hdfgroup.org/HDF5/&amp;amp;gt%3E;" title="HDF5%20Project"&gt;HDF5&lt;/a&gt; binary file format. This is a promising approach, because I advocate storing binary data in HDF5 files whenever possible instead of creating yet another one-off binary file format that nobody will be able to read in ten years. The immediate advantage of using HDF5 to store picked Python objects is that HDF5 files are portable across many platforms, while &amp;ldquo;pickled&amp;rdquo; objects may not be readable on a different platform. The hickle developers have made a good start, and they have a long way to go before hickle will be useful to a wider audience. Right now, hickle can only store NumPy ndarrays and Python list objects. If you only need to store lists and arrays, you might as well use HDF5 bindings for Python such as &lt;a href="http://%3C%3Cwww.pytables.org/moin&amp;amp;gt%3E;" title="PyTables"&gt;PyTables&lt;/a&gt; or &lt;a href="http://%3C%3Cwww.h5py.org/&amp;amp;gt%3E;" title="HDF5%20for%20Python"&gt;h5py&lt;/a&gt;. The power of the pickle module is that you can immediately serialize almost any Python object of arbitrary complexity, store it on disk, and retrieve it. hickle will only achieve its full potential once it replicates this functionality, and I&amp;rsquo;m not sure how difficult this will be. Ideally, you might be able to derive a class from Pickler that uses Picker&amp;rsquo;s methods to serialize an object, and then add your own method to write the serialized object to an HDF5 file. In a future post, I&amp;rsquo;ll describe some of the practical problems with using pickle files to store data, and try to organize some thoughts about how they might be solved.&lt;/p&gt;</description></item><item><title>Tricks for Writing XML with Python 3</title><link>https://shocksolution.com/posts/tricks-for-writing-xml-with-python-3/</link><pubDate>Thu, 27 Sep 2012 16:35:49 +0000</pubDate><guid>https://shocksolution.com/posts/tricks-for-writing-xml-with-python-3/</guid><description>&lt;p&gt;I&amp;rsquo;ve added a &lt;a href="https://github.com/cfinch/Shocksolution_Examples" title="Example:%20generating%20XML%20with%20ElementTree%20in%20Python%203"&gt;Python 3 XML example to my Shocksolution_Examples repo on GitHub&lt;/a&gt;.  The new example shows how to generate an XML file which functions as a template for &lt;a href="http://wxglade.sourceforge.net/" title="wxGlade%20rapid%20GUI%20builder%20tool"&gt;building a GUI with wxGlade&lt;/a&gt;.  However, this example should be helpful for anyone who needs to create XML files with Python.  The full example is on GitHub, so I&amp;rsquo;m just going to highlight a few interesting snippets. Use the SubElement factory function to create a new Element instance and add it to an existing element. Here, I create an element called &lt;em&gt;templatedata&lt;/em&gt; and add it to the root element. I then create another element called &lt;em&gt;author&lt;/em&gt; and add it to templatedata.&lt;/p&gt;</description></item><item><title>Python string format examples</title><link>https://shocksolution.com/posts/python-string-format-examples/</link><pubDate>Thu, 03 Nov 2011 22:38:10 +0000</pubDate><guid>https://shocksolution.com/posts/python-string-format-examples/</guid><description>&lt;p&gt;The &lt;a href="http://docs.python.org/library/string.html#format-string-syntax" title="Python%20strings%20format%20method"&gt;format method for Python strings&lt;/a&gt; (introduced in 2.6) is very flexible and powerful.  It&amp;rsquo;s also easy to use, but the documentation is not very clear.  It all makes sense with a few examples.  I&amp;rsquo;ll add more as I have time: &lt;a href="https://%3C%3Cwww.amazon.com/gp/product/0132269937/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0132269937&amp;amp;linkCode=as2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=44971fe03f445ae25fecb2cc2702d3aa&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0132269937&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;tag=rootwork0f-20" alt="image"&gt;&lt;/a&gt;&lt;img src="//ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;l=am2&amp;amp;o=1&amp;amp;a=0132269937" alt="image"&gt;&lt;/p&gt;&#10;&lt;h2 id="formatting-numbers-in-python-strings"&gt;Formatting Numbers in Python Strings&lt;/h2&gt;&#10;&lt;h3 id="formatting-a-floating-point-number"&gt;Formatting a floating-point number&lt;/h3&gt;&#10;&lt;p&gt;[code language=&amp;ldquo;python&amp;rdquo;] &amp;ldquo;{0:.4f}&amp;quot;.format(0.1234567890) &amp;ldquo;{0:.4f}&amp;quot;.format(10.1234567890) [/code] The result is the following string:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;#39;0.1235&amp;#39;&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&amp;#39;10.1235&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;Braces { } are used to enclose the &amp;ldquo;replacement field&amp;rdquo; 0 indicates the first argument to method &lt;strong&gt;format&lt;/strong&gt; : indicates the start of the format specifier .4 indicates four decimal places f indicates a floating-point number&lt;/p&gt;</description></item><item><title>Parsing INI configuration files with FORTRAN</title><link>https://shocksolution.com/posts/parsing-ini-configuration-files-with-fortran/</link><pubDate>Tue, 23 Aug 2011 21:14:44 +0000</pubDate><guid>https://shocksolution.com/posts/parsing-ini-configuration-files-with-fortran/</guid><description>&lt;p&gt;Fortran would not be my first choice for working with text, in any form! However, sometimes even numerical codes need to read data from configuration files. The easiest way to read a configuration file from a Fortran 90 routine is by using &lt;a href="http://owen.sj.ca.us/~rk/howto/slides/f90model/slides/namelist.html" title="Fortran%20namelist%20I/O"&gt;namelist I/O&lt;/a&gt; (I really need to add an example of that). If you&amp;rsquo;re stuck with &lt;a href="http://en.wikipedia.org/wiki/INI_file" title="All%20about%20INI%20files"&gt;INI files&lt;/a&gt;, I found an &lt;a href="http://%3C%3Cwww.fortranlib.com/freesoft.htm#Miscellaneous&amp;amp;gt%3E;" title="Fortran%20INI%20file%20parser"&gt;INI file parser written in Fortran&lt;/a&gt; buried in an index of free Fortran routine.  I don&amp;rsquo;t even remember how I even found it, since it&amp;rsquo;s not well labeled and doesn&amp;rsquo;t come up in the first few pages of Google results, so I thought I&amp;rsquo;d better write a post about it in case I ever need such a thing in the future.&lt;/p&gt;</description></item><item><title>A git branching strategy suitable for large projects</title><link>https://shocksolution.com/posts/a-git-branching-strategy-suitable-for-large-projects/</link><pubDate>Sat, 13 Aug 2011 21:57:14 +0000</pubDate><guid>https://shocksolution.com/posts/a-git-branching-strategy-suitable-for-large-projects/</guid><description>&lt;p&gt;Git is an amazing tool&amp;hellip;but what is the best way to use it?  Like any tool that gives you great power and flexibility, it&amp;rsquo;s up to you to use the tool in the best way to suit your purpose.  A friend of mine who manages an enterprise-class software development team recommended the &lt;a href="http://nvie.com/posts/a-successful-git-branching-model/" title="Git%20flow%20branching%20strategy"&gt;git branching strategy explained in this blog post&lt;/a&gt;.  I highly recommend reading it.&lt;/p&gt;</description></item><item><title>Replacing text in place with GNU sed</title><link>https://shocksolution.com/posts/replacing-text-in-place-with-gnu-sed/</link><pubDate>Mon, 11 Apr 2011 17:39:38 +0000</pubDate><guid>https://shocksolution.com/posts/replacing-text-in-place-with-gnu-sed/</guid><description>&lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Sed" title="sed%20on%20wikipedia"&gt;sed&lt;/a&gt; is a stream editor, which means that it accepts a stream of text, processes it, and spits out another stream of text.  sed can process files that are too large to load into memory, and it is a completely command-line tool that can easily be integrated into shell scripts.  This &lt;a href="http://%3Cwww.grymoire.com/Unix/Sed.html%3E" title="sed%20tutorial"&gt;excellent sed tutorial&lt;/a&gt; was written for an old version of sed provided by Sun Microsystems, and it doesn&amp;rsquo;t cover one of the most useful features of &lt;a href="http://%3Cwww.gnu.org/software/sed/%3E" title="GNU%20sed"&gt;GNU sed&lt;/a&gt;.  GNU sed accepts a &lt;strong&gt;-i&lt;/strong&gt;command line argument that tells sed to replace the text file in place, rather than writing the output stream to another file.  Another nice feature is that&lt;strong&gt;sed -i&lt;/strong&gt; will create a backup file before processing if you provide a backup suffix:&lt;/p&gt;</description></item><item><title>A self-contained Fortran linear equation solver</title><link>https://shocksolution.com/posts/a-self-contained-fortran-linear-equation-solver/</link><pubDate>Wed, 16 Mar 2011 21:33:27 +0000</pubDate><guid>https://shocksolution.com/posts/a-self-contained-fortran-linear-equation-solver/</guid><description>&lt;p&gt;I&amp;rsquo;ve just released a self-contained Fortran module that solves a system of linear equations using the LU decomposition. &lt;a href="https://github.com/cfinch/Shocksolution_Examples/tree/master/FORTRAN/LinearEquationSolver" title="Fortran%20linear%20system%20solver"&gt;Download the Fortran linear solver from github&lt;/a&gt; This module is based on code that was implemented and released on the Web by &lt;a href="http://jean-pierre.moreau.pagesperso-orange.fr/f_matrices.html"&gt;Jean-Pierre Moreau&lt;/a&gt;.  His implementation was based on one of the &lt;a href="http://%3Cwww.nr.com/%3E"&gt;Numerical Recipes&lt;/a&gt; books.  I updated his code to a more strict Fortran 90 standard and added the necessary comments so that it can be built as a Python module using &lt;a href="http://%3Cwww.scipy.org/F2py%3E" title="f2py"&gt;f2py&lt;/a&gt;.  I replaced Jean-Pierre&amp;rsquo;s Fortran test program with a simpler, self-contained program.  I also included a Python script that implements the same test case. I created this module because sometimes a self-contained routine is more appropriate than a full library.  I am compiling a library that implements a custom boundary condition for a proprietary computational fluid dynamics solver (CFD-ACE+).  The library has to be written in Fortran, and it has to be built using a proprietary set of build scripts.  I could either try to reverse-engineer the build process and to modify it to link to a shared library like &lt;a href="http://%3Cwww.netlib.org/lapack/%3E" title="LAPACK"&gt;LAPACK&lt;/a&gt;, or I could implement a self-contained solver.  Since Pierre had already implemented the solver, I was able to slightly modify his code and get it working relatively quickly.&lt;/p&gt;</description></item><item><title>Finding a value in an unordered Fortran array</title><link>https://shocksolution.com/posts/finding-value-in-unordered-fortran-array/</link><pubDate>Fri, 11 Mar 2011 16:27:51 +0000</pubDate><guid>https://shocksolution.com/posts/finding-value-in-unordered-fortran-array/</guid><description>&lt;p&gt;I have been optimizing some Fortran code that involved searching for an integer value in an unordered array (we know the value occurs only once).  Since there is no intrinsic procedure to accomplish this, I thought I&amp;rsquo;d try a couple of approaches to see which was fastest.  The simple answer is that, in this case, brute force beats elegance, even when the target value is near the end of the array. &lt;a href="https://github.com/cfinch/Shocksolution_Examples/tree/master/FORTRAN/FindElementInArray" title="Example%20code"&gt;Download the full example from GitHub&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Sage: open-source mathematical software</title><link>https://shocksolution.com/posts/sage-open-source-mathematical-software/</link><pubDate>Mon, 07 Mar 2011 14:07:19 +0000</pubDate><guid>https://shocksolution.com/posts/sage-open-source-mathematical-software/</guid><description>&lt;p&gt;I&amp;rsquo;ve recently gained a lot of experience with &lt;a href="http://%3Cwww.sagemath.org/%3E" title="Sage"&gt;Sage&lt;/a&gt;, an open-source alternative to MATLAB, Mathematica, Maple, MuPAD, and Magma.  Here are a couple of links to check out:&lt;/p&gt;&#10;&lt;p&gt;&lt;em&gt;&lt;a href="http://%3Cwww.sagenb.org/%3E" title="Sage%20public%20notebook%20servers"&gt;Public notebook servers&lt;/a&gt;--try it online right now!&lt;/em&gt; &lt;a href="http://wiki.sagemath.org/interact" title="Interactive%20Sage%20examples"&gt;Interactive examples with Sage&lt;/a&gt;&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="http://sagemath.org/library-publications.html" title="Publications%20citing%20Sage"&gt;Mathematical publications citing Sage&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="sage-vs-mathematica"&gt;Sage vs. Mathematica&lt;/h2&gt;&#10;&lt;p&gt;My experience with mathematical software started my freshman year at the University of Illinois when I signed up for a calculus class that was taught almost entirely with Mathematica.  I grew to love Mathematica&amp;rsquo;s symbolic computation and plotting capabilities, although I found its programming language to be cumbersome.  Once I was no longer a student, Mathematica was no longer an option due to the hefty licensing fees.  With the caveat that I haven&amp;rsquo;t used Mathematica in many years,  I will say that Sage compares very favorably to my experience with Mathematica.  Sage has a notebook interface that allows you to integrate code, results, text, typeset equations, and graphics in an interactive document that can be viewed with any standards-compliant web browser.  I don&amp;rsquo;t know how Sage stacks up against Mathematica in areas of advanced mathematics.  I have heard that Sage is far ahead of Mathematica in number theory, because the lead developer of Sage is a number theorist.&lt;/p&gt;</description></item><item><title>Linear system simulation with Python</title><link>https://shocksolution.com/posts/linear-system-simulation-with-python/</link><pubDate>Fri, 17 Dec 2010 21:33:16 +0000</pubDate><guid>https://shocksolution.com/posts/linear-system-simulation-with-python/</guid><description>&lt;p&gt;Linear time-invariant (LTI) systems are widely used in the field of signal processing.  &lt;a href="http://scipy.org/" title="Scipy"&gt;Scipy&lt;/a&gt; contains powerful tools for simulating LTI systems in the &lt;a href="http://docs.scipy.org/doc/scipy/reference/signal.html" title="scipy.signal%20docs"&gt;scipy.signal&lt;/a&gt; package, but they are not well documented.  I will provide a simple example that demonstrates how to use a few of the core classes and functions in scipy.signal for simulating LTI systems with Python.&lt;/p&gt;&#10;&lt;h2 id="define-an-lti-system"&gt;Define an LTI system&lt;/h2&gt;&#10;&lt;p&gt;You will need to have Scipy installed, and you will need to have &lt;a href="http://matplotlib.sourceforge.net/" title="Matplotlib"&gt;Matplotlib&lt;/a&gt; as well to make plots. We will start with an example of a &lt;a href="http://en.wikipedia.org/wiki/Time_constant" title="Time%20constant"&gt;first-order LTI system&lt;/a&gt;, which is characterized by a single parameter known as the time constant.  scipy.signal defines the class &lt;strong&gt;lti&lt;/strong&gt; to represent a linear system in Python.&lt;/p&gt;</description></item><item><title>Storing large Numpy arrays on disk: Python Pickle vs. HDF5</title><link>https://shocksolution.com/posts/storing-large-numpy-arrays-on-disk-python-pickle-vs-hdf5adsf/</link><pubDate>Sun, 10 Jan 2010 23:00:20 +0000</pubDate><guid>https://shocksolution.com/posts/storing-large-numpy-arrays-on-disk-python-pickle-vs-hdf5adsf/</guid><description>&lt;p&gt;&lt;a href="https://shocksolution.com/2008/09/15/python-pickle-painless-binary-storage-for-python-objects/" title="Python%20data%20storage%20with%20Pickle"&gt;In a previous post, I described how Python&amp;rsquo;s Pickle module is fast and convenient&lt;/a&gt; for storing all sorts of data on disk. More recently, I showed &lt;a href="https://shocksolution.com/2009/04/17/profiling-memory-usage-of-python-code/" title="Profiling%20Python%20code"&gt;how to profile the memory usage of Python code&lt;/a&gt;.  In recent weeks, I&amp;rsquo;ve uncovered a serious limitation in the Pickle module when storing large amounts of data: Pickle requires a large amount of memory to save a data structure to disk. Fortunately, there is an open standard called HDF, which defines a binary file format that is designed to efficiently store large scientific data sets. I will demonstrate both approaches, and profile them to see how much memory is required. I am writing the HDF file using the PyTables interface. Here&amp;rsquo;s the little test program I&amp;rsquo;ve been using: [code language=&amp;ldquo;Python&amp;rdquo;]#!/usr/bin/env python from numpy import array&lt;/p&gt;</description></item><item><title>f2py: binding Fortran and Python</title><link>https://shocksolution.com/posts/f2py-binding-fortran-python/</link><pubDate>Wed, 23 Sep 2009 22:56:08 +0000</pubDate><guid>https://shocksolution.com/posts/f2py-binding-fortran-python/</guid><description>&lt;p&gt;I  have recently started using &lt;a href="http://%3C%3Cwww.scipy.org/F2py&amp;amp;gt%3E;" title="F2py"&gt;f2py&lt;/a&gt; to call Fortran from Python.  I have found this useful for two reasons: speeding up Python scripts by calling compiled Fortran code, and using Python as a unit testing framework for Fortran modules.   Unfortunately, the &lt;a href="http://cens.ioc.ee/projects/f2py2e/usersguide/index.html" title="F2py%20docs"&gt;documentation&lt;/a&gt; for f2py is rather sparse, and may not be completely up to date.   In this note, I will hopefully prevent you from wasting a lot of time figuring out how to pass array arguments, and return array results.&lt;/p&gt;</description></item><item><title>Profiling memory usage of Python code</title><link>https://shocksolution.com/posts/profiling-memory-usage-of-python-code/</link><pubDate>Fri, 17 Apr 2009 22:08:52 +0000</pubDate><guid>https://shocksolution.com/posts/profiling-memory-usage-of-python-code/</guid><description>&lt;p&gt;In a previous post, I explained how to use the Python profiler.  The profile is great for finding out which parts of the code run the slowest, or are called most often.  However, the profiler doesn&amp;rsquo;t give any information about how much RAM is being consumed, or where it&amp;rsquo;s being consumed.  If your program needs so much memory that it starts swapping to disk, its speed can be reduced by orders of magnitude.  On the positive side, your code may run much faster if it fits entirely in the processor cache.  In this post, I will introduce two tools that can help you understand the RAM usage of your Python code.&lt;/p&gt;</description></item><item><title>Lookup tables and spline fitting in Python</title><link>https://shocksolution.com/posts/lookup-tables-and-spline-fitting-in-python/</link><pubDate>Wed, 08 Apr 2009 23:36:09 +0000</pubDate><guid>https://shocksolution.com/posts/lookup-tables-and-spline-fitting-in-python/</guid><description>&lt;p&gt;Lookup tables and spline fitting are widely used by scientific programmers.  A particular function may not have an analytic solution&amp;ndash;in other words, it can&amp;rsquo;t be expressed as an equation of elementary functions.  This might happen if the function were empirically determined from experimental data, or if the equation can&amp;rsquo;t be algebraically solved for one variable.  If the analytical function is available, but takes a long time to evaluate, a lookup table or spline approximation can be considerably faster.  In a previous post, I showed how to use the function &lt;a href="https://shocksolution.com/2008/12/11/a-lookup-table-for-fast-python-math/" title="scipy.interpolate.interp1d%20as%20a%20lookup%20table"&gt;interp1d from scipy.interpolate as a lookup table&lt;/a&gt;.  In a later post, I showed that &lt;a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp1d.html#scipy.interpolate.interp1d" title="interp1d%20docs"&gt;interp1d&lt;/a&gt; is actually rather slow, and &lt;a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.UnivariateSpline.html#scipy.interpolate.UnivariateSpline" title="Scipy.interpolate.UnivariateSpline"&gt;scipy.interpolate.UnivariateSpline&lt;/a&gt; is much faster.  Now, I will show some benchmark results, and explain a potential pitfall when using UnivariateSpline. The two functions I will use for this demonstration are not very complicated.  Each function is a piecewise approximation of a more complex function.  Here is one of the functions.  For small z, the function uses one approximation, and for large z, it uses a far-field approximation.  For intermediate values, a polynomial is used to smoothly match the two solutions. &lt;a href="https://%3Cwww.amazon.com/Elegant-SciPy-Art-Scientific-Python/dp/1491922877/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-2&amp;amp;ref=sr_1_2&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=b82af06689ab1a386116469d41f270d6&amp;amp;language=en_US%3E"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1491922877&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1491922877" alt="image"&gt;&lt;a href="https://%3Cwww.amazon.com/Learning-Numerical-Scientific-Computing-Second/dp/1783987707/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-3&amp;amp;ref=sr_1_3&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=4f28164dbe2c853ec36f6f35b052e71a&amp;amp;language=en_US%3E"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1783987707&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1783987707" alt="image"&gt;&lt;a href="https://%3Cwww.amazon.com/SciPy-Recipes-performing-mathematical-computations/dp/1788291468/ref=as_li_ss_il?keywords=scipy&amp;amp;qid=1537721480&amp;amp;sr=8-6&amp;amp;ref=sr_1_6&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=0f24d2d9680bc94c36ebe6665e04c5e3&amp;amp;language=en_US%3E"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1788291468&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1788291468" alt="image"&gt;&lt;/p&gt;</description></item><item><title>3D Plotting Software for Python::Part 1::PyX</title><link>https://shocksolution.com/posts/3d-plotting-software-for-python-pyx/</link><pubDate>Fri, 20 Mar 2009 23:08:55 +0000</pubDate><guid>https://shocksolution.com/posts/3d-plotting-software-for-python-pyx/</guid><description>&lt;p&gt;There are lots of good open-source tools that you can use to make high-resolution, publication-quality 2D plots.  Personally, I like to use &lt;a href="http://python.org/" title="Python%20homepage"&gt;Python&lt;/a&gt;, &lt;a href="http://numpy.scipy.org/" title="Numpy%20home%20page"&gt;numpy&lt;/a&gt;, and &lt;a href="http://matplotlib.sourceforge.net/" title="Matplotlib%20home%20page"&gt;matplotlib&lt;/a&gt;.  Unfortunately, it is much harder to find a good tools to make 3D plots.  Older versions of matplotlib had rudimentary 3D support, but this was removed in version 0.98.  In this post, I will review a Python 3D plotting library called &lt;a href="http://pyx.sourceforge.net/" title="PyX%20homepage"&gt;PyX&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h2 id="preparing-the-data"&gt;Preparing the data&lt;/h2&gt;&#10;&lt;p&gt;Figuring out how to store the data to be plotted was actually the hardest part of learning to use PyX.  The data format for 3D plots is not well documented.  PyX requires a list of (x,y,z) lists like this:&lt;/p&gt;</description></item><item><title>The Python configparser: a way to read simple data files</title><link>https://shocksolution.com/posts/the-python-configparser-a-way-to-read-simple-data-files/</link><pubDate>Tue, 03 Feb 2009 23:42:21 +0000</pubDate><guid>https://shocksolution.com/posts/the-python-configparser-a-way-to-read-simple-data-files/</guid><description>&lt;p&gt;My simulation library, which is written mostly in Python, needs a lot of data and parameters in order to run. In some cases, I just hard-code the values in the script that calls the library, and in other cases I &lt;a href="https://shocksolution.com/2008/09/15/python-pickle-painless-binary-storage-for-python-objects/" title="loading%20Python%20pickle%20files"&gt;load a pickle file&lt;/a&gt; containing a Python objext. What if I want to read in data or configuration parameters from a human-editable text file? If the information is extensive or complex, XML might be a good choice, but XML is overkill for simple configuration or data files. Fortunately, a standard Python library called &lt;a href="http://docs.python.org/library/configparser.html" title="ConfigParser%20docs"&gt;ConfigParser&lt;/a&gt; has already defined a configuration file format, and provides methods to interact with such files. Here is a sample of the format used in a config file:&lt;/p&gt;</description></item><item><title>How to put formatted, highlighted code in a Wordpress post</title><link>https://shocksolution.com/posts/how-to-put-formatted-highlighted-code-in-a-wordpress-post/</link><pubDate>Sat, 17 Jan 2009 21:49:36 +0000</pubDate><guid>https://shocksolution.com/posts/how-to-put-formatted-highlighted-code-in-a-wordpress-post/</guid><description>&lt;p&gt;I found two complementary plugins that enable me to put highlighted formatted code in a Wordpress page or post. Here&amp;rsquo;s an example of what they do:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[sourcecode language=&amp;#34;python&amp;#34;]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# Plot flux at continuum boundary&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;pylab.figure()&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;pylab.hold(True)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;pylab.plot(nd_times, Jl_BD, &amp;#39;b-&amp;#39;, label=&amp;#34;Flux from BD simulation&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;pylab.plot(nd_times, Jl_BD+Jl_BD_std, &amp;#39;b.&amp;#39;, label=&amp;#34;Flux from BD simulation&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;pylab.plot(nd_times, Jl_BD-Jl_BD_std, &amp;#39;b.&amp;#39;, label=&amp;#34;Flux from BD simulation&amp;#34;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;[/sourcecode]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;Test successful! Note that Javascript must be enabled to see the highlighting. Get the plugins here:&lt;/p&gt;</description></item><item><title>Deploying Python applications on Windows</title><link>https://shocksolution.com/posts/deploying-python-applications-on-windows/</link><pubDate>Thu, 15 Jan 2009 16:38:56 +0000</pubDate><guid>https://shocksolution.com/posts/deploying-python-applications-on-windows/</guid><description>&lt;p&gt;Writing applications in Python on a Linux system is almost too easy.  Deploying Python apps on other Linux systems is not hard, because most Linux systems already have Python, with its core libraries and tools, installed.  Most Linux systems also have package managers that make it easy to find and install required components.  But, what happens when your co-workers who use Windows need to use your app?  When you tell them to &amp;ldquo;go to the command line and&amp;hellip;&amp;rdquo; you&amp;rsquo;ve pretty much lost them at &amp;ldquo;command line.&amp;rdquo; How do you package Python in a way that&amp;rsquo;s easy for a Windows user to install? Here is a process that worked for me:&lt;/p&gt;</description></item><item><title>Optimizing Python code for fast math</title><link>https://shocksolution.com/posts/optimizing-python-code-for-fast-math/</link><pubDate>Fri, 09 Jan 2009 21:14:38 +0000</pubDate><guid>https://shocksolution.com/posts/optimizing-python-code-for-fast-math/</guid><description>&lt;p&gt;I spent some time today profiling a Brownian dynamics simulation written in Python to see how I could make it faster before starting some long runs on a Linux cluster. In the sections below, I have attempted to quantify the speed improvements due to various changes. Keep in mind that the actual speed improvement in your code will vary, depending on where the actual bottlenecks occur. See my post about &lt;a href="https://shocksolution.com/2008/10/24/profiling-python-code/" title="Profiling%20Python%20code"&gt;profiling Python code&lt;/a&gt;. Another caveat: I am running Python 2.4.4 because it&amp;rsquo;s installed on our cluster.&lt;/p&gt;</description></item><item><title>Redirecting standard output from Python: another example</title><link>https://shocksolution.com/posts/redirecting-standard-output-from-python-another-example/</link><pubDate>Wed, 07 Jan 2009 21:54:10 +0000</pubDate><guid>https://shocksolution.com/posts/redirecting-standard-output-from-python-another-example/</guid><description>&lt;p&gt;I wrote a previous post about how to &lt;a href="https://shocksolution.com/2008/08/16/redirecting-text-output-from-python-functions/" title="Redirecting%20Python%20standard%20output"&gt;redirect standard output from a Python script to a GUI window&lt;/a&gt;.  In this post, I will give an even simpler example of to redirect standard output to a log file.  During the early development and debugging of Python programs, I use print statements to keep me informed of what&amp;rsquo;s happening.  However, printing to the terminal is not always practical&amp;ndash;for example, when I run numerical code on a parallel cluster, there is no way to determine which output came from which instance of the program.  Here is a class that you can use to redirect standard output to a log file:&lt;/p&gt;</description></item><item><title>Tools for Python software development</title><link>https://shocksolution.com/posts/tools-for-python-software-development/</link><pubDate>Tue, 06 Jan 2009 18:52:45 +0000</pubDate><guid>https://shocksolution.com/posts/tools-for-python-software-development/</guid><description>&lt;p&gt;I have found a few tools over the years that I find extremely useful for developing software. Python is my language of choice at the moment, but I&amp;rsquo;m sure these tools will be handy for any language.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="http://subversion.tigris.org/" title="Subversion%20home%20page"&gt;Subversion&lt;/a&gt; is an open-source version-control system. Version control was designed to allow multiple programmers to work on the same project at the same time without stepping all over one another. However, even though I am a solo developer, I find version control to be extremely helpful.&#10;&lt;ol&gt;&#10;&lt;li&gt;When I commit changes to the repository, I can document what I&amp;rsquo;ve changed and why. This is a great help when I introduce a bug and have to go back and find it.&lt;/li&gt;&#10;&lt;li&gt;The repository is stored on a remote server that is backed up nightly.&lt;/li&gt;&#10;&lt;li&gt;It&amp;rsquo;s easy to make an &amp;ldquo;unstable&amp;rdquo; branch for implementing new features. When I make changes that don&amp;rsquo;t work, it&amp;rsquo;s easy to revert to a previous version that works.&lt;/li&gt;&#10;&lt;li&gt;It is easy to deploy my code to the Linux cluster and make sure that the cluster is running the latest version of my software.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Go read the documentation on the Subversion web site to find out what it can do for you.&lt;em&gt;&lt;a href="http://rapidsvn.tigris.org/" title="RapidSVN%20home%20page"&gt;RapidSVN&lt;/a&gt; is a GUI client for a Subversion server. By default, Subversion comes with a command-line client that does everything you need. However, sometimes it&amp;rsquo;s easier to stay organized when everything is presented visually. Here is a screenshot of RapidSVN: &lt;figure class="ma0 w-75"&gt;&lt;img src="https://shocksolution.com/images/rapidsvn_screenshot-150x150.png"&#10;&#9;&#9;&#9;alt="RapidSVN screenshot"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;RapidSVN screenshot&lt;/p&gt;</description></item><item><title>Using Python to generate XML files for visualization in Paraview</title><link>https://shocksolution.com/posts/using-python-to-generate-xml-files-for-visualization-in-paraview/</link><pubDate>Thu, 13 Nov 2008 19:00:23 +0000</pubDate><guid>https://shocksolution.com/posts/using-python-to-generate-xml-files-for-visualization-in-paraview/</guid><description>&lt;p&gt;&lt;a href="http://%3Cwww.vtk.org/%3E" title="VTK%20homepage"&gt;VTK&lt;/a&gt; is an open-source software system for &amp;ldquo;3D computer graphics, image processing, and visualization&amp;rdquo; developed by by Kitware. VTK is the foundation of &lt;a href="http://%3Cwww.paraview.org/%3E" title="Paraview%20homepage"&gt;Paraview,&lt;/a&gt; an industrial-strength CFD visualization tool that I have found to be very useful. I generate &amp;ldquo;second generation&amp;rdquo; XML-based files from my Python code and import them into Paraview for visualization. I am in the process of creating some Python classes to do, and I hope to publish them soon. Until then, I want to share some useful resources. The &lt;a href="http://%3Cwww.vtk.org/pdf/file-formats.pdf%3E" title="VTK%20File%20Formats"&gt;VTK file formats are specified in this document&lt;/a&gt;. It&amp;rsquo;s a pretty good specification, but it lacks some examples. Soon I will post an example of a valid unstructured, serial .vtu file. Each VTK file includes data from only one time step, so you have to keep track of time yourself (the filename is an easy solution). Paraview can read in data from multiple time steps, but you have to specify them in a .pvd file. This is also an XML file, with the following format: (&lt;a href="http://%3Cwww.cmake.org/pipermail/paraview/2008-August/009062.html%3E" title="Cmake%20discussion%20t%20hread"&gt;reference&lt;/a&gt;)&lt;/p&gt;</description></item><item><title>Unexpected integer/float math behavior in Python</title><link>https://shocksolution.com/posts/unexpected-integerfloat-math-behavior-in-python/</link><pubDate>Fri, 07 Nov 2008 00:21:16 +0000</pubDate><guid>https://shocksolution.com/posts/unexpected-integerfloat-math-behavior-in-python/</guid><description>&lt;p&gt;I wasted some time today tracking down a bug in one of my programs.  It turned out to be &amp;ldquo;unexpected behavior&amp;rdquo; rather than a bug.  I was aware of this aspect of the language, but I made an assumption and got bit.  Read on for a valuable lesson. Python handles integer math differently than floating point math.  If you type a number without a decimal point, Python treats it as an integer.  &lt;strong&gt;All math performed only with integers results in integers.&lt;strong&gt;For example, 1/2 evaluates to 0 while 1./2. evaluates to 0.5.  If you mix integers and floats, Python will  produce a floating point result (1/2.=0.5), but you must be very careful.  For example, you might expect the expression 4/3*3.14159 to yield a floating point result.  It does yield a floating point number, but&lt;/strong&gt;not&lt;/strong&gt;the one you were expecting!  4/3*3.14159 yields 3.14159.  What happened?  Python works from left to right.  4/3 evaluates to the integer &amp;ldquo;1&amp;rdquo;.  1*3.14159 evaluates to  3.14159.  For comparison, 4./3.*3.14159 evaluates to 4.1887866.  Here&amp;rsquo;s the problem with this particular aspect of Python: according to the rules of math, 4/3*3.14159 is exactly the same expression as 4*3.14159/3, but in Python they yield different results if you forget the decimal points!  4*3.14159 evaluates to a floating point, so (4*3.14159)/3 yields the &amp;ldquo;correct&amp;rdquo; floating point value. Lesson Learned: be explicit about specifying&lt;strong&gt;all&lt;/strong&gt; floats if you are doing floating-point math!  Sometimes I get lazy and leave a trailing decimal point off of a number when doing a floating point calculation, knowing that the results are &amp;ldquo;upcast&amp;rdquo; into floats. Not any more! Note: this unexpected behavior &lt;a href="http://docs.python.org/dev/3.0/whatsnew/3.0.html#common-stumbling-blocks" title="Python%203.0%20Changes"&gt;goes away in Python 3.0&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Even faster collision detection in Python using Numpy</title><link>https://shocksolution.com/posts/even-faster-collision-detection-in-python-using-numpy/</link><pubDate>Thu, 16 Oct 2008 19:44:15 +0000</pubDate><guid>https://shocksolution.com/posts/even-faster-collision-detection-in-python-using-numpy/</guid><description>&lt;p&gt;Last night, in the shower, I realized that my collision detection routine could be even faster. Here is a representative snippet of code from my previous post:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; d2 = (x-self.x[0:i])*(x-self.x[0:i]) + (y-self.y[0:i])*(y-self.y[0:i]) + (z-self.z[0:i])*(z-self.z[0:i])&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;For some reason, I used the code (x-self.x)*(x-self.x) instead of (x-self.x)**2. Upon further reflection, I realized that (x-self.x)*(x-self.x) computes the difference between array elements twice, and then multiplies the results. Using a &amp;ldquo;power function&amp;rdquo; should enable the interpreter to compute the difference only once, and then multiply each element times itself. Here is the updated code, using Python&amp;rsquo;s power operator:&lt;/p&gt;</description></item><item><title>Speeding up Python math with Numpy: collision detection example</title><link>https://shocksolution.com/posts/speeding-up-python-math-with-numpy-collision-detection-example/</link><pubDate>Sun, 12 Oct 2008 18:10:20 +0000</pubDate><guid>https://shocksolution.com/posts/speeding-up-python-math-with-numpy-collision-detection-example/</guid><description>&lt;p&gt;Python is a very-high-level language.  That makes it easy to write code quickly, but the program may not be as fast as a program compiled from a lower-level language.  For this reason, many scientific programs are written in Fortran or C++.  However, it has always been my experience that the majority of time on a project is spent in writing, modifiying, and debugging code, rather than executing.  Fortunately, if written correctly, the time-critical parts of Python code can execute almost as fast as compiled software.  Here is an example of a collision-detection algorithm which achieved almost a ten-fold increase in speed when written to use &lt;a href="http://numpy.scipy.org/" title="Numpy%20homepage"&gt;Numpy&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Python Pickle: Painless binary storage for Python objects</title><link>https://shocksolution.com/posts/python-pickle-painless-binary-storage-for-python-objects/</link><pubDate>Mon, 15 Sep 2008 22:23:18 +0000</pubDate><guid>https://shocksolution.com/posts/python-pickle-painless-binary-storage-for-python-objects/</guid><description>&lt;p&gt;The &lt;a href="http://docs.python.org/lib/module-pickle.html"&gt;pickle&lt;/a&gt; module provided with Python is so useful that I&amp;rsquo;m surprised I haven&amp;rsquo;t used it before. Pickle allows you to save an entire data structure (such as an object) to disk as a binary file in a effortless (and fairly efficient) manner. For example, in my latest project I have created a Monte Carlo simulation that can take quite a bit of time to run. I also need to make multiple runs to get statistics on the results. At the end of each run, I need to dump the resulting data to disk so that it can be read in later by an analysis program. If I had to write data in a format that could be interchanged with other scientific software, I&amp;rsquo;d use the &lt;a href="http://hdf.ncsa.uiuc.edu/HDF5/"&gt;hdf5&lt;/a&gt; format with the &lt;a href="http://%3C%3Cwww.pytables.org/moin&amp;amp;gt%3E;"&gt;pytables&lt;/a&gt; package. However, right now I just need to get something working, and the pickle module is perfect. Here is how I save an object called box:&lt;/p&gt;</description></item><item><title>Python threads are easy (with example)</title><link>https://shocksolution.com/posts/python-threads-are-easy-with-example/</link><pubDate>Tue, 19 Aug 2008 22:50:07 +0000</pubDate><guid>https://shocksolution.com/posts/python-threads-are-easy-with-example/</guid><description>&lt;p&gt;It&amp;rsquo;s remarkably easy to spawn a Python thread.  However, before doing so, I caution you that a Python thread is not the same thing as an OS thread.  Python threads run within the Python interpreter, but the Python interpreter always executes in a single process.  The reasons why have already been explained elsewhere, so I refer you to the &lt;a href="http://docs.python.org/api/threads.html" title="thread%20module%20docs"&gt;thread module documentation&lt;/a&gt; to learn about the Global Interpreter Lock.  You probably have objections to this state of affairs, and I assure you they have already been &lt;a href="http://blog.snaplogic.org/?p=94" title="Objections%20to%20the%20Global%20Interpreter%20Lock"&gt;voiced&lt;/a&gt; by Juergen Brendel and &lt;a href="http://%3C%3Cwww.artima.com/weblogs/viewpost.jsp?thread=214235&amp;amp;gt%3E;" title="Guido%20van%20Rossum's%20response"&gt;responded to&lt;/a&gt; by Guido van Rossum (creator of Python).  Anyway, the upshot is that Python can only utilize one core of a multi-core CPU.  This isn&amp;rsquo;t such a big deal for me because I&amp;rsquo;m a scientific programmer, and if I really need to write parallel code it&amp;rsquo;s going to have to run on a cluster or a grid.  Threads don&amp;rsquo;t help with that. Having said all that, threads in Python are still useful.  I will detail one example in which I spawn a thread to load a large binary file.  While this doesn&amp;rsquo;t spread the work across multiple CPU cores, it does enable the GUI to remain interactive while the file loads. All you have to do to create a Python thread is create a class that is derived from Thread. In the example below, I derived a class called Loader, which &amp;ldquo;wraps&amp;rdquo; the function that actually reads the binary files. The __init__ method accepts the filename and other options as arguments. The run() method is required. Don&amp;rsquo;t call run() directly&amp;ndash;instead, call the start() method (inherited from the base class) to start the thread.&lt;/p&gt;</description></item><item><title>Fun with threads in Python and wxPython</title><link>https://shocksolution.com/posts/fun-with-threads-in-python-and-wxpython/</link><pubDate>Mon, 11 Aug 2008 22:12:07 +0000</pubDate><guid>https://shocksolution.com/posts/fun-with-threads-in-python-and-wxpython/</guid><description>&lt;p&gt;I have finally gotten back to programming in the last couple of days.  Our project has finally started to generate a lot of data, so I&amp;rsquo;ve been refactoring and improving my code that &lt;a href="https://shocksolution.com/blog/2008/06/25/reading-labview-binary-files-with-python/" title="Reading%20Labview%20binaries%20with%20Python"&gt;reads data stored in LabView binaries&lt;/a&gt;.  Today I spent a lot of time creating a GUI for browsing data.  Arguably, this wasn&amp;rsquo;t the best use of my time, but I learned a lot about multi-threaded Python GUI programming with wxPython.  You can find a gold mine of &lt;a href="http://wiki.wxpython.org/LongRunningTasks" title="Multi-threading%20with%20wxpython"&gt;information on the multi-threaded wx programming&lt;/a&gt; at the wxPython wiki.  Because the LabView binary data has to be read sequentially, and the files are rather large, it takes a long time to read in a file.  I spawn a thread to handle the file reading,  while allowing the GUI to remain responsive.  The thread posts messages to the GUI window, which are used to update the user on the status of the file reading operation.  When the file is read, a final message containing the data is posted to the window.  It&amp;rsquo;s really pretty slick now that I&amp;rsquo;ve figured out how to do it. I will soon post a clever scheme to capture text output from the file-reading function, and display it in the GUI, without making substantial changes to the file-reading function.&lt;/p&gt;</description></item><item><title>Reading Labview binary files with Python</title><link>https://shocksolution.com/posts/reading-labview-binary-files-with-python/</link><pubDate>Wed, 25 Jun 2008 16:04:46 +0000</pubDate><guid>https://shocksolution.com/posts/reading-labview-binary-files-with-python/</guid><description>&lt;p&gt;My research group uses Labview 7.1 to write custom data acquisition (DAQ) software. I code everything else in Python, so I need to get data from Labview into Python for processing. Our DAQ program produces Labview binary files, so I had to find a way to read them with Python. Binary files are nice because they are a compact way to store numerical data as compared to ASCI or (heaven forbid) XML, but they are much harder to read. The binary format used by Labview is documented only indirectly, so I had to hack a little. The first thing to realize is that the Labview binary file is a direct dump of the data that was stored in RAM. &lt;a href="http://zone.ni.com/reference/en-XX/help/371361A-01/lvconcepts/how_labview_stores_data_in_memory/" title="How%20Labview%20stores%20data%20in%20RAM"&gt;How Labview stores data in memory is documented here.&lt;/a&gt; Indirectly, this documents how binary files are stored on disk. Our DAQ program writes a rather complex &amp;ldquo;cluster&amp;rdquo; (Labview&amp;rsquo;s version of a C structure) to disk. The elements of the cluster are stored contiguously as a sequence of bytes, and there&amp;rsquo;s no way to know which byte goes with which element, unless you know the size of each element and the order in which they are stored in the cluster. So, the first step is to document the cluster that&amp;rsquo;s being written to disk. You can use the context help in Labview to view the data type of the wire that leads to the VI that writes the file. With this in hand, you are ready to write Python code. First, make sure you open the file in binary mode:&lt;/p&gt;</description></item><item><title>Server move completed and general update</title><link>https://shocksolution.com/posts/server-move-completed-and-general-update/</link><pubDate>Sun, 22 Jun 2008 19:37:44 +0000</pubDate><guid>https://shocksolution.com/posts/server-move-completed-and-general-update/</guid><description>&lt;p&gt;The site is back online after a server move.  Actually I can&amp;rsquo;t blame the server move for the downtime, because I went out of town and then had a lot of catching up to do, and as a result I didn&amp;rsquo;t switch the domain to point to the new server. I haven&amp;rsquo;t been blogging much because I haven&amp;rsquo;t done much software development, Linux admin, or lighting design lately.  I have been busy in the lab at work and I&amp;rsquo;ve been supervising a trainee lighting operator instead of running my own shows.  We haven&amp;rsquo;t been moving forward with plans to purchase a new lighting control console, so no update on that, either.  Hopefully, I&amp;rsquo;ll have something interesting to post soon.&lt;/p&gt;</description></item><item><title>Presentation at BarCamp Orlando 2008</title><link>https://shocksolution.com/posts/presentation-at-barcamp-orlando-2008/</link><pubDate>Mon, 07 Apr 2008 03:14:32 +0000</pubDate><guid>https://shocksolution.com/posts/presentation-at-barcamp-orlando-2008/</guid><description>&lt;p&gt;I gave a presentation at BarCamp Orlando on 5 April 2008. Here is a link to my presentation, &lt;a href="https://shocksolution.com/files/dataanalysiswithpython.pdf" title="Data Analysis with Python"&gt;Data Analysis with Python&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>My current Gentoo Linux setup</title><link>https://shocksolution.com/posts/my-current-gentoo-linux-setup/</link><pubDate>Mon, 12 Nov 2007 22:15:03 +0000</pubDate><guid>https://shocksolution.com/posts/my-current-gentoo-linux-setup/</guid><description>&lt;p&gt;This post is a reminder to myself more than it is intended for anyone else.  Well, that&amp;rsquo;s most of this blog.  Gentoo is a great distribution of Linux, but you have to install everything yourself. This is a good thing, because you get a very lean system, but the downside is that you are re-inventing the wheel somewhat with every install. So, without further ado, here is my current favorite configuration: &lt;strong&gt;Global USE flags:&lt;strong&gt;X cups dbus hal jpeg png gs dvi gif tiff mpeg bzip2 gtk lapack tetex -gnome -kde&lt;/strong&gt;Package list (basic software):&lt;/strong&gt;* dbus (&lt;a href="http://%3Cwww.freedesktop.org/wiki/Software/dbus%3E" title="dbus"&gt;message bus system&lt;/a&gt;)* hal  (&lt;a href="http://%3Cwww.freedesktop.org/wiki/Software/hal%3E" title="HAL"&gt;Hardware Abstraction Layer&lt;/a&gt;)&#10;&lt;em&gt;gentoolkit&lt;/em&gt; vim/gvim&#10;&lt;em&gt;x.org&lt;/em&gt; xfce4&#10;&lt;em&gt;thunar&lt;/em&gt; mozilla-firefox&#10;&lt;em&gt;acroread&lt;strong&gt;Package list (technical software):&lt;/strong&gt;&lt;/em&gt; blas-atlas* lapack-reference&#10;&lt;em&gt;numpy (unstable 0.90.1)&lt;/em&gt; matplotlib (Matlab-like plotting package for Python)&#10;&lt;em&gt;texlive (experimental, hard-masked)&lt;/em&gt; lyx&#10;&lt;em&gt;evince (dvi, ps, pdf viewer)&lt;/em&gt; paraview (3D visualization of datasets, unstable)&lt;/p&gt;</description></item><item><title>ODEPACK re-released</title><link>https://shocksolution.com/posts/odepack-re-released/</link><pubDate>Wed, 26 Sep 2007 03:44:58 +0000</pubDate><guid>https://shocksolution.com/posts/odepack-re-released/</guid><description>&lt;p&gt;Minutes ago I uploaded a tarball containing my &lt;a href="https://shocksolution.com/math_tools/odepack/index.html" title="ODEPACK"&gt;re-release of ODEPACK&lt;/a&gt;, a standard numerical tool for the solution of systems of ordinary differential equations. The algorithms and numerical code are identical to the distribution &lt;a href="http://%3Cwww.netlib.org/odepack/%3E" title="ODEPACK%20home"&gt;found on Netlib&lt;/a&gt;, but everything has been placed into an organized &amp;ldquo;package&amp;rdquo; with Makefiles, examples, documentation, etc. The code is set up to be compiled as a shared library that you can link to your code. Download and enjoy! And tell me if you&amp;rsquo;re using it!&lt;/p&gt;</description></item><item><title>Direct access to C++ containers from Python</title><link>https://shocksolution.com/posts/direct-access-to-c-containers-from-python/</link><pubDate>Thu, 13 Sep 2007 16:31:01 +0000</pubDate><guid>https://shocksolution.com/posts/direct-access-to-c-containers-from-python/</guid><description>&lt;p&gt;In previous examples, I&amp;rsquo;ve shown how to pass Python lists into C++ using Boost.python. Because Python lists can contain a mixture of objects of different types, C++ has to use extract&amp;lt;type&amp;gt; to determine what kind of data to get from a list item. This approach works well, but it has its faults. In the C++ code, you might need to have duplicate data structures (a boost.python list to interchange data with Python and a C++ container such as a vector to process the data) and the code to convert between them. If you want to use your C++ library with languages other than Python, you want a non-Python-specific interface. Wouldn&amp;rsquo;t it be great to define your core data structures using a standard C++ container (like vector) and then access and modify them in Python? You can, but it&amp;rsquo;s non-obvious and it&amp;rsquo;s not well explained in the Boost.python docs. Read the &lt;a href="http://%3Cwww.boost.org/libs/python/doc/v2/indexing.html%3E" title="Boost%20indexing%20suite%20docs"&gt;docs for the indexing suite&lt;/a&gt; and take a look at my &lt;a href="https://shocksolution.com/files/Demo_Exposing_Cplusplus_Vectors.zip"&gt;demonstration code for exposing C++ vectors to Python&lt;/a&gt;, and you should be able to figure it out. Once you get it working, it&amp;rsquo;s a very clean way of doing things. Just remember, because you&amp;rsquo;re working with C++ containers that accept only the specified type of object Python will throw a TypeError if you try to append the wrong kind of object.&lt;/p&gt;</description></item><item><title>Mixing objects of different types in a Boost.python list</title><link>https://shocksolution.com/posts/mixing-objects-of-different-types-in-a-boostpython-list/</link><pubDate>Wed, 08 Aug 2007 15:35:26 +0000</pubDate><guid>https://shocksolution.com/posts/mixing-objects-of-different-types-in-a-boostpython-list/</guid><description>&lt;p&gt;&lt;a href="https://shocksolution.com/files/ExtractMultipleClasses.zip" title="Demo Code"&gt;Demonstration Code&amp;ndash;mixing objects of different types in a Boost.python list&lt;/a&gt; In Python, a list is allowed to contain objects of various types. Using Python&amp;rsquo;s introspection capabilities, it&amp;rsquo;s easy to process a mixed list because you can just test each list member to see what kind it is, using isinstance(objectA, TypeB). This creates a problem when the list is passed into C++, where arrays and containers are designed to hold objects of one type. I encountered this problem when writing a small module to parse mathematical expressions. The expression is entered as a string in Python, which is parsed and &amp;ldquo;compiled&amp;rdquo; into a stack of objects. The compiled stack is passed to C++ using boost.python, where it is processed when needed. The stack consists of two or more fundamentally different objects: numerical constants and operators. The evaluation routine pops an object. If it&amp;rsquo;s a numerical constant, the value is placed on the operand stack. If it&amp;rsquo;s an operator, the appropriate operation is performed on the values at the top of the operand stack. With help from Alex Mohr and Christopher Woods on the &lt;a href="http://mail.python.org/pipermail/c++-sig/" title="C++-sig"&gt;C++-sig mailing list&lt;/a&gt;, I developed a method that is illustrated in the example. In C++, define a polymorphic base class (has at least one virtual method) and several classes that are derived from the base class. These classes are exposed to Python using &lt;a href="http://%3Cwww.boost.org/libs/python/doc/%3E" title="Boost.python"&gt;Boost.python&lt;/a&gt; so that objects can be created in Python. A list of mixed objects is then passed back to C++ for processing. When trying to access a member of the list, C++ doesn&amp;rsquo;t know what kind of object to expect, so we have to use the Boost.python function extract&amp;lt;&amp;gt;() (see previous post for an introduction to &lt;em&gt;extract&lt;/em&gt;). Now we extract a pointer to the base class using: object = extract &amp;lt;BaseClass*&amp;gt; (list[index]); This works because every object in the list is derived from the base class. As shown in the example, I first tried to do this with references (to avoid the whole pointer mess) but it did not work, so it seems that pointers are unavoidable here. It seems that this use of introspection is relatively rare in OOP, and is &lt;a href="http://%3Cwww.canonical.org/~kragen/isinstance/%3E" title="Discouraging%20use%20of%20isinstance()"&gt;sometimes actively discouraged&lt;/a&gt;. However, for this type of problem it seems like the most logical design. Is there a different design pattern that would work better?&lt;/p&gt;</description></item><item><title>USPTO tries peer review for software patents</title><link>https://shocksolution.com/posts/uspto-tries-peer-review-for-software-patents/</link><pubDate>Wed, 04 Jul 2007 21:55:06 +0000</pubDate><guid>https://shocksolution.com/posts/uspto-tries-peer-review-for-software-patents/</guid><description>&lt;p&gt;The US Patent and Trademark Office (USPTO) has launched a trial program to subject software patents to &lt;a href="http://%3Cwww.peertopatent.org/%3E"&gt;peer review online&lt;/a&gt;.  Naturally, the big software companies aren&amp;rsquo;t exactly publicizing this.  We all know that a lot of stupid patents get issued.  Well, stop complaining and start reviewing!  Let&amp;rsquo;s make this trial successful!&lt;/p&gt;</description></item><item><title>Example: using an extractor class in Boost.Python</title><link>https://shocksolution.com/posts/example-using-an-extractor-class-in-boostpython/</link><pubDate>Mon, 16 Apr 2007 03:12:23 +0000</pubDate><guid>https://shocksolution.com/posts/example-using-an-extractor-class-in-boostpython/</guid><description>&lt;p&gt;The &lt;a href="http://%3Cwww.boost.org/libs/python/doc/v2/Extractor.html%3E"&gt;documentation for the Boost.Python extractor class&lt;/a&gt; is not terribly enlightening for a new user. The examples given in the tutorial are code fragments, and it&amp;rsquo;s never clear exactly what the context is or what they are supposed to accomplish. That&amp;rsquo;s a shame, because the extractor classes are really cool and easy to use, so people should use them! Here is a &lt;a href="https://shocksolution.com/files/TestExtractor.tgz"&gt;Boost Python extractor example&lt;/a&gt; that should make things clear.&lt;/p&gt;</description></item><item><title>"Ubuntu" actually means "eats your config files"</title><link>https://shocksolution.com/posts/ubuntu-actually-means-eats-your-config-files/</link><pubDate>Wed, 14 Mar 2007 20:08:52 +0000</pubDate><guid>https://shocksolution.com/posts/ubuntu-actually-means-eats-your-config-files/</guid><description>&lt;p&gt;The Dapper-to-Edgy upgrade was surprisingly smooth, once I figured out how to do it. Unfortunately, the new version overwrote my &amp;ldquo;/boot/grub/menu.lst&amp;rdquo; so I could not boot Windows. I have enough experience with Linux that this was a five-minute fix, but it could be pretty scary for an inexperienced person. Who knows what else got over-written and I just didn&amp;rsquo;t realize it. I was further disappointed to find out that the version of &lt;a href="http://pida.co.uk/"&gt;PIDA&lt;/a&gt; in Edgy is broken.&lt;/p&gt;</description></item><item><title>Ubuntu is an African word that means "devours your soul"</title><link>https://shocksolution.com/posts/ubuntu-is-an-african-word-that-means-devours-your-soul/</link><pubDate>Mon, 12 Mar 2007 22:57:45 +0000</pubDate><guid>https://shocksolution.com/posts/ubuntu-is-an-african-word-that-means-devours-your-soul/</guid><description>&lt;p&gt;When it comes to Linux, I&amp;rsquo;m a &lt;a href="http://%3Cwww.gentoo.org%3E" title="Gentoo"&gt;Gentoo&lt;/a&gt; guy. Go ahead, make fun of me and call me a ricer. Then go try to do something difficult on Redhat or Ubuntu, and come back and tell me what you think. I needed a Linux development environment at work, so I took my Windows machine and added a Linux partition. Since Ubuntu has been getting a lot of good press, and I wanted something that would install &lt;em&gt;fast&lt;/em&gt;, I tried Ubuntu. Specifically, I installed Kubuntu, because &lt;a href="http://linux.slashdot.org/article.pl?sid=05/12/13/1340215"&gt;Linus Torvalds doesn&amp;rsquo;t use Gnome&lt;/a&gt;. It really did install quickly and everything worked great out of the box. I installed a number of packages, and they worked too! Too good to be true? Absolutely! It all started when I wanted to compile something. Silly me, I thought &lt;a href="http://gcc.gnu.org/" title="gcc"&gt;gcc&lt;/a&gt; was a basic part of a basic Linux installation&amp;hellip;but no, that must be a Gentoo bias, so I installed gcc. Then I decided to install &lt;a href="http://numpy.scipy.org/" title="numpy"&gt;numpy&lt;/a&gt;, the latest numerical toolkit for Python. It&amp;rsquo;s been around for a couple of years as a beta, so I figured there must be an &amp;ldquo;unstable&amp;rdquo; build out there. Nope. To get numpy, you have to upgrade from Ubuntu 6.06 &amp;ldquo;Dapper&amp;rdquo; to 6.10 &amp;ldquo;Edgy&amp;rdquo;. &amp;lt;sarcasm&amp;gt;Because it makes sense to upgrade gcc, KDE, Firefox, etc just to get a new Python package.&amp;lt;/sarcasm&amp;gt; Now, go find instructions on how to upgrade the Ubuntu distribution. Then try those instructrions and realize that they won&amp;rsquo;t work at all for Kubuntu because the package managers are totally different. While you&amp;rsquo;re there, read the horror stories on the forums from people who followed the &amp;ldquo;official&amp;rdquo; upgrade instructions and ended up with less-than-functioning systems. FYI, the Kubuntu &lt;a href="http://kubuntu.org/announcements/6.10-release.php"&gt;upgrade instructions&lt;/a&gt; are actually easy to find once you know where to look. Kubuntu 6.10 is installing right now, so tomorrow we&amp;rsquo;ll see how it went.&lt;/p&gt;</description></item><item><title>Python calling C++ calling Fortran</title><link>https://shocksolution.com/posts/python-calling-c-calling-fortran/</link><pubDate>Fri, 09 Mar 2007 04:40:03 +0000</pubDate><guid>https://shocksolution.com/posts/python-calling-c-calling-fortran/</guid><description>&lt;p&gt;I got it working a while ago, but I haven&amp;rsquo;t had a chance to update my eager audience.  I built a simple simple simulation tool using this crazy combination of languages.  It&amp;rsquo;s a library written in C++ that uses the finite volume method to simulate diffusion in one dimenstion. What&amp;rsquo;s cool is that it&amp;rsquo;s designed to be called from Python using Boost.  Furthermore, it then uses Boost Bindings (not officially part of Boost) to call LAPACK (a Fortran library) to solve linear equations (as shown in a previous post).  It&amp;rsquo;s pretty cool that all this stuff actually works together.  Why did I do this?  Python is my favorite very-high-level language for doing scientific programming.  Compared to C++ or Fortran, it&amp;rsquo;s just so &lt;em&gt;easy&lt;/em&gt; to do things in Python, like making plots or reading in an xml file.  I chose C++ for the numerical codes because it&amp;rsquo;s faster than Python and the Boost library connects the two.  I could have used Fortran, but the Python interfaces doesn&amp;rsquo;t seem to be as clean, probably because Fortran isn&amp;rsquo;t object-oriented.  Finally, since the reference implementation of LAPACK is still in Fortran, I just used the Boost bindings to call it.  I might switch to a native C++ linear algebra library if a clear leader emerges from the confusing alternatives that are available today.  More complaints on that later&amp;hellip;&lt;/p&gt;</description></item><item><title>Subtle aspects of using Boost and LAPACK</title><link>https://shocksolution.com/posts/subtle-aspects-of-using-boost-and-lapack/</link><pubDate>Tue, 27 Feb 2007 23:43:59 +0000</pubDate><guid>https://shocksolution.com/posts/subtle-aspects-of-using-boost-and-lapack/</guid><description>&lt;p&gt;I spent part of the afternoon wrestling with LAPACK integration in a C++ program, using the unofficial Boost bindings. I learned a couple of interesting things. &lt;a href="https://shocksolution.com/files/test.C" title="test.C"&gt;test.C&lt;/a&gt; is a file that demonstrates them. 1. You need to create column-major matrices to pass to LAPACK. The subtle part about this is that the matrices are internally stored as column-major (like Fortran) but are &lt;em&gt;accessed&lt;/em&gt; like row-major matrices (like C). In other words, even when you declare A as column-major, A(3,5) refers to the third row and fifth column of A. This was not obvious to me. 2. The LAPACK routines may modify the matrices that are passed to them. For example, when using gesv(A,B) to solve a system of linear equations, the matrix B is modified to contain the solution values&amp;ndash;this is obvious. It is not obvious, at first, that the matrix A is also modified (and I don&amp;rsquo;t know what useful information it contains). 3. There does not seem to be any binding to the specialized LAPACK solvers for banded and tri-diagonal matrices. I would like to know why, since my matrix is tri-diagonal and it can probably be solved considerable more quickly.&lt;/p&gt;</description></item><item><title>The need for 3D technical drawing software</title><link>https://shocksolution.com/posts/the-need-for-3d-technical-drawing-software/</link><pubDate>Mon, 26 Feb 2007 21:42:17 +0000</pubDate><guid>https://shocksolution.com/posts/the-need-for-3d-technical-drawing-software/</guid><description>&lt;p&gt;Today I was reminded again of the need for a new kind of technical drawing software.  Here is the problem I am facing: I want to create a vector drawing of a three dimensional structure.  Right now, I can either create it in CAD and export a bitmap, or I can manually draw a 3-D representation using 2-D vector software such as Dia or Xfig.  For publication-quality graphics, the first approach is usually out.  The second approach works, but what if I spend an hour drawing, only to realize that I should have chosen a different perspective or viewpoint to show a critical feature of the drawing?  I have to modify the entire drawing just to change the viewpoint.  Or, what if I need to show two views to capture all the details? I have to create both from scratch. I envion a new type of tool, or CATD (Computer Aided Technical Drawing).  My vision starts with a 3-D CAD tool, which could be built around lines, points, and surfaces (like AutoCAD) or a solid modeling kernel (like SolidWorks).  The user should have the ability to choose surfaces to be transparent or solid, and create cut planes to show internal features.  However, the 3-D model is only the first step. Once the user has created the model and chosen a viewpoint that shows its important features, the 3-D model is projected onto a 2D surface to create a vector drawing that can be further manipulated.  Ideally, the 2-D vectors created from each &amp;ldquo;object&amp;rdquo; in the CAD model would remain grouped together for easy manipulation.  The final output would be a publication-quality PostScript, PDF, or SVG file. I don&amp;rsquo;t know if this is commercially available, but it certainly isn&amp;rsquo;t available as open source.  As a starting point, I propose creating a plugin for Blender that fulfills this purpose.  It would take the 3-D model, as displayed on the screen, and create a vector 2-D representation that can be imported into other software for manipulation. Ultimately, the tool should allow users to import different types of CAD models.  The text should be somehow integrated with LaTeX for seamless typesetting of equations and numbers.&lt;/p&gt;</description></item><item><title>LISP is cool but annoying</title><link>https://shocksolution.com/posts/lisp-is-cool-but-annoying/</link><pubDate>Mon, 26 Feb 2007 05:09:14 +0000</pubDate><guid>https://shocksolution.com/posts/lisp-is-cool-but-annoying/</guid><description>&lt;p&gt;I spent today organizing my personal finances in GnuCash. I also spent a few hours customizing a report, which unfortunately means hacking in Scheme, a &amp;ldquo;dialect&amp;rdquo; of LISP. Don&amp;rsquo;t get me wrong, I actually &lt;em&gt;like&lt;/em&gt; LISP/Scheme quite a bit. What I don&amp;rsquo;t like is writing code in &amp;ldquo;normal&amp;rdquo; languages, like C++ and Python, all week long and then switching to Scheme. Scheme has a totally different syntax and requires a different way of thinking about a problem. Normal language: &lt;code&gt;result = myfunction (argument1, argument2)&lt;/code&gt; Scheme code: &lt;code&gt;(myfunction (argument1 argument2))&lt;/code&gt; If you have never seen a LISP language, find one and check it out. Here are the links I always use:&lt;/p&gt;</description></item></channel></rss>