Skip to content

Instantly share code, notes, and snippets.

View lukoshkin's full-sized avatar
🤗

Vladislav Lukoshkin lukoshkin

🤗
  • Peaceful Place
View GitHub Profile
@lukoshkin
lukoshkin / Dockerfile
Created April 23, 2021 10:47
rust-ubuntu
FROM ubuntu:20.04
ARG UID=1000
ARG GID=1000
ENV USER rust
ENV HOME /home/$USER
ENV PATH "$HOME/.cargo/bin:$PATH"
WORKDIR /tmp
@lukoshkin
lukoshkin / Autodeps.make
Last active March 26, 2021 18:11
Makefile with dependencies auto-generation
OBJDIR = bin
DEPDIR = deps
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.d
src = $(wildcard src/*.cc)
obj = $(src:src/%.cc=$(OBJDIR)/%.o)
DEPFILES = $(src:src/%.cc=$(DEPDIR)/%.d)
# if boost is correctly installed, no need to add pathes to
@lukoshkin
lukoshkin / Dockerfile
Last active October 30, 2023 14:59
Recipe of a docker image with Open-MPI 3.1.4 and mpi4py
FROM ubuntu:18.04
ENV USER mpitest
ENV HOME /home/$USER
ENV MPI_DIR=/opt/ompi
ENV PATH="$MPI_DIR/bin:$HOME/.local/bin:$PATH"
ENV LD_LIBRARY_PATH="$MPI_DIR/lib:$LD_LIBRARY_PATH"
WORKDIR $HOME
RUN apt-get -q update \
@lukoshkin
lukoshkin / landscape.py
Created April 11, 2020 14:36
Persistence landscape discretization
# Task: convert persistence landscape given in the form (N, k, n, 2)
# to its another representation of the shape (N, k, n, p), where N is
# the batch size, k - number of feature dimensionalities, n - number of
# layers. And the last dimension is 2 dates of event's birth and death
# in the former brackets and p is number of discretization steps
# in the latter, on the interval where these event dates are defined.
import torch
import matplotlib.pyplot as plt
def triangle_hat(x, a, b):
@lukoshkin
lukoshkin / bidiagonalization.py
Created April 3, 2020 10:56
Golub-Kahan-Lanczos Bidiagonalization Procedure (implementation of http://www.netlib.org/utk/people/JackDongarra/etemplates/node198.html for the case of lower-bidiagonal matrix)
import numpy as np
import scipy.sparse as scsp
def GKL_bidiagonalization(A):
A = np.matrix(A)
m,n = A.shape
p = max(m, n)
alpha = np.zeros(p)
beta = np.zeros(p-1)
import numpy as np
def pwCDF(fn, m, interval=(0, 1)):
"""
fn probability density function
m number of intervals at which `fn` is approximated
interval `fn`'s domain
"""
A, B = interval
@lukoshkin
lukoshkin / wgan-gp.py
Last active April 3, 2020 11:04
Improving WGAN with the gradient penalty term
def calc_grad_penalty(real_samples, fake_samples, net_D):
"""
Evaluates gradient penalty for `net_D` and allows other gradients
to backpropogate through this penalty term
Args:
real_samples - a tensor (presumably, without `grad` attribute)
fake_samples - tensor of the same shape as `real_samples` tensor
net_D - a 'critic' which takes the input of the same shape
as `real_samples`
@lukoshkin
lukoshkin / metrics.py
Last active July 14, 2021 16:05
ACD metric (or similar to the one that is) used in mocogan
import cv2
import numpy as np
def ACD(filename):
"""
Calculates Average Content Distance for the given short video
Parameters:
-----------
filename : str or path-like - path to .mp4 or .gif file