From the book Fluent Python (which you can get from the Humble Bundle right now):
What would the following piece of code do?
- A TypeError is raised because tuples does not support item assignments?
- Both 1. and 2.
The answer is the link, which is quite surprising.
It turns out that
t.extend([50, 60])doesn’t break Python, and this riddle is really a super esoteric corner case…
The title is probably misleading, but this is a lesson I needed to talk about.
I wrote out some simple code for the quadrature over the reference triangle last time, which involves a double loop. To my chagrin, my immediate reaction to speeding up the code was to put it into Cython, and give it some type declaration.
This did speed up my integrals, but not as much as vectorization. By simply condensing one of the loops into a dot product, and using vector-function evaluation, I sped up my code a substantial amount, especially with higher order integration of “hard” functions.
To see what I mean, consider the following function
The speedup I get is staggering.
Also, I tried to fully vectorize by removing the outer-loop. This actually slowed down the code a bit. Maybe I did it wrong? But for now, I’m decently happy with the speed.
I think I finally understand why software packages like PETSc has an option for an operator when doing something like conjugate gradient. Why isn’t having a matrix good enough for everyone?
Well turns out that while all linear operators can be translated to a matrix, it may not be the best way to represent the operator. As an example, consider a basis transformation from Bernstein polynomials to Jacobi (or vice versa). It’s certainly possible to find and construct a matrix which does the operation, but it’s ugly.
On the other hand, it’s not that bad to write a code which utilizes the properties of the polynomials and convert it within in O(n^2) time. The key is that a Jacobi polynomial is a sum of Bernsteins, and Bernsteins can be degree raised or dropped at will.
This function will outperform the matrix in many sense. For one, there’s no need to construct a matrix, which will take n^2 operations in the first place. Next, matrix multiplication will take a n^3 operation, so if we optimize enough, we will always beat it. Finally, it’s really less painful to code, because each line of the function serves a visible purpose.
Anyways, I’m sold.
(I’ll eventually publish the code in the summer)
Some notes from the past week:
- It is incredibly easy to be an impostor in a more academic party. First of all, most of the people will be already intoxicated to the point where bullshit science can’t be discerned from actual science. This is good as I can just say random facts I remember from Popular Science.Another acceptable thing to do is to just ask questions upon questions. “What’s your research? … Oh that’s so cool! Tell me more about it! … So does this connect to insert scientific news here? Wow.” That’ll burn around 5 minutes minimum.The main problem comes when you run out of questions in the initial barrage. It also fails when the person is laconic or can’t speak English.
- Installing a SSD is extremely easy, but installing operating systems are hard. Right now, I have around 8 entries on my GRUB menu before I migrate everything over to my new distro.I followed the mount guide provided here, which seems intuitive enough on where to put mount points. I’ve also learned that
are my friends. There’s also that good GParted software.
- The Lloyd Trefethren numerical linear algebra book is quite good for a quick overview of the subject. It doesn’t get bogged down with the analysis, and generally refers to other books (mainly the Van Loan) throughout.
- Holy shit URF mode.
- I need to be more brave in a certain subject….
I won’t post the entire code here, because it’s pretty damn ugly. But here’s what I ended up doing:
- I used the
statement to find the beginning and end points to extrapolate a line from.
- Now that I have a line, I use the formula provided by Wikipedia using the vector formulation of the line.
- Simply do a loop over the vertices and find the minimum.
Sorry for note posting recently… I got caught up in things… 🙁
The solution to this if you’re using the GUI on Linux can quite possibly be that ptrace_scope was set to 1.
From the Intel forums:
Note: In Ubuntu 11.4, you may need to disable ptrace_scope.
cat /proc/sys/kernel/yama/ptrace_scope; “0” is expected, if it is “1”,
$echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
Took me a while to find… hope this saves someone some time.
Doing another SPH implementation for parallel computing. It’s amazing how fast adding a hash table, instead of looking at all particles does for one’s speed. 1429.22 seconds to only 327 seconds. That’s 5 times as fast!
I’ve been working on a few things:
- Position-based fluids for my CS5643 class, which is a pain to debug. Normally, I have tons of intuition on what numbers are suppose to be but my intuition is nil here. I’m unsure as we’re guessing the correct parameters or even the right formulas and procedure.It’s a great class, just the project are incredibly tedious. For example, my particles right now just seem to float of into the x direction and stay there. Why would it do that?
Hopefully, what ends up happening is something like the following, except less pretty.
- I finally installed Hearthstone for my Elementary OS Linux box. It was incredibly easy following this tutorial.
- In terms of research, I’ve been reading up on different ways to generate the Krylov basis for GMRES as described in this paper. I’ll probably write up and refined the old “idiot’s guide” again for this paper information (and fix the bad latex in there).
- This soundtrack (not allowed to embed).
- My card handeling has suffered :(.