Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def rebuild(cls, instance, **replkw):
state = instance.__getstate__()
attrs = ("country", "script", "forced")
language = state[0]
kwa = dict(list(zip(attrs, state[1:])))
kwa.update(replkw)
return cls(language, **kwa)
def row_as_hkl( row, txt=['h','k','l']):
result = ""
part = 0
for n,j in zip(row,txt):
nn=""
if n != rational.int(0):
part += 1
if n >rational.int(0):
if part==1:
if n==rational.int(1):
nn = j
else:
nn = str(n)+j
if part > 1:
if n==rational.int(1):
nn = "+"+j
else:
nn = "+"+str(n)+j
if n < rational.int(0):
if part==1:
for var, val in value_set:
if not isinstance(var, Product):
linear.append((
float(val), self._p.getVarByName(self._variables[var])))
else:
if len(var) > 2:
raise ValueError('Invalid objective: {}'.format(var))
quad.append((
float(val), self._p.getVarByName(self._variables[var[0]]),
self._p.getVarByName(self._variables[var[1]])))
if len(quad) > 0:
expr = gurobipy.QuadExpr()
if len(linear) > 0:
expr.addTerms(*zip(*linear))
expr.addTerms(*zip(*quad))
else:
expr = gurobipy.LinExpr(linear)
return expr
shape = x.get_shape().as_list()
if shape is not None:
for axis, value in spec.axes.items():
if hasattr(value, 'value'):
value = value.value
if value is not None and shape[int(axis)] not in {value, None}:
raise ValueError(
'Input ' + str(input_index) + ' of layer ' + self.name + ' is'
' incompatible with the layer: expected axis ' + str(axis) +
' of input shape to have value ' + str(value) +
' but received input with shape ' + str(shape))
# Check shape.
if spec.shape is not None:
shape = x.get_shape().as_list()
if shape is not None:
for spec_dim, dim in zip(spec.shape, shape):
if spec_dim is not None and dim is not None:
if spec_dim != dim:
raise ValueError('Input ' + str(input_index) +
' is incompatible with layer ' + self.name +
': expected shape=' + str(spec.shape) +
', found shape=' + str(shape))
if new_x is None:
new_x = []
if new_y is None:
new_y = []
if new_i is None:
new_i = []
nref_x = np.append(self.xdata, np.array(new_x).astype(np.double))
nref_y = np.append(self.ydata, np.array(new_y).astype(np.double))
nref_i = np.append(self.idata, np.array(new_i).astype(np.double))
self.xdata = nref_x
self.ydata = nref_y
self.idata = nref_i
nref_xy = list(zip(nref_x, nref_y))
all_acc = [i[0] for i in nref_xy if i[1] >= min_bragg]
all_rej = [i[0] for i in nref_xy if i[1] < min_bragg]
if nref_x != [] and nref_y != []:
if self.plot_zoom:
if self.max_lock:
self.x_max = np.max(nref_x)
self.x_min = self.x_max - self.chart_range
else:
self.x_min = -1
self.x_max = np.max(nref_x) + 1
if min_bragg > np.max(nref_y):
self.y_max = min_bragg + int(0.1 * min_bragg)
else:
self.y_max = np.max(nref_y) + int(0.1 * np.max(nref_y))
def fn(*args):
dic = {}
for name, val in zip(self._names, args):
dic[name] = val
fname = os.path.join(
dir, 'DumpTensor-{}.npz'.format(self.global_step))
np.savez(fname, **dic)
super(DumpTensors, self).__init__(names, fn)
def _get_input_tensors(self):
with tf.device('/cpu:0'), self.cached_name_scope():
ret = self.queue.dequeue(name='input_deque')
if isinstance(ret, tf.Tensor): # only one input
ret = [ret]
assert len(ret) == len(self._input_placehdrs)
for qv, v in zip(ret, self._input_placehdrs):
qv.set_shape(v.get_shape())
return ret
Note that this method returns a column-major data
(i.e. :obj:`([a[0], ..., a[3]], ..., [c[0], ... c[3]])`,
:obj:`{'a': [a[0], ..., a[3]], ..., 'c': [c[0], ..., c[3]]}`, or
:obj:`[a[0], ..., a[3]]`).
Returns:
If :attr:`mode` is :class:`tuple`,
this method returns a tuple of lists/arrays.
If :attr:`mode` is :class:`dict`,
this method returns a dict of lists/arrays.
"""
examples = self.get_examples(None, None)
if self.mode is tuple:
return examples
elif self.mode is dict:
return dict(six.moves.zip(self.keys, examples))
elif self.mode is None:
return examples[0]
self._fix_invalid_placements(queue, servers)
self._handle_inactive_servers(servers)
self._handle_blacklisted_apps(queue, servers)
self._fix_invalid_identities(queue, servers)
for label, partition in six.iteritems(self.partitions):
allocation = partition.allocation
allocation.label = label
self.schedule_alloc(allocation, servers)
after = [(app.server, app.placement_expiry)
for app in all_apps]
placement = [
tuple(itertools.chain(b, a))
for b, a in six.moves.zip(before, after)
]
for appname, s_before, exp_before, s_after, exp_after in placement:
if s_before != s_after:
_LOGGER.info('New placement: %s - %s => %s',
appname, s_before, s_after)
else:
if exp_before != exp_after:
_LOGGER.info('Renewed: %s [%s] - %s => %s',
appname, s_before, exp_before, exp_after)
_LOGGER.info('Total scheduler time for %s apps: %r (sec)',
len(all_apps),
time.time() - begin)
return placement
def feed(self, iterable):
converter = []
for lod_level, shape, dtype in six.zip(
self.feed_lod_level, self.feed_shapes, self.feed_dtypes):
converter.append(
DataToLoDTensorConverter(
place=self.place,
lod_level=lod_level,
shape=shape,
dtype=dtype))
for each_sample in iterable:
assert len(each_sample) == len(converter), (
"The number of fields in data (%s) does not match " +
"len(feed_list) (%s)") % (len(each_sample), len(converter))
for each_converter, each_slot in six.zip(converter, each_sample):
each_converter.feed(each_slot)
ret_dict = {}
for each_name, each_converter in six.zip(self.feed_names, converter):