File: vdtNumpyTime.py

package info (click to toggle)
vdt 0.4.4-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 620 kB
  • sloc: cpp: 2,382; ansic: 1,589; python: 1,126; csh: 16; makefile: 8
file content (106 lines) | stat: -rw-r--r-- 2,025 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import imp
vdtnpfun= imp.load_dynamic('vdtnpfun','vdtnpfun_directory/vdtnpfun.so')
import vdtnpfun
print dir(vdtnpfun)


from vdt_ctypes import *
import numpy as np
import timeit

#print vdt_arch()
#print vdt_expf([1,2,3,4])

loadit('vdt_expf')

N=2001
xx = np.linspace(-np.pi, np.pi, N)
xf = np.linspace(-np.pi, np.pi, N)
x = np.linspace(-np.pi, np.pi, N)


def nsc() :
    global xx
    s = np.sin(xx)
    c = np.cos(xx)
    return (s,c)

def nscf() :
    global xf
    s = np.sin(xf)
    c = np.cos(xf)
    return (s,c)


def vsc() :
    global x
    return vdt_sincos(x)

def vscf() :
    global x
    return vdt_sincosf(x)


def nex() :
    global xx
    return np.exp(xx)

def nexf() :
    global xf
    return np.exp(xf)


def vex() :
    global x
    return vdt_exp(x)

def vexf() :
    global x
    return vdt_expf(x)



# (fscf, ftype) = VDTFunMap['vdt_sincosf']
(fexf, ftype) = VDTFunMap['vdt_expf']


requires = ['CONTIGUOUS', 'ALIGNED']
x = numpy.asanyarray(x)
x = numpy.require(x, ftype, requires)
vo1 = numpy.empty_like(x)
vo2 = numpy.empty_like(x)

xf = numpy.asanyarray(xf)
xf = numpy.require(xf, ftype, requires)


def vscff() :
    global x
    global fscf
    global vo1
    global vo2
    fscf(x,vo1,vo2,x.size)

def vexff() :
    global x
    global fexf
    global vo1
    fexf(x,vo1,x.size)

def vexfm() :
 global x
 return vdtnpfun.vdt_exp(x)

def vexm() :
 global xx
 return vdtnpfun.vdt_exp(xx)


print "timing exp"
print timeit.timeit("nex()", setup="from __main__ import nex",number=100000), 'np exp'
print timeit.timeit("nexf()", setup="from __main__ import nexf",number=100000), 'np expf'
#print timeit.timeit("vexf()", setup="from __main__ import vexf",number=100000), 'vdt expf ctypes wrapped'
print timeit.timeit("vexff()", setup="from __main__ import vexff",number=100000), 'vdt expf ctypes'
print timeit.timeit("vexfm()", setup="from __main__ import vexfm",number=100000), 'vdt expf module'
print timeit.timeit("vexm()", setup="from __main__ import vexm",number=100000), 'vdt exp module'