Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cython.locals(d=dict)
def setdefault2(d, key, value):
"""
>>> d = {}
>>> setdefault2(d, 1, 2)
2
>>> len(d)
1
>>> setdefault2(d, 1, 2)
2
>>> len(d)
1
>>> l = setdefault2(d, 2, [])
>>> len(d)
2
>>> l.append(1)
>>> setdefault2(d, 2, [])
@cython.locals(x=X)
def x_of(x):
return x.x
@cython.locals(x=cython.int, y=cython.int, ry=cython.int, id=cython.int)
def print_pos(pos, output):
hex = pos.hex
done = pos.done
size = hex.size
for y in range(size):
print(u" " * (size - y - 1), end=u"", file=output)
for x in range(size + y):
pos2 = (x, y)
id = hex.get_by_pos(pos2).id
if done.already_done(id):
c = str(done[id][0]) if done[id][0] != EMPTY else u"."
else:
c = u"?"
print(u"%s " % c, end=u"", file=output)
print(end=u"\n", file=output)
for y in range(1, size):
@cython.locals(i=cython.int)
def next_cell_first(self):
for i in range(self.count):
if (not self.already_done(i)):
return i
return -1
@cython.locals(i=cython.int)
def next_cell_max_neighbors(self, pos):
maxn = -1
maxi = -1
for i in range(self.count):
if not self.already_done(i):
cells_around = pos.hex.get_by_id(i).links
n = sum([1 if (self.already_done(nid) and (self[nid][0] != EMPTY)) else 0
for nid in cells_around])
if n > maxn:
maxn = n
maxi = i
return maxi
@cy.locals(amount=cy.double, update=cy.bint)
def allocate(self, amount, child=None, update=True):
"""
Allocate capital to Strategy. By default, capital is allocated
recursively down the children, proportionally to the children's
weights. If a child is specified, capital will be allocated
to that specific child.
Allocation also have a side-effect. They will deduct the same amount
from the parent's "account" to offset the allocation. If there is
remaining capital after allocation, it will remain in Strategy.
Args:
* amount (float): Amount to allocate.
* child (str): If specified, allocation will be directed to child
only. Specified by name.
* update (bool): Force update.
@cython.locals(tot=cython.int, tiles=cython.int[8])
def check_valid(pos):
hex = pos.hex
tiles = pos.tiles
done = pos.done
# fill missing entries in tiles
tot = 0
for i in range(8):
if tiles[i] > 0:
tot += tiles[i]
else:
tiles[i] = 0
# check total
if tot != hex.count:
raise Exception("Invalid input. Expected %d tiles, got %d." % (hex.count, tot))
@cython.locals(d_valve=cython.double,d_port=cython.double,C_D=cython.double,
h_valve=cython.double,a_valve=cython.double, l_valve=cython.double,
rho_valve=cython.double,E=cython.double,x_stopper=cython.double,
key_up=cython.bytes,key_down=cython.bytes)
def __init__(self, d_valve, d_port, C_D, h_valve, a_valve,
l_valve, rho_valve, E, x_stopper, key_up, key_down):
I=(d_valve*h_valve**3)/12 #Moment of Intertia for discharge valve,[m^4]
k_valve=(6*E*I)/(a_valve**2*(3*l_valve-a_valve)) #Valve stiffness
m_eff=(1/3)*rho_valve*l_valve*d_valve*h_valve #Effective mass of valve reeds
self.E = E
self.rho_valve = rho_valve
self.a_valve = a_valve
self.l_valve = l_valve
self.h_valve = h_valve
@cython.locals(
css=cython.unicode,
quote=cython.Py_UCS4,
c=cython.Py_UCS4,
start_pos=cython.Py_ssize_t,
pos=cython.Py_ssize_t,
length=cython.Py_ssize_t,
chunks=cython.list,
)
def _consume_quoted_string(css, pos):
"""Return (unescaped_value, new_pos)."""
# http://dev.w3.org/csswg/css-syntax/#consume-a-string-token
quote = css[pos]
assert quote in ('"', "'")
pos += 1
chunks = []
length = len(css)