This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Compute pytorch network layer output size given an input. | |
""" | |
import numpy as np | |
import torch | |
import torch.autograd as autograd | |
import torch.nn as nn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%.o: %.c | |
gcc -c $< | |
%.o: %.cpp | |
g++ -c $< | |
main: main.o mylib.o | |
gcc $^ -o $@ | |
clean: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
write: write.c | |
gcc $< -o $@ | |
test: write | |
./write | |
python read.py |