In [1]:
import numpy as np
from dec.grid1 import Grid_1D
from dec.symbolic import *
In [2]:
g = Grid_1D.periodic(7)
c = Chart(x, )
f = form(0, c, (sin(x),))
In [3]:
fd = f.P(g, True)
(f.lambdify(g.points).dtype,
g.refine.T[f.degree, fd.isprimal](fd.array).dtype)
Out[3]:
In [4]:
f.lambdify(g.points)- g.refine.T[f.degree, fd.isprimal](fd.array)
Out[4]:
In [5]:
fd.array - g.refine.U[f.degree, fd.isprimal](f.lambdify(g.points))
Out[5]:
In [6]:
from dec.spectral import H, Hinv, S, Sinv
In [7]:
# The hodge star of ones must be the lengths of the dual edges
N= 10; H(np.ones(N))-2*np.pi/N
Out[7]:
In [8]:
g.verts.dtype
Out[8]:
In [9]:
g = Grid_1D.periodic(11)
f = form(0, c, (cos(3*x),))
(f.H.P(g, True) - f.P(g, False).H).array
Out[9]:
In [10]:
f = form(1, c, (cos(3*x),))
(f.H.P(g, True) - f.P(g, False).H).array
Out[10]:
In [11]:
from theano import tensor as T
from theano.ifelse import ifelse
import theano, time, numpy
epsilon = T.scalar('epsilon')
x = T.vectors('x')
z_switch = T.switch(T.lt(0, epsilon), x, x)
z_lazy = ifelse(T.lt(0, epsilon), x, x)
f_switch = theano.function([epsilon, x], z_switch,
mode=theano.Mode(linker='vm'))
f_lazyifelse = theano.function([epsilon, x], z_lazy,
mode=theano.Mode(linker='vm'))
big_mat = numpy.ones(10000)
In [12]:
n_times = 10
tic = time.clock()
for i in range(n_times):
f_switch(0, big_mat)
print ('time spent evaluating both values %f sec' % (time.clock() - tic))
tic = time.clock()
for i in range(n_times):
f_lazyifelse(0, big_mat)
print ('time spent evaluating one value %f sec' % (time.clock() - tic))