content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
"""Placeholder/template for staging envs."""
[ 37811, 27271, 13829, 14, 28243, 329, 29475, 551, 14259, 526, 15931, 198 ]
3.75
12
from cognito.check import Check from cognito.table import Table import os import pytest import pandas as pd import numpy as np from os import path from sklearn import preprocessing
[ 6738, 8866, 10094, 13, 9122, 1330, 6822, 198, 6738, 8866, 10094, 13, 11487, 1330, 8655, 198, 11748, 28686, 198, 11748, 12972, 9288, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 28686, 1330, 3108, ...
3.714286
49
from reportlab.lib.units import inch from reportlab.platypus import SimpleDocTemplate, Spacer from reportlab.rl_config import defaultPageSize from reportlab.lib.units import inch from reportlab.platypus.flowables import Flowable
[ 6738, 989, 23912, 13, 8019, 13, 41667, 1330, 11111, 198, 6738, 989, 23912, 13, 489, 265, 4464, 385, 1330, 17427, 23579, 30800, 11, 1338, 11736, 198, 6738, 989, 23912, 13, 45895, 62, 11250, 1330, 4277, 9876, 10699, 198, 6738, 989, 23912,...
3.650794
63
from app.bq_service import BigQueryService if __name__ == "__main__": bq_service = BigQueryService() bq_service.migrate_daily_bot_probabilities_table() print("MIGRATION SUCCESSFUL!")
[ 198, 198, 6738, 598, 13, 65, 80, 62, 15271, 1330, 4403, 20746, 16177, 198, 198, 361, 11593, 3672, 834, 6624, 366, 834, 12417, 834, 1298, 628, 220, 220, 220, 275, 80, 62, 15271, 796, 4403, 20746, 16177, 3419, 628, 220, 220, 220, 275,...
2.61039
77
from copy import deepcopy from dataclasses import asdict, dataclass from enum import IntEnum from colosseum.utils.random_vars import deterministic, get_dist try: from functools import cached_property except: from backports.cached_property import cached_property from typing import Any, Dict, List, Tuple, Type, Union import numpy as np from scipy.stats import beta, rv_continuous from colosseum.mdps import MDP from colosseum.mdps.base_mdp import NextStateSampler from colosseum.mdps.minigrid_rooms.continuous.mdp import MiniGridRoomsContinuous from colosseum.utils.mdps import check_distributions def _calculate_next_nodes_prms( self, node: MiniGridDoorKeyNode, action: int ) -> Tuple[Tuple[dict, float], ...]: newnode_prms = deepcopy(asdict(node)) if action == MiniGridDoorKeyAction.TurnRight: newnode_prms["Dir"] = (node.Dir + 1) % 4 if action == MiniGridDoorKeyAction.TurnLeft: newnode_prms["Dir"] = (node.Dir - 1) % 4 if action == MiniGridDoorKeyAction.MoveForward: if node.Dir == MiniGridDoorKeyDirection.UP: next_coord = (node.X, node.Y + 1) if node.Dir == MiniGridDoorKeyDirection.RIGHT: next_coord = node.X + 1, node.Y if node.Dir == MiniGridDoorKeyDirection.DOWN: next_coord = node.X, node.Y - 1 if node.Dir == MiniGridDoorKeyDirection.LEFT: next_coord = node.X - 1, node.Y if next_coord in self.coordinates_available or ( node.IsDoorOpened and next_coord == self.door_position ): newnode_prms["X"], newnode_prms["Y"] = next_coord if action == MiniGridDoorKeyAction.PickObject: if node.X == node.XKey and node.Y == node.YKey: newnode_prms["XKey"] = newnode_prms["YKey"] = -1 if node.XKey == -1 and not node.IsDoorOpened: if action == MiniGridDoorKeyAction.DropObject: newnode_prms["XKey"] = node.X newnode_prms["YKey"] = node.Y if action == MiniGridDoorKeyAction.UseObject: if node.Dir == MiniGridDoorKeyDirection.UP: next_coord = (node.X, node.Y + 1) if node.Dir == MiniGridDoorKeyDirection.RIGHT: next_coord = node.X + 1, node.Y if node.Dir == MiniGridDoorKeyDirection.DOWN: next_coord = node.X, node.Y - 1 if node.Dir == MiniGridDoorKeyDirection.LEFT: next_coord = node.X - 1, node.Y if next_coord == self.door_position: newnode_prms["IsDoorOpened"] = True return ((newnode_prms, 1.0),) def _calculate_reward_distribution( self, node: Any, action: IntEnum, next_node: Any ) -> rv_continuous: return ( self.optimal_distribution if next_node.X == self.goal_position[0] and next_node.Y == self.goal_position[1] else self.other_distribution ) def _check_input_parameters(self): super(MiniGridDoorKeyMDP, self)._check_input_parameters() assert self.size >= 3 check_distributions( [ self.optimal_distribution, self.other_distribution, ], self.make_reward_stochastic, ) def _instantiate_starting_node_sampler(self) -> NextStateSampler: # noinspection PyAttributeOutsideInit self.wall_position = self._rng.randint(self.size - 2) + 1 # noinspection PyAttributeOutsideInit self.is_wall_horizontal = self._rng.rand() > 0.5 if self.is_wall_horizontal: self.door_position = self._rng.randint(self.size), self.wall_position else: self.door_position = self.wall_position, self._rng.randint(self.size) self.is_goal_before = self._rng.rand() > 0.5 coords = MiniGridRoomsContinuous.get_positions_coords_in_room(self.size, (0, 0)) goal_positions = [] starting_positions = [] for i, j in coords.ravel(): if ( i < self.wall_position if self.is_goal_before else i > self.wall_position ): goal_positions.append((j, i) if self.is_wall_horizontal else (i, j)) elif ( i > self.wall_position if self.is_goal_before else i < self.wall_position ): starting_positions.append((j, i) if self.is_wall_horizontal else (i, j)) possible_starting_positions = deepcopy(starting_positions) self._rng.shuffle(goal_positions) self.goal_position = goal_positions[0] self._rng.shuffle(starting_positions) self.start_key_position = starting_positions.pop(0) starting_positions = [ (x, y, dir) for x, y in starting_positions for dir in MiniGridDoorKeyDirection ] assert self.n_starting_states < len(starting_positions) self._possible_starting_nodes = [ MiniGridDoorKeyNode( x, y, dir.value, *self.start_key_position, False, ) for x, y, dir in starting_positions ] return NextStateSampler( next_states=self._possible_starting_nodes[: self.n_starting_states], probs=[1 / self.n_starting_states for _ in range(self.n_starting_states)], seed=self._next_seed(), ) def calc_grid_repr(self, node: Any) -> np.array: grid_size = self.size door_position = self.door_position wall_position = self.wall_position is_wall_horizontal = self.is_wall_horizontal grid = np.zeros((grid_size, grid_size), dtype=str) grid[:, :] = " " grid[self.goal_position[1], self.goal_position[0]] = "G" if self.cur_node.XKey != -1: grid[self.cur_node.YKey, self.cur_node.XKey] = "K" for i in range(grid_size): if not is_wall_horizontal: grid[i, wall_position] = "W_en" else: grid[wall_position, i] = "W_en" grid[door_position[1], door_position[0]] = ( "O" if self.cur_node.IsDoorOpened else "C" ) if self.cur_node.Dir == MiniGridDoorKeyDirection.UP: grid[self.cur_node.Y, self.cur_node.X] = "^" elif self.cur_node.Dir == MiniGridDoorKeyDirection.RIGHT: grid[self.cur_node.Y, self.cur_node.X] = ">" elif self.cur_node.Dir == MiniGridDoorKeyDirection.DOWN: grid[self.cur_node.Y, self.cur_node.X] = "v" elif self.cur_node.Dir == MiniGridDoorKeyDirection.LEFT: grid[self.cur_node.Y, self.cur_node.X] = "<" return grid[::-1, :]
[ 6738, 4866, 1330, 2769, 30073, 198, 6738, 4818, 330, 28958, 1330, 355, 11600, 11, 4818, 330, 31172, 198, 6738, 33829, 1330, 2558, 4834, 388, 198, 198, 6738, 951, 418, 325, 388, 13, 26791, 13, 25120, 62, 85, 945, 1330, 2206, 49228, 11,...
2.021252
3,435
#coding:utf-8 # # id: bugs.core_6266 # title: Deleting records from MON$ATTACHMENTS using ORDER BY clause doesn't close the corresponding attachments # decription: # Old title: Don't close attach while deleting record from MON$ATTACHMENTS using ORDER BY clause. # Confirmed bug on 3.0.6.33271. # Checked on 3.0.6.33272 (SS/CS) - works fine. # 22.04.2020. Checked separately on 4.0.0.1931 SS/CS: all OK. FB 4.0 can also be tested since this build. # # tracker_id: CORE-6266 # min_versions: ['3.0.0'] # versions: 3.0 # qmid: None import pytest from firebird.qa import db_factory, isql_act, Action # version: 3.0 # resources: None substitutions_1 = [] init_script_1 = """""" db_1 = db_factory(sql_dialect=3, init=init_script_1) # test_script_1 #--- # import os # import sys # import time # import fdb # # ATT_CNT=5 # ATT_DELAY=1 # # os.environ["ISC_USER"] = user_name # os.environ["ISC_PASSWORD"] = user_password # # db_conn.close() # # con_list={} # for i in range(0, ATT_CNT): # if i > 0: # time.sleep( ATT_DELAY ) # # c = fdb.connect(dsn = dsn) # a = c.attachment_id # con_list[ i ] = (a, c) # # print('created attachment ', (a,c) ) # # con_admin = con_list[0][1] # # #print(con_admin.firebird_version) # # # this removes ALL connections --> should NOT be used for reproducing ticket issue: # #con_admin.execute_immediate('delete from mon$attachments where mon$attachment_id != current_connection order by mon$timestamp') # # # this removes ALL connections --> should NOT be used for reproducing ticket issue: # #con_admin.execute_immediate('delete from mon$attachments where mon$system_flag is distinct from 1 and mon$attachment_id != current_connection order by mon$timestamp') # # # This DOES NOT remove all attachments (only 'last' in order of timestamp), but # # DELETE statement must NOT contain phrase 'mon$attachment_id != current_connection': # con_admin.execute_immediate('delete from mon$attachments where mon$system_flag is distinct from 1 order by mon$timestamp') # # con_admin.commit() # # cur_admin = con_admin.cursor() # cur_admin.execute('select mon$attachment_id,mon$user from mon$attachments where mon$system_flag is distinct from 1 and mon$attachment_id != current_connection' ) # i=0 # for r in cur_admin: # print( '### ACHTUNG ### STILL ALIVE ATTACHMENT DETECTED: ', r[0], r[1].strip(), '###' ) # i += 1 # print('Number of attachments that remains alive: ',i) # # cur_admin.close() # # #print('Final cleanup before quit from Python.') # # for k,v in sorted( con_list.items() ): # #print('attempt to close attachment ', v[0] ) # try: # v[1].close() # #print('done.') # except Exception as e: # pass # #print('Got exception:', sys.exc_info()[0]) # #print(e[0]) # # #--- #act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1) expected_stdout_1 = """ Number of attachments that remains alive: 0 """
[ 2, 66, 7656, 25, 40477, 12, 23, 198, 2, 198, 2, 4686, 25, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 11316, 13, 7295, 62, 21, 25540, 198, 2, 3670, 25, 220, 220, 220, 220, 220, 220, 220, 42226, 889, 4406, 422, 25000, 3, ...
2.402746
1,311
from bs4 import BeautifulSoup import logging import pandas as pd import csv import re import requests from urllib.parse import urljoin logging.basicConfig(format="%(asctime)s %(levelname)s:%(message)s", level=logging.INFO)
[ 6738, 275, 82, 19, 1330, 23762, 50, 10486, 198, 11748, 18931, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 269, 21370, 198, 11748, 302, 198, 11748, 7007, 198, 198, 6738, 2956, 297, 571, 13, 29572, 1330, 19016, 22179, 198, 198, 64...
2.910256
78
from test_plus.test import TestCase from ...administrative_units.factories import AdministrativeUnitFactory from ...cases.factories import CaseFactory from ...channels.factories import ChannelFactory from ...events.factories import EventFactory from ...features.factories import FeatureFactory, FeatureOptionFactory from ...generic.tests.test_views import ReadOnlyViewSetMixin from ...institutions.factories import InstitutionFactory from ...letters.factories import DocumentTypeFactory, ReferenceNumberFactory from ...search.tests.mixins import SearchQueryMixin from ...tags.factories import TagFactory from ...users.factories import UserFactory
[ 6738, 1332, 62, 9541, 13, 9288, 1330, 6208, 20448, 198, 198, 6738, 2644, 39081, 13260, 62, 41667, 13, 22584, 1749, 1330, 30048, 26453, 22810, 198, 6738, 2644, 33964, 13, 22584, 1749, 1330, 8913, 22810, 198, 6738, 2644, 354, 8961, 13, 22...
4.30719
153
from typing import Any, List from ..actions.iaction import IAction from ..model.state import LennyBotState
[ 198, 198, 6738, 19720, 1330, 4377, 11, 7343, 198, 198, 6738, 11485, 4658, 13, 72, 2673, 1330, 314, 12502, 198, 6738, 11485, 19849, 13, 5219, 1330, 406, 11870, 20630, 9012, 628 ]
3.580645
31
# -*- coding: utf-8 -*- """ Lacework Container Registries API wrapper. """ import logging logger = logging.getLogger(__name__)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 43, 330, 6433, 43101, 13811, 1678, 7824, 29908, 13, 198, 37811, 198, 198, 11748, 18931, 198, 198, 6404, 1362, 796, 18931, 13, 1136, 11187, 1362, 7, 834, 3672...
2.765957
47
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/01_seq2seq.ipynb (unless otherwise specified). __all__ = ['Encoder', 'NewDecoder', 'Seq2Seq'] # Cell from torch import nn from torch import optim import torch import torch.nn.functional as F from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence # Cell # Cell # Cell import random import pytorch_lightning as pl import pytorch_lightning.metrics.functional as plfunc from pytorch_lightning.loggers import TensorBoardLogger # Cell
[ 2, 47044, 7730, 1677, 1137, 11617, 0, 8410, 5626, 48483, 0, 9220, 284, 4370, 25, 299, 1443, 14, 486, 62, 41068, 17, 41068, 13, 541, 2047, 65, 357, 25252, 4306, 7368, 737, 198, 198, 834, 439, 834, 796, 37250, 27195, 12342, 3256, 705,...
2.982249
169
import json import re import responses from werkzeug.test import Client from werkzeug.wrappers import Response from satosa.proxy_server import make_app from satosa.satosa_config import SATOSAConfig
[ 11748, 33918, 198, 11748, 302, 198, 198, 11748, 9109, 198, 6738, 266, 9587, 2736, 1018, 13, 9288, 1330, 20985, 198, 6738, 266, 9587, 2736, 1018, 13, 29988, 11799, 1330, 18261, 198, 198, 6738, 3332, 8546, 13, 36436, 62, 15388, 1330, 787,...
3.40678
59
# Copyright 2022 Quantapix Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================= # https://arxiv.org/abs/1901.02860 # https://github.com/kimiyoung/transformer-xl import torch from torch import nn from torch.nn import functional as F from transformers.utils import logging from .. import core as qc from ..core import utils as qu from ..core import forward as qf from ..core import output as qo from ..core.embed import Adaptive, Positional from ..core.ffnet import Positionwise from ..prep.config.transfo_xl import PreTrained log = logging.get_logger(__name__)
[ 2, 15069, 33160, 16972, 499, 844, 46665, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, ...
3.747604
313
import argparse import glob import os import pickle from pathlib import Path import numpy as np from PIL import Image from tqdm import tqdm from src.align.align_trans import get_reference_facial_points, warp_and_crop_face # sys.path.append("../../") from src.align.detector import detect_faces if __name__ == "__main__": parser = argparse.ArgumentParser(description="face alignment") parser.add_argument( "-source_root", "--source_root", help="specify your source dir", default="../../data/fiw-videos/new-processed/", type=str, ) parser.add_argument( "-dest_root", "--dest_root", help="specify your destination dir", default="../../data/fiw-videos/new-processed/", type=str, ) parser.add_argument( "-crop_size", "--crop_size", help="specify size of aligned faces, align and crop with padding", default=112, type=int, ) args = parser.parse_args() source_root = args.source_root # specify your source dir dest_root = args.dest_root # specify your destination dir crop_size = ( args.crop_size ) # specify size of aligned faces, align and crop with padding scale = crop_size / 112.0 reference = get_reference_facial_points(default_square=True) * scale cwd = os.getcwd() # delete '.DS_Store' existed in the source_root os.chdir(source_root) os.system("find . -name '*.DS_Store' -type f -delete") os.chdir(cwd) imfiles = [ f for f in glob.glob(f"{source_root}F????/MID*/faces/msceleb*") if Path(f).is_file() ] # images = {imfile.replace(source_root, ''): Image.open(imfile) for imfile in imfiles} meta = {} # for subfolder in tqdm(os.listdir(source_root)): for imfile in tqdm(imfiles): ref = imfile.replace(source_root, "") print("Processing\t{}".format(imfile)) img = Image.open(imfile) try: # Handle exception bbs, landmarks = detect_faces(img) except Exception: print("{} is discarded due to exception!".format(imfile)) continue ref = imfile.replace(source_root, "") ndetections = len(landmarks) if ( ndetections == 0 ): # If the landmarks cannot be detected, the img will be discarded print("{} is discarded due to non-detected landmarks!".format(imfile)) meta[ref] = [] continue li_meta = [] for i in range(ndetections): im_meta = {} im_meta["face"] = i im_meta["landmarks"] = landmarks[i] im_meta["bb"] = bbs[i] facial5points = [[landmarks[i][j], landmarks[i][j + 5]] for j in range(5)] warped_face = warp_and_crop_face( np.array(img), facial5points, reference, crop_size=(crop_size, crop_size), ) img_warped = Image.fromarray(warped_face) image_name = imfile.replace("images", "cropped").replace( ".jpg", "-{:02d}.jpg".format(i) ) # im_meta['ref'] = "/".join(image_name.split('/')[-5:]) img_warped.save(image_name) li_meta.append(im_meta) meta[ref] = li_meta with open(source_root + "cropped-meta.pkl", "wb") as f: pickle.dump(meta, f)
[ 11748, 1822, 29572, 198, 11748, 15095, 198, 11748, 28686, 198, 11748, 2298, 293, 198, 6738, 3108, 8019, 1330, 10644, 198, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 350, 4146, 1330, 7412, 198, 6738, 256, 80, 36020, 1330, 256, 80, 36...
2.16888
1,581
from srtvoiceext import extract if __name__ == '__main__': ext = extract('video.mkv', 'subtitles.srt', 'outdir')
[ 6738, 19677, 14981, 2942, 2302, 1330, 7925, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 1070, 796, 7925, 10786, 15588, 13, 28015, 85, 3256, 705, 7266, 83, 30540, 13, 82, 17034, 3256, 705, 44...
2.659091
44
import collections
[ 11748, 17268 ]
9
2
# encoding: utf-8 import urwid import time, os, copy from rpg_game.utils import log, mod, distance from rpg_game.constants import * from urwid import raw_display SIZE = lambda scr=raw_display.Screen(): scr.get_cols_rows() MIN_HEADER_HEIGHT = 3 MAX_MENU_WIDTH = 48 FOOTER_HEIGHT = 4 PALETTE = [ ("line", 'black', 'white', "standout"), ("top","white","black"), ("frame","white","white"), ("player", "light green", "black"), ("other", "light blue", "black"), ("monster", "dark red", "black"), ("fatigued", "dark red", "white", "standout"), ("reversed", "standout", ""), ("common","white","black"), ("common_line","black","white","standout"), ("uncommon","dark cyan","black"), ("uncommon_line","dark cyan","white","standout"), ("rare","yellow","black"), ("rare_line","yellow","white","standout"), ("unique","light magenta","black"), ("unique_line","light magenta","white","standout"), ("set","light green","black"), ("set_line","light green","white","standout"), ("normal","white","black"), ("positive","light green","black"), ("negative","dark red","black"), ("white","white","black"), ("disabled","dark red","black"), ("red","dark red","black"), ("green","light green","black"), ("yellow","yellow","black"), ("brown","brown","black"), ("white_line","black","white", "standout"), ("red_line","dark red","white", "standout"), ("green_line","light green","white", "standout"), ("yellow_line","yellow","white", "standout"), ("cyan","light cyan","black"), ("cyan_line","light cyan","white", "standout"), ("name","white","black"), ] class GUI(UiFrame): # def exit(self): # self.disconnect() # self.mind.disconnect()#should use dispatch event class IntroFrame(UiFrame): class GameFrame(UiFrame): def update_footer(self): _size = 0 inv_btns = [] for i, obj in self.player.inventory.content.items(): if obj: _size += 1 if obj.is_equipment and obj.is_equipped: _marker = ["[", (obj.color, f"{obj.marker[0]}"), "]"] elif obj.is_equipment and not obj.is_equipped: _marker = ["]", (obj.color, f"{obj.marker[0]}"), "["] elif obj.is_consumable: _marker = ["(", (obj.color, f"{obj.marker[0]}"), ")"] else: _marker = [f" {obj.marker[0]} "] else: _marker = [f" "] if i < 9: _num = f"\n {i+1} " elif i == 9: _num = "\n 0 " elif i == 10: _num = "\n - " elif i == 11: _num = "\n = " if obj and obj is self.player.inventory.selection: _marker += [("line", _num)] else: _marker += [("top", _num)] btn = urwid.Text(_marker, align="center") inv_btns.append((5, urwid.LineBox(btn))) if self.mind.screen_size != (80, 24): inv_btns.append(urwid.Text("\nSET TERMINAL\nTO 80X24", align="center")) self.contents["footer"] = (SelectableColumns(inv_btns, dividechars=0), None) self.footer_content_size = _size def on_update(self): self.update_header() if self.footer_content_size != len(self.player.inventory.all): self.update_footer() if self.mind.screen_size != (80, 24): self.update_footer() self.map.on_update() if self.menu_view: self.menu.on_update() class MapFrame(UiFrame): class MenuFrame(UiFrame): class InventoryFrame(UiFrame): class StatusFrame(UiFrame): class EquipmentFrame(UiFrame): class HelpFrame(UiFrame): class SelectableListBox(urwid.ListBox): class SelectableColumns(urwid.Columns): class FrameColumns(urwid.Columns): class ButtonLabel(urwid.SelectableIcon): def set_text(self, label): ''' set_text is invoked by Button.set_label ''' self.__super.set_text(label) self._cursor_position = len(label) + 1 class MyButton(urwid.Button): ''' - override __init__ to use our ButtonLabel instead of urwid.SelectableIcon - make button_left and button_right plain strings and variable width - any string, including an empty string, can be set and displayed - otherwise, we leave Button behaviour unchanged ''' button_left = "[" button_right = "]" # @property # def disabled(self): # return self._disabled # @disabled.setter # def disabled(self, value): # if self._disabled == value: # return # if self.disabled: # urwid.AttrMap(self, "disabled") # else: # urwid.AttrMap(self, None, "line") def attr_button(label, cmd=None, attr_map=None, focus_map = "line", align = "center", user_args = None, borders=True, disabled=False): btn = create_button(label, cmd=cmd, align = align, user_args = user_args, borders=borders, disabled=disabled) return urwid.AttrMap(btn, attr_map, focus_map=focus_map) def create_button(label, cmd=None, align = "center", user_args = None, borders=True, disabled=False): btn = MyButton(label, borders=borders, disabled=disabled) btn._label.align = align if cmd: if user_args: urwid.connect_signal(btn, "click", cmd, user_args = user_args) else: urwid.connect_signal(btn, "click", cmd) return btn
[ 2, 21004, 25, 3384, 69, 12, 23, 198, 198, 11748, 2956, 28029, 198, 11748, 640, 11, 28686, 11, 4866, 198, 6738, 374, 6024, 62, 6057, 13, 26791, 1330, 2604, 11, 953, 11, 5253, 198, 6738, 374, 6024, 62, 6057, 13, 9979, 1187, 1330, 16...
2.110953
2,803
from numpy import inf, nan from sklearn.linear_model import LinearRegression as Op from lale.docstrings import set_docstrings from lale.operators import make_operator _hyperparams_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "inherited docstring for LinearRegression Ordinary least squares Linear Regression.", "allOf": [ { "type": "object", "required": ["fit_intercept", "normalize", "copy_X", "n_jobs"], "relevantToOptimizer": ["fit_intercept", "normalize", "copy_X"], "additionalProperties": False, "properties": { "fit_intercept": { "type": "boolean", "default": True, "description": "whether to calculate the intercept for this model", }, "normalize": { "type": "boolean", "default": False, "description": "This parameter is ignored when ``fit_intercept`` is set to False", }, "copy_X": { "type": "boolean", "default": True, "description": "If True, X will be copied; else, it may be overwritten.", }, "n_jobs": { "anyOf": [{"type": "integer"}, {"enum": [None]}], "default": 1, "description": "The number of jobs to use for the computation", }, }, }, { "XXX TODO XXX": "Parameter: n_jobs > only provide speedup for n_targets > 1 and sufficient large problems" }, ], } _input_fit_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Fit linear model.", "type": "object", "required": ["X", "y"], "properties": { "X": { "anyOf": [ { "type": "array", "items": {"laleType": "Any", "XXX TODO XXX": "item type"}, "XXX TODO XXX": "array-like or sparse matrix, shape (n_samples, n_features)", }, { "type": "array", "items": {"type": "array", "items": {"type": "number"}}, }, ], "description": "Training data", }, "y": { "type": "array", "items": {"type": "array", "items": {"type": "number"}}, "description": "Target values", }, "sample_weight": { "type": "array", "items": {"type": "number"}, "description": "Individual weights for each sample ", }, }, } _input_predict_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Predict using the linear model", "type": "object", "required": ["X"], "properties": { "X": { "anyOf": [ { "type": "array", "items": {"laleType": "Any", "XXX TODO XXX": "item type"}, "XXX TODO XXX": "array_like or sparse matrix, shape (n_samples, n_features)", }, { "type": "array", "items": {"type": "array", "items": {"type": "number"}}, }, ], "description": "Samples.", } }, } _output_predict_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Returns predicted values.", "type": "array", "items": {"type": "number"}, } _combined_schemas = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Combined schema for expected data and hyperparameters.", "documentation_url": "https://scikit-learn.org/0.20/modules/generated/sklearn.linear_model.LinearRegression#sklearn-linear_model-linearregression", "import_from": "sklearn.linear_model", "type": "object", "tags": {"pre": [], "op": ["estimator"], "post": []}, "properties": { "hyperparams": _hyperparams_schema, "input_fit": _input_fit_schema, "input_predict": _input_predict_schema, "output_predict": _output_predict_schema, }, } set_docstrings(LinearRegressionImpl, _combined_schemas) LinearRegression = make_operator(LinearRegressionImpl, _combined_schemas)
[ 6738, 299, 32152, 1330, 1167, 11, 15709, 198, 6738, 1341, 35720, 13, 29127, 62, 19849, 1330, 44800, 8081, 2234, 355, 8670, 198, 198, 6738, 300, 1000, 13, 15390, 37336, 1330, 900, 62, 15390, 37336, 198, 6738, 300, 1000, 13, 3575, 2024, ...
2.004511
2,217
import numpy as np from keras.applications.inception_v3 import InceptionV3 from keras.initializers import RandomNormal from keras.layers import (BatchNormalization, Conv2D, Conv2DTranspose, Conv3D, Cropping2D, Dense, Flatten, GlobalAveragePooling2D, Input, Lambda, MaxPooling2D, Reshape, UpSampling2D, ZeroPadding2D, ZeroPadding3D, add, concatenate) from keras.layers.advanced_activations import ELU, LeakyReLU from keras.models import Model # Parameterized 2D Block Model def BlockModel2D(input_shape, filt_num=16, numBlocks=3): """Creates a Block CED model for segmentation problems Args: input shape: a list or tuple of [rows,cols,channels] of input images filt_num: the number of filters in the first and last layers This number is multipled linearly increased and decreased throughout the model numBlocks: number of processing blocks. The larger the number the deeper the model output_chan: number of output channels. Set if doing multi-class segmentation regression: Whether to have a continuous output with linear activation Returns: An unintialized Keras model Example useage: SegModel = BlockModel2D([256,256,1],filt_num=8) Notes: Using rows/cols that are powers of 2 is recommended. Otherwise, the rows/cols must be divisible by 2^numBlocks for skip connections to match up properly """ use_bn = True # check for input shape compatibility rows, cols = input_shape[0:2] assert rows % 2**numBlocks == 0, "Input rows and number of blocks are incompatible" assert cols % 2**numBlocks == 0, "Input cols and number of blocks are incompatible" # calculate size reduction startsize = np.max(input_shape[0:2]) minsize = (startsize-np.sum(2**np.arange(1, numBlocks+1)))/2**numBlocks assert minsize > 4, "Too small of input for this many blocks. Use fewer blocks or larger input" # input layer lay_input = Input(shape=input_shape, name='input_layer') # contracting blocks x = lay_input skip_list = [] for rr in range(1, numBlocks+1): x1 = Conv2D(filt_num*rr, (1, 1), padding='same', name='Conv1_{}'.format(rr))(x) if use_bn: x1 = BatchNormalization()(x1) x1 = ELU(name='elu_x1_{}'.format(rr))(x1) x3 = Conv2D(filt_num*rr, (3, 3), padding='same', name='Conv3_{}'.format(rr))(x) if use_bn: x3 = BatchNormalization()(x3) x3 = ELU(name='elu_x3_{}'.format(rr))(x3) x51 = Conv2D(filt_num*rr, (3, 3), padding='same', name='Conv51_{}'.format(rr))(x) if use_bn: x51 = BatchNormalization()(x51) x51 = ELU(name='elu_x51_{}'.format(rr))(x51) x52 = Conv2D(filt_num*rr, (3, 3), padding='same', name='Conv52_{}'.format(rr))(x51) if use_bn: x52 = BatchNormalization()(x52) x52 = ELU(name='elu_x52_{}'.format(rr))(x52) x = concatenate([x1, x3, x52], name='merge_{}'.format(rr)) x = Conv2D(filt_num*rr, (1, 1), padding='valid', name='ConvAll_{}'.format(rr))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_all_{}'.format(rr))(x) x = ZeroPadding2D(padding=(1, 1), name='PrePad_{}'.format(rr))(x) x = Conv2D(filt_num*rr, (4, 4), padding='valid', strides=(2, 2), name='DownSample_{}'.format(rr))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_downsample_{}'.format(rr))(x) x = Conv2D(filt_num*rr, (3, 3), padding='same', name='ConvClean_{}'.format(rr))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_clean_{}'.format(rr))(x) skip_list.append(x) # expanding blocks expnums = list(range(1, numBlocks+1)) expnums.reverse() for dd in expnums: if dd < len(skip_list): x = concatenate([skip_list[dd-1], x], name='skip_connect_{}'.format(dd)) x1 = Conv2D(filt_num*dd, (1, 1), padding='same', name='DeConv1_{}'.format(dd))(x) if use_bn: x1 = BatchNormalization()(x1) x1 = ELU(name='elu_Dx1_{}'.format(dd))(x1) x3 = Conv2D(filt_num*dd, (3, 3), padding='same', name='DeConv3_{}'.format(dd))(x) if use_bn: x3 = BatchNormalization()(x3) x3 = ELU(name='elu_Dx3_{}'.format(dd))(x3) x51 = Conv2D(filt_num*dd, (3, 3), padding='same', name='DeConv51_{}'.format(dd))(x) if use_bn: x51 = BatchNormalization()(x51) x51 = ELU(name='elu_Dx51_{}'.format(dd))(x51) x52 = Conv2D(filt_num*dd, (3, 3), padding='same', name='DeConv52_{}'.format(dd))(x51) if use_bn: x52 = BatchNormalization()(x52) x52 = ELU(name='elu_Dx52_{}'.format(dd))(x52) x = concatenate([x1, x3, x52], name='Dmerge_{}'.format(dd)) x = Conv2D(filt_num*dd, (1, 1), padding='valid', name='DeConvAll_{}'.format(dd))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_Dall_{}'.format(dd))(x) x = UpSampling2D(size=(2, 2), name='UpSample_{}'.format(dd))(x) x = Conv2D(filt_num*dd, (3, 3), padding='same', name='DeConvClean1_{}'.format(dd))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_Dclean1_{}'.format(dd))(x) x = Conv2D(filt_num*dd, (3, 3), padding='same', name='DeConvClean2_{}'.format(dd))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_Dclean2_{}'.format(dd))(x) # classifier lay_out = Conv2D(1, (1, 1), activation='sigmoid', name='output_layer')(x) return Model(lay_input, lay_out) # Parameterized 2D Block Model def BlockModel_Classifier(input_shape, filt_num=16, numBlocks=3): """Creates a Block model for pretraining on classification task Args: input shape: a list or tuple of [rows,cols,channels] of input images filt_num: the number of filters in the first and last layers This number is multipled linearly increased and decreased throughout the model numBlocks: number of processing blocks. The larger the number the deeper the model output_chan: number of output channels. Set if doing multi-class segmentation regression: Whether to have a continuous output with linear activation Returns: An unintialized Keras model Example useage: SegModel = BlockModel2D([256,256,1],filt_num=8) Notes: Using rows/cols that are powers of 2 is recommended. Otherwise, the rows/cols must be divisible by 2^numBlocks for skip connections to match up properly """ use_bn = True # check for input shape compatibility rows, cols = input_shape[0:2] assert rows % 2**numBlocks == 0, "Input rows and number of blocks are incompatible" assert cols % 2**numBlocks == 0, "Input cols and number of blocks are incompatible" # calculate size reduction startsize = np.max(input_shape[0:2]) minsize = (startsize-np.sum(2**np.arange(1, numBlocks+1)))/2**numBlocks assert minsize > 4, "Too small of input for this many blocks. Use fewer blocks or larger input" # input layer lay_input = Input(shape=input_shape, name='input_layer') # contracting blocks x = lay_input skip_list = [] for rr in range(1, numBlocks+1): x1 = Conv2D(filt_num*rr, (1, 1), padding='same', name='Conv1_{}'.format(rr))(x) if use_bn: x1 = BatchNormalization()(x1) x1 = ELU(name='elu_x1_{}'.format(rr))(x1) x3 = Conv2D(filt_num*rr, (3, 3), padding='same', name='Conv3_{}'.format(rr))(x) if use_bn: x3 = BatchNormalization()(x3) x3 = ELU(name='elu_x3_{}'.format(rr))(x3) x51 = Conv2D(filt_num*rr, (3, 3), padding='same', name='Conv51_{}'.format(rr))(x) if use_bn: x51 = BatchNormalization()(x51) x51 = ELU(name='elu_x51_{}'.format(rr))(x51) x52 = Conv2D(filt_num*rr, (3, 3), padding='same', name='Conv52_{}'.format(rr))(x51) if use_bn: x52 = BatchNormalization()(x52) x52 = ELU(name='elu_x52_{}'.format(rr))(x52) x = concatenate([x1, x3, x52], name='merge_{}'.format(rr)) x = Conv2D(filt_num*rr, (1, 1), padding='valid', name='ConvAll_{}'.format(rr))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_all_{}'.format(rr))(x) x = ZeroPadding2D(padding=(1, 1), name='PrePad_{}'.format(rr))(x) x = Conv2D(filt_num*rr, (4, 4), padding='valid', strides=(2, 2), name='DownSample_{}'.format(rr))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_downsample_{}'.format(rr))(x) x = Conv2D(filt_num*rr, (3, 3), padding='same', name='ConvClean_{}'.format(rr))(x) if use_bn: x = BatchNormalization()(x) x = ELU(name='elu_skip_{}'.format(rr))(x) # average pooling x = GlobalAveragePooling2D()(x) # classifier lay_out = Dense(1, activation='sigmoid', name='output_layer')(x) return Model(lay_input, lay_out)
[ 11748, 299, 32152, 355, 45941, 198, 6738, 41927, 292, 13, 1324, 677, 602, 13, 924, 1159, 62, 85, 18, 1330, 554, 4516, 53, 18, 198, 6738, 41927, 292, 13, 36733, 11341, 1330, 14534, 26447, 198, 6738, 41927, 292, 13, 75, 6962, 1330, 35...
2.072201
4,626
#!/bin/env python """Drop and create a new database with schema.""" from sqlalchemy_utils.functions import database_exists, create_database, drop_database from flunkybot.db import engine, base from flunkybot.models import * # noqa db_url = engine.url if database_exists(db_url): drop_database(db_url) create_database(db_url) base.metadata.drop_all() base.metadata.create_all()
[ 2, 48443, 8800, 14, 24330, 21015, 198, 37811, 26932, 290, 2251, 257, 649, 6831, 351, 32815, 526, 15931, 198, 198, 6738, 44161, 282, 26599, 62, 26791, 13, 12543, 2733, 1330, 6831, 62, 1069, 1023, 11, 2251, 62, 48806, 11, 4268, 62, 4880...
3.063492
126
#!/usr/bin/env python # -*- coding: utf-8 -*- import os from setuptools import find_packages, setup from app import __version__ # get the dependencies and installs here = os.path.abspath(os.path.dirname(__file__)) with open(os.path.join(here, 'requirements.txt')) as f: all_requirements = f.read().split('\n') setup( name='webspider', version=__version__, license='MIT', author='heguozhu', author_email='heguozhu@zhihu.com', description='lagou.com spider', url='git@github.com:GuozhuHe/webspider.git', packages=find_packages(exclude=['tests']), package_data={'webspider': ['README.md']}, zip_safe=False, install_requires=all_requirements, entry_points={ 'console_scripts': [ 'web = app.web_app:main', 'production_web = app.quickly_cmd:run_web_app_by_gunicorn', 'crawl_lagou_data = app.tasks:crawl_lagou_data', 'crawl_jobs_count = app.tasks.jobs_count:crawl_lagou_jobs_count', 'celery_jobs_count_worker = app.quickly_cmd:run_celery_jobs_count_worker', 'celery_lagou_data_worker = app.quickly_cmd:run_celery_lagou_data_worker', 'celery_beat = app.quickly_cmd:run_celery_beat', 'celery_flower = app.quickly_cmd.py:run_celery_flower', ], } )
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 11748, 28686, 198, 6738, 900, 37623, 10141, 1330, 1064, 62, 43789, 11, 9058, 198, 198, 6738, 598, 1330, 11593, 9641, 83...
2.222411
589
# # Python documentation build configuration file # # This file is execfile()d with the current directory set to its containing dir. # # The contents of this file are pickled, so don't put values in the namespace # that aren't pickleable (module imports are okay, they're removed automatically). import sys, os, time sys.path.append(os.path.abspath('tools/extensions')) # General configuration # --------------------- extensions = ['sphinx.ext.coverage', 'sphinx.ext.doctest', 'pyspecific', 'c_annotations'] # General substitutions. project = 'Python' copyright = '2001-%s, Python Software Foundation' % time.strftime('%Y') # We look for the Include/patchlevel.h file in the current Python source tree # and replace the values accordingly. import patchlevel version, release = patchlevel.get_version_info() # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: today = '' # Else, today_fmt is used as the format for a strftime call. today_fmt = '%B %d, %Y' # By default, highlight as Python 3. highlight_language = 'python3' # Require Sphinx 1.2 for build. needs_sphinx = '1.2' # Ignore any .rst files in the venv/ directory. exclude_patterns = ['venv/*'] # Options for HTML output # ----------------------- # Use our custom theme. html_theme = 'pydoctheme' html_theme_path = ['tools'] html_theme_options = {'collapsiblesidebar': True} # Short title used e.g. for <title> HTML tags. html_short_title = '%s Documentation' % release # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. html_last_updated_fmt = '%b %d, %Y' # Path to find HTML templates. templates_path = ['tools/templates'] # Custom sidebar templates, filenames relative to this file. html_sidebars = { 'index': 'indexsidebar.html', } # Additional templates that should be rendered to pages. html_additional_pages = { 'download': 'download.html', 'index': 'indexcontent.html', } # Output an OpenSearch description file. html_use_opensearch = 'https://docs.python.org/' + version # Additional static files. html_static_path = ['tools/static'] # Output file base name for HTML help builder. htmlhelp_basename = 'python' + release.replace('.', '') # Split the index html_split_index = True # Options for LaTeX output # ------------------------ # The paper size ('letter' or 'a4'). latex_paper_size = 'a4' # The font size ('10pt', '11pt' or '12pt'). latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, document class [howto/manual]). _stdauthor = r'Guido van Rossum\\and the Python development team' latex_documents = [ ('c-api/index', 'c-api.tex', 'The Python/C API', _stdauthor, 'manual'), ('distributing/index', 'distributing.tex', 'Distributing Python Modules', _stdauthor, 'manual'), ('extending/index', 'extending.tex', 'Extending and Embedding Python', _stdauthor, 'manual'), ('installing/index', 'installing.tex', 'Installing Python Modules', _stdauthor, 'manual'), ('library/index', 'library.tex', 'The Python Library Reference', _stdauthor, 'manual'), ('reference/index', 'reference.tex', 'The Python Language Reference', _stdauthor, 'manual'), ('tutorial/index', 'tutorial.tex', 'Python Tutorial', _stdauthor, 'manual'), ('using/index', 'using.tex', 'Python Setup and Usage', _stdauthor, 'manual'), ('faq/index', 'faq.tex', 'Python Frequently Asked Questions', _stdauthor, 'manual'), ('whatsnew/' + version, 'whatsnew.tex', 'What\'s New in Python', 'A. M. Kuchling', 'howto'), ] # Collect all HOWTOs individually latex_documents.extend(('howto/' + fn[:-4], 'howto-' + fn[:-4] + '.tex', '', _stdauthor, 'howto') for fn in os.listdir('howto') if fn.endswith('.rst') and fn != 'index.rst') # Additional stuff for the LaTeX preamble. latex_preamble = r''' \authoraddress{ \strong{Python Software Foundation}\\ Email: \email{docs@python.org} } \let\Verbatim=\OriginalVerbatim \let\endVerbatim=\endOriginalVerbatim ''' # Documents to append as an appendix to all manuals. latex_appendices = ['glossary', 'about', 'license', 'copyright'] # Get LaTeX to handle Unicode correctly latex_elements = {'inputenc': r'\usepackage[utf8x]{inputenc}', 'utf8extra': ''} # Options for Epub output # ----------------------- epub_author = 'Python Documentation Authors' epub_publisher = 'Python Software Foundation' # Options for the coverage checker # -------------------------------- # The coverage checker will ignore all modules/functions/classes whose names # match any of the following regexes (using re.match). coverage_ignore_modules = [ r'[T|t][k|K]', r'Tix', r'distutils.*', ] coverage_ignore_functions = [ 'test($|_)', ] coverage_ignore_classes = [ ] # Glob patterns for C source files for C API coverage, relative to this directory. coverage_c_path = [ '../Include/*.h', ] # Regexes to find C items in the source files. coverage_c_regexes = { 'cfunction': (r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'), 'data': (r'^PyAPI_DATA\(.*\)\s+([^_][\w_]+)'), 'macro': (r'^#define ([^_][\w_]+)\(.*\)[\s|\\]'), } # The coverage checker will ignore all C items whose names match these regexes # (using re.match) -- the keys must be the same as in coverage_c_regexes. coverage_ignore_c_items = { # 'cfunction': [...] } # Options for the link checker # ---------------------------- # Ignore certain URLs. linkcheck_ignore = [r'https://bugs.python.org/(issue)?\d+', # Ignore PEPs for now, they all have permanent redirects. r'http://www.python.org/dev/peps/pep-\d+'] # Options for extensions # ---------------------- # Relative filename of the reference count data file. refcount_file = 'data/refcounts.dat' # Translation # ----------- gettext_compact = False locale_dirs = ["locale"]
[ 2, 198, 2, 11361, 10314, 1382, 8398, 2393, 198, 2, 198, 2, 770, 2393, 318, 2452, 7753, 3419, 67, 351, 262, 1459, 8619, 900, 284, 663, 7268, 26672, 13, 198, 2, 198, 2, 383, 10154, 286, 428, 2393, 389, 2298, 992, 11, 523, 836, 470...
2.821495
2,140
# Import the matplotlib module here. No other modules should be used. # Import plotting library import matplotlib.pyplot as plt #import.... from os import * # Import Numpy import numpy as np
[ 2, 17267, 262, 2603, 29487, 8019, 8265, 994, 13, 220, 1400, 584, 13103, 815, 307, 973, 13, 198, 2, 17267, 29353, 5888, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 2, 11748, 1106, 220, 198, 6738, 28686, 1330, 1...
3.316667
60
"""This script renames the forthcoming section in changelog files with the upcoming version and the current date""" from __future__ import print_function import argparse import datetime import docutils.core import os import re import sys from catkin_pkg.changelog import CHANGELOG_FILENAME, get_changelog_from_path from catkin_pkg.changelog_generator import FORTHCOMING_LABEL from catkin_pkg.package_version import bump_version from catkin_pkg.packages import find_packages, verify_equal_package_versions
[ 37811, 1212, 4226, 8851, 1047, 262, 21220, 2665, 287, 1488, 417, 519, 3696, 351, 262, 7865, 2196, 290, 262, 1459, 3128, 37811, 198, 198, 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 198, 11748, 1822, 29572, 198, 11748, 4818, 8079...
3.573427
143
import os import unittest import torch import torch.distributed as dist from torch.multiprocessing import Process import torch.nn as nn from machina.optims import DistributedAdamW
[ 11748, 28686, 198, 11748, 555, 715, 395, 198, 198, 11748, 28034, 198, 11748, 28034, 13, 17080, 6169, 355, 1233, 198, 6738, 28034, 13, 16680, 541, 305, 919, 278, 1330, 10854, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 198, 6738, ...
3.471698
53
""" Squeak model. W_Object W_SmallInteger W_MutableSmallInteger W_AbstractObjectWithIdentityHash W_AbstractFloat W_Float W_MutableFloat W_Character W_PointersObject W_AbstractObjectWithClassReference W_LargeInteger W_LargeIntegerWord W_LargeIntegerBig W_BytesObject W_WordsObject W_CompiledMethod W_SpurCompiledMethod W_PreSpurCompiledMethod """ from rsqueakvm.model.base import * from rsqueakvm.model.character import * from rsqueakvm.model.compiled_methods import * # from rsqueakvm.model.display import * from rsqueakvm.model.numeric import * from rsqueakvm.model.pointers import * from rsqueakvm.model.variable import *
[ 37811, 198, 50, 4188, 461, 2746, 13, 628, 220, 220, 220, 370, 62, 10267, 198, 220, 220, 220, 220, 220, 220, 220, 370, 62, 18712, 46541, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 370, 62, 44, 18187, 18712, 46541, ...
2
435
# This code is referenced from # https://github.com/facebookresearch/astmt/ # # Copyright (c) Facebook, Inc. and its affiliates. # All rights reserved. # # License: Attribution-NonCommercial 4.0 International import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.modules.module import Module import numpy as np
[ 2, 770, 2438, 318, 20717, 422, 220, 198, 2, 3740, 1378, 12567, 13, 785, 14, 19024, 34033, 14, 459, 16762, 14, 198, 2, 220, 198, 2, 15069, 357, 66, 8, 3203, 11, 3457, 13, 290, 663, 29116, 13, 198, 2, 1439, 2489, 10395, 13, 198, ...
3.445545
101
from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from matplotlib import cm import numpy as np import os import contorno from constantes import INTERVALOS, PASSOS, TAMANHO_BARRA, DELTA_T, DELTA_X z_temp = contorno.p_3 TAMANHO_BARRA = 2 x = np.linspace(0.0, TAMANHO_BARRA, INTERVALOS+1) y = np.linspace(0.0, DELTA_T, PASSOS+1) z = [] for k in range(PASSOS+1): z_k = np.copy(z_temp) z.append(z_k) for i in range(1, INTERVALOS): z_temp[i] = z_k[i] + (DELTA_T/(DELTA_X**2)) * (z_k[i+1]-2*z_k[i]+z_k[i-1]) z = np.asarray(z) x, y = np.meshgrid(x, y) fig = plt.figure() ax = fig.gca(projection='3d') surf = ax.plot_surface(x, y, z, cmap=cm.coolwarm, antialiased=False) ax.set_xlabel('x') ax.set_ylabel('t') ax.set_zlabel('T(x,t)') fig.colorbar(surf, shrink=0.5, aspect=5) plt.show()
[ 6738, 285, 489, 62, 25981, 74, 896, 13, 76, 29487, 18, 67, 1330, 12176, 274, 18, 35, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 6738, 2603, 29487, 8019, 1330, 12067, 198, 11748, 299, 32152, 355, 45941, 198, 1...
1.990361
415
# solution 1: # Solution 2 if __name__ == '__main__': # begin s = Solution() print(s.convert("PAYPALISHIRING", 3))
[ 2, 4610, 352, 25, 198, 198, 2, 28186, 362, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 198, 220, 220, 220, 1303, 2221, 198, 220, 220, 220, 264, 796, 28186, 3419, 198, 220, 220, 220, 3601, 7, 82, 13, 1102, ...
2.327273
55
# -*- coding: utf-8 -*- """ Created on Thu Feb 11 13:42:45 2021 @author: ASUS """ import pandas as pd df = pd.read_csv(r'D:\nlp\fake-news-data\train.csv') df = df.dropna() X = df.drop('label',axis = 1) y = df['label'] import tensorflow as tf from tensorflow.keras.layers import Embedding, Dense, LSTM from tensorflow.keras.models import Sequential from tensorflow.keras.preprocessing.sequence import pad_sequences from tensorflow.keras.preprocessing.text import one_hot # Vocabulary size voc_size = 5000 # One Hot Representation messages = X.copy() messages.reset_index(inplace = True) import nltk import re from nltk.corpus import stopwords # Dataset Preprocessing from nltk.stem import PorterStemmer ps = PorterStemmer() corpus = [] for i in range(len(messages)): print(i) review = re.sub('[^a-zA-Z]',' ',messages['title'][i]) review = review.lower() review = review.split() review = [ps.stem(word) for word in review if word not in stopwords.words('english')] review = " ".join(review) corpus.append(review) onehot_repr = [one_hot(words,voc_size) for words in corpus] sent_len = 20 embedded_doc = pad_sequences(onehot_repr,maxlen = sent_len,padding = 'pre') # Creating the model embedding_vector_features = 40 model = Sequential() model.add(Embedding(voc_size,embedding_vector_features,input_length=sent_len)) model.add(LSTM(100)) model.add(Dense(1,activation='sigmoid')) model.compile(loss='binary_crossentropy',optimizer = 'adam',metrics = ['accuracy']) model.summary() import numpy as np X_final = np.array(embedded_doc) y_final = np.array(y) from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X_final,y_final,test_size = 0.33,random_state = 42) model.fit(X_train,y_train,validation_data=(X_test,y_test),epochs=10,batch_size=64) y_pred = model.predict_classes(X_test) from sklearn.metrics import confusion_matrix, accuracy_score cm = confusion_matrix(y_test,y_pred) acc = accuracy_score(y_test,y_pred)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 26223, 3158, 1367, 1511, 25, 3682, 25, 2231, 33448, 198, 198, 31, 9800, 25, 38100, 198, 37811, 198, 198, 11748, 19798, 292, 355, 279, 67, 198, ...
2.624511
767
import sys from class_vis import prettyPicture from prep_terrain_data import makeTerrainData import matplotlib.pyplot as plt import copy import numpy as np import pylab as pl features_train, labels_train, features_test, labels_test = makeTerrainData() ########################## SVM ################################# ### we handle the import statement and SVC creation for you here from sklearn.svm import SVC clf = SVC(kernel="linear") #### now your job is to fit the classifier #### using the training features/labels, and to #### make a set of predictions on the test data clf.fit(features_train,labels_train) pred = clf.predict(features_test) #### store your predictions in a list named pred from sklearn.metrics import accuracy_score acc = accuracy_score(pred, labels_test)
[ 11748, 25064, 201, 198, 6738, 1398, 62, 4703, 1330, 2495, 28070, 201, 198, 6738, 3143, 62, 353, 3201, 62, 7890, 1330, 787, 15156, 3201, 6601, 201, 198, 201, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 201, 198, 11748...
3.25
252
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License" # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from auto_scan_test import OPConvertAutoScanTest, BaseNet from hypothesis import reproduce_failure import hypothesis.strategies as st import numpy as np import unittest import paddle if __name__ == "__main__": unittest.main()
[ 2, 15069, 357, 66, 8, 33448, 220, 350, 37382, 47, 37382, 46665, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 1, 198, 2, 345, 743, 407, 779, 428, 2393, 2...
3.637931
232
# -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals from builtins import open from builtins import str from future import standard_library standard_library.install_aliases() try: from queue import Queue, Empty except ImportError: from Queue import Queue, Empty import sys import types import billiard from signal import ( signal, SIGINT, ) from threading import ( Event, Thread, ) __all__ = [ 'multiprocess', 'multithread', 'SignalHandler', 'Task' ] def multithread(tasks, pool_size=10): """ Executes several tasks concurrently via ``threading`` threads, puts the results into a queue, and generates these back to the caller. """ task_q = Queue() num_tasks = 0 for task in tasks: task_q.put(task) num_tasks += 1 result_q = Queue() stopper = Event() threads = tuple(Thread(target=run, args=(i, task_q, result_q, stopper,)) for i in range(pool_size)) handler = SignalHandler(stopper, threads) signal(SIGINT, handler) for thread in threads: thread.start() task_q.join() while not result_q.empty(): key, result = result_q.get_nowait() yield key, result
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 6738, 11593, 37443, 834, 1330, 7297, 198, 6738, 11593, 37443, 834, 1330, 3601, 62, 8818, 198, 6738, 11593, 37443,...
2.692929
495
import copy import itertools from functools import partial from typing import Any, Iterable, List, Optional, Set, Tuple, Type from isort.format import format_simplified from . import parse, sorting, wrap from .comments import add_to_line as with_comments from .identify import STATEMENT_DECLARATIONS from .settings import DEFAULT_CONFIG, Config def sorted_imports( parsed: parse.ParsedContent, config: Config = DEFAULT_CONFIG, extension: str = "py", import_type: str = "import", ) -> str: """Adds the imports back to the file. (at the index of the first import) sorted alphabetically and split between groups """ if parsed.import_index == -1: return _output_as_string(parsed.lines_without_imports, parsed.line_separator) formatted_output: List[str] = parsed.lines_without_imports.copy() remove_imports = [format_simplified(removal) for removal in config.remove_imports] sections: Iterable[str] = itertools.chain(parsed.sections, config.forced_separate) if config.no_sections: parsed.imports["no_sections"] = {"straight": {}, "from": {}} base_sections: Tuple[str, ...] = () for section in sections: if section == "FUTURE": base_sections = ("FUTURE",) continue parsed.imports["no_sections"]["straight"].update( parsed.imports[section].get("straight", {}) ) parsed.imports["no_sections"]["from"].update(parsed.imports[section].get("from", {})) sections = base_sections + ("no_sections",) output: List[str] = [] seen_headings: Set[str] = set() pending_lines_before = False for section in sections: straight_modules = parsed.imports[section]["straight"] if not config.only_sections: straight_modules = sorting.sort( config, straight_modules, key=lambda key: sorting.module_key( key, config, section_name=section, straight_import=True ), reverse=config.reverse_sort, ) from_modules = parsed.imports[section]["from"] if not config.only_sections: from_modules = sorting.sort( config, from_modules, key=lambda key: sorting.module_key(key, config, section_name=section), reverse=config.reverse_sort, ) if config.star_first: star_modules = [] other_modules = [] for module in from_modules: if "*" in parsed.imports[section]["from"][module]: star_modules.append(module) else: other_modules.append(module) from_modules = star_modules + other_modules straight_imports = _with_straight_imports( parsed, config, straight_modules, section, remove_imports, import_type ) from_imports = _with_from_imports( parsed, config, from_modules, section, remove_imports, import_type ) lines_between = [""] * ( config.lines_between_types if from_modules and straight_modules else 0 ) if config.from_first: section_output = from_imports + lines_between + straight_imports else: section_output = straight_imports + lines_between + from_imports if config.force_sort_within_sections: # collapse comments comments_above = [] new_section_output: List[str] = [] for line in section_output: if not line: continue if line.startswith("#"): comments_above.append(line) elif comments_above: new_section_output.append(_LineWithComments(line, comments_above)) comments_above = [] else: new_section_output.append(line) # only_sections options is not imposed if force_sort_within_sections is True new_section_output = sorting.sort( config, new_section_output, key=partial(sorting.section_key, config=config), reverse=config.reverse_sort, ) # uncollapse comments section_output = [] for line in new_section_output: comments = getattr(line, "comments", ()) if comments: section_output.extend(comments) section_output.append(str(line)) section_name = section no_lines_before = section_name in config.no_lines_before if section_output: if section_name in parsed.place_imports: parsed.place_imports[section_name] = section_output continue section_title = config.import_headings.get(section_name.lower(), "") if section_title and section_title not in seen_headings: if config.dedup_headings: seen_headings.add(section_title) section_comment = f"# {section_title}" if section_comment not in parsed.lines_without_imports[0:1]: # pragma: no branch section_output.insert(0, section_comment) if pending_lines_before or not no_lines_before: output += [""] * config.lines_between_sections output += section_output pending_lines_before = False else: pending_lines_before = pending_lines_before or not no_lines_before if config.ensure_newline_before_comments: output = _ensure_newline_before_comment(output) while output and output[-1].strip() == "": output.pop() # pragma: no cover while output and output[0].strip() == "": output.pop(0) if config.formatting_function: output = config.formatting_function( parsed.line_separator.join(output), extension, config ).splitlines() output_at = 0 if parsed.import_index < parsed.original_line_count: output_at = parsed.import_index formatted_output[output_at:0] = output if output: imports_tail = output_at + len(output) while [ character.strip() for character in formatted_output[imports_tail : imports_tail + 1] ] == [""]: formatted_output.pop(imports_tail) if len(formatted_output) > imports_tail: next_construct = "" tail = formatted_output[imports_tail:] for index, line in enumerate(tail): # pragma: no branch should_skip, in_quote, *_ = parse.skip_line( line, in_quote="", index=len(formatted_output), section_comments=config.section_comments, needs_import=False, ) if not should_skip and line.strip(): if ( line.strip().startswith("#") and len(tail) > (index + 1) and tail[index + 1].strip() ): continue next_construct = line break if in_quote: # pragma: no branch next_construct = line break if config.lines_after_imports != -1: formatted_output[imports_tail:0] = [ "" for line in range(config.lines_after_imports) ] elif extension != "pyi" and next_construct.startswith(STATEMENT_DECLARATIONS): formatted_output[imports_tail:0] = ["", ""] else: formatted_output[imports_tail:0] = [""] if parsed.place_imports: new_out_lines = [] for index, line in enumerate(formatted_output): new_out_lines.append(line) if line in parsed.import_placements: new_out_lines.extend(parsed.place_imports[parsed.import_placements[line]]) if ( len(formatted_output) <= (index + 1) or formatted_output[index + 1].strip() != "" ): new_out_lines.append("") formatted_output = new_out_lines return _output_as_string(formatted_output, parsed.line_separator)
[ 11748, 4866, 198, 11748, 340, 861, 10141, 198, 6738, 1257, 310, 10141, 1330, 13027, 198, 6738, 19720, 1330, 4377, 11, 40806, 540, 11, 7343, 11, 32233, 11, 5345, 11, 309, 29291, 11, 5994, 198, 198, 6738, 318, 419, 13, 18982, 1330, 5794...
2.083619
4,090
import datetime import io import json_tricks import logging import os from os.path import (abspath, basename, dirname, exists, expanduser, join, realpath, relpath, splitext) import re import shutil import sys from traits.api import (Any, Dict, Enum, HasTraits, Instance, List, Long, Str) from whoosh import fields, qparser, query from whoosh.util.times import datetime_to_long, long_to_datetime from .common import get_project_dir from .media import Media, MediaData, get_media_data from .directory import Directory from . import processor logger = logging.getLogger(__name__) if sys.version_info[0] > 2: unicode = str string_types = (str,) import csv else: string_types = (basestring,) import backports.csv as csv INT = fields.NUMERIC(numtype=int) FLOAT = fields.NUMERIC(numtype=float) COMMON_TAGS = dict( file_name='string', path='string', relpath='string', ctime='string', mtime='string', size='int', type='string' ) def _search_media(expr, m_key, get_tag): """Given search expression, index to media, and a getter to get the attribute check if the media matches expression. """ if expr.is_leaf(): if isinstance(expr, query.Term): attr = expr.fieldname return _check_value(get_tag(m_key, attr), expr.text) elif isinstance(expr, query.Phrase): attr = expr.fieldname text = " ".join(expr.words) return _check_value(get_tag(m_key, attr), text) elif isinstance(expr, query.DateRange): if expr.fieldname == 'ctime': value = get_tag(m_key, 'ctime_') elif expr.fieldname == 'mtime': value = get_tag(m_key, 'mtime_') return _check_date_range(value, expr) elif isinstance(expr, query.NumericRange): attr = expr.fieldname return _check_range(get_tag(m_key, attr), expr) else: print("Unsupported term: %r" % expr) return False else: if isinstance(expr, query.And): result = True for child in expr.children(): result &= _search_media(child, m_key, get_tag) if not result: break return result elif isinstance(expr, query.Or): result = False for child in expr.children(): result |= _search_media(child, m_key, get_tag) if result: break return result elif isinstance(expr, query.Not): subquery = list(expr.children())[0] return not _search_media(subquery, m_key, get_tag) else: print("Unsupported term: %r" % expr) return False
[ 11748, 4818, 8079, 198, 11748, 33245, 198, 11748, 33918, 62, 83, 23706, 198, 11748, 18931, 198, 11748, 28686, 198, 6738, 28686, 13, 6978, 1330, 357, 397, 2777, 776, 11, 1615, 12453, 11, 26672, 3672, 11, 7160, 11, 4292, 7220, 11, 198, ...
2.178849
1,286
"""This submodule contains a JSON reference translator.""" __author__ = 'tpn Tomsa' __copyright__ = 'Copyright 2021 tpn Tomsa' __license__ = 'MIT' __all__ = () import prance.util.url as _url def _reference_key(ref_url, item_path): """ Return a portion of the dereferenced URL. format - ref-url_obj-path """ return ref_url.path.split('/')[-1] + '_' + '_'.join(item_path[1:]) # Underscored to allow some time for the public API to be stabilized.
[ 37811, 1212, 850, 21412, 4909, 257, 19449, 4941, 33417, 526, 15931, 198, 198, 834, 9800, 834, 796, 705, 83, 21999, 309, 3150, 64, 6, 198, 834, 22163, 4766, 834, 796, 705, 15269, 220, 33448, 256, 21999, 309, 3150, 64, 6, 198, 834, 43...
2.672316
177
from io import StringIO from unittest import TestCase from dropSQL.parser.streams import *
[ 6738, 33245, 1330, 10903, 9399, 198, 6738, 555, 715, 395, 1330, 6208, 20448, 198, 198, 6738, 4268, 17861, 13, 48610, 13, 5532, 82, 1330, 1635, 628 ]
3.576923
26
import os import filecmp import unittest import numpy as np from openql import openql as ql from utils import file_compare curdir = os.path.dirname(os.path.realpath(__file__)) output_dir = os.path.join(curdir, 'test_output') # relates to https://github.com/QE-Lab/OpenQL/issues/171 # various runs of compiles were generating different results or in the best # case strange errors. So multiple (NCOMPILES) runs of compile are executed # to make sure there is no error and output generated in all these runs is same # JvS: more likely, it also had to do with the classical register allocator # depending on stuff like Python's garbage collection to free a register. # The register numbers have to be hardcoded now for that reason. def test_stateful_behavior(self): ql.set_option('optimize', 'no') ql.set_option('scheduler', 'ALAP') platform = ql.Platform("myPlatform", 'cc_light') sweep_points = [1] nqubits = 3 nregs = 3 p = ql.Program("statelessProgram", platform, nqubits, nregs) p.set_sweep_points(sweep_points) k = ql.Kernel("aKernel", platform, nqubits, nregs) k.prepz(0) k.gate('rx180', [0]) k.measure(0) rd = ql.CReg(0) rs1 = ql.CReg(1) rs2 = ql.CReg(2) k.classical(rs1, ql.Operation(3)) k.classical(rs1, ql.Operation(4)) k.classical(rd, ql.Operation(rs1, '+', rs2)) p.add_kernel(k) NCOMPILES=50 QISA_fn = os.path.join(output_dir, p.name+'_last.qasm') for i in range(NCOMPILES): p.compile() self.setUpClass() QISA_fn_i = os.path.join(output_dir, p.name+'_'+str(i)+'_last.qasm') os.rename(QISA_fn,QISA_fn_i) for i in range(NCOMPILES-1): QISA_fn_1 = os.path.join(output_dir, p.name+'_'+str(i)+'_last.qasm') QISA_fn_2 = os.path.join(output_dir, p.name+'_'+str(i+1)+'_last.qasm') self.assertTrue( file_compare(QISA_fn_1, QISA_fn_2)) # Unclear how this test works. # When clear, enable it again. # Now it fails, not clear how to repair, so it is disabled. # def test_empty_infinite_loop(self): # name = 'empty_infinite_loop' # in_fn = 'test_' + name + '.cq' # out_fn = 'test_output/' + name + '_out.cq' # gold_fn = 'golden/' + name + '_out.cq' # ql.initialize() # #ql.set_option('log_level', 'LOG_DEBUG') # ql.compile(in_fn) # self.assertTrue(file_compare(out_fn, gold_fn)) if __name__ == '__main__': unittest.main()
[ 11748, 28686, 198, 11748, 2393, 48991, 198, 11748, 555, 715, 395, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 1280, 13976, 1330, 1280, 13976, 355, 10662, 75, 198, 6738, 3384, 4487, 1330, 2393, 62, 5589, 533, 198, 198, 66, 2799, 343, ...
2.123568
1,222
#!/usr/bin/python """Looks for sensor on the bus and changes it's address to the one specified on command line""" import argparse import minimalmodbus import serial from time import sleep parser = argparse.ArgumentParser() parser.add_argument('address', metavar='ADDR', type=int, choices=range(1, 248), help='An address to set') args = parser.parse_args() ADDRESS1 = 1 ADDRESS2 = args.address minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True minimalmodbus.PARITY=serial.PARITY_NONE minimalmodbus.STOPBITS = 2 minimalmodbus.BAUDRATE=19200 minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True # sensor.debug=True (found, i) = scanModbus() if found: print('Found sensor at address: ' + str(i)) try: sensor = minimalmodbus.Instrument('/dev/ttyUSB5', slaveaddress=i) print("writing new address: " + str(ADDRESS2)) sensor.write_register(0, value=ADDRESS2, functioncode=6) sleep(0.2) sensor = minimalmodbus.Instrument('/dev/ttyUSB5', slaveaddress=ADDRESS2) print("reading address from holding register: ") print(sensor.read_register(0, functioncode=3)) except: print "Could not change the address. Check your connections" else: print('No sensor on the bus found')
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 198, 37811, 41102, 329, 12694, 319, 262, 1323, 290, 2458, 340, 338, 2209, 284, 262, 530, 7368, 319, 3141, 1627, 37811, 220, 198, 198, 11748, 1822, 29572, 198, 198, 11748, 10926, 4666, 10885, ...
2.841346
416
# coding: utf-8 import os import pickle import shutil import tempfile import unittest import ray from ray import tune from ray.rllib import _register_all from ray.tune import Trainable from ray.tune.utils import validate_save_restore if __name__ == "__main__": import pytest import sys sys.exit(pytest.main(["-v", __file__]))
[ 2, 19617, 25, 3384, 69, 12, 23, 198, 11748, 28686, 198, 11748, 2298, 293, 198, 11748, 4423, 346, 198, 11748, 20218, 7753, 198, 11748, 555, 715, 395, 198, 198, 11748, 26842, 198, 6738, 26842, 1330, 14009, 198, 6738, 26842, 13, 81, 297,...
2.834711
121
MANIFEST = { "hilt": { "h1": { "offsets": {"blade": 0, "button": {"x": (8, 9), "y": (110, 111)}}, "colours": { "primary": (216, 216, 216), # d8d8d8 "secondary": (141, 141, 141), # 8d8d8d "tertiary": (180, 97, 19), # b46113 }, "length": 24, "materials": "Alloy metal/Salvaged materials", }, "h2": { "offsets": {"blade": 20, "button": {"x": (8, 8), "y": (100, 105)}}, "colours": { "primary": (112, 112, 112), # 707070 "secondary": (0, 0, 0), # 000000 "tertiary": (212, 175, 55), # 000000 }, "length": 24, "materials": "Alloy metal and carbon composite", }, "h3": { "offsets": {"blade": 0, "button": {"x": (10, 10), "y": (100, 118)}}, "colours": { "primary": (157, 157, 157), # 707070 "secondary": (0, 0, 0), # 000000 "tertiary": (180, 97, 19), # b46113 }, "length": 24, "materials": "Alloy metal", }, "h4": { "offsets": {"blade": 7, "button": {"x": (8, 9), "y": (92, 100)}}, "colours": { "primary": (0, 0, 0), # 000000 "secondary": (157, 157, 157), # 9d9d9d "tertiary": (180, 97, 19), # b46113 }, "length": 13, "materials": "Alloy metal", }, "h5": { "offsets": {"blade": 0, "button": {"x": (8, 8), "y": (92, 105)}}, "colours": { "primary": (111, 111, 111), # 6f6f6f "secondary": (0, 0, 0), # 000000 "tertiary": (180, 97, 19), # b46113 }, "length": 24, "materials": "Alloy metal", }, "h6": { "offsets": {"blade": 2, "button": {"x": (8, 9), "y": (112, 113)}}, "colours": { "primary": (120, 120, 120), # 787878 "secondary": (0, 0, 0), # 000000 "tertiary": (180, 97, 19), # b46113 }, "length": 22, "materials": "Alloy metal/Salvaged materials", }, "h7": { "offsets": {"blade": 0, "button": {"x": (8, 9), "y": (105, 113)}}, "colours": { "primary": (192, 192, 192), # c0c0c0 "secondary": (255, 215, 0), # ffd700 "tertiary": (0, 0, 0), # 000000 }, "length": 22, "materials": "Alloy metal and Gold", }, "h8": { "offsets": {"blade": 0, "button": {"x": (8, 9), "y": (100, 111)}}, "colours": { "primary": (216, 216, 216), # d8d8d8 "secondary": (180, 97, 19), # b46113 "tertiary": (0, 0, 0), # 000000 }, "length": 24, "materials": "Alloy metal/Copper", }, }, "blade": { "b1": {"colour": "Red", "crystal": "Adegan crystal", "type": "Sith"}, "b2": {"colour": "Blue", "crystal": "Zophis crystal", "type": "Jedi"}, "b3": {"colour": "Green", "crystal": "Nishalorite stone", "type": "Jedi"}, "b4": {"colour": "Yellow", "crystal": "Kimber stone", "type": "Jedi"}, "b5": {"colour": "White", "crystal": "Dragite gem", "type": "Jedi"}, "b6": {"colour": "Purple", "crystal": "Krayt dragon pearl", "type": "Jedi"}, "b7": {"colour": "Blue/Green", "crystal": "Dantari crystal", "type": "Jedi"}, "b8": { "colour": "Orange", "crystal": ["Ilum crystal", "Ultima Pearl"], "type": "Sith", }, "b9": { "colour": "Black", "crystal": "Obsidian", "type": ["Jedi", "Mandalorian"], }, }, "pommel": { "p1": {"length": 5,}, "p2": {"length": 14,}, "p3": {"length": 3,}, "p4": {"length": 8,}, "p5": {"length": 5,}, "p6": {"length": 5,}, "p7": {"length": 8,}, }, # These are lightsabers for a specific Jedi or Sith. Should use their name instead of "unique_urls": {""}, }
[ 10725, 5064, 6465, 796, 1391, 198, 220, 220, 220, 366, 71, 2326, 1298, 1391, 198, 220, 220, 220, 220, 220, 220, 220, 366, 71, 16, 1298, 1391, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 366, 8210, 1039, 1298, 19779...
1.746439
2,457
import numpy as np import pytest import theano import theano.tensor as tt # Don't import test classes otherwise they get tested as part of the file from tests import unittest_tools as utt from tests.gpuarray.config import mode_with_gpu, mode_without_gpu, test_ctx_name from tests.tensor.test_basic import ( TestAlloc, TestComparison, TestJoinAndSplit, TestReshape, ) from tests.tensor.utils import rand, safe_make_node from theano.gpuarray.basic_ops import ( GpuAlloc, GpuAllocEmpty, GpuContiguous, GpuEye, GpuFromHost, GpuJoin, GpuReshape, GpuSplit, GpuToGpu, GpuTri, HostFromGpu, gpu_contiguous, gpu_join, host_from_gpu, ) from theano.gpuarray.elemwise import GpuDimShuffle, GpuElemwise from theano.gpuarray.subtensor import GpuSubtensor from theano.gpuarray.type import GpuArrayType, get_context, gpuarray_shared_constructor from theano.tensor import TensorType from theano.tensor.basic import alloc pygpu = pytest.importorskip("pygpu") gpuarray = pygpu.gpuarray utt.seed_rng() rng = np.random.RandomState(seed=utt.fetch_seed()) TestGpuAlloc = makeTester( name="GpuAllocTester", # The +1 is there to allow the lift to the GPU. op=lambda *args: alloc(*args) + 1, gpu_op=GpuAlloc(test_ctx_name), cases=dict( correct01=(rand(), np.int32(7)), # just gives a DeepCopyOp with possibly wrong results on the CPU # correct01_bcast=(rand(1), np.int32(7)), correct02=(rand(), np.int32(4), np.int32(7)), correct12=(rand(7), np.int32(4), np.int32(7)), correct13=(rand(7), np.int32(2), np.int32(4), np.int32(7)), correct23=(rand(4, 7), np.int32(2), np.int32(4), np.int32(7)), bad_shape12=(rand(7), np.int32(7), np.int32(5)), ), ) def test_gpujoin_gpualloc(): a = tt.fmatrix("a") a_val = np.asarray(np.random.rand(4, 5), dtype="float32") b = tt.fmatrix("b") b_val = np.asarray(np.random.rand(3, 5), dtype="float32") f = theano.function( [a, b], tt.join(0, tt.zeros_like(a), tt.ones_like(b)) + 4, mode=mode_without_gpu ) f_gpu = theano.function( [a, b], tt.join(0, tt.zeros_like(a), tt.ones_like(b)), mode=mode_with_gpu ) f_gpu2 = theano.function( [a, b], tt.join(0, tt.zeros_like(a), tt.ones_like(b)) + 4, mode=mode_with_gpu ) assert sum([node.op == tt.alloc for node in f.maker.fgraph.toposort()]) == 2 assert sum([node.op == tt.join_ for node in f.maker.fgraph.toposort()]) == 1 assert ( sum([isinstance(node.op, GpuAlloc) for node in f_gpu.maker.fgraph.toposort()]) == 2 ) assert sum([node.op == gpu_join for node in f_gpu.maker.fgraph.toposort()]) == 1 assert ( sum([isinstance(node.op, GpuAlloc) for node in f_gpu2.maker.fgraph.toposort()]) == 2 ) assert sum([node.op == gpu_join for node in f_gpu2.maker.fgraph.toposort()]) == 1 assert np.allclose(f(a_val, b_val), f_gpu2(a_val, b_val)) def test_gpueye(): for dtype in ["float32", "int32", "float16"]: check(dtype, 3) # M != N, k = 0 check(dtype, 3, 5) check(dtype, 5, 3) # N == M, k != 0 check(dtype, 3, 3, 1) check(dtype, 3, 3, -1) # N < M, k != 0 check(dtype, 3, 5, 1) check(dtype, 3, 5, -1) # N > M, k != 0 check(dtype, 5, 3, 1) check(dtype, 5, 3, -1) # k > M, -k > N, k > M, k > N check(dtype, 5, 3, 3) check(dtype, 3, 5, 3) check(dtype, 5, 3, -3) check(dtype, 3, 5, -3) check(dtype, 5, 3, 6) check(dtype, 3, 5, -6)
[ 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 9288, 198, 198, 11748, 262, 5733, 198, 11748, 262, 5733, 13, 83, 22854, 355, 256, 83, 198, 198, 2, 2094, 470, 1330, 1332, 6097, 4306, 484, 651, 6789, 355, 636, 286, 262, 2393, 198, 6...
2.088622
1,749
# coding: spec from interactor.commander.store import store, load_commands from photons_app.mimic.event import Events from photons_app import helpers as hp from photons_canvas.points.simple_messages import Set64 from unittest import mock import pytest describe "Animation Commands": async it "can get info and help", server, m: await server.assertCommand( "/v1/lifx/command", {"command": "animation/info"}, json_output={"animations": {}, "paused": []}, ) got = await server.assertCommand( "/v1/lifx/command", {"command": "animation/help"}, ) assert b"Available animations include" in got assert b"* dice" in got assert b"To see options for a particular animation, run this again" in got got = await server.assertCommand( "/v1/lifx/command", {"command": "animation/help", "args": {"animation_name": "dice"}}, ) assert b"dice animation" in got assert b"This animation has the following options:" in got assert b"colour range options" in got async it "can control an animation", server, m: await server.assertCommand( "/v1/lifx/command", {"command": "animation/info"}, json_output={"animations": {}, "paused": []}, ) identity = "first" got = await server.assertCommand( "/v1/lifx/command", {"command": "animation/start", "args": {"identity": identity}}, ) assert "animations" in got assert got["animations"] == [identity] assert got["started"] == identity identity2 = "second" got = await server.assertCommand( "/v1/lifx/command", {"command": "animation/start", "args": {"identity": identity2}}, ) assert "animations" in got identities = [identity, identity2] assert got["animations"] == identities assert got["started"] == identity2 info = await server.assertCommand( "/v1/lifx/command", {"command": "animation/info"}, ) assert info == {"animations": {identity: mock.ANY, identity2: mock.ANY}, "paused": []} # pause await server.assertCommand( "/v1/lifx/command", {"command": "animation/pause", "args": {"pause": identity}}, json_output={"animations": identities, "paused": [identity], "pausing": [identity]}, ) await server.assertCommand( "/v1/lifx/command", {"command": "animation/pause", "args": {"pause": identity2}}, json_output={ "animations": identities, "paused": identities, "pausing": [identity2], }, ) # resume await server.assertCommand( "/v1/lifx/command", {"command": "animation/resume", "args": {"resume": identity2}}, json_output={ "animations": identities, "paused": [identity], "resuming": [identity2], }, ) # pause multiple await server.assertCommand( "/v1/lifx/command", {"command": "animation/pause", "args": {"pause": identities}}, json_output={"animations": identities, "paused": identities, "pausing": identities}, ) # resume await server.assertCommand( "/v1/lifx/command", {"command": "animation/resume", "args": {"resume": identities}}, json_output={ "animations": identities, "paused": [], "resuming": identities, }, ) # pause await server.assertCommand( "/v1/lifx/command", {"command": "animation/pause", "args": {"pause": identity}}, json_output={"animations": identities, "paused": [identity], "pausing": [identity]}, ) # info info = await server.assertCommand( "/v1/lifx/command", {"command": "animation/info"}, ) assert info["animations"] == {identity: mock.ANY, identity2: mock.ANY} assert info["paused"] == [identity] # stop await server.assertCommand( "/v1/lifx/command", {"command": "animation/stop", "args": {"stop": identity}}, json_output={ "animations": [identity, identity2], "paused": [identity], "stopping": [identity], }, ) await m.add(0.5) # info info = await server.assertCommand( "/v1/lifx/command", {"command": "animation/info"}, ) assert info["animations"] == {identity2: mock.ANY} assert info["paused"] == [] async it "pausing an animation actually pauses the animation", devices, server, m: tile = devices["tile"] io = tile.io["MEMORY"] store = devices.store(tile) store.clear() first_set_64 = tile.attrs.event_waiter.wait_for_incoming(io, Set64) # start got = await server.assertCommand( "/v1/lifx/command", {"command": "animation/start", "args": {"animations": [["balls", {"every": 3}]]}}, ) identity = got["started"] await first_set_64 now = store.count(Events.INCOMING(tile, io, pkt=Set64)) assert now > 0 await m.add(5) now2 = store.count(Events.INCOMING(tile, io, pkt=Set64)) assert now2 > now identity = got["started"] await m.add(5) assert store.count(Events.INCOMING(tile, io, pkt=Set64)) > now # pause await server.assertCommand( "/v1/lifx/command", {"command": "animation/pause", "args": {"pause": [identity]}}, ) await m.add(5) store.clear() await m.add(5) assert store.count(Events.INCOMING(tile, io, pkt=Set64)) == 0 # resume await server.assertCommand( "/v1/lifx/command", {"command": "animation/resume", "args": {"resume": [identity]}}, ) await m.add(5) assert store.count(Events.INCOMING(tile, io, pkt=Set64)) > 0 # stop await server.assertCommand( "/v1/lifx/command", {"command": "animation/stop", "args": {"stop": [identity]}}, ) store.clear() await m.add(5) store.clear() await m.add(5) assert store.count(Events.INCOMING(tile, io, pkt=Set64)) == 0 # info await server.assertCommand( "/v1/lifx/command", {"command": "animation/info"}, json_output={"animations": {}, "paused": []}, ) async it "can get information", server, m: # start got = await server.assertCommand( "/v1/lifx/command", {"command": "animation/start", "args": {"animations": [["balls", {"every": 0.3}]]}}, ) identity = got["started"] info = await server.assertCommand("/v1/lifx/command", {"command": "animation/info"}) assert info["paused"] == [] assert identity in info["animations"] assert info["animations"][identity]["animations_ran"] == 1 assert info["animations"][identity]["current_animation"] == { "name": "balls", "options": { "ball_colors": "<ManyColor:[((0, 360), (1000.0, 1000.0), (1000.0, 1000.0), (3500.0, 3500.0))]>", "fade_amount": 0.02, "num_balls": 5, "rate": "<Rate 0.9 -> 1>", }, "started": mock.ANY, } assert info["animations"][identity]["options"]["combined"] assert "unlocked" in info["animations"][identity]["options"]["pauser"] assert info["animations"][identity]["options"]["noisy_network"] == 0 specific = await server.assertCommand( "/v1/lifx/command", {"command": "animation/info", "args": {"identity": identity}} ) info["animations"][identity]["current_animation"]["started"] = mock.ANY assert info["animations"][identity] == specific
[ 2, 19617, 25, 1020, 198, 198, 6738, 9427, 273, 13, 9503, 4066, 13, 8095, 1330, 3650, 11, 3440, 62, 9503, 1746, 198, 198, 6738, 44378, 62, 1324, 13, 76, 320, 291, 13, 15596, 1330, 18715, 198, 6738, 44378, 62, 1324, 1330, 49385, 355, ...
2.108608
3,950
from pytube import YouTube
[ 6738, 12972, 29302, 1330, 7444, 198 ]
4.5
6
# Copyright 2015 Open Source Robotics Foundation, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import ast import distutils.core import os try: import setuptools except ImportError: pass import subprocess import sys from threading import Lock from ament_tools.build_type import get_command_prefix from ament_tools.helper import quote_shell_command setup_lock = None def get_setup_arguments_with_context(build_type, context): """ Capture the arguments of the setup() function in the setup.py file. To provide a custom environment when introspecting the setup() function a separate Python interpreter is being used which can have an extended PYTHONPATH etc. :param build_type: the build type :param context: the context :type context: :py:class:`ament_tools.context.Context` :returns: a dictionary containing the arguments of the setup() function """ prefix = get_command_prefix( '%s__setup' % build_type, context.build_space, context.build_dependencies) ament_tools_path = os.path.dirname(os.path.dirname(__file__)) setuppy = os.path.join(context.source_space, 'setup.py') if os.name == 'nt': ament_tools_path = ament_tools_path.replace(os.sep, os.altsep) setuppy = setuppy.replace(os.sep, os.altsep) code_lines = [ 'import sys', "sys.path.insert(0, '%s')" % ament_tools_path, 'from ament_tools.setup_arguments import get_setup_arguments', "print(repr(get_setup_arguments('%s')))" % setuppy] # invoke get_setup_arguments() in a separate interpreter cmd = prefix + [sys.executable, '-c', ';'.join(code_lines)] cmd = quote_shell_command(cmd) result = subprocess.run( cmd, stdout=subprocess.PIPE, shell=True, check=True) output = result.stdout.decode() return ast.literal_eval(output) def get_setup_arguments(setup_py_path): """ Capture the arguments of the setup() function in the setup.py file. The function is being run within the current Python interpreter. Therefore the processed setup.py file can not have any additional dependencies not available in the current environment. :param setup_py_path: the path to the setup.py file :returns: a dictionary containing the arguments of the setup() function """ global setup_lock if not setup_lock: setup_lock = Lock() assert os.path.basename(setup_py_path) == 'setup.py' # prevent side effects in other threads with setup_lock: # change to the directory containing the setup.py file old_cwd = os.getcwd() os.chdir(os.path.dirname(os.path.abspath(setup_py_path))) try: data = {} mock_setup = create_mock_setup_function(data) # replace setup() function of distutils and setuptools # in order to capture its arguments try: distutils_setup = distutils.core.setup distutils.core.setup = mock_setup try: setuptools_setup = setuptools.setup setuptools.setup = mock_setup except NameError: pass # evaluate the setup.py file with open('setup.py', 'r') as h: exec(h.read()) finally: distutils.core.setup = distutils_setup try: setuptools.setup = setuptools_setup except NameError: pass return data finally: os.chdir(old_cwd) def create_mock_setup_function(data): """ Create a mock function to capture its arguments. It can replace either distutils.core.setup or setuptools.setup. :param data: a dictionary which is updated with the captured arguments :returns: a function to replace disutils.core.setup and setuptools.setup """ return setup def get_data_files_mapping(data_files): """ Transform the data_files structure into a dictionary. :param data_files: either a list of source files or a list of tuples where the first element is the destination path and the second element is a list of source files :returns: a dictionary mapping the source file to a destination file """ mapping = {} for data_file in data_files: if isinstance(data_file, tuple): assert len(data_file) == 2 dest = data_file[0] assert not os.path.isabs(dest) sources = data_file[1] assert isinstance(sources, list) for source in sources: assert not os.path.isabs(source) mapping[source] = os.path.join(dest, os.path.basename(source)) else: assert not os.path.isabs(data_file) mapping[data_file] = os.path.basename(data_file) return mapping
[ 2, 15069, 1853, 4946, 8090, 47061, 5693, 11, 3457, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, ...
2.539869
2,132
# Copyright (c) Meta Platforms, Inc. and affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import torch from neuralcompression.functional import soft_round, soft_round_inverse
[ 2, 15069, 357, 66, 8, 30277, 19193, 82, 11, 3457, 13, 290, 29116, 13, 198, 2, 198, 2, 770, 2723, 2438, 318, 11971, 739, 262, 17168, 5964, 1043, 287, 262, 198, 2, 38559, 24290, 2393, 287, 262, 6808, 8619, 286, 428, 2723, 5509, 13, ...
3.926471
68
from easydict import EasyDict hopper_ppo_default_config = dict( env=dict( env_id='HopperMuJoCoEnv-v0', norm_obs=dict(use_norm=False, ), norm_reward=dict(use_norm=False, ), collector_env_num=8, evaluator_env_num=10, use_act_scale=True, n_evaluator_episode=10, stop_value=3000, ), policy=dict( cuda=True, on_policy=True, recompute_adv=True, model=dict( obs_shape=11, action_shape=3, continuous=True, ), continuous=True, learn=dict( epoch_per_collect=10, batch_size=64, learning_rate=3e-4, value_weight=0.5, entropy_weight=0.0, clip_ratio=0.2, adv_norm=True, value_norm=True, ), collect=dict( n_sample=2048, unroll_len=1, discount_factor=0.99, gae_lambda=0.97, ), eval=dict(evaluator=dict(eval_freq=5000, )), other=dict(replay_buffer=dict( replay_buffer_size=10000, replay_buffer_start_size=0, ), ), ), ) hopper_ppo_default_config = EasyDict(hopper_ppo_default_config) main_config = hopper_ppo_default_config hopper_ppo_create_default_config = dict( env=dict( type='pybullet', import_names=['dizoo.pybullet.envs.pybullet_env'], ), env_manager=dict(type='subprocess'), policy=dict( type='ppo', import_names=['ding.policy.ppo'], ), replay_buffer=dict(type='naive', ), ) hopper_ppo_create_default_config = EasyDict(hopper_ppo_create_default_config) create_config = hopper_ppo_create_default_config
[ 6738, 2562, 11600, 1330, 16789, 35, 713, 198, 198, 8873, 2848, 62, 16634, 62, 12286, 62, 11250, 796, 8633, 7, 198, 220, 220, 220, 17365, 28, 11600, 7, 198, 220, 220, 220, 220, 220, 220, 220, 17365, 62, 312, 11639, 28900, 2848, 33239...
1.872845
928
import json from cisco_sdwan_policy.BaseObject import BaseObject
[ 11748, 33918, 198, 198, 6738, 269, 4861, 62, 21282, 8149, 62, 30586, 13, 14881, 10267, 1330, 7308, 10267, 628 ]
3.526316
19
"""DNS docker object.""" import logging from ..const import ENV_TIME from ..coresys import CoreSysAttributes from .interface import DockerInterface _LOGGER: logging.Logger = logging.getLogger(__name__) DNS_DOCKER_NAME: str = "hassio_dns"
[ 37811, 35, 8035, 36253, 2134, 526, 15931, 198, 11748, 18931, 198, 198, 6738, 11485, 9979, 1330, 12964, 53, 62, 34694, 198, 6738, 11485, 66, 2850, 893, 1330, 7231, 44387, 29021, 198, 6738, 764, 39994, 1330, 25716, 39317, 198, 198, 62, 25...
3.025
80
# Copyright 2019, Kay Hayen, mailto:kay.hayen@gmail.com # # Part of "Nuitka", an optimizing Python compiler that is compatible and # integrates with CPython, but also works on its own. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """ Operator code tables These are mostly used to look up the Python C/API from operations or a wrapper used. """ from nuitka.PythonVersions import python_version binary_operator_codes = { # Those commented out in this section have fully specialized variants already. # "Add" : "PyNumber_Add", # "Sub" : "PyNumber_Subtract", # "Div" : "PyNumber_Divide", # "Mult" : "PyNumber_Multiply", # "Mod" : "PyNumber_Remainder", # "Div" : "PyNumber_Divide", # "FloorDiv" : "PyNumber_FloorDivide", # "TrueDiv" : "PyNumber_TrueDivide", # These have their own variants only to make sure the generic code is in-lined # but the CPython code is not in-lined. # "Pow" : "PyNumber_Power", # "IPow" : "PyNumber_InPlacePower", # The others are generic code and would be faster if they had a specialized variant too. "LShift": "PyNumber_Lshift", "RShift": "PyNumber_Rshift", "BitAnd": "PyNumber_And", "BitOr": "PyNumber_Or", "BitXor": "PyNumber_Xor", "IAdd": "PyNumber_InPlaceAdd", "ISub": "PyNumber_InPlaceSubtract", "IMult": "PyNumber_InPlaceMultiply", "IDiv": "PyNumber_InPlaceDivide", "IFloorDiv": "PyNumber_InPlaceFloorDivide", "ITrueDiv": "PyNumber_InPlaceTrueDivide", "IMod": "PyNumber_InPlaceRemainder", "ILShift": "PyNumber_InPlaceLshift", "IRShift": "PyNumber_InPlaceRshift", "IBitAnd": "PyNumber_InPlaceAnd", "IBitOr": "PyNumber_InPlaceOr", "IBitXor": "PyNumber_InPlaceXor", } # Python 3.5 only operator if python_version >= 350: binary_operator_codes["MatMult"] = "PyNumber_MatrixMultiply" binary_operator_codes["IMatMult"] = "PyNumber_InPlaceMatrixMultiply" unary_operator_codes = { "UAdd": ("PyNumber_Positive", 1), "USub": ("PyNumber_Negative", 1), "Invert": ("PyNumber_Invert", 1), "Repr": ("PyObject_Repr", 1), "Not": ("UNARY_NOT", 0), } rich_comparison_codes = { "Lt": "LT", "LtE": "LE", "Eq": "EQ", "NotEq": "NE", "Gt": "GT", "GtE": "GE", } containing_comparison_codes = ("In", "NotIn")
[ 2, 220, 220, 220, 220, 15069, 13130, 11, 17356, 9075, 268, 11, 6920, 1462, 25, 5568, 13, 71, 323, 268, 31, 14816, 13, 785, 198, 2, 198, 2, 220, 220, 220, 220, 2142, 286, 366, 45, 5013, 4914, 1600, 281, 45780, 11361, 17050, 326, ...
2.501709
1,170
import sys from dagster import check from dagster.config.validate import validate_config_from_snap from dagster.core.host_representation import ExternalPipeline, PipelineSelector, RepositorySelector from dagster.core.workspace.context import BaseWorkspaceRequestContext from dagster.utils.error import serializable_error_info_from_exc_info from graphql.execution.base import ResolveInfo from .utils import UserFacingGraphQLError, capture_error
[ 11748, 25064, 198, 198, 6738, 48924, 1706, 1330, 2198, 198, 6738, 48924, 1706, 13, 11250, 13, 12102, 378, 1330, 26571, 62, 11250, 62, 6738, 62, 45380, 198, 6738, 48924, 1706, 13, 7295, 13, 4774, 62, 15603, 341, 1330, 34579, 47, 541, 4...
3.632
125
import os from tempfile import TemporaryDirectory from quickbase_client.utils.pywriting_utils import BasicPyFileWriter from quickbase_client.utils.pywriting_utils import PyPackageWriter
[ 11748, 28686, 198, 6738, 20218, 7753, 1330, 46042, 43055, 198, 198, 6738, 2068, 8692, 62, 16366, 13, 26791, 13, 9078, 16502, 62, 26791, 1330, 14392, 20519, 8979, 34379, 198, 6738, 2068, 8692, 62, 16366, 13, 26791, 13, 9078, 16502, 62, 2...
4.021277
47
""" Residual Networks (ResNet) """ # adapted from # https://github.com/fchollet/deep-learning-models/blob/master/resnet50.py import tensorflow as tf def identity_block( input_tensor, filters, stage, block, train_bn=False ): """ Builds an identity shortcut in a bottleneck building block of a ResNet. Parameters ---------- input_tensor : tf tensor, [batch_size, height, width, channels] An input tensor. filters : list, positive integers The number of filters in 3 conv layers at the main path, where last number is equal to input_tensor's channels. stage : integer A number in [2,5] used for generating layer names. block : string A lowercase letter, used for generating layer names. train_bn : boolean, optional Whether one should normalize the layer input by the mean and variance over the current batch. The default is False, i.e., use the moving average of mean and variance to normalize the layer input. Returns ------- output_tensor : tf tensor, [batch_size, height, width, channels] The output tensor same shape as input_tensor. """ num_filters_1, num_filters_2, num_filters_3 = filters conv_prefix = 'res' + str(stage) + block + '_branch' bn_prefix = 'bn' + str(stage) + block + '_branch' x = tf.keras.layers.Conv2D( num_filters_1, (1,1), name=conv_prefix + '2a')(input_tensor) x = tf.keras.layers.BatchNormalization( name=bn_prefix + '2a')(x, training=train_bn) x = tf.keras.layers.Activation('relu')(x) x = tf.keras.layers.Conv2D( num_filters_2, (3,3), padding='same', name=conv_prefix + '2b')(x) x = tf.keras.layers.BatchNormalization( name=bn_prefix + '2b')(x, training=train_bn) x = tf.keras.layers.Activation('relu')(x) x = tf.keras.layers.Conv2D( num_filters_3, (1,1), name=conv_prefix + '2c')(x) x = tf.keras.layers.BatchNormalization( name=bn_prefix + '2c')(x, training=train_bn) x = tf.keras.layers.Add()([input_tensor, x]) output_tensor = tf.keras.layers.Activation( 'relu', name='res' + str(stage) + block + '_out')(x) return output_tensor def conv_block( input_tensor, filters, stage, block, strides=(2, 2), train_bn=False ): """ Builds a projection shortcut in a bottleneck block of a ResNet. Parameters ---------- input_tensor : tf tensor, [batch_size, height, width, channels] An input tensor. filters : list, positive integers The number of filters in 3 conv layers at the main path. stage : integer A number in [2,5] used for generating layer names. block : string A lowercase letter, used for generating layer names. strides : tuple, integers, optional The conv layer strides. The default is (2, 2). train_bn : boolean, optional Whether one should normalize the layer input by the mean and variance over the current batch. The default is False, i.e., use the moving average of mean and variance to normalize the layer input. Returns ------- output_tensor : tf tensor [batch_size, height//strides, width//strides, num_filters_3] where num_filters_3 is the last number in filters, the output tensor. """ num_filters_1, num_filters_2, num_filters_3 = filters conv_prefix = 'res' + str(stage) + block + '_branch' bn_prefix = 'bn' + str(stage) + block + '_branch' x = tf.keras.layers.Conv2D( num_filters_1, (1,1), strides, name=conv_prefix + '2a')(input_tensor) x = tf.keras.layers.BatchNormalization( name=bn_prefix + '2a')(x, training=train_bn) x = tf.keras.layers.Activation('relu')(x) x = tf.keras.layers.Conv2D( num_filters_2, (3,3), padding='same', name=conv_prefix + '2b')(x) x = tf.keras.layers.BatchNormalization( name=bn_prefix + '2b')(x, training=train_bn) x = tf.keras.layers.Activation('relu')(x) x = tf.keras.layers.Conv2D( num_filters_3, (1,1), name=conv_prefix + '2c')(x) x = tf.keras.layers.BatchNormalization( name=bn_prefix + '2c')(x, training=train_bn) shortcut = tf.keras.layers.Conv2D( num_filters_3, (1,1), strides, name=conv_prefix + '1')(input_tensor) shortcut = tf.keras.layers.BatchNormalization( name=bn_prefix + '1')(shortcut, training=train_bn) x = tf.keras.layers.Add()([shortcut, x]) output_tensor = tf.keras.layers.Activation( 'relu', name='res' + str(stage) + block + '_out')(x) return output_tensor def backbone_resnet(input_image, architecture, stage5=True, train_bn=False): """ Builds a backbone ResNet. Parameters ---------- input_image : tf tensor, [batch_size, height, width, channels] An input tensor. architecture : string The ResNet architecture in {'resnet50', 'resnet101'}. stage5 : boolean, optional Whether create stage5 of network. The default is True. train_bn : boolean, optional Whether one should normalize the layer input by the mean and variance over the current batch. The default is False, i.e., use the moving average of mean and variance to normalize the layer input. Returns ------- outputs : list Feature maps at each stage. """ assert architecture in ['resnet50', 'resnet101'], \ 'Only support ResNet50\101' # stage 1 x = tf.keras.layers.ZeroPadding2D((3,3))(input_image) x = tf.keras.layers.Conv2D(64, (7,7), (2,2), name='conv1')(x) x = tf.keras.layers.BatchNormalization(name='bn_conv1')(x, training=train_bn) x = tf.keras.layers.Activation('relu')(x) C1 = x = tf.keras.layers.MaxPooling2D((3,3), (2,2), padding='same')(x) # stage 2 x = conv_block( x, [64,64,256], stage=2, block='a', strides=(1,1), train_bn=train_bn) x = identity_block(x, [64,64,256], stage=2, block='b', train_bn=train_bn) C2 = x = identity_block( x, [64,64,256], stage=2, block='c', train_bn=train_bn) # stage 3 x = conv_block(x, [128,128,512], stage=3, block='a', train_bn=train_bn) x = identity_block(x, [128,128,512], stage=3, block='b', train_bn=train_bn) x = identity_block(x, [128,128,512], stage=3, block='c', train_bn=train_bn) C3 = x = identity_block( x, [128,128,512], stage=3, block='d', train_bn=train_bn) # stage 4 x = conv_block(x, [256,256,1024], stage=4, block='a', train_bn=train_bn) num_blocks = {'resnet50':5, 'resnet101':22}[architecture] for i in range(num_blocks): x = identity_block( x, [256,256,1024], stage=4, block=chr(98+i), train_bn=train_bn) C4 = x # stage 5 if stage5: x = conv_block(x, [512,512,2048], stage=5, block='a', train_bn=train_bn) x = identity_block( x, [512,512,2048], stage=5, block='b', train_bn=train_bn) C5 = x = identity_block( x, [512,512,2048], stage=5, block='c', train_bn=train_bn) else: C5 = None return [C1, C2, C3, C4, C5]
[ 37811, 198, 4965, 312, 723, 27862, 357, 4965, 7934, 8, 198, 37811, 198, 198, 2, 16573, 422, 220, 198, 2, 3740, 1378, 12567, 13, 785, 14, 69, 354, 349, 1616, 14, 22089, 12, 40684, 12, 27530, 14, 2436, 672, 14, 9866, 14, 411, 3262, ...
2.27125
3,200
from rds_log_cat.parser.parser import Parser, LineParserException
[ 6738, 374, 9310, 62, 6404, 62, 9246, 13, 48610, 13, 48610, 1330, 23042, 263, 11, 6910, 46677, 16922, 628 ]
3.526316
19
from functools import partial from corpustools.corpus.classes import Word from corpustools.symbolsim.edit_distance import edit_distance from corpustools.symbolsim.khorsi import khorsi from corpustools.symbolsim.phono_edit_distance import phono_edit_distance from corpustools.symbolsim.phono_align import Aligner from corpustools.multiproc import filter_mp, score_mp def neighborhood_density_all_words(corpus_context, tierdict, tier_type = None, sequence_type = None, algorithm = 'edit_distance', max_distance = 1, output_format = 'spelling', num_cores = -1, settable_attr = None, collapse_homophones = False, stop_check = None, call_back = None): """Calculate the neighborhood density of all words in the corpus and adds them as attributes of the words. Parameters ---------- corpus_context : CorpusContext Context manager for a corpus algorithm : str The algorithm used to determine distance max_distance : float, optional Maximum edit distance from the queried word to consider a word a neighbor. stop_check : callable, optional Optional function to check whether to gracefully terminate early call_back : callable, optional Optional function to supply progress information during the function settable_attr: string Name of attribute that neighbourhood density results will be assigned to """ function = partial(neighborhood_density, corpus_context, tierdict = tierdict, tier_type = tier_type, sequence_type = sequence_type, algorithm = algorithm, max_distance = max_distance, collapse_homophones = collapse_homophones) if call_back is not None: call_back('Calculating neighborhood densities...') call_back(0,len(corpus_context)) cur = 0 results = dict() last_value_removed = None last_key_removed = None if num_cores == -1 or num_cores == 1: for w in corpus_context: if stop_check is not None and stop_check(): return if last_value_removed: tierdict[last_key_removed].append(last_value_removed) w_sequence = getattr(w, corpus_context.sequence_type) last_key_removed = str(w_sequence) for i, item in enumerate(tierdict[last_key_removed]): if str(item) == str(w): last_value_removed = tierdict[last_key_removed].pop(i) break res = neighborhood_density(corpus_context, w, tierdict, tier_type = tier_type, sequence_type = sequence_type, algorithm = algorithm, max_distance = max_distance, collapse_homophones = collapse_homophones) results[str(w)] = [getattr(r, output_format) for r in res[1]] setattr(w.original, settable_attr.name, res[0]) # for w in corpus_context: # if stop_check is not None and stop_check(): # return # cur += 1 # call_back(cur) # res = function(w) # results[str(w)] = [getattr(r, output_format) for r in res[1]] # setattr(w.original, settable_attr.name, res[0]-1) # #the -1 is to account for the fact that words are counted as their own neighbour, and this is incorrect # #subtracting 1 here is easier than fixing the neighbourhood density algorithm else: iterable = ((w,) for w in corpus_context) neighbors = score_mp(iterable, function, num_cores, call_back, stop_check, chunk_size = 1) for n in neighbors: #Have to look up the key, then look up the object due to how #multiprocessing pickles objects setattr(corpus_context.corpus.find(corpus_context.corpus.key(n[0])), #corpus_context.attribute.name, n[1][0]) settable_attr.name, n[1][0]) return results def neighborhood_density(corpus_context, query, tierdict, algorithm = 'edit_distance', max_distance = 1, collapse_homophones = False, force_quadratic = False, file_type = None, tier_type=None, sequence_type = None, stop_check = None, call_back = None): """Calculate the neighborhood density of a particular word in the corpus. Parameters ---------- corpus_context : CorpusContext Context manager for a corpus query : Word The word whose neighborhood density to calculate. algorithm : str The algorithm used to determine distance max_distance : float, optional Maximum edit distance from the queried word to consider a word a neighbor force_quadratic : bool Force use of the less efficient quadratic algorithm even when finding edit distance of 1 neighborhoods stop_check : callable, optional Optional function to check whether to gracefully terminate early call_back : callable, optional Optional function to supply progress information during the function Returns ------- tuple(int, set) Tuple of the number of neighbors and the set of neighbor Words. """ matches = [] query = ensure_query_is_word(query, corpus_context, corpus_context.sequence_type, tier_type) if call_back is not None: call_back('Finding neighbors for {}...'.format(query)) call_back(0,len(corpus_context)) cur = 0 if algorithm == 'edit_distance' and max_distance == 1 and not force_quadratic: return fast_neighborhood_density(corpus_context, query, corpus_context.sequence_type, tier_type, tierdict, file_type=file_type, collapse_homophones=collapse_homophones) if algorithm == 'edit_distance': is_neighbor = partial(_is_edit_distance_neighbor, sequence_type = corpus_context.sequence_type, max_distance = max_distance) elif algorithm == 'phono_edit_distance': is_neighbor = partial(_is_phono_edit_distance_neighbor, specifier = corpus_context.specifier, sequence_type = corpus_context.sequence_type, max_distance = max_distance) elif algorithm == 'khorsi': freq_base = corpus_context.get_frequency_base() is_neighbor = partial(_is_khorsi_neighbor, freq_base = freq_base, sequence_type = corpus_context.sequence_type, max_distance = max_distance) for w in corpus_context: if stop_check is not None and stop_check(): return if call_back is not None: cur += 1 if cur % 10 == 0: call_back(cur) if not is_neighbor(w, query): continue matches.append(w) neighbors = set(matches)-set([query]) return (len(neighbors), neighbors) def fast_neighborhood_density(corpus_context, query, sequence_type, tier_type, tierdict, file_type=None, trans_delimiter='.', collapse_homophones = False): """Generates all neighbors of edit distance <= 1 and searches for them in corpus_context. Will be faster than neighborhood_density when: n > m * (1 + s), where n: number of words in corpus m: length of query s: size of segment inventory """ neighbors = list() query = ensure_query_is_word(query, corpus_context, sequence_type, tier_type, file_type=file_type) for candidate in generate_neighbor_candidates(corpus_context, query, sequence_type): if tier_type.att_type == 'tier': cand_str = trans_delimiter.join(candidate) else: cand_str = ''.join(candidate) if cand_str in tierdict: for w in tierdict[cand_str]: w_sequence = getattr(w, sequence_type) if collapse_homophones and any(getattr(word, sequence_type) == w_sequence for word in neighbors): continue else: neighbors.append(w) return (len(neighbors), neighbors) def find_mutation_minpairs(corpus_context, query, tier_type = None, collapse_homophones = False, stop_check = None, call_back = None): """Find all minimal pairs of the query word based only on segment mutations (not deletions/insertions) Parameters ---------- corpus_context : CorpusContext Context manager for a corpus query : Word The word whose minimal pairs to find stop_check : callable or None Optional function to check whether to gracefully terminate early call_back : callable or None Optional function to supply progress information during the function Returns ------- list The found minimal pairs for the queried word """ matches = [] sequence_type = corpus_context.sequence_type query = ensure_query_is_word(query, corpus_context, corpus_context.sequence_type, tier_type) if call_back is not None: call_back('Finding neighbors...') call_back(0,len(corpus_context)) cur = 0 al = Aligner(features_tf=False, ins_penalty=float('inf'), del_penalty=float('inf'), sub_penalty=1) for w in corpus_context: w_sequence = getattr(w, sequence_type) query_sequence = getattr(query, sequence_type) if stop_check is not None and stop_check(): return if call_back is not None: cur += 1 if cur % 10 == 0: call_back(cur) if (len(w_sequence) > len(query_sequence)+1 or len(w_sequence) < len(query_sequence)-1): continue m = al.make_similarity_matrix(query_sequence, w_sequence) if m[-1][-1]['f'] != 1: continue w_sequence = getattr(w, sequence_type) if collapse_homophones and any(getattr(m, sequence_type) == w_sequence for m in matches): continue else: #matches.append(str(w_sequence)) matches.append(w) matches = [m.spelling for m in matches] neighbors = list(set(matches)-set([str(query_sequence)])) return (len(neighbors), neighbors)
[ 6738, 1257, 310, 10141, 1330, 13027, 198, 198, 6738, 24614, 436, 10141, 13, 10215, 79, 385, 13, 37724, 1330, 9678, 198, 6738, 24614, 436, 10141, 13, 1837, 2022, 10220, 320, 13, 19312, 62, 30246, 1330, 4370, 62, 30246, 198, 6738, 24614, ...
2.344021
4,491
# Generated by Django 2.1.1 on 2018-11-06 17:19 from django.conf import settings from django.db import migrations
[ 2, 2980, 515, 416, 37770, 362, 13, 16, 13, 16, 319, 2864, 12, 1157, 12, 3312, 1596, 25, 1129, 198, 198, 6738, 42625, 14208, 13, 10414, 1330, 6460, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 628 ]
3.052632
38
import gym import numpy as np from itertools import product import matplotlib.pyplot as plt def print_policy(Q, env): """ This is a helper function to print a nice policy from the Q function""" moves = [u'', u'',u'', u''] if not hasattr(env, 'desc'): env = env.env dims = env.desc.shape policy = np.chararray(dims, unicode=True) policy[:] = ' ' for s in range(len(Q)): idx = np.unravel_index(s, dims) policy[idx] = moves[np.argmax(Q[s])] if env.desc[idx] in ['H', 'G']: policy[idx] = u'' print('\n'.join([''.join([u'{:2}'.format(item) for item in row]) for row in policy])) def plot_V(Q, env): """ This is a helper function to plot the state values from the Q function""" fig = plt.figure() if not hasattr(env, 'desc'): env = env.env dims = env.desc.shape V = np.zeros(dims) for s in range(len(Q)): idx = np.unravel_index(s, dims) V[idx] = np.max(Q[s]) if env.desc[idx] in ['H', 'G']: V[idx] = 0. plt.imshow(V, origin='upper', extent=[0,dims[0],0,dims[1]], vmin=.0, vmax=.6, cmap=plt.cm.RdYlGn, interpolation='none') for x, y in product(range(dims[0]), range(dims[1])): plt.text(y+0.5, dims[0]-x-0.5, '{:.3f}'.format(V[x,y]), horizontalalignment='center', verticalalignment='center') plt.xticks([]) plt.yticks([]) def plot_Q(Q, env): """ This is a helper function to plot the Q function """ from matplotlib import colors, patches fig = plt.figure() ax = fig.gca() if not hasattr(env, 'desc'): env = env.env dims = env.desc.shape up = np.array([[0, 1], [0.5, 0.5], [1,1]]) down = np.array([[0, 0], [0.5, 0.5], [1,0]]) left = np.array([[0, 0], [0.5, 0.5], [0,1]]) right = np.array([[1, 0], [0.5, 0.5], [1,1]]) tri = [left, down, right, up] pos = [[0.2, 0.5], [0.5, 0.2], [0.8, 0.5], [0.5, 0.8]] cmap = plt.cm.RdYlGn norm = colors.Normalize(vmin=.0,vmax=.6) ax.imshow(np.zeros(dims), origin='upper', extent=[0,dims[0],0,dims[1]], vmin=.0, vmax=.6, cmap=cmap) ax.grid(which='major', color='black', linestyle='-', linewidth=2) for s in range(len(Q)): idx = np.unravel_index(s, dims) x, y = idx if env.desc[idx] in ['H', 'G']: ax.add_patch(patches.Rectangle((y, 3-x), 1, 1, color=cmap(.0))) plt.text(y+0.5, dims[0]-x-0.5, '{:.2f}'.format(.0), horizontalalignment='center', verticalalignment='center') continue for a in range(len(tri)): ax.add_patch(patches.Polygon(tri[a] + np.array([y, 3-x]), color=cmap(Q[s][a]))) plt.text(y+pos[a][0], dims[0]-1-x+pos[a][1], '{:.2f}'.format(Q[s][a]), horizontalalignment='center', verticalalignment='center', fontsize=9, fontweight=('bold' if Q[s][a] == np.max(Q[s]) else 'normal')) plt.xticks([]) plt.yticks([]) env=gym.make('FrozenLake-v0') #env=gym.make('FrozenLake-v0', is_slippery=False) #env=gym.make('FrozenLake-v0', map_name="8x8") print("Running sarsa...") Q = sarsa(env) plot_V(Q, env) plot_Q(Q, env) print_policy(Q, env) plt.show() print("Running qlearning") Q = qlearning(env) plot_V(Q, env) plot_Q(Q, env) print_policy(Q, env) plt.show()
[ 11748, 11550, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 340, 861, 10141, 1330, 1720, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 628, 198, 4299, 3601, 62, 30586, 7, 48, 11, 17365, 2599, 198, 220, 220, 220, 37227...
1.925255
1,766
# Generated by Django 3.0.4 on 2020-07-14 11:00 from django.db import migrations, models import django.db.models.deletion
[ 2, 2980, 515, 416, 37770, 513, 13, 15, 13, 19, 319, 12131, 12, 2998, 12, 1415, 1367, 25, 405, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 198, 11748, 42625, 14208, 13, 9945, 13, 27530, 13, 2934, 1616, 295, ...
2.818182
44
from .BaseRequest import BaseRequest
[ 6738, 764, 14881, 18453, 1330, 7308, 18453, 628 ]
4.75
8
# -*- coding: utf-8 -*- # Copyright (c) 2019, Frappe Technologies and Contributors # License: MIT. See LICENSE import unittest import frappe from frappe.utils import set_request from frappe.website.serve import get_response test_dependencies = ["Blog Post"]
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 15069, 357, 66, 8, 13130, 11, 39313, 27768, 21852, 290, 25767, 669, 198, 2, 13789, 25, 17168, 13, 4091, 38559, 24290, 198, 11748, 555, 715, 395, 198, 198, 11748, 53...
3.182927
82
import numpy as np from .VariableUnitTest import VariableUnitTest from gwlfe.MultiUse_Fxns.Runoff import AgRunoff
[ 11748, 299, 32152, 355, 45941, 198, 198, 6738, 764, 43015, 26453, 14402, 1330, 35748, 26453, 14402, 198, 6738, 308, 86, 1652, 68, 13, 29800, 11041, 62, 37, 87, 5907, 13, 10987, 2364, 1330, 2449, 10987, 2364, 628 ]
3.135135
37
# Lint as: python3 # Copyright 2019 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== """Tests for car_layers.""" from lingvo import compat as tf from lingvo.core import py_utils from lingvo.core import test_utils from lingvo.tasks.car import car_layers if __name__ == '__main__': tf.test.main()
[ 2, 406, 600, 355, 25, 21015, 18, 198, 2, 15069, 13130, 383, 309, 22854, 37535, 46665, 13, 1439, 6923, 33876, 13, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743...
3.786885
244
import oblate import numpy as np import pytest # TODO!
[ 11748, 909, 17660, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 9288, 198, 198, 2, 16926, 46, 0, 198 ]
2.8
20
# -*- coding: utf-8 -*- # @Filename : take_snapshot.py # @Date : 2019-07-15-13-44 # @Project: ITC-sniff-for-changes-in-directory # @Author: Piotr Wooszyn # @Website: http://itcave.eu # @Email: contact@itcave.eu # @License: MIT # @Copyright (C) 2019 ITGO Piotr Wooszyn # Generic imports import os import pickle import re import argparse from datetime import datetime def clear_path_string(s): """ Simple function that removes chars that are not allowed in file names :param s: path_string :return: cleaned_path_string """ return (re.sub('[^a-zA-Z]+', '#', s)).lower() def sniff(sniff_path): """ Walks the path and stores information about directory content :param sniff_path: relative or absolute path :return: void """ sniff_path = str(sniff_path).lower() # Variable in which information will be stored dir_store = {} # Recursive loop that walks through all of the subdirectories for subdir, dirs, files in os.walk(sniff_path): if subdir not in dir_store: dir_store[subdir] = {} dir_store[subdir]['subdirs'] = dirs dir_store[subdir]['files'] = files dir_store[subdir]['file_details'] = {} for file in files: f_path = os.path.join(subdir, file) # The information that will be store for each of the files - in this case last file modification date # Important: it's cross-platform relevant! modified_date = os.path.getmtime(f_path) dir_store[subdir]['file_details'][file] = (modified_date,) # Name of a file in which data will be stored dump_name = clear_path_string(sniff_path) + '_' + datetime.now().strftime('%Y%m%d%H%M%S') # Save pickled data with open(dump_name + '.pkl', 'wb') as output: pickle.dump(dir_store, output, pickle.HIGHEST_PROTOCOL) print("Directory Snapshot taken:", dump_name) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Directory Sniffer') parser.add_argument('path', help='Path to the directory that you want to take a snapshot of') args = parser.parse_args() sniff(args.path)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2488, 35063, 1058, 1011, 62, 45380, 9442, 13, 9078, 198, 2, 2488, 10430, 1058, 13130, 12, 2998, 12, 1314, 12, 1485, 12, 2598, 198, 2, 2488, 16775, 25, 314, 4825, ...
2.583532
838
# Copyright 2020, Kay Hayen, mailto:kay.hayen@gmail.com # # Part of "Nuitka", an optimizing Python compiler that is compatible and # integrates with CPython, but also works on its own. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """ Globals/locals/single arg dir nodes These nodes give access to variables, highly problematic, because using them, the code may change or access anything about them, so nothing can be trusted anymore, if we start to not know where their value goes. The "dir()" call without arguments is reformulated to locals or globals calls. """ from .ConstantRefNodes import makeConstantRefNode from .DictionaryNodes import ExpressionKeyValuePair, ExpressionMakeDict from .ExpressionBases import ExpressionBase, ExpressionBuiltinSingleArgBase from .VariableRefNodes import ExpressionTempVariableRef, ExpressionVariableRef
[ 2, 220, 220, 220, 220, 15069, 12131, 11, 17356, 9075, 268, 11, 6920, 1462, 25, 5568, 13, 71, 323, 268, 31, 14816, 13, 785, 198, 2, 198, 2, 220, 220, 220, 220, 2142, 286, 366, 45, 5013, 4914, 1600, 281, 45780, 11361, 17050, 326, ...
3.546835
395
import math import pytest import chainerx all_scalar_values = [ -2, 1, -1.5, 2.3, True, False, float('inf'), float('nan')] def test_init_invalid(): with pytest.raises(TypeError): chainerx.Scalar("1") # string, which is not a numeric
[ 11748, 10688, 198, 198, 11748, 12972, 9288, 198, 198, 11748, 6333, 263, 87, 628, 198, 198, 439, 62, 1416, 282, 283, 62, 27160, 796, 685, 198, 220, 220, 220, 532, 17, 11, 352, 11, 532, 16, 13, 20, 11, 362, 13, 18, 11, 6407, 11, ...
2.366071
112
import sys import pygame from app_window import App_window from button import Button from snake import Snake from food import Food from settings import WIDTH, HEIGHT, FONT, BG_COL, QUIT_BUTTON_COLOUR, PLAY_BUTTON_COLOUR, BLACK, FPS, RED
[ 11748, 25064, 198, 11748, 12972, 6057, 198, 6738, 598, 62, 17497, 1330, 2034, 62, 17497, 198, 6738, 4936, 1330, 20969, 198, 6738, 17522, 1330, 16705, 198, 6738, 2057, 1330, 7318, 198, 6738, 6460, 1330, 370, 2389, 4221, 11, 11179, 9947, ...
3.352113
71
from pupa.utils import fix_bill_id from opencivicdata.legislative.models import (Bill, RelatedBill, BillAbstract, BillTitle, BillIdentifier, BillAction, BillActionRelatedEntity, BillSponsorship, BillSource, BillDocument, BillVersion, BillDocumentLink, BillVersionLink) from .base import BaseImporter from ..exceptions import PupaInternalError
[ 6738, 15552, 64, 13, 26791, 1330, 4259, 62, 35546, 62, 312, 198, 6738, 1280, 66, 16482, 7890, 13, 1455, 3044, 876, 13, 27530, 1330, 357, 17798, 11, 19809, 17798, 11, 3941, 23839, 11, 3941, 19160, 11, 198, 220, 220, 220, 220, 220, 22...
2.123348
227
from sklearn.metrics import f1_score,accuracy_score import numpy as np from utilities.tools import load_model import pandas as pd
[ 6738, 1341, 35720, 13, 4164, 10466, 1330, 277, 16, 62, 26675, 11, 4134, 23843, 62, 26675, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 20081, 13, 31391, 1330, 3440, 62, 19849, 198, 11748, 19798, 292, 355, 279, 67, 198 ]
3.333333
39
# coding=utf-8 import logging import traceback from os import makedirs from os.path import exists, join from textwrap import fill import matplotlib.patheffects as PathEffects import matplotlib.pyplot as plt import numpy as np import seaborn as sns from koino.plot import big_square, default_alpha from matplotlib import cm from ..utils.base import jaccard def plot_cluster_assignments( X, y, n_clusters, figures_dir, transparent=False, cluster_names=None, title="" ): """Clustering assignments scatter plot Notes ----- Can use mean or median to fix cluster centroid coordinates.""" if cluster_names is None: cluster_names = ["Cluster {}".format(i + 1) for i in range(n_clusters)] # We first reorder the data points according to the centroids labels X = np.vstack([X[y == i] for i in range(n_clusters)]) y = np.hstack([y[y == i] for i in range(n_clusters)]) # Choose a color palette with seaborn. palette = np.array(sns.color_palette("hls", n_clusters)) fig, ax = plt.subplots(figsize=big_square) # for i in range(n_clusters): # mask = y == i # ax.scatter(X[mask, 0], X[mask, 1], lw=0, s=20, c=palette[i], # label=cluster_names[i]) ax.set_title(title) ax.scatter(X[:, 0], X[:, 1], lw=0, s=20, c=palette[y.astype(np.int)]) ax.axis("off") # Add the labels for each cluster. for i in range(n_clusters): # Position of each label. samples = np.atleast_2d(X[y == i, :2]) if not len(samples): logging.warning( "Probably singular cluster {} (shape:{})".format(i + 1, X[y == i].shape) ) continue xtext, ytext = np.median(samples, axis=0) name = fill(cluster_names[i], width=20) assert np.isfinite(xtext) assert np.isfinite(ytext) txt = ax.text(xtext, ytext, name, fontsize=20, wrap=True, ha="left") txt.set_path_effects( [PathEffects.Stroke(linewidth=5, foreground="w"), PathEffects.Normal()] ) # plt.legend() figure_fp = join(figures_dir, "Clustered {}.png".format(title)) fig.tight_layout() try: fig.savefig(figure_fp, transparent=transparent) except ValueError: logging.warning(traceback.format_exc()) finally: plt.close() plt.clf() def overlap_jaccard( indx, y_a, y_b, names_a, names_b, n_a=None, n_b=None, figsize=None, output_dir=None, alabel="socio-demographic", blabel="purchases", transparent=False, ): """Compute and plot contingency tables based on set intersection and jaccard score. # TODO: Normaliser par len(sd_set) ou len(diet_set) ? """ if not (n_a or n_b) or not output_dir: return elif output_dir and not exists(output_dir): makedirs(output_dir) else: assert n_a and n_b assert len(indx) == len(y_a) == len(y_b) assert len(names_a) == n_a assert len(names_b) == n_b a_sets = [set(indx[y_a == i]) for i in range(n_a)] b_sets = [set(indx[y_b == i]) for i in range(n_b)] inter_sets = np.asarray( [[len(set_a & set_t) for set_a in a_sets] for set_t in b_sets], dtype=np.int_ ) fig, ax = plt.subplots(figsize=figsize) plt.title("Overlap between {} and {} clusters".format(alabel, blabel)) sns.heatmap( inter_sets, annot=True, fmt="6.0f", ax=ax, square=True, xticklabels=names_a, yticklabels=names_b, ) plt.tight_layout() inter_path = join(output_dir, "Clusters Intersection.png") plt.savefig(inter_path, transparent=transparent) plt.close() plt.clf() jac_arr = np.asarray( [[jaccard(set_a, set_b) for set_a in a_sets] for set_b in b_sets], dtype=np.float_, ) fig, ax = plt.subplots(figsize=figsize) plt.title("Jaccard scores between {} and {} clusters".format(alabel, blabel)) sns.heatmap( jac_arr, annot=True, fmt=".3f", ax=ax, square=True, xticklabels=names_a, yticklabels=names_b, ) plt.tight_layout() jaccard_path = join(output_dir, "Clusters Jaccard.png") plt.savefig(jaccard_path, transparent=transparent) plt.close() plt.clf()
[ 2, 19617, 28, 40477, 12, 23, 198, 11748, 18931, 198, 11748, 12854, 1891, 198, 6738, 28686, 1330, 285, 4335, 17062, 198, 6738, 28686, 13, 6978, 1330, 7160, 11, 4654, 198, 6738, 2420, 37150, 1330, 6070, 198, 198, 11748, 2603, 29487, 8019,...
2.171717
1,980
import typing nt = typing.NamedTuple("name", [("field", str)])
[ 11748, 19720, 198, 198, 429, 796, 19720, 13, 45, 2434, 51, 29291, 7203, 3672, 1600, 685, 7203, 3245, 1600, 965, 8, 12962 ]
2.863636
22
#!/usr/bin/env python # -*- coding: utf-8 -*- # import web import time from bson.objectid import ObjectId from config import setting import helper db = setting.db_web # url = ('/plat/index_news_remove')
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 220, 198, 11748, 3992, 198, 11748, 640, 198, 6738, 275, 1559, 13, 15252, 312, 1330, 9515, 7390, 198, 6738, 4566, 1...
2.679487
78
#!/usr/bin/env python # encoding: utf-8 # # Copyright SAS Institute # # Licensed under the Apache License, Version 2.0 (the License); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from __future__ import print_function, division, absolute_import, unicode_literals import os import pandas as pd import six from .base import BaseWindow, attribute from .features import SchemaFeature, ModelsFeature, ConnectorsFeature from .utils import get_args, ensure_element
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 21004, 25, 3384, 69, 12, 23, 198, 2, 198, 2, 15069, 35516, 5136, 198, 2, 198, 2, 220, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 13789, 1776, 198, 2, 22...
3.645161
248
from CommonServerPython import * ''' IMPORTS ''' import re import requests # Disable insecure warnings requests.packages.urllib3.disable_warnings() ''' GLOBALS/PARAMS ''' VENDOR = 'Have I Been Pwned? V2' MAX_RETRY_ALLOWED = demisto.params().get('max_retry_time', -1) API_KEY = demisto.params().get('api_key') USE_SSL = not demisto.params().get('insecure', False) BASE_URL = 'https://haveibeenpwned.com/api/v3' HEADERS = { 'hibp-api-key': API_KEY, 'user-agent': 'DBOT-API', 'Content-Type': 'application/json', 'Accept': 'application/json' } DEFAULT_DBOT_SCORE_EMAIL = 2 if demisto.params().get('default_dbot_score_email') == 'SUSPICIOUS' else 3 DEFAULT_DBOT_SCORE_DOMAIN = 2 if demisto.params().get('default_dbot_score_domain') == 'SUSPICIOUS' else 3 SUFFIXES = { "email": '/breachedaccount/', "domain": '/breaches?domain=', "username": '/breachedaccount/', "paste": '/pasteaccount/', "email_truncate_verified": '?truncateResponse=false&includeUnverified=true', "domain_truncate_verified": '&truncateResponse=false&includeUnverified=true', "username_truncate_verified": '?truncateResponse=false&includeUnverified=true' } RETRIES_END_TIME = datetime.min ''' HELPER FUNCTIONS ''' def html_description_to_human_readable(breach_description): """ Converting from html description to hr :param breach_description: Description of breach from API response :return: Description string that altered HTML urls to clickable urls for better readability in war-room """ html_link_pattern = re.compile('<a href="(.+?)"(.+?)>(.+?)</a>') patterns_found = html_link_pattern.findall(breach_description) for link in patterns_found: html_actual_address = link[0] html_readable_name = link[2] link_from_desc = '[' + html_readable_name + ']' + '(' + html_actual_address + ')' breach_description = re.sub(html_link_pattern, link_from_desc, breach_description, count=1) return breach_description ''' COMMANDS + REQUESTS FUNCTIONS ''' def test_module(args_dict): """ If the http request was successful the test will return OK :return: 3 arrays of outputs """ http_request('GET', SUFFIXES.get("username", '') + 'test') return ['ok'], [None], [None] def pwned_email_command(args_dict): """ Executing the pwned request for emails list, in order to support list input, the function returns 3 lists of outputs :param args_dict: the demisto argument - in this case the email list is needed :return: 3 arrays of outputs """ email_list = argToList(args_dict.get('email', '')) api_email_res_list, api_paste_res_list = pwned_email(email_list) md_list = [] ec_list = [] for email, api_email_res, api_paste_res in zip(email_list, api_email_res_list, api_paste_res_list): md_list.append(data_to_markdown('Email', email, api_email_res, api_paste_res)) ec_list.append(email_to_entry_context(email, api_email_res or [], api_paste_res or [])) return md_list, ec_list, api_email_res_list def pwned_email(email_list): """ Executing the http requests :param email_list: the email list that needed for the http requests :return: 2 arrays of http requests outputs """ api_email_res_list = [] api_paste_res_list = [] for email in email_list: email_suffix = SUFFIXES.get("email") + email + SUFFIXES.get("email_truncate_verified") paste_suffix = SUFFIXES.get("paste") + email api_email_res_list.append(http_request('GET', url_suffix=email_suffix)) api_paste_res_list.append(http_request('GET', url_suffix=paste_suffix)) return api_email_res_list, api_paste_res_list def pwned_domain_command(args_dict): """ Executing the pwned request for domains list, in order to support list input, the function returns 3 lists of outputs :param args_dict: the demisto argument - in this case the domain list is needed :return: 3 arrays of outputs """ domain_list = argToList(args_dict.get('domain', '')) api_res_list = pwned_domain(domain_list) md_list = [] ec_list = [] for domain, api_res in zip(domain_list, api_res_list): md_list.append(data_to_markdown('Domain', domain, api_res)) ec_list.append(domain_to_entry_context(domain, api_res or [])) return md_list, ec_list, api_res_list def pwned_domain(domain_list): """ Executing the http request :param domain_list: the domains list that needed for the http requests :return: an array of http requests outputs """ api_res_list = [] for domain in domain_list: suffix = SUFFIXES.get("domain") + domain + SUFFIXES.get("domain_truncate_verified") api_res_list.append(http_request('GET', url_suffix=suffix)) return api_res_list def pwned_username_command(args_dict): """ Executing the pwned request for usernames list, in order to support list input, the function returns 3 lists of outputs :param args_dict: the demisto argument - in this case the username list is needed :return: 3 arrays of outputs """ username_list = argToList(args_dict.get('username', '')) api_res_list = pwned_username(username_list) md_list = [] ec_list = [] for username, api_res in zip(username_list, api_res_list): md_list.append(data_to_markdown('Username', username, api_res)) ec_list.append(domain_to_entry_context(username, api_res or [])) return md_list, ec_list, api_res_list def pwned_username(username_list): """ Executing the http request :param username_list: the username list that needed for the http requests :return: an array of http requests outputs """ api_res_list = [] for username in username_list: suffix = SUFFIXES.get("username") + username + SUFFIXES.get("username_truncate_verified") api_res_list.append(http_request('GET', url_suffix=suffix)) return api_res_list command = demisto.command() LOG('Command being called is: {}'.format(command)) try: handle_proxy() set_retry_end_time() commands = { 'test-module': test_module, 'email': pwned_email_command, 'pwned-email': pwned_email_command, 'domain': pwned_domain_command, 'pwned-domain': pwned_domain_command, 'pwned-username': pwned_username_command } if command in commands: md_list, ec_list, api_email_res_list = commands[command](demisto.args()) for md, ec, api_paste_res in zip(md_list, ec_list, api_email_res_list): return_outputs(md, ec, api_paste_res) # Log exceptions except Exception as e: return_error(str(e))
[ 6738, 8070, 10697, 37906, 1330, 1635, 198, 198, 7061, 6, 30023, 33002, 705, 7061, 198, 198, 11748, 302, 198, 11748, 7007, 198, 198, 2, 31529, 31955, 14601, 198, 8897, 3558, 13, 43789, 13, 333, 297, 571, 18, 13, 40223, 62, 40539, 654, ...
2.618787
2,555
from moshmosh.extension import Extension from moshmosh.ast_compat import ast
[ 6738, 285, 3768, 76, 3768, 13, 2302, 3004, 1330, 27995, 198, 6738, 285, 3768, 76, 3768, 13, 459, 62, 5589, 265, 1330, 6468, 628 ]
3.25
24
import argparse import os import r2pipe import struct import mmap import base64 from shutil import copyfile import pprint pp = pprint.PrettyPrinter(indent=4) if __name__ == '__main__': main()
[ 11748, 1822, 29572, 198, 11748, 28686, 198, 11748, 374, 17, 34360, 198, 11748, 2878, 198, 11748, 8085, 499, 198, 11748, 2779, 2414, 198, 6738, 4423, 346, 1330, 4866, 7753, 198, 11748, 279, 4798, 198, 381, 796, 279, 4798, 13, 35700, 6836...
2.927536
69
# Generated by Django 2.2.15 on 2021-01-29 20:20 from django.db import migrations, models import django.db.models.deletion
[ 2, 2980, 515, 416, 37770, 362, 13, 17, 13, 1314, 319, 33448, 12, 486, 12, 1959, 1160, 25, 1238, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 198, 11748, 42625, 14208, 13, 9945, 13, 27530, 13, 2934, 1616, 295, ...
2.840909
44
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright: (c) 2016, Julien Stroheker <juliens@microsoft.com> # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} DOCUMENTATION = ''' --- module: azure_rm_availabilityset_info short_description: Get Azure Availability Set facts description: - Get facts for a specific availability set or all availability sets. options: name: description: - Limit results to a specific availability set. resource_group: description: - The resource group to search for the desired availability set. tags: description: - List of tags to be matched. extends_documentation_fragment: - azure.azcollection.azure author: - Julien Stroheker (@julienstroheker) deprecated: removed_in: '2.0.0' why: The Ansible collection community.azure is deprecated. Use azure.azcollection instead. alternative: Use M(azure.azcollection.azure_rm_availabilityset_info) instead. ''' EXAMPLES = ''' - name: Get facts for one availability set community.azure.azure_rm_availabilityset_info: name: Testing resource_group: myResourceGroup - name: Get facts for all availability sets in a specific resource group community.azure.azure_rm_availabilityset_info: resource_group: myResourceGroup ''' RETURN = ''' azure_availabilityset: description: List of availability sets dicts. returned: always type: complex contains: location: description: - Location where the resource lives. type: str sample: eastus2 name: description: - Resource name. type: str sample: myAvailabilitySet properties: description: - The properties of the resource. type: dict contains: platformFaultDomainCount: description: - Fault Domain count. type: int sample: 3 platformUpdateDomainCount: description: - Update Domain count. type: int sample: 2 virtualMachines: description: - A list of references to all virtualmachines in the availability set. type: list sample: [] sku: description: - Location where the resource lives. type: str sample: Aligned type: description: - Resource type. type: str sample: "Microsoft.Compute/availabilitySets" tags: description: - Resource tags. type: dict sample: { env: sandbox } ''' from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase try: from msrestazure.azure_exceptions import CloudError except Exception: # handled in azure_rm_common pass AZURE_OBJECT_CLASS = 'AvailabilitySet' def main(): """Main module execution code path""" AzureRMAvailabilitySetInfo() if __name__ == '__main__': main()
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 2, 15069, 25, 357, 66, 8, 1584, 11, 5979, 2013, 30183, 258, 6122, 1279, 73, 377, 10465, 31, 40485, 13, 785, 29, 198, ...
2.20679
1,620
import inspect import json import os import random import subprocess import time import requests import ast import paramiko import rancher from rancher import ApiError from lib.aws import AmazonWebServices DEFAULT_TIMEOUT = 120 DEFAULT_MULTI_CLUSTER_APP_TIMEOUT = 300 CATTLE_TEST_URL = os.environ.get('CATTLE_TEST_URL', "http://localhost:80") ADMIN_TOKEN = os.environ.get('ADMIN_TOKEN', "None") CATTLE_API_URL = CATTLE_TEST_URL + "/v3" kube_fname = os.path.join(os.path.dirname(os.path.realpath(__file__)), "k8s_kube_config") MACHINE_TIMEOUT = float(os.environ.get('RANCHER_MACHINE_TIMEOUT', "1200")) TEST_IMAGE = "sangeetha/mytestcontainer" CLUSTER_NAME = os.environ.get("RANCHER_CLUSTER_NAME", "") RANCHER_CLEANUP_CLUSTER = \ ast.literal_eval(os.environ.get('RANCHER_CLEANUP_CLUSTER', "True")) env_file = os.path.join( os.path.dirname(os.path.realpath(__file__)), "rancher_env.config") CLUSTER_NAME_2 = ""
[ 11748, 10104, 198, 11748, 33918, 198, 11748, 28686, 198, 11748, 4738, 198, 11748, 850, 14681, 198, 11748, 640, 198, 11748, 7007, 198, 11748, 6468, 198, 11748, 5772, 12125, 198, 11748, 32205, 372, 198, 6738, 32205, 372, 1330, 5949, 72, 123...
2.32809
445
# Given a string containing just the characters '(', ')', '{', '}', '[' and ']', # determine if the input string is valid. # An input string is valid if: # Open brackets must be closed by the same type of brackets. # Open brackets must be closed in the correct order. # Note that an empty string is also considered valid. # Example 1: # Input: "()" # Output: true # Example 2: # Input: "()[]{}" # Output: true # Example 3: # Input: "(]" # Output: false # Example 4: # Input: "([)]" # Output: false # Example 5: # Input: "{[]}" # Output: true if __name__ == "__main__": main()
[ 2, 11259, 257, 4731, 7268, 655, 262, 3435, 29513, 3256, 705, 8, 3256, 705, 90, 3256, 705, 92, 3256, 705, 17816, 290, 705, 60, 3256, 220, 198, 2, 5004, 611, 262, 5128, 4731, 318, 4938, 13, 198, 198, 2, 1052, 5128, 4731, 318, 4938, ...
3.015385
195
from flask import current_app from sqlalchemy.exc import InterfaceError from sqlalchemy.exc import OperationalError try: from ibutsu_server.db.model import Result IS_CONNECTED = True except ImportError: IS_CONNECTED = False def get_health(token_info=None, user=None): """Get a health report :rtype: Health """ return {"status": "OK", "message": "Service is running"} def get_database_health(token_info=None, user=None): """Get a health report for the database :rtype: Health """ response = ({"status": "Pending", "message": "Fetching service status"}, 200) # Try to connect to the database, and handle various responses try: if not IS_CONNECTED: response = ({"status": "Error", "message": "Incomplete database configuration"}, 500) else: Result.query.first() response = ({"status": "OK", "message": "Service is running"}, 200) except OperationalError: response = ({"status": "Error", "message": "Unable to connect to the database"}, 500) except InterfaceError: response = ({"status": "Error", "message": "Incorrect connection configuration"}, 500) except Exception as e: response = ({"status": "Error", "message": str(e)}, 500) return response def get_health_info(token_info=None, user=None): """Get the information about this server :rtype: HealthInfo """ return { "frontend": current_app.config.get("FRONTEND_URL", "http://localhost:3000"), "backend": current_app.config.get("BACKEND_URL", "http://localhost:8080"), "api_ui": current_app.config.get("BACKEND_URL", "http://localhost:8080") + "/api/ui/", }
[ 6738, 42903, 1330, 1459, 62, 1324, 198, 6738, 44161, 282, 26599, 13, 41194, 1330, 26491, 12331, 198, 6738, 44161, 282, 26599, 13, 41194, 1330, 6564, 864, 12331, 198, 198, 28311, 25, 198, 220, 220, 220, 422, 24283, 36567, 62, 15388, 13, ...
2.778502
614
"""Bindings for the Barnes Hut TSNE algorithm with fast nearest neighbors Refs: References [1] van der Maaten, L.J.P.; Hinton, G.E. Visualizing High-Dimensional Data Using t-SNE. Journal of Machine Learning Research 9:2579-2605, 2008. [2] van der Maaten, L.J.P. t-Distributed Stochastic Neighbor Embedding http://homepage.tudelft.nl/19j49/t-SNE.html """ import numpy as N import ctypes import os import pkg_resources
[ 37811, 36180, 654, 329, 262, 21335, 32767, 26136, 12161, 11862, 351, 3049, 16936, 12020, 198, 198, 8134, 82, 25, 198, 19927, 198, 58, 16, 60, 5719, 4587, 6669, 36686, 11, 406, 13, 41, 13, 47, 15089, 367, 2371, 11, 402, 13, 36, 13, ...
2.772152
158
# contains any CRUD not related to strictly editing users info and courses info from .views import admin
[ 2, 4909, 597, 8740, 8322, 407, 3519, 284, 14084, 12857, 2985, 7508, 290, 10902, 7508, 198, 6738, 764, 33571, 1330, 13169, 198 ]
4.772727
22
r''' This module provides utilities to get the absolute filenames so that we can be sure that: - The case of a file will match the actual file in the filesystem (otherwise breakpoints won't be hit). - Providing means for the user to make path conversions when doing a remote debugging session in one machine and debugging in another. To do that, the PATHS_FROM_ECLIPSE_TO_PYTHON constant must be filled with the appropriate paths. @note: in this context, the server is where your python process is running and the client is where eclipse is running. E.g.: If the server (your python process) has the structure /user/projects/my_project/src/package/module1.py and the client has: c:\my_project\src\package\module1.py the PATHS_FROM_ECLIPSE_TO_PYTHON would have to be: PATHS_FROM_ECLIPSE_TO_PYTHON = [(r'c:\my_project\src', r'/user/projects/my_project/src')] alternatively, this can be set with an environment variable from the command line: set PATHS_FROM_ECLIPSE_TO_PYTHON=[['c:\my_project\src','/user/projects/my_project/src']] @note: DEBUG_CLIENT_SERVER_TRANSLATION can be set to True to debug the result of those translations @note: the case of the paths is important! Note that this can be tricky to get right when one machine uses a case-independent filesystem and the other uses a case-dependent filesystem (if the system being debugged is case-independent, 'normcase()' should be used on the paths defined in PATHS_FROM_ECLIPSE_TO_PYTHON). @note: all the paths with breakpoints must be translated (otherwise they won't be found in the server) @note: to enable remote debugging in the target machine (pydev extensions in the eclipse installation) import pydevd;pydevd.settrace(host, stdoutToServer, stderrToServer, port, suspend) see parameter docs on pydevd.py @note: for doing a remote debugging session, all the pydevd_ files must be on the server accessible through the PYTHONPATH (and the PATHS_FROM_ECLIPSE_TO_PYTHON only needs to be set on the target machine for the paths that'll actually have breakpoints). ''' from _pydevd_bundle.pydevd_constants import IS_PY2, IS_PY3K, DebugInfoHolder, IS_WINDOWS, IS_JYTHON from _pydev_bundle._pydev_filesystem_encoding import getfilesystemencoding import json import os.path import sys import traceback _os_normcase = os.path.normcase basename = os.path.basename exists = os.path.exists join = os.path.join try: rPath = os.path.realpath # @UndefinedVariable except: # jython does not support os.path.realpath # realpath is a no-op on systems without islink support rPath = os.path.abspath # defined as a list of tuples where the 1st element of the tuple is the path in the client machine # and the 2nd element is the path in the server machine. # see module docstring for more details. try: PATHS_FROM_ECLIPSE_TO_PYTHON = json.loads(os.environ.get('PATHS_FROM_ECLIPSE_TO_PYTHON', '[]')) except Exception: sys.stderr.write('Error loading PATHS_FROM_ECLIPSE_TO_PYTHON from environment variable.\n') traceback.print_exc() PATHS_FROM_ECLIPSE_TO_PYTHON = [] else: if not isinstance(PATHS_FROM_ECLIPSE_TO_PYTHON, list): sys.stderr.write('Expected PATHS_FROM_ECLIPSE_TO_PYTHON loaded from environment variable to be a list.\n') PATHS_FROM_ECLIPSE_TO_PYTHON = [] else: # Converting json lists to tuple PATHS_FROM_ECLIPSE_TO_PYTHON = [tuple(x) for x in PATHS_FROM_ECLIPSE_TO_PYTHON] # example: # PATHS_FROM_ECLIPSE_TO_PYTHON = [ # (r'd:\temp\temp_workspace_2\test_python\src\yyy\yyy', # r'd:\temp\temp_workspace_2\test_python\src\hhh\xxx') # ] convert_to_long_pathname = lambda filename:filename convert_to_short_pathname = lambda filename:filename get_path_with_real_case = lambda filename:filename if sys.platform == 'win32': try: import ctypes from ctypes.wintypes import MAX_PATH, LPCWSTR, LPWSTR, DWORD GetLongPathName = ctypes.windll.kernel32.GetLongPathNameW GetLongPathName.argtypes = [LPCWSTR, LPWSTR, DWORD] GetLongPathName.restype = DWORD GetShortPathName = ctypes.windll.kernel32.GetShortPathNameW GetShortPathName.argtypes = [LPCWSTR, LPWSTR, DWORD] GetShortPathName.restype = DWORD # Check that it actually works _get_path_with_real_case(__file__) except: # Something didn't quite work out, leave no-op conversions in place. if DebugInfoHolder.DEBUG_TRACE_LEVEL > 2: traceback.print_exc() else: convert_to_long_pathname = _convert_to_long_pathname convert_to_short_pathname = _convert_to_short_pathname get_path_with_real_case = _get_path_with_real_case elif IS_JYTHON and IS_WINDOWS: if IS_WINDOWS: if IS_JYTHON: else: else: _ide_os = 'WINDOWS' if IS_WINDOWS else 'UNIX' def set_ide_os(os): ''' We need to set the IDE os because the host where the code is running may be actually different from the client (and the point is that we want the proper paths to translate from the client to the server). :param os: 'UNIX' or 'WINDOWS' ''' global _ide_os prev = _ide_os if os == 'WIN': # Apparently PyCharm uses 'WIN' (https://github.com/fabioz/PyDev.Debugger/issues/116) os = 'WINDOWS' assert os in ('WINDOWS', 'UNIX') if prev != os: _ide_os = os # We need to (re)setup how the client <-> server translation works to provide proper separators. setup_client_server_paths(_last_client_server_paths_set) DEBUG_CLIENT_SERVER_TRANSLATION = os.environ.get('DEBUG_PYDEVD_PATHS_TRANSLATION', 'False').lower() in ('1', 'true') # Caches filled as requested during the debug session. NORM_PATHS_CONTAINER = {} NORM_PATHS_AND_BASE_CONTAINER = {} # Returns tuple of absolute path and real path for given filename _ZIP_SEARCH_CACHE = {} _NOT_FOUND_SENTINEL = object() # Now, let's do a quick test to see if we're working with a version of python that has no problems # related to the names generated... try: try: code = rPath.func_code except AttributeError: code = rPath.__code__ if not exists(_NormFile(code.co_filename)): sys.stderr.write('-------------------------------------------------------------------------------\n') sys.stderr.write('pydev debugger: CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)\n') sys.stderr.write('pydev debugger: The debugger may still function, but it will work slower and may miss breakpoints.\n') sys.stderr.write('pydev debugger: Related bug: http://bugs.python.org/issue1666807\n') sys.stderr.write('-------------------------------------------------------------------------------\n') sys.stderr.flush() NORM_SEARCH_CACHE = {} initial_norm_paths = _NormPaths except: # Don't fail if there's something not correct here -- but at least print it to the user so that we can correct that traceback.print_exc() # Note: as these functions may be rebound, users should always import # pydevd_file_utils and then use: # # pydevd_file_utils.norm_file_to_client # pydevd_file_utils.norm_file_to_server # # instead of importing any of those names to a given scope. _original_file_to_server = _NormFile norm_file_to_client = _original_file_to_client norm_file_to_server = _original_file_to_server _last_client_server_paths_set = [] def setup_client_server_paths(paths): '''paths is the same format as PATHS_FROM_ECLIPSE_TO_PYTHON''' global norm_file_to_client global norm_file_to_server global _last_client_server_paths_set _last_client_server_paths_set = paths[:] # Work on the client and server slashes. python_sep = '\\' if IS_WINDOWS else '/' eclipse_sep = '\\' if _ide_os == 'WINDOWS' else '/' norm_filename_to_server_container = {} norm_filename_to_client_container = {} initial_paths = list(paths) paths_from_eclipse_to_python = initial_paths[:] # Apply normcase to the existing paths to follow the os preferences. for i, (path0, path1) in enumerate(paths_from_eclipse_to_python[:]): if IS_PY2: if isinstance(path0, unicode): path0 = path0.encode(sys.getfilesystemencoding()) if isinstance(path1, unicode): path1 = path1.encode(sys.getfilesystemencoding()) path0 = _fix_path(path0, eclipse_sep) path1 = _fix_path(path1, python_sep) initial_paths[i] = (path0, path1) paths_from_eclipse_to_python[i] = (normcase(path0), normcase(path1)) if not paths_from_eclipse_to_python: # no translation step needed (just inline the calls) norm_file_to_client = _original_file_to_client norm_file_to_server = _original_file_to_server return # only setup translation functions if absolutely needed! norm_file_to_server = _norm_file_to_server norm_file_to_client = _norm_file_to_client setup_client_server_paths(PATHS_FROM_ECLIPSE_TO_PYTHON) # For given file f returns tuple of its absolute path, real path and base name
[ 81, 7061, 6, 198, 220, 220, 220, 770, 8265, 3769, 20081, 284, 651, 262, 4112, 1226, 268, 1047, 523, 326, 356, 460, 307, 1654, 326, 25, 198, 220, 220, 220, 220, 220, 220, 220, 532, 383, 1339, 286, 257, 2393, 481, 2872, 262, 4036, ...
2.6133
3,579
import os import socket from random import randint from src import Constants from src.Constants import Network from src.networking import NetworkPackets, Actions from src.networking.Client import Client from src.utils.DH_Encryption import Encryption from src.utils.Enum import Enum
[ 11748, 28686, 198, 11748, 17802, 198, 6738, 4738, 1330, 43720, 600, 198, 198, 6738, 12351, 1330, 4757, 1187, 198, 6738, 12351, 13, 34184, 1187, 1330, 7311, 198, 6738, 12351, 13, 3262, 16090, 1330, 7311, 11869, 1039, 11, 24439, 198, 6738, ...
3.851351
74
# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: resource_requirements.proto import sys _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() from influxdb_service_sdk.model.container import resource_list_pb2 as influxdb__service__sdk_dot_model_dot_container_dot_resource__list__pb2 DESCRIPTOR = _descriptor.FileDescriptor( name='resource_requirements.proto', package='container', syntax='proto3', serialized_options=_b('ZCgo.easyops.local/contracts/protorepo-models/easyops/model/container'), serialized_pb=_b('\n\x1bresource_requirements.proto\x12\tcontainer\x1a\x38influxdb_service_sdk/model/container/resource_list.proto\"j\n\x14ResourceRequirements\x12\'\n\x06limits\x18\x01 \x01(\x0b\x32\x17.container.ResourceList\x12)\n\x08requests\x18\x02 \x01(\x0b\x32\x17.container.ResourceListBEZCgo.easyops.local/contracts/protorepo-models/easyops/model/containerb\x06proto3') , dependencies=[influxdb__service__sdk_dot_model_dot_container_dot_resource__list__pb2.DESCRIPTOR,]) _RESOURCEREQUIREMENTS = _descriptor.Descriptor( name='ResourceRequirements', full_name='container.ResourceRequirements', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( name='limits', full_name='container.ResourceRequirements.limits', index=0, number=1, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( name='requests', full_name='container.ResourceRequirements.requests', index=1, number=2, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), ], extensions=[ ], nested_types=[], enum_types=[ ], serialized_options=None, is_extendable=False, syntax='proto3', extension_ranges=[], oneofs=[ ], serialized_start=100, serialized_end=206, ) _RESOURCEREQUIREMENTS.fields_by_name['limits'].message_type = influxdb__service__sdk_dot_model_dot_container_dot_resource__list__pb2._RESOURCELIST _RESOURCEREQUIREMENTS.fields_by_name['requests'].message_type = influxdb__service__sdk_dot_model_dot_container_dot_resource__list__pb2._RESOURCELIST DESCRIPTOR.message_types_by_name['ResourceRequirements'] = _RESOURCEREQUIREMENTS _sym_db.RegisterFileDescriptor(DESCRIPTOR) ResourceRequirements = _reflection.GeneratedProtocolMessageType('ResourceRequirements', (_message.Message,), { 'DESCRIPTOR' : _RESOURCEREQUIREMENTS, '__module__' : 'resource_requirements_pb2' # @@protoc_insertion_point(class_scope:container.ResourceRequirements) }) _sym_db.RegisterMessage(ResourceRequirements) DESCRIPTOR._options = None # @@protoc_insertion_point(module_scope)
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2980, 515, 416, 262, 8435, 11876, 17050, 13, 220, 8410, 5626, 48483, 0, 198, 2, 2723, 25, 8271, 62, 8897, 18883, 13, 1676, 1462, 198, 198, 11748, 25064, 198, 62, ...
2.767442
1,204
from __future__ import absolute_import, division, print_function import pytest import json import asyncio import stripe import urllib3 from stripe import six, util from async_stripe.http_client import TornadoAsyncHTTPClient pytestmark = pytest.mark.asyncio VALID_API_METHODS = ("get", "post", "delete") def test_request(self, request_mock, mock_response, check_call): mock_response(request_mock, '{"foo": "baz"}', 200) for method in VALID_API_METHODS: abs_url = self.valid_url data = "" if method != "post": abs_url = "%s?%s" % (abs_url, data) data = None headers = {"my-header": "header val"} body, code, _ = self.make_request(method, abs_url, headers, data) assert code == 200 assert body == '{"foo": "baz"}' check_call(request_mock, method, abs_url, data, headers) def test_request_stream( self, mocker, request_mock, mock_response, check_call ): for method in VALID_API_METHODS: mock_response(request_mock, "some streamed content", 200) abs_url = self.valid_url data = "" if method != "post": abs_url = "%s?%s" % (abs_url, data) data = None headers = {"my-header": "header val"} print(dir(self)) print("make_request_stream" in dir(self)) stream, code, _ = self.make_request_stream( method, abs_url, headers, data ) assert code == 200 # Here we need to convert and align all content on one type (string) # as some clients return a string stream others a byte stream. body_content = stream.read() if hasattr(body_content, "decode"): body_content = body_content.decode("utf-8") assert body_content == "some streamed content" mocker.resetall() class TestTornadoAsyncHTTPClient: # :TODO: Write tests for tornado client pass
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 11, 7297, 11, 3601, 62, 8818, 198, 198, 11748, 12972, 9288, 198, 11748, 33918, 198, 11748, 30351, 952, 198, 198, 11748, 39858, 198, 11748, 2956, 297, 571, 18, 198, 6738, 39858, 1330, 2237,...
2.21097
948
"""\ Provides html file visualization of a json dataset """ import json import subprocess
[ 37811, 59, 198, 15946, 1460, 27711, 2393, 32704, 286, 257, 33918, 27039, 198, 37811, 198, 11748, 33918, 198, 11748, 850, 14681, 628 ]
4.136364
22
import sys from PyQt5 import QtGui from PyQt5.QtCore import QEvent, QPoint, Qt from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import (QApplication, QDialog, QGroupBox, QMainWindow, QTabWidget, QVBoxLayout, QWidget) from sim2d_game_analyzer.fmdb_tab import FMDBTab if __name__ == "__main__": app = QApplication(sys.argv) mainwindow = MainWindow() sys.exit(app.exec())
[ 11748, 25064, 198, 198, 6738, 9485, 48, 83, 20, 1330, 33734, 8205, 72, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 14055, 1330, 1195, 9237, 11, 1195, 12727, 11, 33734, 198, 6738, 9485, 48, 83, 20, 13, 48, 83, 8205, 72, 1330, 1195, ...
2.254054
185
# pip install openpyxl # pip install cuid import os.path import json import datetime from openpyxl import load_workbook import cuid # https://github.com/necaris/cuid.py - create uuid's in the format that graphcool expects SOURCE_XLSX = "./data/CLP_combined.xlsx" EXTRACT_OUTPUT_DIR = "../server/extract" SCHOOL_TITLES = ["ORGANISATION_ID", "ORGANISATION_NAME", "ORG_ELECTORATE", "P_ADDRESS1", "P_SUBURB", "P_STATE", "P_POSTCODE", "S_ADDRESS1", "S_SUBURB", "S_STATE", "S_POSTCODE", "SCHOOL_NAME", "SCH_ELECTORATE", "SCHOOL_ID", "SCHOOL_P_ADDRESS1", "SCHOOL_P_SUBURB", "SCHOOL_P_STATE", "SCHOOL_P_POSTCODE", "SCHOOL_S_ADDRESS1", "SCHOOL_S_SUBURB", "SCHOOL_S_STATE", "SCHOOL_S_POSTCODE", "LOCATION_NAME", "LOC_ELECTORATE", "LOC_S_ADDRESS1", "LOC_S_SUBURB", "LOC_S_STATE", "LOC_S_POSTCODE"] ORGANISATION_FIELDS = {"ORGANISATION_ID": "CLP_ORGANISATION_ID", "ORGANISATION_NAME": "NAME", "ORG_ELECTORATE": "ELECTORATE", "S_ADDRESS1": "ADDRESS", "S_SUBURB": "SUBURB", "S_STATE": "STATE", "S_POSTCODE": "POSTCODE", } SCHOOL_FIELDS = {"SCHOOL_NAME": "NAME", "SCH_ELECTORATE": "ELECTORATE", "SCHOOL_ID": "CLP_SCHOOL_ID", "ORGANISATION_ID": "CLP_ORGANISATION_ID", "SCHOOL_S_ADDRESS1": "ADDRESS", "SCHOOL_S_SUBURB": "SUBURB", "SCHOOL_S_STATE": "STATE", "SCHOOL_S_POSTCODE": "POSTCODE", } LOCATION_FIELDS = {"LOCATION_NAME": "NAME", "LOC_ELECTORATE": "ELECTORATE", "SCHOOL_ID": "CLP_SCHOOL_ID", "LOC_S_ADDRESS1": "ADDRESS", "LOC_S_SUBURB": "SUBURB", "LOC_S_STATE": "STATE", "LOC_S_POSTCODE": "POSTCODE"} TEACHER_TITLES = ["TEACHER_ID", "ORGANISATION_NAME", "SCHOOL_NAME", "TEACHER_NAME", "TITLE", "LNAME", "FNAME", "TEACHER_LANGUAGES", "P_ADDRESS1", "P_ADDRESS2", "P_SUBURB", "P_STATE", "P_POSTCODE", "TELEPHONE", "TEL_EVENING", "EMAIL", "MOBILE", "LEVEL_TAUGHT", "LEVEL_OF_EDUCATION", "FIELD_OF_EDUCATION", "DEGREE_COUNTRY", "DEGREE_YEAR", "ORGANISATION_ID", "SCHOOL_ID"] STUDENT_TITLES = ["SCHOOL_NAME", "SCHOOL_ID", "STUDENT_ID", "STUDENT_SRN", "LOCATION_NAME", "STUDENT_LNAME", "STUDENT_FNAME", "DOB", "TEL", "LOCATION_NAME_1"] TEACHER_FIELDS = {"TEACHER_ID": "CLP_TEACHER_ID", "ORGANISATION_NAME": "ORGANISATION_NAME", "SCHOOL_NAME": "SCHOOL_NAME", "TITLE": "TITLE", "LNAME": "FAMILY_NAME", "FNAME": "GIVEN_NAMES", "TEACHER_LANGUAGES": "LANGUAGES", "P_ADDRESS1": "ADDRESS1", "P_ADDRESS2": "ADDRESS2", "P_SUBURB": "SUBURB", "P_STATE": "STATE", "P_POSTCODE": "POSTCODE", "TELEPHONE": "DAY_PHONE", "TEL_EVENING": "EVENING_PHONE", "EMAIL": "EMAIL", "MOBILE": "MOBILE", "LEVEL_TAUGHT": "LEVEL_TAUGHT", "LEVEL_OF_EDUCATION": "EDUCATION_LEVEL", "FIELD_OF_EDUCATION": "EDUCATION_FIELD", "DEGREE_COUNTRY": "EDUCATION_COUNTRY", "DEGREE_YEAR": "EDUCATION_YEAR", "ORGANISATION_ID": "ORGANISATION_ID", "SCHOOL_ID": "SCHOOL_ID", } STUDENT_FIELDS = {"SCHOOL_NAME": "SCHOOL_NAME", "SCHOOL_ID": "SCHOOL_ID", "STUDENT_ID": "CLP_STUDENT_ID", "STUDENT_SRN": "SRN", "LOCATION_NAME": "LOCATION", "STUDENT_LNAME": "FAMILY_NAME", "STUDENT_FNAME": "GIVEN_NAMES", "DOB": "DATE_OF_BIRTH", "TEL": "PHONE", "LOCATION_NAME_1": "DAY_SCHOOL", } def to_camel(s): """Convert an underscored title into camel case. 'PARENT_ORGANISATION_ID' => 'parentOrganisationId'""" bits = [(x.lower() if i == 0 else x.title()) for (i, x) in enumerate(s.split("_"))] return "".join(bits) def inject_required(type_name, dicts): "Inject the required fields that graphcool import required" for x in dicts: x["_typeName"] = type_name x["id"] = cuid.cuid() x["createdAt"] = x["updatedAt"] = now_as_iso8601() return list(dicts) def convert_dob_to_datetime(s): "Convert the string from 99/MON/YY to a ISO date" dt = datetime.datetime.strptime(s, "%d/%b/%y") return dt.isoformat() + ".0Z" # GraphCool import insists on microseconds, hence the ".0" def copy_without(dicts, *keys_to_remove): "Return iterable that contains copies of the given dictionary with all the given keys removed" copies = [x.copy() for x in dicts] for d in copies: for to_remove in keys_to_remove: d.pop(to_remove, None) return copies if __name__ == "__main__": main()
[ 2, 7347, 2721, 1280, 9078, 87, 75, 198, 2, 7347, 2721, 18912, 312, 198, 11748, 28686, 13, 6978, 198, 11748, 33918, 198, 11748, 4818, 8079, 198, 198, 6738, 1280, 9078, 87, 75, 1330, 3440, 62, 1818, 2070, 198, 11748, 18912, 312, 220, ...
1.93928
2,388
import os import sys from lxml import html import pathlib import json import m3u8 from seleniumwire import webdriver from selenium.common.exceptions import TimeoutException, NoSuchElementException from selenium.webdriver.firefox.options import Options as FirefoxOptions IFRAME_CSS_SELECTOR = '.iframe-container>iframe' # Disable # Restore
[ 11748, 28686, 198, 11748, 25064, 198, 6738, 300, 19875, 1330, 27711, 198, 11748, 3108, 8019, 198, 11748, 33918, 198, 11748, 285, 18, 84, 23, 198, 198, 6738, 384, 11925, 1505, 21809, 1330, 3992, 26230, 198, 6738, 384, 11925, 1505, 13, 11...
3.530612
98
VERSION = "1.4.0" DATE = "2016-Sept-21"
[ 43717, 796, 366, 16, 13, 19, 13, 15, 1, 198, 35, 6158, 796, 366, 5304, 12, 14635, 12, 2481, 1, 198 ]
1.904762
21
import pygame import shared
[ 11748, 12972, 6057, 201, 198, 11748, 4888, 201 ]
3.625
8
import sys import threading import logging import time logger = logging.getLogger("interchange.strategy.base")
[ 11748, 25064, 198, 11748, 4704, 278, 198, 11748, 18931, 198, 11748, 640, 198, 198, 6404, 1362, 796, 18931, 13, 1136, 11187, 1362, 7203, 3849, 3803, 13, 2536, 4338, 13, 8692, 4943, 628, 198 ]
3.454545
33
import torch import torchvision import matplotlib import matplotlib.pyplot as plt from PIL import Image from captum.attr import GuidedGradCam, GuidedBackprop from captum.attr import LayerActivation, LayerConductance, LayerGradCam from data_utils import * from image_utils import * from captum_utils import * import numpy as np from visualizers import GradCam plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots plt.rcParams['image.interpolation'] = 'nearest' plt.rcParams['image.cmap'] = 'gray' X, y, class_names = load_imagenet_val(num=5) # FOR THIS SECTION ONLY, we need to use gradients. We introduce a new model we will use explicitly for GradCAM for this. gc_model = torchvision.models.squeezenet1_1(pretrained=True) gc = GradCam() X_tensor = torch.cat([preprocess(Image.fromarray(x)) for x in X], dim=0).requires_grad_(True) y_tensor = torch.LongTensor(y) # Guided Back-Propagation gbp_result = gc.guided_backprop(X_tensor,y_tensor, gc_model) plt.figure(figsize=(24, 24)) for i in range(gbp_result.shape[0]): plt.subplot(1, 5, i + 1) img = gbp_result[i] img = rescale(img) plt.imshow(img) plt.title(class_names[y[i]]) plt.axis('off') plt.gcf().tight_layout() plt.savefig('visualization/guided_backprop.png') # GradCam # GradCAM. We have given you which module(=layer) that we need to capture gradients from, which you can see in conv_module variable below gc_model = torchvision.models.squeezenet1_1(pretrained=True) for param in gc_model.parameters(): param.requires_grad = True X_tensor = torch.cat([preprocess(Image.fromarray(x)) for x in X], dim=0).requires_grad_(True) y_tensor = torch.LongTensor(y) gradcam_result = gc.grad_cam(X_tensor, y_tensor, gc_model) plt.figure(figsize=(24, 24)) for i in range(gradcam_result.shape[0]): gradcam_val = gradcam_result[i] img = X[i] + (matplotlib.cm.jet(gradcam_val)[:,:,:3]*255) img = img / np.max(img) plt.subplot(1, 5, i + 1) plt.imshow(img) plt.title(class_names[y[i]]) plt.axis('off') plt.gcf().tight_layout() plt.savefig('visualization/gradcam.png') # As a final step, we can combine GradCam and Guided Backprop to get Guided GradCam. X_tensor = torch.cat([preprocess(Image.fromarray(x)) for x in X], dim=0).requires_grad_(True) y_tensor = torch.LongTensor(y) gradcam_result = gc.grad_cam(X_tensor, y_tensor, gc_model) gbp_result = gc.guided_backprop(X_tensor, y_tensor, gc_model) plt.figure(figsize=(24, 24)) for i in range(gradcam_result.shape[0]): gbp_val = gbp_result[i] gradcam_val = np.expand_dims(gradcam_result[i], axis=2) # Pointwise multiplication and normalization of the gradcam and guided backprop results (2 lines) img = gradcam_val * gbp_val img = np.expand_dims(img.transpose(2, 0, 1), axis=0) img = np.float32(img) img = torch.from_numpy(img) img = deprocess(img) plt.subplot(1, 5, i + 1) plt.imshow(img) plt.title(class_names[y[i]]) plt.axis('off') plt.gcf().tight_layout() plt.savefig('visualization/guided_gradcam.png') # **************************************************************************************** # # Captum model = torchvision.models.squeezenet1_1(pretrained=True) # We don't want to train the model, so tell PyTorch not to compute gradients # with respect to model parameters. for param in model.parameters(): param.requires_grad = False # Convert X and y from numpy arrays to Torch Tensors X_tensor = torch.cat([preprocess(Image.fromarray(x)) for x in X], dim=0) y_tensor = torch.LongTensor(y) conv_module = model.features[12] ############################################################################## # TODO: Compute/Visualize GuidedBackprop and Guided GradCAM as well. # # visualize_attr_maps function from captum_utils.py is useful for # # visualizing captum outputs # # Use conv_module as the convolution layer for gradcam # ############################################################################## # Computing Guided GradCam ggc = GuidedGradCam(model, conv_module) attribution_gcc = compute_attributions(ggc, X_tensor, target = y_tensor) # print(X_tensor.shape, y_tensor.shape, attribution_gcc.shape) visualize_attr_maps('visualization/GuidedGradCam.png', X, y, class_names, [attribution_gcc], ['Guided_Grad_Cam']) # Computing Guided BackProp gbp = GuidedBackprop(model) attribution_gbp = compute_attributions(gbp, X_tensor, target = y_tensor) visualize_attr_maps('visualization/GuidedBackpropCam.png', X, y, class_names, [attribution_gbp], ['Guided_Backprop_Cam']) ############################################################################## # END OF YOUR CODE # ############################################################################## # Try out different layers and see observe how the attributions change layer = model.features[3] # Example visualization for using layer visualizations # layer_act = LayerActivation(model, layer) # layer_act_attr = compute_attributions(layer_act, X_tensor) # layer_act_attr_sum = layer_act_attr.mean(axis=1, keepdim=True) ############################################################################## # TODO: Visualize Individual Layer Gradcam and Layer Conductance (similar # # to what we did for the other captum sections, using our helper methods), # # but with some preprocessing calculations. # # # # You can refer to the LayerActivation example above and you should be # # using 'layer' given above for this section # # # # Also note that, you would need to customize your 'attr_preprocess' # # parameter that you send along to 'visualize_attr_maps' as the default # # 'attr_preprocess' is written to only to handle multi channel attributions. # # # # For layer gradcam look at the usage of the parameter relu_attributions # ############################################################################## # Layer gradcam aggregates across all channels from captum.attr import LayerAttribution N, C, H, W = X_tensor.shape LC = LayerConductance(model, layer) LC_attr = compute_attributions(LC, X_tensor, target = y_tensor) LC_attr_sum = LC_attr.mean(axis = 1, keepdim = True) LC_attr_int = LayerAttribution.interpolate(LC_attr_sum, (H,W) ) LC_attr_int = LC_attr_int.repeat(1, 3, 1, 1) visualize_attr_maps('visualization/LayerConductance.png', X, y, class_names, [LC_attr_int], ['LayerConductance']) LGC = LayerGradCam(model, layer) LGC_attr = compute_attributions(LGC, X_tensor, target = y_tensor) LGC_attr_sum = LGC_attr.mean(axis = 1, keepdim = True) LGC_attr_int = LayerAttribution.interpolate(LGC_attr_sum, (H,W)) LGC_attr_int = LGC_attr_int.repeat(1, 3, 1, 1) visualize_attr_maps ('visualization/LayerGradCam.png', X, y, class_names, [LGC_attr_int], ['LayerGradCam']) ############################################################################## # END OF YOUR CODE # ##############################################################################
[ 11748, 28034, 198, 11748, 28034, 10178, 198, 11748, 2603, 29487, 8019, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 6738, 350, 4146, 1330, 7412, 198, 6738, 3144, 388, 13, 35226, 1330, 1962, 1384, 42731, 21701, 11, ...
2.595096
2,855
from collections import namedtuple Genotype = namedtuple('Genotype', 'normal normal_concat reduce reduce_concat') PRIMITIVES = [ 'none', 'max_pool_3x3', 'avg_pool_3x3', 'skip_connect', 'sep_conv_3x3', 'sep_conv_5x5', 'dil_conv_3x3', 'dil_conv_5x5' ] CRBPRIMITIVES = [ 'max_pool_3x3', 'avg_pool_3x3', 'skip_connect', 'sep_conv_3x3', 'sep_conv_5x5', 'dil_conv_3x3', 'dil_conv_5x5' ] NASNet = Genotype( normal=[ ('sep_conv_5x5', 1), ('sep_conv_3x3', 0), ('sep_conv_5x5', 0), ('sep_conv_3x3', 0), ('avg_pool_3x3', 1), ('skip_connect', 0), ('avg_pool_3x3', 0), ('avg_pool_3x3', 0), ('sep_conv_3x3', 1), ('skip_connect', 1), ], normal_concat=[2, 3, 4, 5, 6], reduce=[ ('sep_conv_5x5', 1), ('sep_conv_7x7', 0), ('max_pool_3x3', 1), ('sep_conv_7x7', 0), ('avg_pool_3x3', 1), ('sep_conv_5x5', 0), ('skip_connect', 3), ('avg_pool_3x3', 2), ('sep_conv_3x3', 2), ('max_pool_3x3', 1), ], reduce_concat=[4, 5, 6], ) AmoebaNet = Genotype( normal=[ ('avg_pool_3x3', 0), ('max_pool_3x3', 1), ('sep_conv_3x3', 0), ('sep_conv_5x5', 2), ('sep_conv_3x3', 0), ('avg_pool_3x3', 3), ('sep_conv_3x3', 1), ('skip_connect', 1), ('skip_connect', 0), ('avg_pool_3x3', 1), ], normal_concat=[4, 5, 6], reduce=[ ('avg_pool_3x3', 0), ('sep_conv_3x3', 1), ('max_pool_3x3', 0), ('sep_conv_7x7', 2), ('sep_conv_7x7', 0), ('avg_pool_3x3', 1), ('max_pool_3x3', 0), ('max_pool_3x3', 1), ('conv_7x1_1x7', 0), ('sep_conv_3x3', 5), ], reduce_concat=[3, 4, 6] ) DARTS_V1 = Genotype( normal=[('sep_conv_3x3', 1), ('sep_conv_3x3', 0), ('skip_connect', 0), ('sep_conv_3x3', 1), ('skip_connect', 0), ('sep_conv_3x3', 1), ('sep_conv_3x3', 0), ('skip_connect', 2)], normal_concat=[2, 3, 4, 5], reduce=[('max_pool_3x3', 0), ('max_pool_3x3', 1), ('skip_connect', 2), ('max_pool_3x3', 0), ('max_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 2), ('avg_pool_3x3', 0)], reduce_concat=[2, 3, 4, 5]) DARTS_V2 = Genotype( normal=[('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('sep_conv_3x3', 0), ('sep_conv_3x3', 1), ('sep_conv_3x3', 1), ('skip_connect', 0), ('skip_connect', 0), ('dil_conv_3x3', 2)], normal_concat=[2, 3, 4, 5], reduce=[('max_pool_3x3', 0), ('max_pool_3x3', 1), ('skip_connect', 2), ('max_pool_3x3', 1), ('max_pool_3x3', 0), ('skip_connect', 2), ('skip_connect', 2), ('max_pool_3x3', 1)], reduce_concat=[2, 3, 4, 5]) DARTS = DARTS_V2 BATH = Genotype( normal=[('max_pool_3x3', 0), ('max_pool_3x3', 1), ('max_pool_3x3', 0), ('sep_conv_5x5', 2), ('dil_conv_5x5', 0), ('max_pool_3x3', 2), ('sep_conv_3x3', 2), ('sep_conv_3x3', 0)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 1), ('max_pool_3x3', 0), ('max_pool_3x3', 1), ('sep_conv_5x5', 2), ('skip_connect', 3), ('avg_pool_3x3', 2), ('sep_conv_3x3', 4), ('dil_conv_5x5', 1)], reduce_concat=range(2, 6)) BATH2 = Genotype( normal=[('max_pool_3x3', 1), ('skip_connect', 0), ('skip_connect', 2), ('max_pool_3x3', 1), ('skip_connect', 1), ('skip_connect', 2), ('max_pool_3x3', 1), ('max_pool_3x3', 0)], normal_concat=range(2, 6), reduce=[('max_pool_3x3', 0), ('max_pool_3x3', 1), ('skip_connect', 0), ('dil_conv_3x3', 1), ('skip_connect', 1), ('skip_connect', 0), ('dil_conv_5x5', 0), ('sep_conv_3x3', 4)], reduce_concat=range(2, 6))
[ 6738, 17268, 1330, 3706, 83, 29291, 198, 198, 13746, 8690, 796, 3706, 83, 29291, 10786, 13746, 8690, 3256, 705, 11265, 3487, 62, 1102, 9246, 4646, 4646, 62, 1102, 9246, 11537, 198, 198, 4805, 3955, 2043, 42472, 796, 685, 198, 220, 220, ...
1.773161
2,094
#!/usr/bin/python # # Copyright 2020 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Library for using Logica in CoLab.""" from .common import color from .common import concertina_lib from .compiler import functors from .compiler import rule_translate from .compiler import universe import IPython from IPython.core.magic import register_cell_magic from IPython.display import display import os import pandas from .parser_py import parse from .common import sqlite3_logica BQ_READY = True # By default. try: from google.cloud import bigquery except: BQ_READY = False print('Could not import google.cloud.bigquery.') try: from google.colab import auth except: BQ_READY = False print('Could not import google.cloud.auth.') try: from google.colab import widgets WIDGETS_IMPORTED = True except: WIDGETS_IMPORTED = False print('Could not import google.colab.widgets.') PROJECT = None # TODO: Should this be renamed to PSQL_ENGINE, PSQL_CONNECTION? DB_ENGINE = None DB_CONNECTION = None USER_AUTHENTICATED = False TABULATED_OUTPUT = True SHOW_FULL_QUERY = True PREAMBLE = None if not WIDGETS_IMPORTED: SetTabulatedOutput(False) def TabBar(*args): """Returns a real TabBar or a mock. Useful for UIs that don't support JS.""" if TABULATED_OUTPUT: return widgets.TabBar(*args) return MockTabBar() def ShowError(error_text): print(color.Format('[ {error}Error{end} ] ' + error_text)) def Logica(line, cell, run_query): """Running Logica predicates and storing results.""" predicates = ParseList(line) if not predicates: ShowError('No predicates to run.') return try: program = ';\n'.join(s for s in [PREAMBLE, cell] if s) parsed_rules = parse.ParseFile(program)['rule'] except parse.ParsingException as e: e.ShowMessage() return try: program = universe.LogicaProgram(parsed_rules) except functors.FunctorError as e: e.ShowMessage() return engine = program.annotations.Engine() if engine == 'bigquery' and not BQ_READY: ShowError( 'BigQuery client and/or authentification is not installed. \n' 'It is the easiest to run BigQuery requests from Google CoLab:\n' ' https://colab.research.google.com/.\n' 'Note that running Logica on SQLite requires no installation.\n' 'This could be a good fit for working with small data or learning Logica.\n' 'Use {warning}@Engine("sqlite");{end} annotation in your program to use SQLite.') return bar = TabBar(predicates + ['(Log)']) logs_idx = len(predicates) executions = [] sub_bars = [] ip = IPython.get_ipython() for idx, predicate in enumerate(predicates): with bar.output_to(logs_idx): try: sql = program.FormattedPredicateSql(predicate) executions.append(program.execution) ip.push({predicate + '_sql': sql}) except rule_translate.RuleCompileException as e: print('Encountered error when compiling %s.' % predicate) e.ShowMessage() return # Publish output to Colab cell. with bar.output_to(idx): sub_bar = TabBar(['SQL', 'Result']) sub_bars.append(sub_bar) with sub_bar.output_to(0): if SHOW_FULL_QUERY: print( color.Format( 'The following query is stored at {warning}%s{end} ' 'variable.' % ( predicate + '_sql'))) print(sql) else: print('Query is stored at %s variable.' % color.Warn(predicate + '_sql')) with bar.output_to(logs_idx): if engine == 'sqlite': sql_runner = SqliteRunner() elif engine == 'psql': sql_runner = PostgresRunner() elif engine == 'bigquery': EnsureAuthenticatedUser() sql_runner = RunSQL else: raise Exception('Logica only supports BigQuery, PostgreSQL and SQLite ' 'for now.') result_map = concertina_lib.ExecuteLogicaProgram( executions, sql_runner=sql_runner, sql_engine=engine) for idx, predicate in enumerate(predicates): t = result_map[predicate] ip.push({predicate: t}) with bar.output_to(idx): with sub_bars[idx].output_to(1): if run_query: print( color.Format( 'The following table is stored at {warning}%s{end} ' 'variable.' % predicate)) display(t) else: print('The query was not run.') print(' ') # To activate the tabbar.
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 198, 2, 15069, 12131, 3012, 11419, 198, 2, 198, 2, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 198, 2, 345, 743, 407, 779, 428, 2393, 2845, 287...
2.556847
1,979
from sympy.core.basic import Basic as sp_Basic
[ 6738, 10558, 88, 13, 7295, 13, 35487, 1330, 14392, 355, 599, 62, 26416, 628 ]
3.428571
14
from itertools import product import numpy as np import pytest from alibi_detect.utils.discretizer import Discretizer x = np.random.rand(10, 4) n_features = x.shape[1] feature_names = [str(_) for _ in range(n_features)] categorical_features = [[], [1, 3]] percentiles = [list(np.arange(25, 100, 25)), list(np.arange(10, 100, 10))] tests = list(product(categorical_features, percentiles)) n_tests = len(tests)
[ 6738, 340, 861, 10141, 1330, 1720, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 9288, 198, 6738, 435, 27567, 62, 15255, 478, 13, 26791, 13, 15410, 1186, 7509, 1330, 8444, 1186, 7509, 198, 198, 87, 796, 45941, 13, 25120, 13, ...
2.753333
150
# -*- coding: utf-8 -*- """ Created on Mon Jun 14 11:49:43 2021 @author: Andres """ import sys,time import unittest from tinc import * if __name__ == '__main__': unittest.main()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 2892, 7653, 1478, 1367, 25, 2920, 25, 3559, 33448, 198, 198, 31, 9800, 25, 843, 411, 198, 37811, 198, 198, 11748, 25064, 11, 2435, 198, 11748, ...
2.157895
95