Skip to content

Instantly share code, notes, and snippets.

View lebedov's full-sized avatar

Lev E. Givon lebedov

View GitHub Profile
@lebedov
lebedov / show_layer_sizes.lua
Created September 28, 2016 14:01
Recursively show layer output tensor sizes in a Torch model.
-- Recursively show layer output tensor sizes in a Torch model.
require 'nn'
require 'torch'
function join(list, sep)
local sep = sep or ' '
return table.concat(list, sep)
end
@lebedov
lebedov / thumb_grid.py
Last active August 4, 2020 16:50
Display a grid of thumbnails.
#!/usr/bin/env python
"""
Display a grid of thumbnails.
"""
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np
import PIL
@lebedov
lebedov / torch_dataset.lua
Created September 16, 2016 13:37
Class for passing data to Torch's nn.StochasticGradient
-- Use the class rock to create a Dataset class
-- that can be used by nn.StochasticGradient in Torch
local class = require 'class'
local Dataset = class('Dataset')
function Dataset:__init(inputs, labels)
self.inputs = inputs
self.labels = labels
end
@lebedov
lebedov / cusolver_getrf_demo.py
Created August 28, 2016 20:51
CUSOLVER getrf demo
#!/usr/bin/env python
"""
CUSOLVER getrf demo.
"""
import numpy as np
import scipy.linalg
import scipy as sp
import pycuda.autoinit
@lebedov
lebedov / nx_partly_relabel_graph_with_sorted_attrib.py
Created April 11, 2016 18:16
Relabel some of the nodes of a NetworkX graph with IDs sorted according to the order of some attribute such that only the nodes that have that attribute are relabeled.
import networkx as nx
def partly_relabel_by_sorted_attr(g_old, select_attr, select_attr_vals, sort_attr):
"""
Relabel nodes of NetworkX graph such that the new IDs are
sorted according to the order of some attribute such that
only the nodes that have that attribute are relabeled.
Parameters
----------
@lebedov
lebedov / multiprocessing_skcuda_demo.py
Last active December 3, 2015 16:34
Simple demo of how to use scikit-cuda with multiprocessing.
#!/usr/bin/env python
"""
Simple demo of how to use scikit-cuda with multiprocessing.
"""
import atexit
import multiprocessing as mp
import numpy as np
@lebedov
lebedov / custom_gremlin_step_pyorient.py
Created October 28, 2015 23:21
Define and use custom step in Gremlin via pyorient.
#!/usr/bin/env python
"""
Define and use custom step in Gremlin via pyorient.
"""
from pyorient.ogm import Graph, Config
from pyorient.ogm.declarative import declarative_node, declarative_relationship
from pyorient.ogm.property import String
@lebedov
lebedov / mpi4py_pycuda_async_demo.py
Created September 3, 2015 20:20
Demo of how to asynchronously pass GPU memory managed by pycuda to mpi4py.
#!/usr/bin/env python
"""
Demo of how to asynchronously pass GPU memory managed by pycuda to mpi4py.
Notes
-----
This code can be used to perform peer-to-peer communication of data via
NVIDIA's GPUDirect technology if mpi4py has been built against a
CUDA-enabled MPI implementation such as MVAPICH2 or OpenMPI.
@lebedov
lebedov / maximize_matrix_trace.py
Created June 16, 2015 18:35
Find permutation of matrix that maximizes its trace using the Munkres algorithm.
#!/usr/bin/env python
"""
Find permutation of matrix that maximizes its trace using the Munkres algorithm.
Reference
---------
https://stat.ethz.ch/pipermail/r-help/2010-April/236664.html
"""
@lebedov
lebedov / lsof_funcs.py
Last active January 24, 2024 02:09
Python functions for finding open files and PIDs that have opened a file.
#!/usr/bin/env python
"""
Python functions for finding open files and PIDs that have opened a file.
"""
import numbers
import subprocess
try: