rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
class test_trapz(unittest.TestCase): def check_basic(self): x = [1,4,6,7,12] y = [11,15,6,3,9] val = (11+15)/2.0*3 + (15+6)/2.0*2 + (6+3)/2.0 + (3+9)/2.0*5.0 assert_equal(trapz(y,x),val) def check_nd(self): x = sort(20*rand(10,20,30)) y = x**2 + 2*x + 1 dx = x[:,1:,:] - x[:,:-1,:] val = add.reduce(dx*(y[:,1:,:] + y[:,... | def check_basic(self): ba = [1,2,10,11,6,5,4] ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] for ctype in ['1','b','s','i','l','f','d','F','D']: a = array(ba,ctype) a2 = array(ba2,ctype) if ctype in ['1', 'b']: self.failUnlessRaises(ArithmeticError, cumprod, a) self.failUnlessRaises(ArithmeticError, cumprod, a2, 1) self.failUn... | |
return threeAddrProgram, signature, tempsig, constants | return threeAddrProgram, signature, tempsig, constants, input_names | def registerMaker(node, temporary=False): reg = Register(node, temporary=temporary) reg.n = reg_num[0] reg_num[0] -= 1 return reg |
threeAddrProgram, inputsig, tempsig, constants = \ | threeAddrProgram, inputsig, tempsig, constants, input_names = \ | def numexpr(ex, signature=(), copy_args=(), **kwargs): """Compile an expression built using E.<variable> variables to a function. ex can also be specified as a string "2*a+3*b". The order of the input variables and their types can be specified using the signature parameter, which is a list of (name, type) pairs. """... |
return interpreter.NumExpr(inputsig, tempsig, program, constants) | return interpreter.NumExpr(inputsig, tempsig, program, constants, input_names) | def numexpr(ex, signature=(), copy_args=(), **kwargs): """Compile an expression built using E.<variable> variables to a function. ex can also be specified as a string "2*a+3*b". The order of the input variables and their types can be specified using the signature parameter, which is a list of (name, type) pairs. """... |
r_constants = 1 + nex.n_inputs | r_constants = 1 + len(nex.signature) | def disassemble(nex): rev_opcodes = {} for op in interpreter.opcodes: rev_opcodes[interpreter.opcodes[op]] = op r_constants = 1 + nex.n_inputs r_temps = r_constants + len(nex.constants) def getArg(pc): arg = ord(nex.program[pc]) if arg == 0: return 'r0' elif arg == 255: return None elif arg < r_constants: return 'r%d[%... |
b = time.clock() | b = timer() | def initialize(self,reseed = 1): b = time.clock() self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] if reseed: rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.settings['s... |
self.step_time = time.clock() - b | self.step_time = timer() - b | def initialize(self,reseed = 1): b = time.clock() self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] if reseed: rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.settings['s... |
b = time.clock() | b = timer() | def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover):... |
e1 = time.clock(); | e1 = timer(); | def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover):... |
e2 = time.clock(); | e2 = timer(); | def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover):... |
e3 = time.clock(); | e3 = timer(); | def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover):... |
e = time.clock(); self.step_time = e - b | e = timer(); self.step_time = e - b | def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover):... |
b = time.clock() | b = timer() | def evolve(self): b = time.clock() self.initialize() self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step() self.p_dev = self.pop_deviation() self.iteration_output() if(self.gen % self.settings['u... |
self.db_entry['run_time'] = time.clock() - b | self.db_entry['run_time'] = timer() - b | def evolve(self): b = time.clock() self.initialize() self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step() self.p_dev = self.pop_deviation() self.iteration_output() if(self.gen % self.settings['u... |
b = time.clock() | b = timer() | def initialize(self, mode = 'serial'): b = time.clock() #same as galg self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.se... |
self.step_time = time.clock() - b | self.step_time = timer() - b | def initialize(self, mode = 'serial'): b = time.clock() #same as galg self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.se... |
b = time.clock() | b = timer() | def step(self,steps=1,mode = 'serial'): for st in range(steps): b = time.clock() cnt = 0 #self.pop._size(0) # used if we keep a single pop if mode[0] == 'p' or mode[0] == 'P': """ sys.setcheckinterval(100) finished = sync.event() bar = sync.barrier(len(self.GAs)) for ga in self.GAs: thread.start_new_thread(GA_stepper,(... |
e = time.clock(); self.step_time = e - b | e = timer(); self.step_time = e - b | def step(self,steps=1,mode = 'serial'): for st in range(steps): b = time.clock() cnt = 0 #self.pop._size(0) # used if we keep a single pop if mode[0] == 'p' or mode[0] == 'P': """ sys.setcheckinterval(100) finished = sync.event() bar = sync.barrier(len(self.GAs)) for ga in self.GAs: thread.start_new_thread(GA_stepper,(... |
b = time.clock() | b = timer() | def evolve(self, mode = 'serial'): b = time.clock() self.initialize(mode) self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step(1,mode) self.p_dev = self.pop_deviation() self.iteration_output() sel... |
self.db_entry['run_time'] = time.clock() - b | self.db_entry['run_time'] = timer() - b | def evolve(self, mode = 'serial'): b = time.clock() self.initialize(mode) self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step(1,mode) self.p_dev = self.pop_deviation() self.iteration_output() sel... |
t1 = time.time() | t1 = timer() | def GA_stepper(bar,finished,GA): t1 = time.time() GA.step() t2 = time.time() print 'thread ' + `thread.get_ident()` + 'time ' + `t2-t1` + ' sec.' bar.enter() finished.post() |
t2 = time.time() | t2 = timer() | def GA_stepper(bar,finished,GA): t1 = time.time() GA.step() t2 = time.time() print 'thread ' + `thread.get_ident()` + 'time ' + `t2-t1` + ' sec.' bar.enter() finished.post() |
def __init__(self, format, maxprint=MAXPRINT, allocsize=ALLOCSIZE): self.format = format | def __init__(self, maxprint=MAXPRINT, allocsize=ALLOCSIZE): self.format = self.__class__.__name__[:3] if self.format == 'spm': raise ValueError, "This class is not intended" \ " to be instantiated directly." | def __init__(self, format, maxprint=MAXPRINT, allocsize=ALLOCSIZE): self.format = format self.maxprint = maxprint self.allocsize = allocsize |
spmatrix.__init__(self, 'csc') | spmatrix.__init__(self) | def __init__(self,s,ij=None,M=None,N=None,nzmax=100,typecode=Float,copy=0): spmatrix.__init__(self, 'csc') if isinstance(s,spmatrix): if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: ... |
spmatrix.__init__(self, 'csr') | spmatrix.__init__(self) | def __init__(self,s,ij=None,M=None,N=None,nzmax=100,typecode=Float,copy=0): spmatrix.__init__(self, 'csr') if isinstance(s,spmatrix): if isinstance(s, csr_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.colind = s.colind.copy() self.indptr = s.indptr.copy() else: ... |
spmatrix.__init__(self,'dok') | spmatrix.__init__(self) | def __init__(self,A=None): dict.__init__(self) spmatrix.__init__(self,'dok') self.shape = (0,0) self.nnz = 0 if A is not None: A = asarray(A) N,M = A.shape for n in range(N): for m in range(M): if A[n,m] != 0: self[n,m] = A[n,m] |
spmatrix.__init__(self, 'coo') | spmatrix.__init__(self) | def __init__(self, obj, ij, M=None, N=None, nzmax=None, typecode=None): spmatrix.__init__(self, 'coo') if type(ij) is type(()) and len(ij)==2: if M is None: M = amax(ij[0]) if N is None: N = amax(ij[1]) self.row = asarray(ij[0],'i') self.col = asarray(ij[1],'i') else: aij = asarray(ij,'i') if M is None: M = amax(aij[:,... |
Pk = mu**k * exp(-mu) / arr(special.gamma(k+1)) return Pk | Pk = k*log(mu)-special.gammaln(k+1) - mu return exp(Pk) | def _pmf(self, k, mu): Pk = mu**k * exp(-mu) / arr(special.gamma(k+1)) return Pk |
ret_val = apply(obj, args, kw) | ret_val = apply(obj, d_args, d_kw) | def __call__(self, *args, **kw): """Performs the call to the proxied callable object by dispatching the method to the secondary thread.""" obj = self.__dont_mess_with_me_unless_you_know_what_youre_doing ret_val = None if main.in_proxy_call: ret_val = apply(obj, args, kw) else: finished = threading.Event() evt = proxy_e... |
evt = proxy_event(obj, args, kw, finished) | evt = proxy_event(obj, d_args, d_kw, finished) | def __call__(self, *args, **kw): """Performs the call to the proxied callable object by dispatching the method to the secondary thread.""" obj = self.__dont_mess_with_me_unless_you_know_what_youre_doing ret_val = None if main.in_proxy_call: ret_val = apply(obj, args, kw) else: finished = threading.Event() evt = proxy_e... |
exec(function) | exec function in globals(), locals() | def remap (listoflists,criterion): function = 'lines = map(lambda x: '+criterion+',listoflists)' exec(function) return lines |
p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, | p = [-.9077932138396487614720659-82196399419401501888968130.0e-27*1j, -.9077932138396487614720659+82196399419401501888968130.0e-27*1j, | def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.941... |
p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, | p = [-.9072099595087001356491337-72142113041117326028823950.0e-27*1j, -.9072099595087001356491337+72142113041117326028823950.0e-27*1j, | def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.941... |
p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, | p = [-.9067004324162775554189031-64279241063930693839360680.0e-27*1j, -.9067004324162775554189031+64279241063930693839360680.0e-27*1j, | def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.941... |
p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, | p = [-.9062570115576771146523497-57961780277849516990208850.0e-27*1j, -.9062570115576771146523497+57961780277849516990208850.0e-27*1j, | def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.941... |
p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, | p = [-.9058702269930872551848625-52774908289999045189007100.0e-27*1j, -.9058702269930872551848625+52774908289999045189007100.0e-27*1j, | def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.941... |
p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, | p = [-.9055312363372773709269407-48440066540478700874836350.0e-27*1j, -.9055312363372773709269407+48440066540478700874836350.0e-27*1j, | def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.941... |
-.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, | -.9028833390228020537142561-93077131185102967450643820.0e-27*1j, -.9028833390228020537142561+93077131185102967450643820.0e-27*1j, | def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.941... |
b = io.read_array(fname,atype=N.Int) | b = io.read_array(fname,atype=a.dtypechar) | def check_integer(self): from scipy import stats a = stats.randint.rvs(1,20,size=(3,4)) fname = tempfile.mktemp('.dat') io.write_array(fname,a) b = io.read_array(fname,atype=N.Int) assert_array_equal(a,b) os.remove(fname) |
Ap = apply(approx_fhess_p,(xk,psupi,fprime,espilon)+args) | Ap = apply(approx_fhess_p,(xk,psupi,fprime,epsilon)+args) | def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=1e-8, maxiter=None, full_output=0, disp=1): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is not given, finit... |
e = 0.0 | deltax= 0.0 | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
if (abs(e) <= tol1): if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: | if (abs(deltax) <= tol1): if (x>=xmid): deltax=a-x else: deltax=b-x rat = _cg*deltax else: | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
etemp = e e = d | dx_temp = deltax deltax= rat | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 u = x + d | if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*dx_temp))): rat = p*1.0/tmp2 u = x + rat | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
if xmid-x >= 0: d = tol1 else: d = -tol1 | if xmid-x >= 0: rat = tol1 else: rat = -tol1 | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
if (x>=xmid): e=a-x else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 | if (x>=xmid): deltax=a-x else: deltax=b-x rat = _cg*deltax if (abs(rat) < tol1): if rat >= 0: u = x + tol1 | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
u = x + d fu = apply(func, (u,)+args) | u = x + rat fu = apply(func, (u,)+args) | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
if data.dtype.char == 'f' and data2.dtype.char == 'f': new = zeros(data.shape,'F') new.real = data new.imag = data2 data = new del(new) del(data2) | new = zeros(data.shape,data.dtype.char.capitalize()) new.real = data new.imag = data2 data = new del(new) del(data2) | def loadmat(name, dict=None, appendmat=1, basename='raw'): """Load the MATLAB(tm) mat file. If name is a full path name load it in. Otherwise search for the file on the sys.path list and load the first one found (the current directory is searched first). Both v4 (Level 1.0) and v6 matfiles are supported. Version 7.... |
def is_numeric_array(x): try: x.typecode() in ['c','b','l','d','f','D','F'] return 1 except AttributeError: pass return 0 | def is_immutable(x): """ Checks if object is completely immutable. A tuple is not considered completely immutable since it could contain references to objects that could change. Returns 1 if it is immutable or 0 if object is mutable.""" imm = () try: imm = (types.StringType, types.FloatType, types.IntType, types.Comp... | |
exec exec_code | exec exec_code in globals, globals | def exec_code(code,inputs,returns,global_vars,addendum=None): if addendum: inputs.update(addendum) if not returns: returns = () if type(returns) == type(''): raise TypeError, 'returns must be a sequence object - not a string' exec_code = build_globals(global_vars) exec_code = exec_code + build_inputs(inputs) exec_code ... |
exec exec_code | exec exec_code in globals, globals | def loop_code(code,loop_var,inputs,returns,global_vars,addendum=None): if type(returns) == type(''): raise TypeError, 'returns must be a sequence object - not a string' if addendum: inputs.update(addendum) _loop_data = inputs[loop_var] del inputs[loop_var] #not strictly necessary exec_code = build_loop_code(code,loop_v... |
m,n (m<=n) and argument theta and phi: Y^m_n(theta,phi) | m,n (|m|<=n) and argument theta and phi: Y^m_n(theta,phi) | def _sph_harmonic(m,n,theta,phi): """inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (m<=n) and argument theta and phi: Y^m_n(theta,phi) """ x = cos(phi) m,n = int(m), int(n) Pmn,Pmnd = lpmn(m,n,x) val = Pmn[m,n] val *= sqrt((2*m+1)/4.0/pi) val *= exp(0.5*gammaln(n-m+1)-gammaln(n+m+1)) val *= exp(1j*... |
val *= sqrt((2*m+1)/4.0/pi) | val *= sqrt((2*n+1)/4.0/pi) | def _sph_harmonic(m,n,theta,phi): """inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (m<=n) and argument theta and phi: Y^m_n(theta,phi) """ x = cos(phi) m,n = int(m), int(n) Pmn,Pmnd = lpmn(m,n,x) val = Pmn[m,n] val *= sqrt((2*m+1)/4.0/pi) val *= exp(0.5*gammaln(n-m+1)-gammaln(n+m+1)) val *= exp(1j*... |
sources = ['cobyla.pyf','cobyla2.f'] | sources = ['cobyla.pyf','cobyla2.f','trstlp.f'] | def configuration(parent_package='',parent_path=None): package = 'optimize' config = default_config_dict(package, parent_package) local_path = get_path(__name__,parent_path) minpack = ('minpack',{'sources': glob(os.path.join(local_path,'minpack','*.f'))}) sources = ['_minpackmodule.c'] sources = [os.path.join(local_p... |
def day(self): return self.getDate().day def day_of_week(self): return self.getDate().day_of_week def month(self): return self.getDate().month def quarter(self): return monthToQuarter(self.getDate().month) def year(self): return self.getDate().year def seconds(self): return int(self.g... | def day(self): return self.mxDate().day def day_of_week(self): return self.mxDate().day_of_week def month(self): return self.mxDate().month def quarter(self): return monthToQuarter(self.mxDate().month) def year(self): return self.mxDate().year def seconds(self): return int(self.mxDate... | def day(self): return self.getDate().day |
def get_eig_func(): try: import scipy.linalg eig = scipy.linalg.eig except ImportError: try: import linalg eig = linalg.eig except ImportError: try: import LinearAlgebra eig = LinearAlgebra.eigenvectors except: raise ImportError, \ "You must have scipy.linalg or LinearAlgebra to "\ "use this function." return eig | def __init__(self, roots, weights=None, hn=1.0, An=1.0, wfunc=None, limits=None, monic=0): poly1d.__init__(self, roots, r=1) | |
from scipy.linalg import eig | eig = get_eig_func() | def gen_roots_and_weights(n,an_func,sqrt_bn_func,mu): """[x,w] = gen_roots_and_weights(n,an_func,sqrt_bn_func,mu) Returns the roots (x) of an nth order orthogonal polynomail, and weights (w) to use in appropriate Gaussian quadrature with that orthogonal polynomial. The polynomials have the recurrence relation P_n+1(x... |
lena = scipy.array(cPickle.load(f)) | lena = array(cPickle.load(f)) | def lena(): import cPickle, os fname = os.path.join(os.path.dirname(__file__),'plt','lena.dat') f = open(fname,'rb') lena = scipy.array(cPickle.load(f)) f.close() return lena |
g = Numeric.array([[5,6,4,3],[3,5,6,2],[2,3,5,6],[1,6,9,7]],'d') correct = Numeric.array([[2.16374269,3.2222222222, 2.8888888889, 1.6666666667],[2.666666667, 4.33333333333, 4.44444444444, 2.8888888888],[2.222222222, 4.4444444444, 5.4444444444, 4.801066874837],[1.33333333333, 3.92735042735, 6.0712560386, 5.0404040404]])... | g = array([[5,6,4,3],[3,5,6,2],[2,3,5,6],[1,6,9,7]],'d') correct = array([[2.16374269,3.2222222222, 2.8888888889, 1.6666666667],[2.666666667, 4.33333333333, 4.44444444444, 2.8888888888],[2.222222222, 4.4444444444, 5.4444444444, 4.801066874837],[1.33333333333, 3.92735042735, 6.0712560386, 5.0404040404]]) h = signal.wien... | def check_basic(self): g = Numeric.array([[5,6,4,3],[3,5,6,2],[2,3,5,6],[1,6,9,7]],'d') correct = Numeric.array([[2.16374269,3.2222222222, 2.8888888889, 1.6666666667],[2.666666667, 4.33333333333, 4.44444444444, 2.8888888888],[2.222222222, 4.4444444444, 5.4444444444, 4.801066874837],[1.33333333333, 3.92735042735, 6.0712... |
artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float | artype = mintypecode((a,b)) | def lp2bp(b,a,wo=1.0, bw=1.0): """Return a band-pass filter with center frequency wo and bandwidth bw from a low-pass filter prototype with unity cutoff frequency. """ a,b = map(atleast_1d,(a,b)) D = len(a) - 1 N = len(b) - 1 artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float ma = max([N,D]) N... |
artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float | artype = mintypecode((a,b)) | def lp2bs(b,a,wo=1,bw=1): """Return a band-stop filter with center frequency wo and bandwidth bw from a low-pass filter prototype with unity cutoff frequency. """ a,b = map(atleast_1d,(a,b)) D = len(a) - 1 N = len(b) - 1 artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float M = max([N,D]) Np = M ... |
nnz = sum(ravel(s != 0.0)) | nnz = (s != 0.0).sum() | def __init__(self, arg1, dims=None, nzmax=100, dtype=None, copy=False): spmatrix.__init__(self) if isdense(arg1): self.dtype = getdtype(dtype, arg1) # Convert the dense array or matrix arg1 to CSC format if rank(arg1) == 1: # Convert to a row vector arg1 = arg1.reshape(1, arg1.shape[0]) if rank(arg1) == 2: #s = asarray... |
percent_to_go = 1- (1.0*kcol) / N | print "Resizing...", kcol, irow, ierr percent_to_go = 1- (1.0*kcol*M + irow) / (N*M) | def matmat(self, other): if isspmatrix(other): M, K1 = self.shape K2, N = other.shape if (K1 != K2): raise ValueError, "shape mismatch error" a, rowa, ptra = self.data, self.rowind, self.indptr if isinstance(other, csr_matrix): other._check() dtypechar = _coerce_rules[(self.dtype.char, other.dtype.char)] ftype = _trans... |
if amax(ravel(abs(new.imag))) == 0: | if abs(new.imag).max() == 0: | def toarray(self): new = zeros(self.shape, dtype=self.dtype) for key in self: ikey0 = int(key[0]) ikey1 = int(key[1]) new[ikey0, ikey1] = self[key] if amax(ravel(abs(new.imag))) == 0: new = new.real return new |
slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd slice1[axis] = slice(1,None) slice2[axis] = slice(None,-1) | slice1 = tupleset((slice(None),)*nd, axis, slice(1, None)) slice2 = tupleset((slice(None),)*nd, axis, slice(None, -1)) | def cumtrapz(y, x=None, dx=1.0, axis=-1): """Cumulatively integrate y(x) using samples along the given axis and the composite trapezoidal rule. If x is None, spacing given by dx is assumed. """ y = asarray(y) if x is None: d = dx else: d = diff(x,axis=axis) nd = len(y.shape) slice1 = [slice(None)]*nd slice2 = [slice(N... |
slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd | def _basic_simps(y,start,stop,x,dx,axis): nd = len(y.shape) slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if start is None: start = 0 step = 2 slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step) if x is None: # Even ... | |
slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step) | all = (slice(None),)*nd slice0 = tupleset(all, axis, slice(start, stop, step)) slice1 = tupleset(all, axis, slice(start+1, stop+1, step)) slice2 = tupleset(all, axis, slice(start+2, stop+2, step)) | def _basic_simps(y,start,stop,x,dx,axis): nd = len(y.shape) slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if start is None: start = 0 step = 2 slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step) if x is None: # Even ... |
sl0 = [slice(None)]*nd sl1 = [slice(None)]*nd sl0[axis] = slice(start,stop,step) sl1[axis] = slice(start+1,stop+1,step) | sl0 = tupleset(all, axis, slice(start, stop, step)) sl1 = tupleset(all, axis, slice(start+1, stop+1, step)) | def _basic_simps(y,start,stop,x,dx,axis): nd = len(y.shape) slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if start is None: start = 0 step = 2 slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step) if x is None: # Even ... |
slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd | slice1 = (slice(None),)*nd slice2 = (slice(None),)*nd | def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of inte... |
slice1[axis] = -1 slice2[axis] = -2 | slice1 = tupleset(slice1, axis, -1) slice2 = tupleset(slice2, axis, -2) | def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of inte... |
slice1[axis] = 0 slice2[axis] = 1 | slice1 = tupleset(slice1, axis, 0) slice2 = tupleset(slice2, axis, 1) | def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of inte... |
first_dx = x[slice2] - x[slice1] | first_dx = x[tuple(slice2)] - x[tuple(slice1)] | def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of inte... |
slice0 = [slice(None)]*nd slice0[axis] = 0 slicem1 = [slice(None)]*nd slicem1[axis] = -1 | all = (slice(None),) * nd slice0 = tupleset(all, axis, 0) slicem1 = tupleset(all, axis, -1) | def romb(y, dx=1.0, axis=-1, show=0): """Uses Romberg integration to integrate y(x) using N samples along the given axis which are assumed equally spaced with distance dx. The number of samples must be 1 + a non-negative power of two: N=2**k + 1 """ y = asarray(y) nd = len(y.shape) Nsamps = y.shape[axis] Ninterv = Nsam... |
slice_R = [slice(None)]*nd | slice_R = all | def romb(y, dx=1.0, axis=-1, show=0): """Uses Romberg integration to integrate y(x) using N samples along the given axis which are assumed equally spaced with distance dx. The number of samples must be 1 + a non-negative power of two: N=2**k + 1 """ y = asarray(y) nd = len(y.shape) Nsamps = y.shape[axis] Ninterv = Nsam... |
slice_R[axis] = slice(start,stop,step) | slice_R = tupleset(slice_R, slice(start,stop,step)) | def romb(y, dx=1.0, axis=-1, show=0): """Uses Romberg integration to integrate y(x) using N samples along the given axis which are assumed equally spaced with distance dx. The number of samples must be 1 + a non-negative power of two: N=2**k + 1 """ y = asarray(y) nd = len(y.shape) Nsamps = y.shape[axis] Ninterv = Nsam... |
argument 'n' indicates the number of rows (observations). | argument 'nrow' indicates the number of rows (observations). | def __call__(self, *args, **kw): |
if (nzmax>0) and (max(self.rowind[:nnz]) >= M): | if (nzmax < nnz): raise ValueError, "Nzmax must not be less than nnz." if (nnz>0) and (max(self.rowind[:nnz]) >= M): | def _check(self): M,N = self.shape nnz = self.indptr[-1] nzmax = len(self.rowind) |
if (len(self.colind)>0) and (max(self.colind) >= N): | if (nzmax < nnz): raise ValueError, "Nzmax must not be less than nnz." if (nnz>0) and (max(self.colind[:nnz]) >= M): | def _check(self): M,N = self.shape if (rank(self.data) != 1) or (rank(self.colind) != 1) or \ (rank(self.indptr) != 1): raise ValueError, "Data, colind, and indptr arrays "\ "should be rank 1." if (len(self.data) != len(self.colind)): raise ValueError, "Data and row list should have same length" if (len(self.indptr) !=... |
"""Minimze Description: Optimize the function, f, whose gradient is given by fprime using the | """Description: Minimize the function, f, whose gradient is given by fprime using the | def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, maxiter=None, full_output=0, disp=1): """Minimze Description: Optimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is not given, finite-diff... |
save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py' | x11_info = get_x11_info() if not x11_info: return | def configuration(parent_package=''): """ gist only works with an X-windows server This will install *.gs and *.gp files to '%spython%s/site-packages/scipy/xplt' % (sys.prefix,sys.version[:3]) """ # Check for X11 libraries save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py... |
try: exec(open(save_file).read()) try: X11 = X11 except NameError: X11 = check_and_save() except IOError: X11 = check_and_save() if X11: config = default_config_dict() | config = default_config_dict('xplt',parent_package) local_path = get_path(__name__) sources = ['gistCmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(dot_join(parent_package,'xplt.gistC'), sources, include_dirs = x11_info.get('include_dirs',[]), library_dirs = x11_info.get('library_d... | def configuration(parent_package=''): """ gist only works with an X-windows server This will install *.gs and *.gp files to '%spython%s/site-packages/scipy/xplt' % (sys.prefix,sys.version[:3]) """ # Check for X11 libraries save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py... |
if parent_package: parent_package = parent_package + '.' local_path = get_path(__name__) config['packages'].append(parent_package+'xplt') from scipy_distutils.core import Extension sources = ['gistCmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(parent_package+'xplt.gistC', sources... | if __name__ == '__main__': from scipy_distutils.core import setup setup(**configuration()) | def configuration(parent_package=''): """ gist only works with an X-windows server This will install *.gs and *.gp files to '%spython%s/site-packages/scipy/xplt' % (sys.prefix,sys.version[:3]) """ # Check for X11 libraries save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py... |
pass | def check_basic(self): | |
if __name__ == "__main__": | def _testme(): | def speye(n, m = None, k = 0, dtype = 'd'): """ speye(n, m) returns a (n x m) matrix stored in CSC sparse matrix format, where the k-th diagonal is all ones, and everything else is zeros. """ diags = ones((1, n), dtype = dtype) return spdiags(diags, k, n, m) |
_endprint(x, flag, fval, maxfun, tol, disp) | _endprint(x, flag, fval, maxfun, xtol, disp) | def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500, full_output=0, disp=1): """Bounded minimization for scalar functions. Description: Finds a local minimizer of the scalar function func in the interval x1 < xopt < x2 using Brent's method. (See brent for auto-bracketing). Inputs: func -- the function to be... |
raise ValuError, "Bracketing interval must be length 2 or 3 sequence." | raise ValueError, "Bracketing interval must be length 2 or 3 sequence." | def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If... |
raise ValuError, "Bracketing interval must be length 2 or 3 sequence." | raise ValueError, "Bracketing interval must be length 2 or 3 sequence." | def golden(func, args=(), brack=None, tol=_epsilon, full_output=0): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is... |
raise RunTimeError, "Too many iterations." | raise RuntimeError, "Too many iterations." | def bracket(func, xa=0.0, xb=1.0, args=(), grow_limit=110.0): """Given a function and distinct initial points, search in the downhill direction (as defined by the initital points) and return new points xa, xb, xc that bracket the minimum of the function: f(xa) > f(xb) < f(xc) """ _gold = 1.618034 _verysmall_num = 1e-21... |
(-10,1):0L, (10,-1):0L, (-10,-3):0L,(10,11),0L} | (-10,1):0L, (10,-1):0L, (-10,-3):0L,(10,11):0L} | def check_exact(self): resdict = {(10,2):45L, (10,5):252L, (1000,20):339482811302457603895512614793686020778700L, (1000,975):47641862536236518640933948075167736642053976275040L, (-10,1):0L, (10,-1):0L, (-10,-3):0L,(10,11),0L} for key in resdict.keys(): assert_equal(comb(key[0],key[1],exact=1),resdict[key]) |
except (AttributeError, TypeError): try: return self.matvec(asarray(other)) except: raise TypeError, "x.dot(y): y must be matrix, vector, or seq" except ValueError: K2 = other.shape[0] N = 1 if N == 1: | elif len(other.shape) == 1: K2, N = other.shape[0], 1 else: raise ValueError, "could not interpret dimensions" if N == 1 or K2 == 1: | def dot(self, other): """ A generic interface for matrix-matrix or matrix-vector multiplication. Returns A.transpose().conj() * other or A.transpose() * other. """ M, K1 = self.shape try: K2, N = other.shape except (AttributeError, TypeError): # Not sparse or dense. Interpret it as a sequence. try: return self.matvec... |
with a dense matrix d | with a dense array or matrix d | def save( self, file_name, format = '%d %d %f\n' ): try: fd = open( file_name, 'w' ) except Exception, e: raise e, file_name fd.write( '%d %d\n' % self.shape ) fd.write( '%d\n' % self.size ) for ii in xrange( self.size ): ir, ic = self.rowcol( ii ) data = self.getdata( ii ) fd.write( format % (ir, ic, data) ) fd.close... |
def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): | def __init__(self, arg1, dims=None, nzmax=100, dtype='d', copy=False): | def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): ... |
s = asarray(arg1) | s = arg1 | def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): ... |
dtype = s.dtype.char func = getattr(sparsetools, _transtabl[dtype]+'fulltocsc') | dtype = s.dtype func = getattr(sparsetools, _transtabl[dtype.char]+'fulltocsc') | def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): ... |
temp = coo_matrix( s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr except: | except (AssertionError, TypeError, ValueError): | def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): ... |
other = asarray(other) return self.transpose().dot(other.transpose()).transpose() | try: tr = other.transpose() except AttributeError: tr = asarray(other).transpose() return self.transpose().dot(tr).transpose() | def __rmul__(self, other): # other * self if isscalar(other) or (isdense(other) and rank(other)==0): new = self.copy() new.data = other * new.data new.dtype = new.data.dtype new.ftype = _transtabl[new.dtype.char] return new else: other = asarray(other) return self.transpose().dot(other.transpose()).transpose() |
if (rank(other) != 1) or (len(other) != self.shape[1]): raise ValueError, "dimension mismatch" | def matvec(self, other): if isdense(other): if (rank(other) != 1) or (len(other) != self.shape[1]): raise ValueError, "dimension mismatch" func = getattr(sparsetools, self.ftype+'cscmux') y = func(self.data, self.rowind, self.indptr, other, self.shape[0]) return y elif isspmatrix(other): raise NotImplementedError, "use... | |
if (rank(other) != 1) or (len(other) != self.shape[0]): raise ValueError, "dimension mismatch" | def rmatvec(self, other, conjugate=True): if isdense(other): if (rank(other) != 1) or (len(other) != self.shape[0]): raise ValueError, "dimension mismatch" func = getattr(sparsetools, self.ftype+'csrmux') if conjugate: cd = conj(self.data) else: cd = self.data y = func(cd, self.rowind, self.indptr, other) return y elif... | |
raise KeyError, "index out of bounds" | raise IndexError, "index out of bounds" | def __getitem__(self, key): if isinstance(key, types.TupleType): row = key[0] col = key[1] func = getattr(sparsetools, self.ftype+'cscgetel') M, N = self.shape if not (0<=row<M) or not (0<=col<N): raise KeyError, "index out of bounds" ind, val = func(self.data, self.rowind, self.indptr, row, col) return val #elif isins... |
raise KeyError, "key out of bounds" | raise IndexError, "index out of bounds" | def __setitem__(self, key, val): if isinstance(key, types.TupleType): row = key[0] col = key[1] func = getattr(sparsetools, self.ftype+'cscsetel') M, N = self.shape if (row < 0): row = M + row if (col < 0): col = N + col if (row < 0) or (col < 0): raise IndexError, "index out of bounds" if (col >= N): self.indptr = res... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.