Skip to content

Instantly share code, notes, and snippets.

View jmbr's full-sized avatar

Juan M. Bello-Rivas jmbr

View GitHub Profile
@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 / python-interpreter.lisp
Created February 14, 2023 16:56
Python interpreter embedded in SBCL
(defpackage :python-interpreter
(:use :common-lisp :cffi)
(:export #:run-python))
(in-package :python-interpreter)
(define-foreign-library libpython (:unix "libpython3.10.so"))
(use-foreign-library libpython)
@jmbr
jmbr / common-lisp-vs-python-3.11-vs-cython-vs-c++-performance-for-simulations.org
Last active December 28, 2022 22:54
Common Lisp vs. Python 3.11 vs. Cython vs. C++ Performance for Simulations

Common Lisp vs. Python 3.11 vs. Cython vs. C++ Performance for Simulations

Introduction

We compare the median run times of the agent-based simulation code discussed in the article titled The Bitter Truth: Python 3.11 vs Cython vs C++ Performance for Simulations published on Dec 19, 2022 against a corresponding Common Lisp implementation.

The Common Lisp implementation is (emphatically) written in non-idiomatic Lisp closely following the reference implementations, with some type declarations and compiled using SBCL.

The fastest implementation turns out to be Lisp, with a slight advantage over C++ (see table below).

@jmbr
jmbr / embedding.py
Created November 3, 2022 22:16
Code for experiments on Bayesian optimization in dimensionally-reduced models
from abc import ABC, abstractmethod
from typing import Optional
import numpy as np
from diffusion_maps import diffusion_maps
from mapping import Mapping
class Embedding(ABC):
@jmbr
jmbr / evince.patch
Created September 19, 2022 18:52
Change default scrolling mode of Evince when changing pages.
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 1ffbf16..079cfd0 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -8616,7 +8616,7 @@ ev_view_change_page (EvView *view,
gint x, y;
view->current_page = new_page;
- view->pending_scroll = SCROLL_TO_PAGE_POSITION;
+ view->pending_scroll = SCROLL_TO_KEEP_POSITION;
@jmbr
jmbr / reparameterization.py
Last active May 14, 2022 04:40
Reparameterize a curve by its arc-length.
"""Numerically reparameterize a curve by its arc-length.
"""
from typing import Optional
import numpy as np
import scipy
import scipy.interpolate
@jmbr
jmbr / double2.h
Created March 29, 2014 16:32
Simple example of the RATTLE algorithm
#ifndef DOUBLE2_H
#define DOUBLE2_H
#include <cmath>
#include <ostream>
#include <initializer_list>
struct double2 {
union {
@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 / check-bibtex.sh
Created March 9, 2022 15:53
Find BibTeX entries that are not referenced from the TeX document files.
#!/bin/sh
if [ $# -ge 1 ]; then
bibtex_file=$1
else
bibtex_file="bibliography.bib"
fi
awk -F "[{,]" '/^@/ { print $2 }' $bibtex_file \
| while read reference; do
@jmbr
jmbr / mfpt.py
Created February 7, 2022 19:32
Example of how to compute mean first passage times by brute force in parallel.
from joblib import Parallel, delayed
import numpy as np
n = 10000 # Number of experiments
dt: float = 1e-5 # Time step length
def integrate_until_exit(random_seed):
np.random.seed(random_seed)