Skip to content

Instantly share code, notes, and snippets.

Lev E. Givon lebedov

Block or report user

Report or block lebedov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lebedov
lebedov / compare_construct_numpy_timing.py
Last active Jun 27, 2017
Compare timing of record parsing in construct and numpy.
View compare_construct_numpy_timing.py
#!/usr/bin/env python
"""
Compare timing of record parsing in construct and numpy.
"""
import time
from construct import LazyStruct, Struct, Int16un, Int8un
import numpy as np
@lebedov
lebedov / cast_void_ptr_to_2d_ptr_array.cpp
Created Apr 27, 2017
How to save a 2D array of pointers to a class attribute and access the array's contents properly.
View cast_void_ptr_to_2d_ptr_array.cpp
// How to save a 2D array of pointers to a class attribute and
// access the array's contents properly.
#include <iostream>
#include <stdio.h>
// Show pointer values in array:
void show_ptr(int *a[2][2]) {
for (int i=0; i<2; i++) {
for (int j=0; j<2; j++) {
printf("[%d,%d] %p\n", i, j, &a[i][j]);
@lebedov
lebedov / cuda_cpp_class.cu
Created Apr 24, 2017
How to "wrap" a CUDA kernel with a C++ class.
View cuda_cpp_class.cu
// How to "wrap" a CUDA kernel with a C++ class; the kernel must be defined outside of
// the class and launched from within a class instance's method.
#include <iostream>
#include <cuda.h>
#include <cuda_runtime.h>
#define LEN 10
__global__ void kernel(int *a, int *b, unsigned int N);
@lebedov
lebedov / translate_bilinear_interp.py
Created Apr 20, 2017
Translate an image by fractional number of pixels using bilinear interpolation.
View translate_bilinear_interp.py
#!/usr/bin/env python
"""
Translate an image by fractional number of pixels using bilinear interpolation.
Based on various snippets of code on StackOverflow.
"""
import numpy as np
import skimage.draw as skdraw
@lebedov
lebedov / ct_win.py
Created Apr 6, 2017
Routines for scaling biomedical image data by window level and width.
View ct_win.py
#!/usr/bin/env python
"""
Routines for scaling biomedical image data by window level and width.
"""
import numpy as np
win_dict = {'abdomen':
{'wl': 60, 'ww': 400},
@lebedov
lebedov / tick_space.py
Created Apr 4, 2017
Adjust evenly spaced ticks on current matplotlib axis.
View tick_space.py
#!/usr/bin/env python
"""
Adjust evenly spaced ticks on current matplotlib axis.
"""
import matplotlib.pyplot as plt
import numpy as np
def tick_space(space, which='major', axis='both'):
@lebedov
lebedov / Makefile
Last active Apr 3, 2017
Example of how to access a static C++ class instance from C.
View Makefile
%.o: %.c
gcc -c $<
%.o: %.cpp
g++ -c $<
main: main.o mylib.o
gcc $^ -o $@
clean:
@lebedov
lebedov / lasso_imshow.py
Last active Oct 2, 2019
How to interactively select part of an array displayed as an image with matplotlib.
View lasso_imshow.py
#!/usr/bin/env python
"""
How to interactively select part of an array displayed as an image with matplotlib.
"""
import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.widgets import LassoSelector
import numpy as np
@lebedov
lebedov / Makefile
Last active Mar 15, 2017
Simple demo of how to write structs from C and read them in Python.
View Makefile
write: write.c
gcc $< -o $@
test: write
./write
python read.py
@lebedov
lebedov / cat_half.py
Created Feb 23, 2017
Algorithm for concatenating half precision pytorch tensors.
View cat_half.py
#!/usr/bin/env python
"""
Algorithm for concatenating half precision tensors by allocating new output matrix
of appropriate size and copying each of the constituent tensors into it with
appropriate offsets.
"""
import numpy as np
import torch
You can’t perform that action at this time.