Skip to content

Instantly share code, notes, and snippets.

View piti118's full-sized avatar

Piti Ongmongkolkul piti118

  • Mahidol University International College
  • Nakorn Pathom, Thailand
View GitHub Profile
@hovren
hovren / CMakeLists.txt
Created December 12, 2017 15:35
pybind11 with CMake and setup.py
# Build a Python extension module using pybind11
# pybindings_add_module(<module>)
# Here <module> should be the fully qualified name for the module,
# e.g. pybindings_add_module(foo.bar._baz)
# <module> becomes the target name in case you wish to do something to it later
# The source for the binding *must* be placed in src/pybindings/{relpath}/py{name}.cc
# E.g. for module=foo.bar._baz -> src/pybindings/bar/py_baz.cc
function(pybindings_add_module module)
set(target_name ${module})
string(REPLACE "." "/" modpath ${module})
@piti118
piti118 / python_array_product.py
Created February 9, 2011 13:57
find array product like http://www.python.org/dev/peps/pep-0211/ (takes variable number of argument) [1,2,3]@[4,5]@[6,7] = [ [1,4,6],[1,4,7],[1,5,6],[1,5,7],[2,4,6]... and so on ]
# find array product like http://www.python.org/dev/peps/pep-0211/
# which means
# [1,2,3]@[4,5]@[6,7] = [1,4,6],[1,4,7],[1,5,6],[1,5,7],[2,4,6]... and so on
def aprod(*arg):
numarg = len(arg)
lenarray = map(len,arg)
finallen = reduce(lambda x,y:x*y,lenarray)
divisor = map(lambda i: reduce(lambda x,y:x*y,lenarray[i+1:],1),xrange(numarg))
index = [map(lambda n,l: (x/n)%l,divisor,lenarray) for x in xrange(finallen)]
#if you just want index for loop you can return index here