The snippet for scan test is:
x = T.matrix()
y, _ = th.scan(fn=lambda x : T.sum(x*x), sequences=x)
fn_sum_scan = theano.function([x], y)
xval = np.random.randn(5000,10000).astype(np.float32)
timeit(fn(xval))
GEN | |
elltaniyama(GEN e, long prec) | |
{ | |
GEN x, w, c, d, X, C, b2, b4; | |
long n, m; | |
pari_sp av = avma; | |
checkell_Q(e); | |
if (prec < 0) pari_err_DOMAIN("elltaniyama","precision","<",gen_0,stoi(prec)); | |
if (!prec) retmkvec2(triv_ser(gen_1,-2), triv_ser(gen_m1,-3)); |
#!/usr/bin/env python | |
''' | |
minimal reference implementation of bitcoin's secp256k1 with general prime field | |
requires pari && cypari2 for certain operations. | |
''' | |
class EcPoint: | |
__slots__ = ('x', 'y') | |
def __init__(self, x, y): |
class memfd_create: | |
'''create in memory file with actual fileno using memfd_create | |
usage: | |
with memfd_create('file_name') as f: | |
pass # treat f as file-like in binary mode | |
''' | |
import ctypes, os | |
_libc = ctypes.CDLL(None) | |
_syscall = _libc.syscall | |
def __init__(self, name:str): |
#!/usr/bin/env python | |
import io | |
import tarfile | |
a_content = ''' | |
content:aaa | |
content:111 | |
''' | |
b_content = ''' | |
content:bbb | |
content:222 |
# binary carry accumulator with O(log(N)) space requirement | |
# better numerical stability when adding lots of small numbers | |
class Accumulator: | |
__slots__ = ('fn', 'data', 'index', 'init') | |
def __init__(self, size=31, init=0., fn='add'): | |
if fn == 'mean': | |
fn=lambda x,wx,y,wy:(x*wx+y*wy)/(wx+wy) | |
elif fn == 'add': | |
fn=lambda x,wx,y,wy:x+y | |
self.fn = fn |
#!/usr/bin/env python3 | |
import os | |
import sys | |
import subprocess as subp | |
if len(sys.argv) != 2: | |
appname = sys.argv[0] | |
print('%s - unmount USB directory and power it off' % appname, file=sys.stderr) | |
print('Usage: %s <directory>' % appname, file=sys.stderr) | |
sys.exit(-1) |
#include <stdlib.h> | |
#include <vector> | |
#include <string> | |
#include "wstp.h" | |
using namespace std; | |
int main() { | |
int err; | |
auto env_p = WSInitialize((void*)0); |
from random import randint | |
from time import time | |
import numpy as np | |
import theano as th | |
import theano.tensor as T | |
from theano.tensor.padding import idx, at_idx | |
N = 256 | |
x = T.matrix() |
from itertools import product | |
from random import randint | |
from time import time | |
import numpy as np | |
import theano as th | |
T = th.tensor | |
from theano.tensor.padding import idx, at_idx | |
from theano.tensor.signal import conv | |
N = 256 |
The snippet for scan test is:
x = T.matrix()
y, _ = th.scan(fn=lambda x : T.sum(x*x), sequences=x)
fn_sum_scan = theano.function([x], y)
xval = np.random.randn(5000,10000).astype(np.float32)
timeit(fn(xval))