This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* y += A*x | |
* | |
* Matrix-Vector multiplication optimization experiment | |
* TODO: Benchmark against the following: | |
* eigen2: ourselves, with the default options (SSE2 vectorization enabled). | |
* eigen2_novec: ourselves but with Eigen's explicit vectorization disabled. However, gcc's auto-vectorization was enabled. | |
* INTEL_MKL: The Intel Math Kernel Library, which includes a BLAS/LAPACK (11.0). Closed-source. | |
* ACML: The AMD's core math library, which includes a BLAS/LAPACK (4.2.0). Closed-source. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <cblas.h> | |
double m[] = { | |
3, 1, 3, | |
1, 5, 9, | |
2, 6, 5 | |
}; | |
double x[] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"fmt" | |
"flag" | |
"strconv" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import subprocess | |
import sys | |
import os | |
import re | |
# output directory for generated png files | |
global basedir | |
basedir = '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iterator> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
// find all occurrences of pattern in the text as a vector of indices | |
// using the knuth morris pratt algorithm in time O(|text| + |pattern|) | |
vector<int> kmp_find_all(const string &t, const string &p) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In[79]:= Rz[x_] := ( { | |
{Cos[x], -Sin[x], 0}, | |
{Sin[x], Cos[x], 0}, | |
{0, 0, 1} | |
} ); | |
Ry[x_] := ( { | |
{Cos[x], 0, Sin[x]}, | |
{0, 1, 0}, | |
{-Sin[x], 0, Cos[x]} | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is just an instructive exercise using pointers. The goal is to | |
// reverse a linked list, which is not difficult but this solution | |
// illustrates a particular idea that I first came across in a talk by | |
// Linus Torvalds. | |
// | |
// The idea is simply that holding a pointer to pointer allows | |
// changing what is being pointed to, and that this can be used in a | |
// neat way in the context of linked lists. Take the example of | |
// inserting an item in a list. Here, the role played by the `head` | |
// pointer is similar to the role played by the `next` pointer of some |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A little exercise to demonstrate the lifetime of temporaries in | |
// C++. Inspired by the comment in this video | |
// https://youtu.be/xu7q8dGvuwk?t=3156 at CppCon2017 by Titus Winters. | |
// | |
// Two things to note: | |
// | |
// - Temporaries (rvalues) can have their lifetimes extended by | |
// binding them to a const reference. But the lifetime is extended | |
// only to the lifetime of the const reference itself, no more (see | |
// the Split(..) function below). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code presents an alternate style of runtime polymorphism | |
// fleshed out in Sean Parent's talk on the subject | |
// (https://www.youtube.com/watch?v=QGcVXgEVMJg). The goal is to treat | |
// different collections of types polymorphically based on their uses | |
// in different contexts without requiring client-side inheritance of | |
// those types depending on each of the uses. | |
#include <iostream> | |
#include <memory> | |
#include <string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Study to understand the semantics of moves vs. copies in C++. | |
// | |
// * These operations are different only for reference types like the | |
// String class defined below. Unlike value types, a literal bitwise | |
// copy does not make sense for reference types. Instead, a copy | |
// typically involves a heap allocation followed by a bitwise copy | |
// from the object(s) being pointed to. | |
// | |
// * The goal of a move operation is to avoid unnecessary copying (and | |
// the associated heap allocations) when possible. For instance, in |