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
def is_sq(a): | |
for i in range(2,50): | |
if i*i==a: | |
return True | |
if i*i>a: | |
return False | |
assert False | |
def append_next(cur_arr, max_n): | |
if len(cur_arr)==max_n: #gotit |
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
import numpy as np | |
import time | |
import sys | |
import itertools | |
connections = [[0,1,0,1,1,1,0,1,0], | |
[1,0,1,1,1,1,1,0,1], | |
[0,1,0,1,1,1,0,1,0], | |
[1,1,1,0,1,0,1,1,1], |
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/bash | |
set -e | |
echo "PID GPU MEM USER TTY STAT START TIME COMMAND"; | |
join -1 3 -2 1 <( nvidia-smi | grep -A100 PID | sed -n '3,$p' | grep -v -- ------- | awk '{print $2,$6,$3}' | sort -k3,3 ) <( LC_ALL=C ps aux | awk '{print $2,$1,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20}' | sort -k1,1 ) | sort -k 2,2 | while read -r LINE ; do | |
printf "%-7s%2s%13s %-10s%7s%5s%7s%8s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n" $LINE | |
done | awk '{print $0; gsub("MiB","",$3); u[$2]+=$3}END{print "\nGPU MEM USAGE";for(i=0;i<8;i++){printf "%2s %7s MiB %.1f%%\n",i,u[i],u[i]/244.78}}' | cut -b1-`tput cols` | |
echo |
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/bash | |
echo "PID GPU MEM USER TTY STAT START TIME COMMAND" | |
join -1 3 -2 1 <( nvidia-smi | grep -A100 PID | sed -n '3,$p' | grep -v -- ------- | awk '{print $2,$6,$3}' | sort -k3,3 ) <( LC_ALL=C ps aux | awk '{print $2,$1,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20}' | sort -k1,1 ) | sort -k 2,2 | while read -r LINE ; do | |
printf "%-7s%2s%13s %-10s%7s%5s%7s%8s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n" $LINE | |
done | awk '{print $0; gsub("MiB","",$3); u[$2]+=$3}END{print "GPU MEM USAGE";for(i=0;i<8;i++){printf "%2s %7s MiB %.1f%%\n",i,u[i],u[i]/244.78}}' | cut -b1-`tput cols` |
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
#!/Users/ph/anaconda2/bin/python | |
# Suppose, | |
# ls pdf_folder/ | |
# cover.pdf even174.pdf even352.pdf odd1.pdf odd175.pdf | |
# # number is starting page, `even*` is in reverse order, `odd*` is in right order. | |
# # cover.pdf includes 3 pages, 1,2 are front pages and 3 is last cover. | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
import glob | |
import os |
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
% test data generation | |
snr = 7; | |
xy = [awgn(repmat(1, 100, 1), snr) awgn(repmat(2, 100, 1), snr); | |
awgn(repmat(3, 100, 1), snr) awgn(repmat(4, 100, 1), snr)]; | |
S = squareform(pdist(xy)); % distance matrix | |
S = -S + max(S(:))+9; | |
S(logical(eye(200))) = 0; | |
% affinity propagation | |
% http://www.psi.toronto.edu/affinitypropagation/FreyDueckScience07.pdf |