Skip to content

Instantly share code, notes, and snippets.

View jmbr's full-sized avatar

Juan M. Bello-Rivas jmbr

View GitHub Profile
/*
* Example: spy("foobar.ppm", A);
*/
int spy(std::string const& ppmfile, arma::mat const& M) {
ofstream ofs(ppmfile);
if (!ofs.is_open())
return -1;
ofs << "P3\n" << M.n_rows << " " << M.n_cols << "\n1\n";
@jmbr
jmbr / test-cholmod.cpp
Last active November 19, 2023 05:09
Simple example of how to use SuiteSparse's SPQR by creating a matrix of triplets.
#include <cstdlib>
#include <iostream>
#include <SuiteSparseQR.hpp>
int main(int argc, char* argv[]) {
cholmod_common common;
cholmod_sparse *A;
cholmod_dense *x, *b, *residual;
@jmbr
jmbr / gnome-flashback-stumpwm
Last active May 22, 2020 00:48
StumpWM with Gnome Flashback: all the amenities of Gnome plus the slick features of StumpWM.
This file goes in /usr/lib/gnome-flashback/
#! /bin/sh
exec gnome-session --session=gnome-flashback-stumpwm --disable-acceleration-check "$@"
.text
.align 4,0x90
.globl __Z21matrix_vector_productPKdPd
__Z21matrix_vector_productPKdPd:
LFB18:
movsd (%rdi), %xmm0
movsd 8(%rdi), %xmm4
movapd %xmm0, %xmm5
movsd 16(%rdi), %xmm3
mulsd %xmm0, %xmm5
.text
.align 4,0x90
.globl __Z21matrix_vector_productPKdPd
__Z21matrix_vector_productPKdPd:
LFB18:
vmovsd 8(%rdi), %xmm2
vmovsd (%rdi), %xmm1
vmulsd %xmm2, %xmm2, %xmm3
vmovsd 16(%rdi), %xmm0
vmovsd 32(%rdi), %xmm6
@jmbr
jmbr / build-mpisbcl.sh
Created June 15, 2019 17:20
Create an MPI-enabled SBCL executable
#!/bin/sh
sbcl --eval "(ql:quickload '(:swank :cl-mpi))" \
--eval "(defun toplevel () \
(push #'mpi:mpi-finalize *exit-hooks*) \
(mpi:mpi-init) \
(let ((port (+ swank::default-server-port (mpi:mpi-comm-rank)))) \
(swank:create-server :port port :dont-close t)) \
(sb-impl::toplevel-init))" \
--eval "(save-lisp-and-die \"mpisbcl\" :executable t :toplevel #'toplevel)"
@jmbr
jmbr / .stumpwmrc.lisp
Last active August 8, 2020 06:15
My StumpWM configuration file
;;; StumpWM initialization file.
(ql:quickload "swank")
(in-package :stumpwm)
(setf *window-border-style* :none
*resize-hides-windows* nil)
;;; Redirect output to ~/.stumpwm.d/stumpwm.log
@jmbr
jmbr / fig-example.gp
Created September 19, 2020 23:23
Gnuplot figure rendered in LaTeX with proper fonts and sizes
reset
load '~/gnuplot-colorbrewer/qualitative/Set2.plt' # Optional
set terminal push
set terminal epslatex size 3.22in, 2.255in
set output "fig-example.tex"
unset key
set border 3
@jmbr
jmbr / compute_distance_matrix.py
Created February 1, 2021 19:50
Compute RMS distances between frames in an mdtraj Trajectory object
import numpy as np
import mdtraj as md
import tqdm
def compute_distance_matrix(trajectory: md.Trajectory) -> np.ndarray:
"""Compute distance matrix.
"""
topology = trajectory.topology
@jmbr
jmbr / diffusion_maps.py
Last active April 13, 2021 04:07
Fast and simple computation of diffusion maps
from typing import Tuple
import numpy as np
import scipy.spatial
DEFAULT_NUM_EIGENPAIRS: int = 10 + 1
def diffusion_maps(points: np.ndarray, epsilon2: float,