Skip to content

Instantly share code, notes, and snippets.

View turgeonmaxime's full-sized avatar

Max Turgeon turgeonmaxime

View GitHub Profile
@gurunars
gurunars / ask_confirmation.py
Created May 4, 2016 13:43
Ask for confirmation in Python
def confirm():
"""
Ask user to enter Y or N (case-insensitive).
:return: True if the answer is Y.
:rtype: bool
"""
answer = ""
while answer not in ["y", "n"]:
answer = raw_input("OK to push to continue [Y/N]? ").lower()
@redpony
redpony / logdet.cc
Last active May 13, 2023 12:49
Computing log(M.determinant()) in Eigen C++ is risky for large matrices since it may overflow or underflow. This gist uses LU (or, if applicable, Cholesky) decompositions to do the risky components in the log space.
// set use_cholesky if M is symmetric - it's faster and more stable
// for dep paring it won't be
template <typename MatrixType>
inline typename MatrixType::Scalar logdet(const MatrixType& M, bool use_cholesky = false) {
using namespace Eigen;
using std::log;
typedef typename MatrixType::Scalar Scalar;
Scalar ld = 0;
if (use_cholesky) {
LLT<Matrix<Scalar,Dynamic,Dynamic>> chol(M);
@tajmorton
tajmorton / bigcorPar.r
Last active January 3, 2016 04:59 — forked from bobthecat/bigcorPar.r
Fix a type and change `MAT` to `x` to refer to input matrix.
bigcorPar <- function(x, nblocks = 10, verbose = TRUE, ncore="all", ...){
library(ff, quietly = TRUE)
require(doMC)
if(ncore=="all"){
ncore = multicore:::detectCores()
registerDoMC(cores = ncore)
} else{
registerDoMC(cores = ncore)
}