common_id
stringlengths
1
5
image
stringlengths
15
19
code
stringlengths
26
239
4327
Train/png/4327.png
def beta_pdf(x, a, b): bc = 1 / beta(a, b) fc = x ** (a - 1) sc = (1 - x) ** (b - 1) return bc * fc * sc
6613
Train/png/6613.png
def nni_log(log_type, log_message): dt = datetime.now() print('[{0}] {1} {2}'.format(dt, log_type.value, log_message))
3404
Train/png/3404.png
def gday_of_year(self): return (self.date - dt.date(self.date.year, 1, 1)).days
386
Train/png/386.png
def predict(self, X): return self.__cost(self.__unroll(self.__thetas), 0, np.matrix(X))
1479
Train/png/1479.png
def _writer(func): name = func.__name__ return property(fget=lambda self: getattr(self, '_%s' % name), fset=func)
4915
Train/png/4915.png
def doflip(dec, inc): if inc < 0: inc = -inc dec = (dec + 180.) % 360. return dec, inc
6232
Train/png/6232.png
def do_sing(self, arg): color_escape = COLORS.get(self.songcolor, Fore.RESET) self.poutput(arg, color=color_escape)
2046
Train/png/2046.png
def _process_added_port_event(self, port_name): LOG.info("Hyper-V VM vNIC added: %s", port_name) self._added_ports.add(port_name)
6343
Train/png/6343.png
def heappush(heap, item): heap.append(item) _siftdown(heap, 0, len(heap)-1)
2562
Train/png/2562.png
def get_right_axes(self): "create, if needed, and return right-hand y axes" if len(self.fig.get_axes()) < 2: ax = self.axes.twinx() return self.fig.get_axes()[1]
5120
Train/png/5120.png
def date_in_past(self): now = datetime.datetime.now() return (now.date() > self.date)
3557
Train/png/3557.png
def write_int(self, number): buf = pack(self.byte_order + "i", number) self.write(buf)
439
Train/png/439.png
def zero_pad(m, n=1): return np.pad(m, (n, n), mode='constant', constant_values=[0])
5635
Train/png/5635.png
def complete_pbar(self): if hasattr(self, 'pbar') and self.pbar: self.pbar.n = len(self.nb.cells) self.pbar.refresh()
3675
Train/png/3675.png
def write(self, chunk, offset): return lib.zfile_write(self._as_parameter_, chunk, offset)
7997
Train/png/7997.png
def get_selected_values(self, selection): return [v for b, v in self._choices if b & selection]
1001
Train/png/1001.png
def on_change(self, callable_): self.model.add_observer( callable_, self.entity_type, 'change', self.entity_id)
4371
Train/png/4371.png
def to_tuple(self, iterable, surround="()", joiner=", "): return "{0}{1}{2}".format(surround[0], joiner.join(iterable), surround[1])
1465
Train/png/1465.png
def set_random_seed(self, seed): self.config['mc']['seed'] = seed np.random.seed(seed)
5341
Train/png/5341.png
def create_prefix_dir(self, path, fmt): create_prefix_dir(self._get_os_path(path.strip('/')), fmt)
3031
Train/png/3031.png
def setageing(self, time): _runshell([brctlexe, 'setageing', self.name, str(time)], "Could not set ageing time in %s." % self.name)
2664
Train/png/2664.png
def path_yield(path): for part in (x for x in path.strip(SEP).split(SEP) if x not in (None, '')): yield part
2596
Train/png/2596.png
def addFilter(self, filter): self.FILTERS.append(filter) return "FILTER#{}".format(len(self.FILTERS) - 1)
7115
Train/png/7115.png
def xAxisIsMinor(self): return min(self.radius.x, self.radius.y) == self.radius.x
1049
Train/png/1049.png
def parse_items(self, field: Field) -> Mapping[str, Any]: return self.build_parameter(field.container)
6569
Train/png/6569.png
def raw_nogpu_session(graph=None): config = tf.compat.v1.ConfigProto(device_count={'GPU': 0}) return tf.compat.v1.Session(config=config, graph=graph)
4824
Train/png/4824.png
def saveWeightsToFile(self, filename, mode='pickle', counter=None): self.saveWeights(filename, mode, counter)
9950
Train/png/9950.png
def recv_sub(self, id_, name, params): self.api.sub(id_, name, *params)
1595
Train/png/1595.png
def set_row_height(self, n=0, height=18): self._widget.setRowHeight(n, height) return self
3138
Train/png/3138.png
def put_readme(self, content): logger.debug("Putting readme") key = self.get_readme_key() self.put_text(key, content)
1947
Train/png/1947.png
def get_field_type(f): types = (t[5:] for t in dir(f) if t[:4] == 'TYPE' and getattr(f, t) == f.type) return next(types)
1917
Train/png/1917.png
def serialize(self, value, **kwargs): return [self.item_type.serialize(val, **kwargs) for val in value]
2703
Train/png/2703.png
def really_bad_du(path): "Don't actually use this, it's just an example." return sum([os.path.getsize(fp) for fp in list_files(path)])
10014
Train/png/10014.png
def rvalues(self): tmp = self while tmp is not None: yield tmp.data tmp = tmp.prev
352
Train/png/352.png
def check_vprint(s, vprinter): if vprinter is True: print(s) elif callable(vprinter): vprinter(s)
8966
Train/png/8966.png
def _exp_schedule(iteration, k=20, lam=0.005, limit=100): return k * math.exp(-lam * iteration)
9790
Train/png/9790.png
def doWrite(self, sim, data): sim.write(data, self.intf.data)
4331
Train/png/4331.png
def merge(parent, idx, value): target = get_child(parent, idx) for key, val in value.items(): target[key] = val
9357
Train/png/9357.png
def extract_tarfile(archive_name, destpath): "Unpack a tar archive, optionally compressed" archive = tarfile.open(archive_name) archive.extractall(destpath)
8702
Train/png/8702.png
def show_popup_menu(self, pos): self.popup_pos = self.image_coordinates(pos) self.frame.PopupMenu(self.wx_popup_menu, pos)
6732
Train/png/6732.png
def get_image_label(name, default="not_found.png"): label = QLabel() label.setPixmap(QPixmap(get_image_path(name, default))) return label
2137
Train/png/2137.png
def read_utf8(fh, byteorder, dtype, count, offsetsize): return fh.read(count).decode('utf-8')
4386
Train/png/4386.png
def kvlclient(self): if self._kvlclient is None: self._kvlclient = kvlayer.client() return self._kvlclient
2785
Train/png/2785.png
def _make_object(name): klass = type(name, (SWFObject,), {'__str__': _str, '__repr__': _repr, 'name': name}) return klass()
8548
Train/png/8548.png
def choice_type(self, tchain, p_elem): elem = SchemaNode.choice(p_elem, occur=2) self.handle_substmts(tchain[0], elem)
3073
Train/png/3073.png
def remove_accent_string(string): return utils.join([add_accent_char(c, Accent.NONE) for c in string])
8137
Train/png/8137.png
def distance(self, other): return distance((self.separation, self.pa), (other.separation, other.pa))
1296
Train/png/1296.png
def arrows(self): for o in self.arrow.values(): for arro in o.values(): yield arro
2973
Train/png/2973.png
def resetTimeout(self): if self.__timeoutCall is not None and self.timeOut is not None: self.__timeoutCall.reset(self.timeOut)
1412
Train/png/1412.png
def load(self, arguments): "Load the values from the a ServerConnection arguments" features = arguments[1:-1] list(map(self.load_feature, features))
7850
Train/png/7850.png
def listen(): msg = MSG() ctypes.windll.user32.GetMessageA(ctypes.byref(msg), 0, 0, 0)
8859
Train/png/8859.png
def update(self): for s in self.sensors: s.colliding = self.io.get_collision_state(collision_name=s.name)
4307
Train/png/4307.png
def plotGene(self): pl.plot(self.x, self.y, '.') pl.grid(True) pl.show()
2553
Train/png/2553.png
def magnitude(a): "calculates the magnitude of a vecor" from math import sqrt sum = 0 for coord in a: sum += coord ** 2 return sqrt(sum)
5742
Train/png/5742.png
def cancel(self, refund=True): if refund: self.refund() self.status = self.CANCELLED self.save()
874
Train/png/874.png
def set_src_builder(self, builder): self.sbuilder = builder if not self.has_builder(): self.builder_set(builder)
3349
Train/png/3349.png
def output_for_debugging(self, stream, data): with open('%s.spec.out' % stream.name, 'w') as f: f.write(str(data))
4707
Train/png/4707.png
def get_property(self, filename): with open(self.filepath(filename)) as f: return f.read().strip()
8309
Train/png/8309.png
def _base_resize(img, size): img = tf.expand_dims(img, 0) return tf.image.resize_bilinear(img, size)[0, :, :, :]
7669
Train/png/7669.png
def to_snake_case(name): s1 = FIRST_CAP_REGEX.sub(r'\1_\2', name) return ALL_CAP_REGEX.sub(r'\1_\2', s1).lower()
6904
Train/png/6904.png
def combine(self, a, b): for l in (a, b): for x in l: yield x
524
Train/png/524.png
def bonds_iter(self): for u, v, bond in self.graph.edges.data("bond"): yield u, v, bond
5399
Train/png/5399.png
def merge(*maps): copies = map(deepcopy, maps) return reduce(lambda acc, val: acc.update(val) or acc, copies)
4696
Train/png/4696.png
def initialize_directories(self): makedirs(self.config.source_index) makedirs(self.config.eggs_cache)
16
Train/png/16.png
def format_item(item, template, name='item'): ctx = {name: item} return render_template_to_string(template, **ctx)
8536
Train/png/8536.png
def get_pidfile_path(working_dir): pid_filename = virtualchain_hooks.get_virtual_chain_name() + ".pid" return os.path.join(working_dir, pid_filename)
9350
Train/png/9350.png
def py(self, output): import pprint pprint.pprint(output, stream=self.outfile)
96
Train/png/96.png
def copy_file(src, dest): try: shutil.copy2(src, dest) except Exception as ex: print('ERROR copying file' + str(ex))
6420
Train/png/6420.png
def write(self) -> None: "Writes single model graph to Tensorboard." self.tbwriter.add_graph( model=self.model, input_to_model=self.input_to_model)
5472
Train/png/5472.png
def write_file(writer, filename): for line in txt_line_iterator(filename): writer.write(line) writer.write("\n")
7843
Train/png/7843.png
def shuffle_into_deck(self): return self.game.cheat_action(self, [actions.Shuffle(self.controller, self)])
8388
Train/png/8388.png
def local_decorated_likelihoods(obj): for name, like in six.iteritems(likelihoods): obj[name + '_like'] = gofwrapper(like, snapshot)
2106
Train/png/2106.png
def info(self): if self.name not in jobs: return {'status': self.status} else: return jobs[self.name]
3702
Train/png/3702.png
def build(self): self.load_builtins() self.load_functions(self.tree) self.visit(self.tree)
5593
Train/png/5593.png
def as_ompenv(cls, obj): if isinstance(obj, cls): return obj if obj is None: return cls() return cls(**obj)
2803
Train/png/2803.png
def add_cron(self, name, minute, hour, mday, month, wday, who, command, env=None): raise NotImplementedError
4282
Train/png/4282.png
def update(self, key: str, data: np.ndarray) -> None: self.data[key] = data
9978
Train/png/9978.png
def clone(self, url): return self.execute("%s branch %s %s" % (self.executable, url, self.path))
5676
Train/png/5676.png
def _split_str(s, n): length = len(s) return [s[i:i + n] for i in range(0, length, n)]
5719
Train/png/5719.png
def merge(cls, trees): first = trees[0] for tree in trees: first.update(tree) return first
8001
Train/png/8001.png
def print_gateway(): print("Printing information about the Gateway") data = api(gateway.get_gateway_info()).raw print(jsonify(data))
3496
Train/png/3496.png
def estimate_lambda(pv): LOD2 = sp.median(st.chi2.isf(pv, 1)) L = (LOD2/0.456) return (L)
5163
Train/png/5163.png
def readme(): from livereload import Server server = Server() server.watch("README.rst", "py cute.py readme_build") server.serve(open_url_delay=1, root="build/readme")
7596
Train/png/7596.png
def is_accessable_by_others(filename): mode = os.stat(filename)[stat.ST_MODE] return mode & (stat.S_IRWXG | stat.S_IRWXO)
5312
Train/png/5312.png
def srbt1(bt_address, pkts, *args, **kargs): a, b = srbt(bt_address, pkts, *args, **kargs) if len(a) > 0: return a[0][1]
4909
Train/png/4909.png
def rows(self): for line in self.text.splitlines(): yield tuple(self.getcells(line))
5394
Train/png/5394.png
def _xy_locs(mask): y, x = mask.nonzero() return list(zip(x, y))
10066
Train/png/10066.png
def perr(msg, log=None): _print(msg, sys.stderr, log_func=log.error if log else None)
5060
Train/png/5060.png
def backend(self): from indico_livesync.plugin import LiveSyncPlugin return LiveSyncPlugin.instance.backend_classes.get(self.backend_name)
4812
Train/png/4812.png
def convert_to_underscore(name): s1 = _first_cap_re.sub(r'\1_\2', name) return _all_cap_re.sub(r'\1_\2', s1).lower()
2266
Train/png/2266.png
def parse_domain(url): domain_match = lib.DOMAIN_REGEX.match(url) if domain_match: return domain_match.group()
7634
Train/png/7634.png
def add_check(self, check_item): self.checks.append(check_item) for other in self.others: other.add_check(check_item)
5565
Train/png/5565.png
def add_category(self, category): self._categories = self._ensure_append(category, self._categories)
10020
Train/png/10020.png
def add_rule(self, rule, rn, alts) -> bool: rule.rulename = self.value(rn) rule.parser_tree = alts.parser_tree return True
5498
Train/png/5498.png
def pvt(bars): trend = ((bars['close'] - bars['close'].shift(1)) / bars['close'].shift(1)) * bars['volume'] return trend.cumsum()
6656
Train/png/6656.png
def valuePop(ctxt): if ctxt is None: ctxt__o = None else: ctxt__o = ctxt._o ret = libxml2mod.valuePop(ctxt__o) return ret
3437
Train/png/3437.png
def stop(self): if self.run is True and all([self.job, self.job.is_alive()]): print('Done.') self.job.terminate()
7194
Train/png/7194.png
def replacenode(self, othereplus, node): node = node.upper() self.dt[node.upper()] = othereplus.dt[node.upper()]
7794
Train/png/7794.png
def rename(self, req, parent, name, newparent, newname): self.reply_err(req, errno.EROFS)
7721
Train/png/7721.png
def gen_sdiv(src1, src2, dst): assert src1.size == src2.size return ReilBuilder.build(ReilMnemonic.SDIV, src1, src2, dst)