Skip to content

Instantly share code, notes, and snippets.

@ml-edu
ml-edu / README.md
Created April 27, 2023 04:51 — forked from lantiga/README.md
Indexed convolution

Indexed convolutions

A convolution operator over a 1D tensor (BxCxL), where a list of neighbors for each element is provided through a indices tensor (LxK), where K is the size of the convolution kernel. Each row of indices specifies the indices of the K neighbors of the corresponding element in the input. A -1 is handled like for zero padding.

Note that the neighbors specified in indices are not relative, but rather absolute. They have to be specified for each of the elements of the output.

A use case is for convolutions over non-square lattices, such as images on hexagonal lattices coming from Cherenkov telescopes (http://www.isdc.unige.ch/%7Elyard/FirstLight/FirstLight_slowHD.mov).

Example:

@ml-edu
ml-edu / multinomial_sample.py
Created October 13, 2022 23:51 — forked from lmc2179/multinomial_sample.py
Class which samples from a multinomial distribution in python
import random
import partition_tree
class Multinomial_Sampler(object):
def __init__(self, probabilities, event_names):
intervals = self._build_intervals_from_probabilities(probabilities)
self.tree = partition_tree.PartitionTree(intervals, event_names)
def _build_intervals_from_probabilities(self, probabilities):
if sum(probabilities) != 1.0:
@ml-edu
ml-edu / wiener_deconvolution_example.py
Created September 22, 2022 17:08 — forked from danstowell/wiener_deconvolution_example.py
Simple example of Wiener deconvolution in Python
#!/usr/bin/env python
# Simple example of Wiener deconvolution in Python.
# We use a fixed SNR across all frequencies in this example.
#
# Written 2015 by Dan Stowell. Public domain.
import numpy as np
from numpy.fft import fft, ifft, ifftshift
@ml-edu
ml-edu / gist:f2e5c801a841b65cc45ce815ddf924d0
Created April 30, 2022 00:16 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@ml-edu
ml-edu / README.md
Created September 1, 2021 01:14 — forked from ginrou/README.md
Fast Bilateral Filter

Fast Bilateral Filter implementation for OpenCV

Algorithm and implementation is based on http://people.csail.mit.edu/sparis/bf/ Please cite above paper for research purpose.

Sample Code

#include <iostream>
#include "fastBilateral.hpp"
@ml-edu
ml-edu / ddp_example.py
Created August 27, 2021 14:48 — forked from sgraaf/ddp_example.py
PyTorch Distributed Data Parallel (DDP) example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from argparse import ArgumentParser
import torch
import torch.distributed as dist
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.utils.data import DataLoader, Dataset
from torch.utils.data.distributed import DistributedSampler
from transformers import BertForMaskedLM
@ml-edu
ml-edu / jemalloc.sh
Created August 27, 2021 13:00 — forked from diginfo/jemalloc.sh
Install latest jemalloc & configure mysql - Ubuntu
#!/bin/sh
## Install latest jemalloc & configure mysql - Ubuntu
## bash <(curl -Ls https://gist.github.com/diginfo/be7347e6e6c4f05375c51bca90f220e8/raw/)
##
apt-get -y install autoconf libxslt-dev xsltproc docbook-xsl
git clone https://github.com/jemalloc/jemalloc.git
cd jemalloc
autoconf
./configure
make dist