Skip to content

Instantly share code, notes, and snippets.

View aldro61's full-sized avatar

Alexandre Drouin aldro61

View GitHub Profile
@aldro61
aldro61 / logspace.sh
Last active February 15, 2020 19:35
A bash function to generate a logspace
# Generate a logspace from numpy in bash
# Usage: logspace start end [count, default=10]
# Just source this file or add it to your .bashrc
logspace () {
start=$1
end=$2
if [ $# -ne 3 ]
then
count=10
else
@aldro61
aldro61 / load_mnist.py
Created July 24, 2017 20:12
Load the MNIST dataset into numpy arrays
"""
Load the MNIST dataset into numpy arrays
Author: Alexandre Drouin
License: BSD
"""
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data

Keybase proof

I hereby claim:

  • I am aldro61 on github.
  • I am aldro61 (https://keybase.io/aldro61) on keybase.
  • I have a public key whose fingerprint is 70AC 5392 B66E 4935 58E6 B243 F5E3 1272 81E8 C206

To claim this, I am signing this object:

def load_hic_matrix(hic_path):
f = open(hic_path, "r")
# Parse the header
header = f.next()
assert header[0] == "#"
min_row, max_row, min_col, max_col = [int(x) for x in header[2:].split(" ")]
# Create an empty matrix of n_fragments x n_fragments
hic = np.zeros((max_col + 1, max_col + 1))
@aldro61
aldro61 / popcount_array.pyx
Last active October 2, 2023 13:07
Popcount of a numpy array of 32-bit integers
"""
Compile with gcc flag -mpopcnt
"""
import numpy as np
cimport numpy as np
cimport cython
from libc.stdint cimport uint32_t, uint8_t
cdef extern int __builtin_popcount(unsigned int) nogil
@aldro61
aldro61 / linear_least_squares.py
Last active August 9, 2021 15:20
A linear least squares solver for python. This function outperforms numpy.linalg.lstsq in terms of computation time and memory.
# Copyright (c) 2013 Alexandre Drouin. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all