All Samples(707503) | Call(707503) | Derive(0) | Import(0)
len(object) -> integer Return the number of items of a sequence or mapping.
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/psd_demo2.py matplotlib(Download)
#Plot the PSD with different amounts of zero padding. This uses the entire
#time series at once
ax2 = fig.add_subplot(2, 3, 4)
ax2.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
ax2.psd(y, NFFT=len(t), pad_to=len(t)*2, Fs=fs)
ax2.psd(y, NFFT=len(t), pad_to=len(t)*4, Fs=fs)
plt.title('zero padding')
#Plot the PSD with different block sizes, Zero pad to the length of the orignal
#data sequence.
ax3 = fig.add_subplot(2, 3, 5, sharex=ax2, sharey=ax2)
ax3.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
ax3.psd(y, NFFT=len(t)//2, pad_to=len(t), Fs=fs)
ax3.psd(y, NFFT=len(t)//4, pad_to=len(t), Fs=fs)
#Plot the PSD with different amounts of overlap between blocks
ax4 = fig.add_subplot(2, 3, 6, sharex=ax2, sharey=ax2)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=0, Fs=fs)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.05*len(t)/2.), Fs=fs)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.2*len(t)/2.), Fs=fs)
ax4.set_ylabel('')
src/m/a/matplotlib-HEAD/examples/pylab_examples/psd_demo2.py matplotlib(Download)
#Plot the PSD with different amounts of zero padding. This uses the entire
#time series at once
ax2 = fig.add_subplot(2, 3, 4)
ax2.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
ax2.psd(y, NFFT=len(t), pad_to=len(t)*2, Fs=fs)
ax2.psd(y, NFFT=len(t), pad_to=len(t)*4, Fs=fs)
plt.title('zero padding')
#Plot the PSD with different block sizes, Zero pad to the length of the orignal
#data sequence.
ax3 = fig.add_subplot(2, 3, 5, sharex=ax2, sharey=ax2)
ax3.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
ax3.psd(y, NFFT=len(t)//2, pad_to=len(t), Fs=fs)
ax3.psd(y, NFFT=len(t)//4, pad_to=len(t), Fs=fs)
#Plot the PSD with different amounts of overlap between blocks
ax4 = fig.add_subplot(2, 3, 6, sharex=ax2, sharey=ax2)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=0, Fs=fs)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.05*len(t)/2.), Fs=fs)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.2*len(t)/2.), Fs=fs)
ax4.set_ylabel('')
src/m/a/Matplotlib--JJ-s-dev-HEAD/examples/pylab_examples/psd_demo2.py Matplotlib--JJ-s-dev(Download)
#Plot the PSD with different amounts of zero padding. This uses the entire
#time series at once
ax2 = fig.add_subplot(2, 3, 4)
ax2.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
ax2.psd(y, NFFT=len(t), pad_to=len(t)*2, Fs=fs)
ax2.psd(y, NFFT=len(t), pad_to=len(t)*4, Fs=fs)
plt.title('zero padding')
#Plot the PSD with different block sizes, Zero pad to the length of the orignal
#data sequence.
ax3 = fig.add_subplot(2, 3, 5, sharex=ax2, sharey=ax2)
ax3.psd(y, NFFT=len(t), pad_to=len(t), Fs=fs)
ax3.psd(y, NFFT=len(t)//2, pad_to=len(t), Fs=fs)
ax3.psd(y, NFFT=len(t)//4, pad_to=len(t), Fs=fs)
#Plot the PSD with different amounts of overlap between blocks
ax4 = fig.add_subplot(2, 3, 6, sharex=ax2, sharey=ax2)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=0, Fs=fs)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.05*len(t)/2.), Fs=fs)
ax4.psd(y, NFFT=len(t)//2, pad_to=len(t), noverlap=int(0.2*len(t)/2.), Fs=fs)
ax4.set_ylabel('')
src/l/a/Langtangen-HEAD/src/py/examples/efficiency/pyefficiency.py Langtangen(Download)
def addelm_NumPy(n):
a = zeros(1)
for i in xrange(n):
a = resize(a, (len(a)+1,))
def addelm_list(n):
a = [0.0]
for i in xrange(n):
a.append(0.0)
def delelm_NumPy(n):
a = zeros(n)
for i in xrange(n):
a = resize(a, (len(a),))
def py_loop1_sin(x):
from math import sin # scalar sin
for i in xrange(len(x)):
x[i] = sin(x[i])
return x
def py_loop2_sin(x):
from numpy import sin # vector sin (inefficient!)
for i in xrange(len(x)):
def py_loop3_sin(x):
for i in xrange(len(x)):
x[i] = I(x[i])
return x
def NumPy_loop_sin(x):
from numpy import sin
x = sin(x)
return x
def py_loop1_sincos_x2(x):
from math import sin, cos, pow # scalar sin
for i in xrange(len(x)):
def py_loop2_sincos_x2(x):
from numpy import sin, cos
for i in xrange(len(x)):
x[i] = sin(x[i])*cos(x[i]) + x[i]**2
return x
def py_loop2b_sincos_x2(x):
from math import sin, cos # scalar sin
for i in xrange(len(x)):
def py_loop3_sincos_x2(x):
for i in xrange(len(x)):
x[i] = I2(x[i])
return x
def py_loop4_sincos_x2(x):
from math import sin, cos
for i in xrange(len(x)):
def py_loop1_ip2(x):
for i in xrange(len(x)):
x[i] = i+2
return x
def NumPy_loop1_ip2(x):
x = arange(2, n+2, 1)
return x
def NumPy_loop2_ip2(x):
x = fromfunction(lambda i: i+2, (len(x),))
def py_loop1_2Dsincos(x, y):
u = zeros((len(x),len(y)))
from math import sin as msin, cos as mcos
def I(x, y):
return msin(x)*mcos(y)
# x[i], y[j]: coordinates of grid point (i,j)
for i in xrange(len(x)):
for j in xrange(len(y)):
def py_loop2_2Dsincos(x, y):
# inlined expressions
u = zeros((len(x),len(y)))
from math import sin as msin, cos as mcos
# x[i], y[j]: coordinates of grid point (i,j)
for i in xrange(len(x)):
for j in xrange(len(y)):
u[i,j] = msin(x[i])*mcos(y[j])
return u
def py_loop3_2Dsincos(x, y):
# reverse the order of traversal
u = zeros((len(x),len(y)))
def py_loop3_2Dsincos(x, y):
# reverse the order of traversal
u = zeros((len(x),len(y)))
from math import sin as msin, cos as mcos
# x[i], y[j]: coordinates of grid point (i,j)
for j in xrange(len(y)):
for i in xrange(len(x)):
def py_loop1_manyarit(x):
from math import sin, cos
for i in xrange(len(x)):
x[i] = sin(x[i])*cos(x[i]) + sin(2*x[i])*cos(2*x[i]) + \
sin(3*x[i])*cos(3*x[i]) + \
sin(4*x[i])*cos(4*x[i]) + sin(5*x[i])*cos(5*x[i])
return x
print '\n\ninitializing a %dx%d array\n' % (m,m)
x = seq(0, 1, 1/float(m-1))
y = x.copy()
u = zeros((len(x), len(y)))
t1 = timer(py_loop3_2Dsincos, args=(x,y), repetitions=1*j)
t1 = timer(py_loop2_2Dsincos, args=(x,y), repetitions=1*j)
t1 = timer(py_loop1_2Dsincos, args=(x,y), repetitions=1*j)
print test_tp, 'not implemented'
if __name__ == '__main__':
if len(sys.argv) < 2:
print "Usage: %s test-type\ntypes: allocate range call "\
"flops matrixfill_f77 matrixfill_Cpp vectorization "\
"exception iterator resize type grep factorial" \
src/b/a/badger-lib-HEAD/packages/pyparsing/examples/pymicko.py badger-lib(Download)
#available working registers (the last one is the register for function's return value!)
REGISTERS = "%0 %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13".split()
#register for function's return value
FUNCTION_REGISTER = len(REGISTERS) - 1
#the index of last working register
LAST_WORKING_REGISTER = len(REGISTERS) - 2
#list of relational operators
def display(self):
"""Displays the symbol table content"""
#Finding the maximum length for each column
sym_name = "Symbol name"
sym_len = max(max(len(i.name) for i in self.table),len(sym_name))
kind_name = "Kind"
kind_len = max(max(len(SharedData.KINDS[i.kind]) for i in self.table),len(kind_name))
type_name = "Type"
type_len = max(max(len(SharedData.TYPES[i.type]) for i in self.table),len(type_name))
attr_name = "Attribute"
attr_len = max(max(len(i.attribute_str()) for i in self.table),len(attr_name))
stype - symbol type
"""
self.table.append(SymbolTableEntry(sname, skind, stype))
self.table_len = len(self.table)
return self.table_len-1
def clear_symbols(self, index):
"""Clears all symbols begining with the index to the end of table"""
try:
del self.table[index:]
except Exception:
self.error()
self.table_len = len(self.table)
"""
skind = skind if isinstance(skind, list) else [skind]
stype = stype if isinstance(stype, list) else [stype]
for i, sym in [[x, self.table[x]] for x in range(len(self.table) - 1, SharedData.LAST_WORKING_REGISTER, -1)]:
if (sym.name == sname) and (sym.kind in skind) and (sym.type in stype):
return i
return None
def take_register(self, rtype = SharedData.TYPES.NO_TYPE):
"""Reserves one working register and sets its type"""
if len(self.free_registers) == 0:
self.error("no more free registers")
reg = self.free_registers.pop()
self.used_registers.append(reg)
self.symtab.set_type(reg, rtype)
def relop_code(self, relop, operands_type):
"""Returns code for relational operator
relop - relational operator
operands_type - int or unsigned
"""
code = self.RELATIONAL_DICT[relop]
offset = 0 if operands_type == SharedData.TYPES.INT else len(SharedData.RELATIONAL_OPERATORS)
if DEBUG > 2: return
#iterate through all multiplications/divisions
m = list(mul)
while len(m) > 1:
if not self.symtab.same_types(m[0], m[2]):
raise SemanticException("Invalid opernads to binary '%s'" % m[1])
reg = self.codegen.arithmetic(m[1], m[0], m[2])
if DEBUG > 2: return
#iterate through all additions/substractions
n = list(num)
while len(n) > 1:
if not self.symtab.same_types(n[0], n[2]):
raise SemanticException("Invalid opernads to binary '%s'" % n[1])
reg = self.codegen.arithmetic(n[1], n[0], n[2])
print "ARGUMENT:",arg.exp
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
arg_ordinal = len(self.function_arguments)
#check argument's type
if not self.symtab.same_type_as_argument(arg.exp, self.function_call_index, arg_ordinal):
raise SemanticException("Incompatible type for argument %d in '%s'" % (arg_ordinal + 1, self.symtab.get_name(self.function_call_index)))
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
#check number of arguments
if len(self.function_arguments) != self.symtab.get_attribute(self.function_call_index):
raise SemanticException("Wrong number of arguments for function '%s'" % fun.name)
#arguments should be pushed to stack in reverse order
self.function_arguments.reverse()
mc = MicroC()
output_file = "output.asm"
if len(argv) == 1:
input_file = stdin
elif len(argv) == 2:
input_file = argv[1]
elif len(argv) == 3:
src/r/e/reporter-lib-HEAD/packages/pyparsing/examples/pymicko.py reporter-lib(Download)
#available working registers (the last one is the register for function's return value!)
REGISTERS = "%0 %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13".split()
#register for function's return value
FUNCTION_REGISTER = len(REGISTERS) - 1
#the index of last working register
LAST_WORKING_REGISTER = len(REGISTERS) - 2
#list of relational operators
def display(self):
"""Displays the symbol table content"""
#Finding the maximum length for each column
sym_name = "Symbol name"
sym_len = max(max(len(i.name) for i in self.table),len(sym_name))
kind_name = "Kind"
kind_len = max(max(len(SharedData.KINDS[i.kind]) for i in self.table),len(kind_name))
type_name = "Type"
type_len = max(max(len(SharedData.TYPES[i.type]) for i in self.table),len(type_name))
attr_name = "Attribute"
attr_len = max(max(len(i.attribute_str()) for i in self.table),len(attr_name))
stype - symbol type
"""
self.table.append(SymbolTableEntry(sname, skind, stype))
self.table_len = len(self.table)
return self.table_len-1
def clear_symbols(self, index):
"""Clears all symbols begining with the index to the end of table"""
try:
del self.table[index:]
except Exception:
self.error()
self.table_len = len(self.table)
"""
skind = skind if isinstance(skind, list) else [skind]
stype = stype if isinstance(stype, list) else [stype]
for i, sym in [[x, self.table[x]] for x in range(len(self.table) - 1, SharedData.LAST_WORKING_REGISTER, -1)]:
if (sym.name == sname) and (sym.kind in skind) and (sym.type in stype):
return i
return None
def take_register(self, rtype = SharedData.TYPES.NO_TYPE):
"""Reserves one working register and sets its type"""
if len(self.free_registers) == 0:
self.error("no more free registers")
reg = self.free_registers.pop()
self.used_registers.append(reg)
self.symtab.set_type(reg, rtype)
def relop_code(self, relop, operands_type):
"""Returns code for relational operator
relop - relational operator
operands_type - int or unsigned
"""
code = self.RELATIONAL_DICT[relop]
offset = 0 if operands_type == SharedData.TYPES.INT else len(SharedData.RELATIONAL_OPERATORS)
if DEBUG > 2: return
#iterate through all multiplications/divisions
m = list(mul)
while len(m) > 1:
if not self.symtab.same_types(m[0], m[2]):
raise SemanticException("Invalid opernads to binary '%s'" % m[1])
reg = self.codegen.arithmetic(m[1], m[0], m[2])
if DEBUG > 2: return
#iterate through all additions/substractions
n = list(num)
while len(n) > 1:
if not self.symtab.same_types(n[0], n[2]):
raise SemanticException("Invalid opernads to binary '%s'" % n[1])
reg = self.codegen.arithmetic(n[1], n[0], n[2])
print "ARGUMENT:",arg.exp
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
arg_ordinal = len(self.function_arguments)
#check argument's type
if not self.symtab.same_type_as_argument(arg.exp, self.function_call_index, arg_ordinal):
raise SemanticException("Incompatible type for argument %d in '%s'" % (arg_ordinal + 1, self.symtab.get_name(self.function_call_index)))
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
#check number of arguments
if len(self.function_arguments) != self.symtab.get_attribute(self.function_call_index):
raise SemanticException("Wrong number of arguments for function '%s'" % fun.name)
#arguments should be pushed to stack in reverse order
self.function_arguments.reverse()
mc = MicroC()
output_file = "output.asm"
if len(argv) == 1:
input_file = stdin
elif len(argv) == 2:
input_file = argv[1]
elif len(argv) == 3:
src/m/a/matplotlib-HEAD/py4science/examples/sphinx_template2/tools/sphinxext/apigen.py matplotlib(Download)
'''
# get the names of all classes and functions
functions, classes = self._parse_module(uri)
if not len(functions) and not len(classes):
print 'WARNING: Empty -',uri # dbg
return ''
ad = '.. AUTO-GENERATED FILE -- DO NOT EDIT!\n\n'
chap_title = uri_short
ad += (chap_title+'\n'+ self.rst_section_levels[1] * len(chap_title)
+ '\n\n')
# Set the chapter title to read 'module' for all modules except for the
# main packages
if '.' in uri:
title = 'Module: :mod:`' + uri_short + '`'
else:
title = ':mod:`' + uri_short + '`'
ad += title + '\n' + self.rst_section_levels[2] * len(title)
title = ':mod:`' + uri_short + '`'
ad += title + '\n' + self.rst_section_levels[2] * len(title)
if len(classes):
ad += '\nInheritance diagram for ``%s``:\n\n' % uri
ad += '.. inheritance-diagram:: %s \n' % uri
ad += ' :parts: 3\n'
ad += '\n.. automodule:: ' + uri + '\n'
ad += '\n.. currentmodule:: ' + uri + '\n'
multi_class = len(classes) > 1
multi_fx = len(functions) > 1
if multi_class:
ad += '\n' + 'Classes' + '\n' + \
self.rst_section_levels[2] * 7 + '\n'
elif len(classes) and multi_fx:
ad += '\n' + 'Class' + '\n' + \
self.rst_section_levels[2] * 5 + '\n'
for c in classes:
ad += '\n:class:`' + c + '`\n' \
+ self.rst_section_levels[multi_class + 2 ] * \
(len(c)+9) + '\n\n'
if multi_fx:
ad += '\n' + 'Functions' + '\n' + \
self.rst_section_levels[2] * 9 + '\n\n'
elif len(functions) and multi_class:
ad += '\n' + 'Function' + '\n' + \
self.rst_section_levels[2] * 8 + '\n\n'
for f in functions:
raise ValueError('Cannot interpret match type "%s"'
% match_type)
# Match to URI without package name
L = len(self.package_name)
if matchstr[:L] == self.package_name:
matchstr = matchstr[L:]
for pat in patterns:
src/m/a/matplotlib-HEAD/py4science/examples/filtilt_demo.py matplotlib(Download)
# states in forward-backward filtering, IEEE Transactions on
# Signal Processing, pp. 988--992, April 1996, Volume 44, Issue 4
n=max(len(a),len(b))
zin = ( eye(n-1) - hstack( (-a[1:n,newaxis],
vstack((eye(n-2), zeros(n-2))))))
zi_return=[]
#convert the result into a regular array (not a matrix)
for i in range(len(zi_matrix)):
zi_return.append(float(zi_matrix[i][0]))
return array(zi_return)
def filtfilt(b,a,x):
#For now only accepting 1d arrays
ntaps=max(len(a),len(b))
e="Input vector needs to be bigger than 3 * max(len(a),len(b)."
raise ValueError(e)
if len(a) < ntaps:
a=r_[a,zeros(len(b)-len(a))]
if len(b) < ntaps:
b=r_[b,zeros(len(a)-len(b))]
x = sin(2*pi*t*.5+2)
# add some noise to the signa
xn = x+randn(len(t))*0.05
# parameters for a butterworth lowpass filter
[b,a] = signal.butter(3,0.05)
src/v/t/VT-USRP-daughterboard-drivers_python-HEAD/gnuradio-core/src/python/gnuradio/gr/qa_rational_resampler.py VT-USRP-daughterboard-drivers_python(Download)
self.fg.run()
result_data = dst.data()
L1 = len(result_data)
L2 = len(expected_result)
L = min(L1, L2)
if False:
sys.stderr.write('delta = %2d: ntaps = %d interp = %d ilen = %d\n' %
(L2 - L1, len(taps), interpolation, len(src_data)))
sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' %
(len(result_data), len(expected_result)))
self.fg.run()
result_data = dst.data()
L1 = len(result_data)
L2 = len(expected_result)
L = min(L1, L2)
if False:
sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' %
(L2 - L1, len(taps), decimation, len(src_data)))
sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' %
(len(result_data), len(expected_result)))
fg.run()
fg = None
result_data = dst.data()
L1 = len(result_data)
L2 = len(expected_result)
L = min(L1, L2)
if False:
sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' % (L2 - L1, ntaps, decim, ilen))
sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' %
(len(result_data), len(expected_result)))
fg.run()
fg = None
result_data = dst.data()
L1 = len(result_data)
L2 = len(expected_result)
L = min(L1, L2)
#if True or abs(L1-L2) > 1:
self.fg.run()
result_data = dst.data()
L1 = len(result_data)
L2 = len(expected_result)
L = min(L1, L2)
if False:
sys.stderr.write('delta = %2d: ntaps = %d decim = %d ilen = %d\n' %
(L2 - L1, len(taps), decimation, len(src_data)))
sys.stderr.write(' len(result_data) = %d len(expected_result) = %d\n' %
(len(result_data), len(expected_result)))
src/s/h/shedskin-HEAD/examples/adatron.py shedskin(Download)
def extract_composition(self):
self.local_composition = dict(((x, 0.0) for x in AMINOACIDS))
for counter in range(LENGTH):
self.local_composition[self.sequence[counter]] += 1.0 / LENGTH
self.global_composition = dict(((x, 0.0) for x in AMINOACIDS))
for aminoacid in self.sequence:
self.global_composition[aminoacid] += 1.0 / len(self.sequence)
def create_kernel_table(feature_table):
kernel_table = []
for row in feature_table:
kernel_row = []
for candidate in feature_table:
difference = 0.0
for counter in range(len(row)):
def train_adatron(kernel_table, label_table, h, c):
tolerance = 0.5
alphas = [([0.0] * len(kernel_table)) for _ in range(len(label_table[0]))]
betas = [([0.0] * len(kernel_table)) for _ in range(len(label_table[0]))]
bias = [0.0] * len(label_table[0])
labelalphas = [0.0] * len(kernel_table)
max_differences = [(0.0, 0)] * len(label_table[0])
for iteration in range(10*len(kernel_table)):
print "Starting iteration %s..." % iteration
if iteration == 20: # XXX shedskin test
return alphas, bias
for klass in range(len(label_table[0])):
max_differences[klass] = (0.0, 0)
for elem in range(len(kernel_table)):
max_differences[klass] = (0.0, 0)
for elem in range(len(kernel_table)):
labelalphas[elem] = label_table[elem][klass] * alphas[klass][elem]
for col_counter in range(len(kernel_table)):
prediction = 0.0
for row_counter in range(len(kernel_table)):
prediction += kernel_table[col_counter][row_counter] * \
else:
alphas[klass][max_differences[klass][1]] = betas[klass][max_differences[klass][1]]
element_sum = 0.0
for element_counter in range(len(kernel_table)):
element_sum += label_table[element_counter][klass] * alphas[klass][element_counter] / 4
bias[klass] = bias[klass] + element_sum
def calculate_error(alphas, bias, kernel_table, label_table):
prediction = 0.0
predictions = [([0.0] * len(kernel_table)) for _ in range(len(label_table[0]))]
for klass in range(len(label_table[0])):
for col_counter in range(len(kernel_table)):
for row_counter in range(len(kernel_table)):
label_table[row_counter][klass] * alphas[klass][row_counter]
predictions[klass][col_counter] = prediction + bias[klass]
for col_counter in range(len(kernel_table)):
current_predictions = []
error = 0
for row_counter in range(len(label_table[0])):
if label_table[col_counter][predicted_class] < 0:
error += 1
return 1.0 * error / len(kernel_table)
def main():
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next