Skip to content

Instantly share code, notes, and snippets.

Links are in the TODO details :P
@odelalleau
odelalleau / gist:3952414
Created October 25, 2012 12:59
Queries explained
Related to: http://stackoverflow.com/questions/13056049/how-to-specify-the-from-tables-in-sqlalchemy-subqueries
1st Query:
EXPLAIN
SELECT MAX(d2.id)
FROM my_table d1
JOIN my_table d2
ON d2.id < d1.id
WHERE d1.id IN (111283470, 111283370, 111282470)
@odelalleau
odelalleau / gist:3948097
Created October 24, 2012 18:58
Failed attempt at building query with SQLAlchemy
from sqlalchemy import create_engine, or_
from sqlalchemy import Column, Integer, MetaData, Table
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///:memory:', echo=True)
meta = MetaData(bind=engine)
table = Table('tbl', meta, Column('id', Integer))
session = sessionmaker(bind=engine)()
meta.create_all()
@odelalleau
odelalleau / gist:2413903
Created April 18, 2012 14:20
Using pyutools to debug a Theano function execution
import theano
from theano import tensor
import pyutools.theano
import numpy
def post_inspect(index, node, thunk):
print 'INSPECTING:'
theano.printing.debugprint(node)
print 'Input shapes : %s' % ' / '.join([str(x[0].shape) for x in thunk.inputs])
print 'Output shapes: %s' % ' / '.join([str(x[0].shape) for x in thunk.outputs])
@odelalleau
odelalleau / gist:1445800
Created December 8, 2011 02:19
Code exhibiting an issue with Theano reshape optimization
# This is a simplified version of some code from Justin Bayer.
import scipy
import theano, theano.tensor as T
# Create parameters.
#
# Parameters are first allocated in a long consecutive array as a shared
# variable. Afterwards, reshaped subtensors are used in the expressions in.
@odelalleau
odelalleau / gist:1436172
Created December 6, 2011 00:59
Simple Theano Op that maintains a state
import sys
import numpy
import theano
from theano import tensor
from theano.printing import debugprint
class MyOp(theano.gof.Op):