Skip to content

Instantly share code, notes, and snippets.

联想A850这款机子挺漂亮的,,屏幕很大,就是有一点缺陷是屏幕的分辨率稍微有一点儿低,像素有一点儿低,哈哈,,还是很满意的啦!
@goog
goog / gist:7366050
Created November 8, 2013 03:54
a trie
using namespace std;
#include <iostream>
#include <cstring>
#define NUM 26
class Node
{
public:
int count; // occurrence times
import numpy,timeit
def filter2d(image, filt):
M, N = image.shape
Mf, Nf = filt.shape
Mf2 = Mf // 2
Nf2 = Nf // 2
result = numpy.zeros_like(image)
for i in range(Mf2, M - Mf2):
for j in range(Nf2, N - Nf2):
import numpy as np
from numba import double
from numba.decorators import jit
@jit(argtypes=[double[:,:], double[:,:]])
def pairwise_numba(X, D):
M = X.shape[0]
N = X.shape[1]
for i in range(M):
for j in range(M):
@autojit(locals=dict(array=double[:, :], scalar1=double))
def func(array):
scalar1 = array[0, 0] # scalar is declared double
scalar2 = double(array[0, 0])
from numba import jit
import numpy as np
@jit('f8(f8[:])')
def sum1d(my_double_array):
sum = 0.0
for i in range(my_double_array.shape[0]):
sum += my_double_array[i]
return sum
from numba import autojit
import numpy as np
@autojit
def sum1d(my_double_array):
sum = 0.0
for i in range(my_double_array.shape[0]):
sum += my_double_array[i]
return sum

A closure occurs when a function has access to a local variable from an enclosing scope that has finished its execution.

def make_printer(msg): def printer(): print msg return printer

printer = make_printer('Foo!') printer()

from numpy import zeros
from scipy import weave
import numpy as np
import time
import timeit
import scipy.weave as weave
import pyximport
pyximport.install(setup_args={'include_dirs':[np.get_include()]})
dx = 0.1
In [328]: timeit.Timer('if done is None:pass','done = 1').timeit()
Out[328]: 0.09523200988769531
In [329]: timeit.Timer('if done!=None:pass','done = 1').timeit()
Out[329]: 0.2190079689025879