Skip to content

Instantly share code, notes, and snippets.

@4u9u5tsong
4u9u5tsong / matlab
Last active August 29, 2015 14:09
matlab gists
* command line call
matlabc -nodesktop -nosplash -r "matlabpool 12;benchname = '$bench'; function_name ; quit"
* normcdf and precision
p = normcdf([256-56 256+56],256, sqrt(128));vpa(p(2)-p(1))
for k=50:56; p = normcdf([256-k 256+k],256, sqrt(128));display(vpa(p(2)-p(1))); end
@4u9u5tsong
4u9u5tsong / pdf
Last active August 29, 2015 14:09
pdf
* combine pdfs
pdfunite *.pdf all.pdf
@4u9u5tsong
4u9u5tsong / linux
Created December 3, 2014 02:16
linux
* timeout command
kill the command after some specified time, to set a hard time limit for the executed command.
man timeout to read more.
@4u9u5tsong
4u9u5tsong / read numbers
Last active August 29, 2015 14:11
c++, read numbers, many lines, and different # in each line, remove redundant
ifstream pbinfile(argv[2]);
vector<unordered_set<int> > numbers;
while(getline(pbinfile, stemp)){
istringstream buffer(stemp);
vector<int> line((istream_iterator<int>(buffer)),
istream_iterator<int>());
unordered_set<int> s(line.begin(), line.end());
numbers.push_back(s);
}
@4u9u5tsong
4u9u5tsong / readdata.py
Created January 30, 2015 17:07
python read cvs file float64 to binary string
#!/usr/bin/env python
import struct
import scipy as sp
import numpy as np
def binary(num):
return ''.join(bin(ord(c)).replace('0b', '').rjust(8, '0') for c in struct.pack('!d', num))
@4u9u5tsong
4u9u5tsong / gist:447133da601b3486762f
Created March 24, 2015 18:26
genfromtxt read from a pipe with subprocess
inpstream = subprocess.check_output(cmdstr).split('\n')
data = sp.genfromtxt(inpstream, dtype=np.uint64)
@4u9u5tsong
4u9u5tsong / gist:8c5a355df430f63740bf
Created March 27, 2015 00:15
python scipy CSR format
# Got an answer from the Scipy user group:
# http://stackoverflow.com/questions/8955448/save-load-scipy-sparse-csr-matrix-in-portable-data-format
# A csr_matrix has 3 data attributes that matter: .data, .indices, and .indptr. All are simple ndarrays, so numpy.save will work on them. Save the three arrays with numpy.save or numpy.savez, load them back with numpy.load, and then recreate the sparse matrix object with:
# new_csr = csr_matrix((data, indices, indptr), shape=(M, N))
# So for example:
def save_sparse_csr(filename,array):
np.savez(filename,data = array.data ,indices=array.indices,
indptr =array.indptr, shape=array.shape )
@4u9u5tsong
4u9u5tsong / gist:ea8c81532fbec69accce
Last active August 29, 2015 14:17
python bit manipulation
def float64Tobinary(num):
return ''.join(bin(ord(c)).replace('0b', '').rjust(8, '0') for c in
struct.pack('!d', num))
def convertTo1DIntArray(d, start, end, patternwidth, f):
sview = 'S' + str(patternwidth)
return f(d[start:end]).view(sview)
@4u9u5tsong
4u9u5tsong / gist:c1b73d09f5215de7af3d
Created March 27, 2015 03:34
synergy over ssh tunnel
ssh -f -L 24800:127.0.0.1:24800 128.151.160.230 -N
@4u9u5tsong
4u9u5tsong / gist:93b4c5acece0ba99ab2d
Last active August 29, 2015 14:18
marss and dramsim

compile

  1. in DRAMSim2 folder: make libdramsim.so
  2. in Marss: scons dramsim=/full/path/to/DRAMSim2

flags

DRAMSim2/Makefile: comment -DLOG_OUTPUT for extra logs