Accuracy


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]:
(dtype('float64'), dtype('float64'))

In [4]:
f.lambdify(g.points)- g.refine.T[f.degree, fd.isprimal](fd.array)


Out[4]:
array([  0.00000000e+00,   1.66533454e-16,   0.00000000e+00,
         8.88178420e-16,   0.00000000e+00,   2.22044605e-16,
         0.00000000e+00,   1.70849757e-15,   0.00000000e+00,
        -4.44089210e-16,   0.00000000e+00,  -6.66133815e-16,
         0.00000000e+00,   5.55111512e-17])

In [5]:
fd.array - g.refine.U[f.degree, fd.isprimal](f.lambdify(g.points))


Out[5]:
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.])

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]:
array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

In [8]:
g.verts.dtype


Out[8]:
dtype('float64')

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]:
array([  5.55111512e-17,   1.66533454e-16,  -3.88578059e-16,
        -1.11022302e-16,  -8.18789481e-16,  -3.33066907e-16,
         1.72084569e-15,   1.66533454e-16,   6.10622664e-16,
        -4.44089210e-16,  -8.88178420e-16])

In [10]:
f = form(1, c, (cos(3*x),))
(f.H.P(g, True) - f.P(g, False).H).array


Out[10]:
array([  6.66133815e-16,  -1.66533454e-16,  -2.22044605e-16,
        -1.05471187e-15,  -1.66533454e-15,   9.99200722e-16,
         1.11022302e-15,  -3.10862447e-15,   1.22124533e-15,
        -2.22044605e-16,   8.32667268e-17])

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))


time spent evaluating both values 0.000518 sec
time spent evaluating one value 0.001594 sec