Skip to content

Instantly share code, notes, and snippets.

View andres-fr's full-sized avatar

Andres Fernandez andres-fr

View GitHub Profile
@andres-fr
andres-fr / xdiagpp.py
Last active October 23, 2025 19:10
Combining XDiag with Hutch++
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Combining XDiag with Hutch++.
Copyright (C) 2025 aferro (ORCID: 0000-0003-3830-3595)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@andres-fr
andres-fr / dask_qr_test.py
Last active September 24, 2025 00:39
Out-of-core QR decompositions using dask
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Exploring out-of-core QR decompositions via dask.
conda create -n dask python=3.10
conda activate dask
pip install numpy
pip install h5py
@andres-fr
andres-fr / exr_to_np.py
Created September 19, 2019 20:26
Convert EXR files to numpy float32 matrices
# -*- coding:utf-8 -*-
"""
Place this script on a directory and convert the .exr files it contains
into np.float32 matrices
"""
import os
import OpenEXR
@andres-fr
andres-fr / distributed_hdf5.py
Last active January 21, 2024 05:48
Static class to manage distributed (virtual) HDF5 databases
#!/usr/bin python
# -*- coding:utf-8 -*-
"""
"""
import os
import h5py
@andres-fr
andres-fr / py3_color_logger.py
Last active October 15, 2023 01:06
A well-suported and pre-configured color logger for Python 3
#!/usr/bin python
# -*- coding:utf-8 -*-
"""
This module features convenient color logger (wrapping the built-in ``loging.``
class), plus some helper functionality.
"""
@andres-fr
andres-fr / flask__server__client.py
Last active June 25, 2023 18:41
Flask client/server to exchange compressed numpy arrays:
################################################################################
### server.py
################################################################################
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Dummy server, interacts with the client receiving, altering and returning
@andres-fr
andres-fr / plt_font_manager.py
Last active March 26, 2023 01:12
Setting arbitrary fonts in matplotlib
import matplotlib.pyplot as plt
import matplotlib.font_manager as plt_fm
class PltFontManager:
"""
Sometimes matplotlib finds the system font paths, but setting them can
still be challenging due to using the wrong name or matplotlib complaining
about missing elements.
This manager static class is intended to aid with that, by facilitating
@andres-fr
andres-fr / subset_sampler_pytorch.py
Last active March 14, 2023 23:14
PyTorch dataset sampler that retrieves a subset of the indices, with the possibility of deterministic and balanced behaviour.
from collections import defaultdict
import random
class SubsetSampler(torch.utils.data.Sampler):
"""
Like ``torch.utils.data.SubsetRandomsampler``, but without the random,
and with the possibility of balanced sampling. Samples a subset of the
given dataset from a given list of indices, without replacement.
Usage example::
@andres-fr
andres-fr / cose_noisy_parallel.py
Last active February 5, 2023 01:49
Parallelized implementation of L1 CoSe with error tolerance
#!/usr/bin/env python
# -*-coding:utf-8-*-
"""
This module contains 2 functions:
* ``cose_recovery``: Implements the L1 compressed sensing program, allowing
for L2 error tolerance in the constraint.
* ``cose_recovery_mpp``: Parallelized version of ``cose_recovery`` that runs
@andres-fr
andres-fr / gsnr_backpack.py
Last active November 18, 2022 16:05
Different ways of computing GSNR with PyTorch+BackPACK
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The quantities computed in this gist are wrong. While a correction is
pending, see the following discussion for more details. The TLDR is that
they must be divided by batch_size^2, or use the alternative Cockpit