content
stringlengths
1
1.05M
input_ids
listlengths
1
883k
ratio_char_token
float64
1
22.9
token_count
int64
1
883k
from decimal import ROUND_HALF_DOWN, ROUND_HALF_EVEN, ROUND_HALF_UP, Decimal from math import ceil, floor, log2 from typing import Union import torch from ppq.core import RoundingPolicy def ppq_numerical_round(value: float, policy: RoundingPolicy=RoundingPolicy.ROUND_HALF_EVEN) -> int: """ reference: https://en.wikipedia.org/wiki/Rounding decimal defination: - decimal.ROUND_CEILING (towards Infinity) - decimal.ROUND_DOWN (towards zero) - decimal.ROUND_FLOOR (towards -Infinity) - decimal.ROUND_HALF_DOWN (to nearest with ties going towards zero) - decimal.ROUND_HALF_EVEN (to nearest with ties going to nearest even integer) - decimal.ROUND_HALF_UP (to nearest with ties going away from zero) - decimal.ROUND_UP (away from zero) - decimal.ROUND_05UP (away from zero if last digit after rounding towards zero would have been 0 or 5; otherwise towards zero) Args: value (float): [description] policy (RoundingPolicy, optional): [description]. Defaults to RoundingPolicy.ROUND_HALF_EVEN. Raises: ValueError: [description] Returns: int: [description] """ assert isinstance(value, float), 'numerical round only takes effect on float number.' if policy == RoundingPolicy.ROUND_HALF_EVEN: return int(Decimal(value).quantize(exp=Decimal(1), rounding=ROUND_HALF_EVEN)) elif policy == RoundingPolicy.ROUND_HALF_UP: if value > 0: return int(Decimal(value).quantize(exp=Decimal(1), rounding=ROUND_HALF_UP)) else: return int(Decimal(value).quantize(exp=Decimal(1), rounding=ROUND_HALF_DOWN)) elif policy == RoundingPolicy.ROUND_HALF_DOWN: if value > 0: return int(Decimal(value).quantize(exp=Decimal(1), rounding=ROUND_HALF_DOWN)) else: return int(Decimal(value).quantize(exp=Decimal(1), rounding=ROUND_HALF_UP)) elif policy == RoundingPolicy.ROUND_HALF_TOWARDS_ZERO: return ppq_numerical_round(value, RoundingPolicy.ROUND_HALF_DOWN) elif policy == RoundingPolicy.ROUND_HALF_FAR_FORM_ZERO: return ppq_numerical_round(value, RoundingPolicy.ROUND_HALF_UP) elif policy == RoundingPolicy.ROUND_TO_NEAR_INT: if value > 0: return floor(value + 0.5) else: return ceil(value - 0.5) elif policy == RoundingPolicy.ROUND_UP: return ceil(value) else: raise ValueError('Unexpected rounding policy found.') def ppq_tensor_round(value: torch.Tensor, policy:RoundingPolicy=RoundingPolicy.ROUND_HALF_EVEN) -> torch.Tensor: """ reference: https://en.wikipedia.org/wiki/Rounding Args: value (torch.Tensor): [description] policy (RoundingPolicy, optional): [description]. Defaults to RoundingPolicy.ROUND_HALF_EVEN. Raises: ValueError: [description] Returns: torch.Tensor: [description] """ assert isinstance(value, torch.Tensor), 'tensor round only takes effect on torch tensor.' if policy == RoundingPolicy.ROUND_HALF_EVEN: # default rounding policy of torch is ROUND_TO_NEAR_EVEN # try this: print(torch.Tensor([1.5, 2.5, 3.5, 4.5]).round()) # However it may generate unexpected results due to version difference. return value.round() elif policy == RoundingPolicy.ROUND_UP: return value.ceil() elif policy == RoundingPolicy.ROUND_HALF_TOWARDS_ZERO: return torch.sign(value) * torch.ceil(value.abs() - 0.5) elif policy == RoundingPolicy.ROUND_HALF_FAR_FORM_ZERO: return torch.sign(value) * torch.floor(value.abs() + 0.5) elif policy == RoundingPolicy.ROUND_HALF_DOWN: return torch.ceil(value - 0.5) elif policy == RoundingPolicy.ROUND_HALF_UP: return torch.floor(value + 0.5) elif policy == RoundingPolicy.ROUND_TO_NEAR_INT: raise NotImplementedError(f'Torch Tensor can not use this rounding policy({policy}) try ROUND_HALF_EVEN instead.') else: raise ValueError('Unexpected rounding policy found.')
[ 6738, 32465, 1330, 371, 15919, 62, 39, 1847, 37, 62, 41925, 11, 371, 15919, 62, 39, 1847, 37, 62, 20114, 1677, 11, 371, 15919, 62, 39, 1847, 37, 62, 8577, 11, 4280, 4402, 198, 6738, 10688, 1330, 2906, 346, 11, 4314, 11, 2604, 17, ...
2.431384
1,676
#!/usr/bin/env python3 # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You 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 copy import time import numpy as np # type: ignore[import] import pandas as pd # type: ignore[import] from collections import namedtuple from typing import Any, Dict, List, Optional, Tuple from repair.utils import elapsed_time, get_option_value, setup_logger _logger = setup_logger() # List of internal configurations _option = namedtuple('_option', 'key default_value type_class validator err_msg') _opt_boosting_type = \ _option('model.lgb.boosting_type', 'gbdt', str, lambda v: v in ['gbdt', 'dart', 'goss', 'rf'], "`{}` should be in ['gbdt', 'dart', 'goss', 'rf']") _opt_class_weight = \ _option('model.lgb.class_weight', 'balanced', str, None, None) _opt_learning_rate = \ _option('model.lgb.learning_rate', 0.01, float, lambda v: v > 0.0, '`{}` should be positive') _opt_max_depth = \ _option('model.lgb.max_depth', 7, int, None, None) _opt_max_bin = \ _option('model.lgb.max_bin', 255, int, None, None) _opt_reg_alpha = \ _option('model.lgb.reg_alpha', 0.0, float, lambda v: v >= 0.0, '`{}` should be greater than or equal to 0.0') _opt_min_split_gain = \ _option('model.lgb.min_split_gain', 0.0, float, lambda v: v >= 0.0, '`{}` should be greater than or equal to 0.0') _opt_n_estimators = \ _option('model.lgb.n_estimators', 300, int, lambda v: v > 0, '`{}` should be positive') _opt_importance_type = \ _option('model.lgb.importance_type', 'gain', str, lambda v: v in ['split', 'gain'], "`{}` should be in ['split', 'gain']") _opt_n_splits = \ _option('model.cv.n_splits', 3, int, lambda v: v >= 3, '`{}` should be greater than 2') _opt_timeout = \ _option('model.hp.timeout', 0, int, None, None) _opt_max_evals = \ _option('model.hp.max_evals', 100000000, int, lambda v: v > 0, '`{}` should be positive') _opt_no_progress_loss = \ _option('model.hp.no_progress_loss', 50, int, lambda v: v > 0, '`{}` should be positive') train_option_keys = [ _opt_boosting_type.key, _opt_class_weight.key, _opt_learning_rate.key, _opt_max_depth.key, _opt_max_bin.key, _opt_reg_alpha.key, _opt_min_split_gain.key, _opt_n_estimators.key, _opt_importance_type.key, _opt_n_splits.key, _opt_timeout.key, _opt_max_evals.key, _opt_no_progress_loss.key ]
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 2, 198, 2, 49962, 284, 262, 24843, 10442, 5693, 357, 1921, 37, 8, 739, 530, 393, 517, 198, 2, 18920, 5964, 11704, 13, 220, 4091, 262, 28536, 2393, 9387, 351, 198, 2, 428, ...
2.552526
1,247
from django.conf.urls import patterns, url from roomsensor import views urlpatterns = patterns('', url(r'^$', views.index, name='roomsensor'), # ex: /roomsensor/name/ url(r'^(?P<roomsensor_name>\w+)/$', views.display, name='roomsensor_display'), url(r'^(?P<roomsensor_name>\w+)/read/$', views.read, name='roomsensor_read'), # JSON data for graph creation url(r'^(?P<roomsensor_name>\w+)/rawdata/(?P<datapoints>\d+)/(?P<compression_factor>\d+)/$', views.rawdata, name='roomsensor_rawdata'), )
[ 6738, 42625, 14208, 13, 10414, 13, 6371, 82, 1330, 7572, 11, 19016, 198, 198, 6738, 9519, 22854, 1330, 5009, 198, 198, 6371, 33279, 82, 796, 7572, 10786, 3256, 198, 220, 220, 220, 19016, 7, 81, 6, 61, 3, 3256, 5009, 13, 9630, 11, ...
2.483254
209
# main.py # # currently just an example script I use to test my optimization_results module # # WARNING: design point numbers 0-indexed in pandas database, but # eval_id column is the original 1-indexed value given by DAKOTA import optimization_results as optr if __name__=='__main__': main()
[ 2, 1388, 13, 9078, 198, 2, 198, 2, 3058, 655, 281, 1672, 4226, 314, 779, 284, 1332, 616, 23989, 62, 43420, 8265, 198, 2, 198, 2, 39410, 25, 1486, 966, 3146, 657, 12, 9630, 276, 287, 19798, 292, 6831, 11, 475, 220, 198, 2, 5418, ...
3.382022
89
# # Copyright (c) 2017 Joy Diamond. All rights reserved. #
[ 2, 198, 2, 220, 220, 15069, 357, 66, 8, 2177, 14087, 13566, 13, 220, 1439, 2489, 10395, 13, 198, 2, 198 ]
2.952381
21
import flask from flask import Flask from flask import jsonify from flask import request from flask_cors import CORS, cross_origin from flask import render_template import mwoauth import requests_oauthlib import os import yaml import mwapi from tasks.main import Tasks from save import Save from db import DB from typo.fix import TypoFix app = Flask(__name__, static_folder="./frontend/build/static", template_folder="./frontend/build") #app = Flask(__name__) CORS(app) user_agent = 'WikiBooster' __dir__ = os.path.dirname(__file__) configFile = open(os.path.join(__dir__, 'config.yaml')) app.config.update(yaml.safe_load(configFile)) #http://127.0.0.1:5000/task/lvwiki/1/Helna Mrnija # if __name__ == '__main__': app.run(debug=True)
[ 11748, 42903, 198, 6738, 42903, 1330, 46947, 198, 6738, 42903, 1330, 33918, 1958, 198, 6738, 42903, 1330, 2581, 198, 6738, 42903, 62, 66, 669, 1330, 327, 20673, 11, 3272, 62, 47103, 198, 6738, 42903, 1330, 8543, 62, 28243, 198, 198, 117...
2.828897
263
import numpy as np from collections import defaultdict, Counter import random import json from tqdm import tqdm if __name__ == '__main__': transX('Wiki')
[ 11748, 299, 32152, 355, 45941, 220, 198, 6738, 17268, 1330, 4277, 11600, 11, 15034, 198, 11748, 4738, 198, 11748, 33918, 198, 198, 6738, 256, 80, 36020, 1330, 256, 80, 36020, 628, 198, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, ...
3.115385
52
"""Contains the Fortune Teller Character class""" import json import random import discord import datetime from botc import Action, ActionTypes, Townsfolk, Character, Storyteller, RedHerring, \ RecurringAction, Category, StatusList from botc.BOTCUtils import GameLogic from ._utils import TroubleBrewing, TBRole import globvars with open('botc/gamemodes/troublebrewing/character_text.json') as json_file: character_text = json.load(json_file)[TBRole.fortuneteller.value.lower()] with open('botutils/bot_text.json') as json_file: bot_text = json.load(json_file) butterfly = bot_text["esthetics"]["butterfly"] with open('botc/game_text.json') as json_file: strings = json.load(json_file) fortune_teller_nightly = strings["gameplay"]["fortune_teller_nightly"] copyrights_str = strings["misc"]["copyrights"] yes = strings["gameplay"]["yes"] no = strings["gameplay"]["no"] good_link = strings["images"]["good"] evil_link = strings["images"]["evil"]
[ 37811, 4264, 1299, 262, 20425, 309, 12368, 15684, 1398, 37811, 198, 198, 11748, 33918, 198, 11748, 4738, 198, 11748, 36446, 220, 198, 11748, 4818, 8079, 198, 6738, 10214, 66, 1330, 7561, 11, 7561, 31431, 11, 40752, 19956, 11, 15684, 11, ...
2.862069
348
from unittest.mock import call, MagicMock, patch from schmetterling.build.maven import build_multi_modules from schmetterling.build.maven import create_build_result from schmetterling.build.maven import create_command from schmetterling.build.maven import create_multi_modules from schmetterling.build.maven import create_state from schmetterling.build.maven import get_maven_infos from schmetterling.build.maven import get_maven_repos from schmetterling.build.maven import get_multi_modules from schmetterling.build.state import BuildState, Build from schmetterling.setup.state import Repo
[ 6738, 555, 715, 395, 13, 76, 735, 1330, 869, 11, 6139, 44, 735, 11, 8529, 198, 198, 6738, 5513, 4164, 353, 1359, 13, 11249, 13, 2611, 574, 1330, 1382, 62, 41684, 62, 18170, 198, 6738, 5513, 4164, 353, 1359, 13, 11249, 13, 2611, 57...
3.243243
185
#Sacar las lineas con DEBUG para que el juego funcione import random DIGITOS = 4 def mastermind(): """Funcion principal del juego Mastermind""" print("Bienvenido al Mastermind!") print("Instrucciones: Tenes que adivinar un codigo de {} digitos distintos. Tu cantidad de aciertos son los numeros que estan correctamente posicionados, tu cantidad de coincidencias son los numeros bien elegidos pero mal posicionados. Suerte!".format(DIGITOS)) codigo = elegir_codigo() intentos = 1 propuesta = input("Que codigo propones? (o pone 'Me retiro') ") retirarse = "Me retiro" while propuesta != codigo and propuesta != retirarse: intentos+=1 aciertos, coincidencias = analizar_propuesta(propuesta, codigo) print ("Tu propuesta ({}) tiene {} aciertos y {} coincidencias.".format(propuesta,aciertos,coincidencias)) propuesta = input("Propone otro codigo: ") if propuesta == retirarse: print ("El codigo era: {}".format(codigo)) else: print ("Ganaste! Ganaste en {} intentos".format(intentos)) def elegir_codigo(): """Elige un codigo de DIGITOS digitos al azar""" digitos= ("0","1","2","3","4","5","6","7","8","9") codigo = "" for i in range(DIGITOS): candidato = random.choice(digitos) print("[DEBUG] candidato:", candidato) while candidato in codigo: candidato = random.choice(digitos) codigo = codigo + candidato print("[DEBUG] el codigo va siendo", codigo) return codigo def analizar_propuesta(propuesta, codigo): """Determina aciertos y coincidencias""" aciertos = 0 coincidencias = 0 for i in range(DIGITOS): if propuesta[i] == codigo[i]: aciertos += 1 elif propuesta[i] in codigo: coincidencias += 1 return aciertos,coincidencias mastermind()
[ 2, 38318, 283, 39990, 1627, 292, 369, 16959, 31215, 8358, 1288, 474, 518, 2188, 25439, 7935, 201, 198, 201, 198, 11748, 4738, 201, 198, 35, 3528, 2043, 2640, 796, 604, 201, 198, 4299, 41353, 33529, 201, 198, 197, 37811, 37, 19524, 295...
2.472496
709
#!/usr/bin/env python # -*- coding: utf-8 -*- """The setup script.""" from setuptools import setup, find_packages with open("README.rst") as readme_file: readme = readme_file.read() with open("HISTORY.rst") as history_file: history = history_file.read() requirements = ["Click>=6.0", "suds2==0.7.1"] setup_requirements = [ # TODO(ovnicraft): put setup requirements (distutils extensions, etc.) here ] test_requirements = [ # TODO: put package test requirements here ] setup( name="runa", version="0.2.10", description="Librera para uso de WS del Bus Gubernamental de Ecuador", long_description=readme + "\n\n" + history, author="Cristian Salamea", author_email="cristian.salamea@gmail.com", url="https://github.com/ovnicraft/runa", packages=find_packages(include=["runa"]), entry_points={"console_scripts": ["runa=runa.cli:main"]}, include_package_data=True, install_requires=requirements, license="MIT license", zip_safe=False, keywords="runa webservices ecuador bgs", classifiers=[ "Development Status :: 3 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", ], test_suite="tests", tests_require=test_requirements, setup_requires=setup_requirements, )
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 37811, 464, 9058, 4226, 526, 15931, 198, 198, 6738, 900, 37623, 10141, 1330, 9058, 11, 1064, 62, 43789, 198, 198, ...
2.618881
572
import time import board import displayio import busio from analogio import AnalogIn import neopixel import adafruit_adt7410 from adafruit_bitmap_font import bitmap_font from adafruit_display_text.label import Label from adafruit_button import Button import adafruit_touchscreen from adafruit_pyportal import PyPortal # ------------- Inputs and Outputs Setup ------------- # # init. the temperature sensor i2c_bus = busio.I2C(board.SCL, board.SDA) adt = adafruit_adt7410.ADT7410(i2c_bus, address=0x48) adt.high_resolution = True # init. the light sensor light_sensor = AnalogIn(board.LIGHT) pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=1) WHITE = 0xffffff RED = 0xff0000 YELLOW = 0xffff00 GREEN = 0x00ff00 BLUE = 0x0000ff PURPLE = 0xff00ff BLACK = 0x000000 # ---------- Sound Effects ------------- # soundDemo = '/sounds/sound.wav' soundBeep = '/sounds/beep.wav' soundTab = '/sounds/tab.wav' # ------------- Other Helper Functions------------- # # Helper for cycling through a number set of 1 to x. # ------------- Screen Setup ------------- # pyportal = PyPortal() display = board.DISPLAY display.rotation = 270 # Backlight function # Value between 0 and 1 where 0 is OFF, 0.5 is 50% and 1 is 100% brightness. # Set the Backlight set_backlight(0.3) # Touchscreen setup # ------Rotate 270: screen_width = 240 screen_height = 320 ts = adafruit_touchscreen.Touchscreen(board.TOUCH_YD, board.TOUCH_YU, board.TOUCH_XR, board.TOUCH_XL, calibration=((5200, 59000), (5800, 57000)), size=(screen_width, screen_height)) # ------------- Display Groups ------------- # splash = displayio.Group(max_size=15) # The Main Display Group view1 = displayio.Group(max_size=15) # Group for View 1 objects view2 = displayio.Group(max_size=15) # Group for View 2 objects view3 = displayio.Group(max_size=15) # Group for View 3 objects # ------------- Setup for Images ------------- # # Display an image until the loop starts pyportal.set_background('/images/loading.bmp') bg_group = displayio.Group(max_size=1) splash.append(bg_group) icon_group = displayio.Group(max_size=1) icon_group.x = 180 icon_group.y = 120 icon_group.scale = 1 view2.append(icon_group) # This will handel switching Images and Icons def set_image(group, filename): """Set the image file for a given goup for display. This is most useful for Icons or image slideshows. :param group: The chosen group :param filename: The filename of the chosen image """ print("Set image to ", filename) if group: group.pop() if not filename: return # we're done, no icon desired image_file = open(filename, "rb") image = displayio.OnDiskBitmap(image_file) try: image_sprite = displayio.TileGrid(image, pixel_shader=displayio.ColorConverter()) except TypeError: image_sprite = displayio.TileGrid(image, pixel_shader=displayio.ColorConverter(), position=(0, 0)) group.append(image_sprite) set_image(bg_group, "/images/BGimage.bmp") # ---------- Text Boxes ------------- # # Set the font and preload letters font = bitmap_font.load_font("/fonts/Helvetica-Bold-16.bdf") font.load_glyphs(b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()') # Default Label styling: TABS_X = 5 TABS_Y = 50 # Text Label Objects feed1_label = Label(font, text="Text Wondow 1", color=0xE39300, max_glyphs=200) feed1_label.x = TABS_X feed1_label.y = TABS_Y view1.append(feed1_label) feed2_label = Label(font, text="Text Wondow 2", color=0xFFFFFF, max_glyphs=200) feed2_label.x = TABS_X feed2_label.y = TABS_Y view2.append(feed2_label) sensors_label = Label(font, text="Data View", color=0x03AD31, max_glyphs=200) sensors_label.x = TABS_X sensors_label.y = TABS_Y view3.append(sensors_label) sensor_data = Label(font, text="Data View", color=0x03AD31, max_glyphs=100) sensor_data.x = TABS_X+15 sensor_data.y = 170 view3.append(sensor_data) text_hight = Label(font, text="M", color=0x03AD31, max_glyphs=10) # return a reformatted string with word wrapping using PyPortal.wrap_nicely # ---------- Display Buttons ------------- # # Default button styling: BUTTON_HEIGHT = 40 BUTTON_WIDTH = 80 # We want three buttons across the top of the screen TAPS_HEIGHT = 40 TAPS_WIDTH = int(screen_width/3) TAPS_Y = 0 # We want two big buttons at the bottom of the screen BIG_BUTTON_HEIGHT = int(screen_height/3.2) BIG_BUTTON_WIDTH = int(screen_width/2) BIG_BUTTON_Y = int(screen_height-BIG_BUTTON_HEIGHT) # This group will make it easy for us to read a button press later. buttons = [] # Main User Interface Buttons button_view1 = Button(x=0, y=0, width=TAPS_WIDTH, height=TAPS_HEIGHT, label="View1", label_font=font, label_color=0xff7e00, fill_color=0x5c5b5c, outline_color=0x767676, selected_fill=0x1a1a1a, selected_outline=0x2e2e2e, selected_label=0x525252) buttons.append(button_view1) # adding this button to the buttons group button_view2 = Button(x=TAPS_WIDTH, y=0, width=TAPS_WIDTH, height=TAPS_HEIGHT, label="View2", label_font=font, label_color=0xff7e00, fill_color=0x5c5b5c, outline_color=0x767676, selected_fill=0x1a1a1a, selected_outline=0x2e2e2e, selected_label=0x525252) buttons.append(button_view2) # adding this button to the buttons group button_view3 = Button(x=TAPS_WIDTH*2, y=0, width=TAPS_WIDTH, height=TAPS_HEIGHT, label="View3", label_font=font, label_color=0xff7e00, fill_color=0x5c5b5c, outline_color=0x767676, selected_fill=0x1a1a1a, selected_outline=0x2e2e2e, selected_label=0x525252) buttons.append(button_view3) # adding this button to the buttons group button_switch = Button(x=0, y=BIG_BUTTON_Y, width=BIG_BUTTON_WIDTH, height=BIG_BUTTON_HEIGHT, label="Switch", label_font=font, label_color=0xff7e00, fill_color=0x5c5b5c, outline_color=0x767676, selected_fill=0x1a1a1a, selected_outline=0x2e2e2e, selected_label=0x525252) buttons.append(button_switch) # adding this button to the buttons group button_2 = Button(x=BIG_BUTTON_WIDTH, y=BIG_BUTTON_Y, width=BIG_BUTTON_WIDTH, height=BIG_BUTTON_HEIGHT, label="Button", label_font=font, label_color=0xff7e00, fill_color=0x5c5b5c, outline_color=0x767676, selected_fill=0x1a1a1a, selected_outline=0x2e2e2e, selected_label=0x525252) buttons.append(button_2) # adding this button to the buttons group # Add all of the main buttons to the spalsh Group for b in buttons: splash.append(b.group) # Make a button to change the icon image on view2 button_icon = Button(x=150, y=60, width=BUTTON_WIDTH, height=BUTTON_HEIGHT, label="Icon", label_font=font, label_color=0xffffff, fill_color=0x8900ff, outline_color=0xbc55fd, selected_fill=0x5a5a5a, selected_outline=0xff6600, selected_label=0x525252, style=Button.ROUNDRECT) buttons.append(button_icon) # adding this button to the buttons group # Add this button to view2 Group view2.append(button_icon.group) # Make a button to play a sound on view2 button_sound = Button(x=150, y=170, width=BUTTON_WIDTH, height=BUTTON_HEIGHT, label="Sound", label_font=font, label_color=0xffffff, fill_color=0x8900ff, outline_color=0xbc55fd, selected_fill=0x5a5a5a, selected_outline=0xff6600, selected_label=0x525252, style=Button.ROUNDRECT) buttons.append(button_sound) # adding this button to the buttons group # Add this button to view2 Group view3.append(button_sound.group) #pylint: disable=global-statement #pylint: enable=global-statement # Set veriables and startup states button_view1.selected = False button_view2.selected = True button_view3.selected = True showLayer(view1) hideLayer(view2) hideLayer(view3) view_live = 1 icon = 1 icon_name = "Ruby" button_mode = 1 switch_state = 0 button_switch.label = "OFF" button_switch.selected = True # Update out Labels with display text. text_box(feed1_label, TABS_Y, "The text on this screen is wrapped so that all of it fits nicely into a \ text box that is ### x ###.", 30) text_box(feed1_label, TABS_Y, 'The text on this screen is wrapped so that all of it fits nicely into a \ text box that is {} x {}.' .format(feed1_label.bounding_box[2], feed1_label.bounding_box[3]*2), 30) text_box(feed2_label, TABS_Y, 'Tap on the Icon button to meet a new friend.', 18) text_box(sensors_label, TABS_Y, "This screen can display sensor readings and tap Sound to play a WAV file.", 28) board.DISPLAY.show(splash) # ------------- Code Loop ------------- # while True: touch = ts.touch_point light = light_sensor.value tempC = round(adt.temperature) tempF = tempC * 1.8 + 32 sensor_data.text = 'Touch: {}\nLight: {}\n Temp: {}F'.format(touch, light, tempF) # ------------- Handle Button Press Detection ------------- # if touch: # Only do this if the screen is touched # loop with buttons using enumerate() to number each button group as i for i, b in enumerate(buttons): if b.contains(touch): # Test each button to see if it was pressed print('button%d pressed' % i) if i == 0 and view_live != 1: # only if view1 is visable pyportal.play_file(soundTab) switch_view(1) while ts.touch_point: pass if i == 1 and view_live != 2: # only if view2 is visable pyportal.play_file(soundTab) switch_view(2) while ts.touch_point: pass if i == 2 and view_live != 3: # only if view3 is visable pyportal.play_file(soundTab) switch_view(3) while ts.touch_point: pass if i == 3: pyportal.play_file(soundBeep) # Toggle switch button type if switch_state == 0: switch_state = 1 b.label = "ON" b.selected = False pixel.fill(WHITE) print("Swich ON") else: switch_state = 0 b.label = "OFF" b.selected = True pixel.fill(BLACK) print("Swich OFF") # for debounce while ts.touch_point: pass print("Swich Pressed") if i == 4: pyportal.play_file(soundBeep) # Momentary button type b.selected = True print('Button Pressed') button_mode = numberUP(button_mode, 5) if button_mode == 1: pixel.fill(RED) elif button_mode == 2: pixel.fill(YELLOW) elif button_mode == 3: pixel.fill(GREEN) elif button_mode == 4: pixel.fill(BLUE) elif button_mode == 5: pixel.fill(PURPLE) switch_state = 1 button_switch.label = "ON" button_switch.selected = False # for debounce while ts.touch_point: pass print("Button released") b.selected = False if i == 5 and view_live == 2: # only if view2 is visable pyportal.play_file(soundBeep) b.selected = True while ts.touch_point: pass print("Icon Button Pressed") icon = numberUP(icon, 3) if icon == 1: icon_name = "Ruby" elif icon == 2: icon_name = "Gus" elif icon == 3: icon_name = "Billie" b.selected = False text_box(feed2_label, TABS_Y, "Every time you tap the Icon button the icon image will \ change. Say hi to {}!".format(icon_name), 18) set_image(icon_group, "/images/"+icon_name+".bmp") if i == 6 and view_live == 3: # only if view3 is visable b.selected = True while ts.touch_point: pass print("Sound Button Pressed") pyportal.play_file(soundDemo) b.selected = False
[ 11748, 640, 198, 11748, 3096, 198, 11748, 3359, 952, 198, 11748, 1323, 952, 198, 6738, 15075, 952, 1330, 50088, 818, 198, 11748, 497, 404, 7168, 198, 11748, 512, 1878, 4872, 62, 324, 83, 4524, 940, 198, 6738, 512, 1878, 4872, 62, 2545...
2.023999
6,667
import json from btse_futures.constants import OrderType, Side, TimeInForce
[ 11748, 33918, 198, 198, 6738, 275, 83, 325, 62, 69, 315, 942, 13, 9979, 1187, 1330, 8284, 6030, 11, 12075, 11, 3862, 818, 10292, 628, 628 ]
3.076923
26
"""Simple mock responses definitions.""" from blinkpy.helpers.util import BlinkURLHandler import blinkpy.helpers.constants as const LOGIN_RESPONSE = { 'region': {'mock': 'Test'}, 'networks': { '1234': {'name': 'test', 'onboarded': True} }, 'authtoken': {'authtoken': 'foobar123', 'message': 'auth'} } def mocked_session_send(*args, **kwargs): """Mock session.""" prepped = args[0] url = prepped.url header = prepped.headers method = prepped.method if method == 'GET': expected_token = LOGIN_RESPONSE['authtoken']['authtoken'] if header['TOKEN_AUTH'] != expected_token: response = {'message': 'Not Authorized', 'code': 400} status = 400 elif url == 'use_bad_response': response = {'foo': 'bar'} status = 200 elif url == 'reauth': response = {'message': 'REAUTH', 'code': 777} status = 777 else: response = {'test': 'foo'} status = 200 elif method == 'POST': if url in (const.LOGIN_URL, const.LOGIN_BACKUP_URL): response = LOGIN_RESPONSE status = 200 elif url == 'http://wrong.url/' or url is None: response = {'message': 'Error', 'code': 404} status = 404 else: response = {'message': 'foo', 'code': 200} status = 200 return MockResponse(response, status)
[ 37811, 26437, 15290, 9109, 17336, 526, 15931, 198, 198, 6738, 21019, 9078, 13, 16794, 364, 13, 22602, 1330, 41732, 21886, 25060, 198, 11748, 21019, 9078, 13, 16794, 364, 13, 9979, 1187, 355, 1500, 198, 198, 25294, 1268, 62, 19535, 47, 1...
2.180451
665
from astropy import coordinates as coord from astropy import wcs from astropy.io import fits from astropy import units as u from misc import bcolors import numpy as np import os def convert_hms_dd(RA, DEC): ''' Convert HMS to DD system ''' if (':' in RA) and (':' in DEC): Coord_dd = coord.SkyCoord(RA, DEC, unit=(u.hour,u.degree), frame='icrs') RA_dd = Coord_dd.ra.deg Dec_dd = Coord_dd.dec.deg elif (not (':' in RA) and not (':' in DEC)) and (('.' in RA) and ('.' in DEC)): RA_dd, Dec_dd = float(RA), float(DEC) else: print(bcolors.FAIL + 'Coordinates have wrong format.' + bcolors.ENDC) sys.exit() return RA_dd, Dec_dd def get_header(FILE, KEYWORD): ''' Get keyword from fits file ''' header = fits.getheader(FILE) return header[KEYWORD] def pix2arcsec(FITS): ''' Get pixel scale ''' hdu = fits.open(FITS) if len(hdu) > 1: header = fits.getheader(FITS, 0) header += fits.getheader(FITS, 1) else: header = fits.getheader(FITS) hdu_wcs = wcs.WCS(header) return np.median(wcs.utils.proj_plane_pixel_scales(hdu_wcs)) * 3600 def sky2xy (FITS, RA=False, DEC=False, CAT=None): ''' Coordinate transformation: sky -> xy ''' if CAT == None: if RA != False and DEC != False: cmd=('sky2xy %s %s %s | grep -v off' %(FITS, RA, DEC)) program_call = os.popen(cmd) xy = [] for line in program_call: xy=np.array(line.strip().split()[-2:]).astype(float) if len(xy) > 0: return xy else: cmd =("more %s | awk '{print $1,$2}' > %s" %(CAT, CAT.replace(CAT.split('.')[-1], 'reg'))) os.system(cmd) cmd = ("sky2xy %s @%s | grep -v off | awk '{print $5, $6}'" %(FITS, CAT.replace(CAT.split('.')[-1], 'reg'))) cat = os.popen(cmd) xy = [] for line in cat: xy.append(list(map(float, line.replace('\n', '').split()))) return np.array(xy) def xy2sky (FITSFILE,X,Y): ''' Coordinate transformation: xy -> sky ''' program_call = os.popen('xy2sky %s %s %s' %(FITSFILE, X, Y)) sky = [] for line in program_call: sky.append(line.strip().split()[:2]) return sky
[ 6738, 220, 197, 459, 28338, 1330, 22715, 355, 6349, 198, 6738, 220, 197, 459, 28338, 1330, 266, 6359, 198, 6738, 220, 197, 459, 28338, 13, 952, 1330, 11414, 198, 6738, 220, 197, 459, 28338, 1330, 4991, 355, 334, 198, 6738, 220, 197, ...
2.213749
931
import argparse import torch import torch.nn as nn import torchvision import torchvision.transforms as transforms from n3ml.model import DynamicModel_STBP_SNN if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--data', default='data') parser.add_argument('--batch_size', default=100, type=int) parser.add_argument('--num_steps', default=15, type=int) parser.add_argument('--pretrained', default='pretrained/stbp_dynamic_acc_9897.pt') app(parser.parse_args())
[ 11748, 1822, 29572, 198, 198, 11748, 28034, 198, 11748, 28034, 13, 20471, 355, 299, 77, 198, 11748, 28034, 10178, 198, 11748, 28034, 10178, 13, 7645, 23914, 355, 31408, 198, 198, 6738, 299, 18, 4029, 13, 19849, 1330, 26977, 17633, 62, 2...
2.921788
179
# If you're new to file handling, be sure to check out with_open.py first! # You'll also want to check out read_text.py before this example. This one is a bit more advanced. with open('read_csv.csv', 'r') as states_file: # Instead of leaving the file contents as a string, we're splitting the file into a list at every new line, and we save that list into the variable states states = states_file.read().split("\n") # Since this is a spreadsheet in comma separated values (CSV) format, we can think of states as a list of rows. # But we'll need to split the columns into a list as well! for index, state in enumerate(states): states[index] = state.split(",") # Now we have a nested list with all of the information! # Our file looks like this: # State, Population Estimate, Percent of Total population # California, 38332521, 11.91% # Texas, 26448193, 8.04% # ... # Our header row is at state[0], so we can use that to display the information in a prettier way. for state in states[1:]: # We use [1:] so we skip the header row. # state[0] is the first column in the row, which contains the name of the state. print("\n---{0}---".format(state[0])) for index, info in enumerate(state[1:]): # We use [1:] so we don't repeat the state name. print("{0}:\t{1}".format(states[0][index+1], info)) # states is the full list of all of the states. It's a nested list. The outer list contains the rows, each inner list contains the columns in that row. # states[0] refers to the header row of the list # So states[0][0] would refer to "State", states[0][1] would refer to "Population Estimate", and states[0][2] would refer to "Percent of total population" # state is one state within states. state is also a list, containing the name, population, and percentage of that particular state. # So the first time through the loop, state[0] would refer to "California", state[1] would refer to 38332521, and state[2] would refer to 11.91% # Since state is being create by the for loop in line 24, it gets a new value each time through. # We're using enumerate to get the index (slicing number) of the column we're on, along with the information. # That way we can pair the column name with the information, as shown in line 30. # NOTE: Since we're slicing from [1:] in line 29, we need to increase the index by + 1, otherwise our headers will be off by one. # Sample output: # ---"California"--- # "Population Estimate": 38332521 # "Percent of Total population": "11.91%" # ---"Texas"--- # "Population Estimate": 26448193 # "Percent of Total population": "8.04%" # ---"New York"--- # "Population Estimate": 19651127 # "Percent of Total population": "6.19%"
[ 2, 1002, 345, 821, 649, 284, 2393, 9041, 11, 307, 1654, 284, 2198, 503, 351, 62, 9654, 13, 9078, 717, 0, 198, 2, 921, 1183, 635, 765, 284, 2198, 503, 1100, 62, 5239, 13, 9078, 878, 428, 1672, 13, 220, 770, 530, 318, 257, 1643, ...
3.251179
848
import math from torch.optim.lr_scheduler import _LRScheduler from torch.optim.optimizer import Optimizer func_zoo = { "cosine_decay": lambda epoch, step, len_epoch, total_epoch: 0.5 * (math.cos(step * math.pi / (total_epoch * len_epoch)) + 1) }
[ 11748, 10688, 198, 198, 6738, 28034, 13, 40085, 13, 14050, 62, 1416, 704, 18173, 1330, 4808, 43, 6998, 1740, 18173, 198, 6738, 28034, 13, 40085, 13, 40085, 7509, 1330, 30011, 7509, 628, 198, 198, 20786, 62, 89, 2238, 796, 1391, 198, 2...
2.539216
102
from .dataset import load_data
[ 6738, 764, 19608, 292, 316, 1330, 3440, 62, 7890 ]
3.333333
9
import json import logging logger = logging.getLogger(__name__) with open('configuration.json') as f: config = json.load(f) TELEGRAM_TOKEN = config["telegram-bot-token"] NOTION_TOKEN = config["notion-token"] NOTION_TABLE_URL = config["inbox_table"]["table_url"] def check_allowed_user(user_id): """ check if allowed user :param user_id: telegram user id :return True if user is valid , False otherwise """ valid_user = config["allowed_user_id"] user_id = str(user_id) return user_id == valid_user def restrict_action(handled_action): """ Wrapper for creating a private bot :param handled_action: the action to perform """ return check_private
[ 11748, 33918, 198, 11748, 18931, 198, 198, 6404, 1362, 796, 18931, 13, 1136, 11187, 1362, 7, 834, 3672, 834, 8, 198, 198, 4480, 1280, 10786, 11250, 3924, 13, 17752, 11537, 355, 277, 25, 198, 220, 220, 220, 4566, 796, 33918, 13, 2220, ...
2.772549
255
#------------------------------------------------------------------------------ # Copyright (c) 2013-2018, Nucleic Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file COPYING.txt, distributed with this software. #------------------------------------------------------------------------------ from ...compat import USE_WORDCODE if USE_WORDCODE: from .wbyteplay import * else: from .byteplay3 import *
[ 2, 10097, 26171, 198, 2, 15069, 357, 66, 8, 2211, 12, 7908, 11, 399, 14913, 291, 7712, 4816, 13, 198, 2, 198, 2, 4307, 6169, 739, 262, 2846, 286, 262, 40499, 347, 10305, 13789, 13, 198, 2, 198, 2, 383, 1336, 5964, 318, 287, 262,...
4.45283
106
from time import time from typing import Type, TypeVar, MutableMapping, Any, Iterable, Generator, Union import arrow import datetime import math from datapipelines import DataSource, PipelineContext, Query, NotFoundError, validate_query from .common import RiotAPIService, APINotFoundError from ...data import Platform, Season, Queue, SEASON_IDS, QUEUE_IDS from ...dto.match import MatchDto, MatchListDto, TimelineDto from ..uniquekeys import convert_region_to_platform T = TypeVar("T")
[ 6738, 640, 1330, 640, 198, 6738, 19720, 1330, 5994, 11, 5994, 19852, 11, 13859, 540, 44, 5912, 11, 4377, 11, 40806, 540, 11, 35986, 11, 4479, 198, 11748, 15452, 198, 11748, 4818, 8079, 198, 11748, 10688, 198, 198, 6738, 4818, 499, 541...
3.464789
142
""" This caching is very important for speed and memory optimizations. There's nothing really spectacular, just some decorators. The following cache types are available: - module caching (`load_parser` and `save_parser`), which uses pickle and is really important to assure low load times of modules like ``numpy``. - ``time_cache`` can be used to cache something for just a limited time span, which can be useful if there's user interaction and the user cannot react faster than a certain time. This module is one of the reasons why |jedi| is not thread-safe. As you can see there are global variables, which are holding the cache information. Some of these variables are being cleaned after every API usage. """ import time import os import sys import json import hashlib import gc import inspect import shutil import re try: import cPickle as pickle except ImportError: import pickle from jedi import settings from jedi import common from jedi import debug _time_caches = {} # for fast_parser, should not be deleted parser_cache = {} def clear_time_caches(delete_all=False): """ Jedi caches many things, that should be completed after each completion finishes. :param delete_all: Deletes also the cache that is normally not deleted, like parser cache, which is important for faster parsing. """ global _time_caches if delete_all: for cache in _time_caches.values(): cache.clear() parser_cache.clear() else: # normally just kill the expired entries, not all for tc in _time_caches.values(): # check time_cache for expired entries for key, (t, value) in list(tc.items()): if t < time.time(): # delete expired entries del tc[key] def time_cache(time_add_setting): """ s This decorator works as follows: Call it with a setting and after that use the function with a callable that returns the key. But: This function is only called if the key is not available. After a certain amount of time (`time_add_setting`) the cache is invalid. """ return _temp def underscore_memoization(func): """ Decorator for methods:: class A(object): def x(self): if self._x: self._x = 10 return self._x Becomes:: class A(object): @underscore_memoization def x(self): return 10 A now has an attribute ``_x`` written by this decorator. """ name = '_' + func.__name__ return wrapper def memoize_method(method): """A normal memoize function.""" return wrapper def memoize_function(obj): """ A normal memoize function for memoizing free functions. """ cache = obj.cache = {} return memoizer def _invalidate_star_import_cache_module(module, only_main=False): """ Important if some new modules are being reparsed """ try: t, modules = _time_caches['star_import_cache_validity'][module] except KeyError: pass else: del _time_caches['star_import_cache_validity'][module] def invalidate_star_import_cache(path): """On success returns True.""" try: parser_cache_item = parser_cache[path] except KeyError: pass else: _invalidate_star_import_cache_module(parser_cache_item.parser.module) def load_parser(path): """ Returns the module or None, if it fails. """ p_time = os.path.getmtime(path) if path else None try: parser_cache_item = parser_cache[path] if not path or p_time <= parser_cache_item.change_time: return parser_cache_item.parser else: # In case there is already a module cached and this module # has to be reparsed, we also need to invalidate the import # caches. _invalidate_star_import_cache_module(parser_cache_item.parser.module) except KeyError: if settings.use_filesystem_cache: return ParserPickling.load_parser(path, p_time) # is a singleton ParserPickling = ParserPickling()
[ 37811, 198, 1212, 40918, 318, 845, 1593, 329, 2866, 290, 4088, 41446, 13, 1318, 338, 198, 22366, 1107, 15013, 11, 655, 617, 11705, 2024, 13, 383, 1708, 12940, 3858, 389, 198, 15182, 25, 198, 198, 12, 8265, 40918, 357, 63, 2220, 62, ...
2.681206
1,559
#!/usr/bin/env python # # Software License Agreement (Apache License) # # Copyright 2013 Open Source Robotics Foundation # Author: Morgan Quigley # # 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 roslib; roslib.load_manifest('sandia_hand_teleop') import rospy import sys from sandia_hand_msgs.srv import SimpleGraspSrv, SimpleGraspSrvResponse, SimpleGraspWithSlew, SimpleGraspWithSlewResponse from sandia_hand_msgs.msg import SimpleGrasp from osrf_msgs.msg import JointCommands g_jc_pub = None g_jc = JointCommands() g_prev_jc_target = JointCommands() if __name__ == '__main__': rospy.init_node('simple_grasp') g_jc.name = ["f0_j0", "f0_j1", "f0_j2", "f1_j0", "f1_j1", "f1_j2", "f2_j0", "f2_j1", "f2_j2", "f3_j0", "f3_j1", "f3_j2"] g_jc.position = [0] * 12 g_prev_jc_target.position = [0] * 12 g_jc_pub = rospy.Publisher('joint_commands', JointCommands, queue_size=1) # same namespace g_jc_srv = rospy.Service('simple_grasp', SimpleGraspSrv, grasp_srv) g_sgws_srv = rospy.Service('simple_grasp_with_slew', SimpleGraspWithSlew, grasp_slew_srv) g_jc_sub = rospy.Subscriber('simple_grasp', SimpleGrasp, grasp_cb) print "simple grasp service is now running." rospy.spin()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 198, 2, 10442, 13789, 12729, 357, 25189, 4891, 13789, 8, 198, 2, 198, 2, 15069, 2211, 4946, 8090, 47061, 5693, 198, 2, 6434, 25, 10805, 2264, 328, 1636, 198, 2, 198, 2, 49962, 7...
2.613534
665
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'PrestamoDeLibros.ui' # # Created by: PyQt4 UI code generator 4.11.4 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: try: _encoding = QtGui.QApplication.UnicodeUTF8 except AttributeError: if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) Form = QtGui.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_())
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 2, 5178, 7822, 7560, 422, 3555, 334, 72, 2393, 705, 47, 2118, 18811, 5005, 25835, 4951, 13, 9019, 6, 198, 2, 198, 2, 15622, 416, 25, 9485, 48, 83, 19, 12454, ...
2.405858
239
############################################################################## # # Copyright (c) 2002 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Content Type convenience lookup functions.""" from zope.interface import provider from zope.interface import providedBy from zope.schema.interfaces import IVocabularyFactory from zope.app.content.interfaces import IContentType from zope.componentvocabulary.vocabulary import UtilityVocabulary from zope.security.proxy import removeSecurityProxy def queryType(object, interface): """Returns the object's interface which implements interface. >>> from zope.interface import Interface >>> class IContentType(Interface): ... pass >>> from zope.interface import Interface, implementer, directlyProvides >>> class I(Interface): ... pass >>> class J(Interface): ... pass >>> directlyProvides(I, IContentType) >>> @implementer(I) ... class C(object): ... pass >>> @implementer(J, I) ... class D(object): ... pass >>> obj = C() >>> c1_ctype = queryType(obj, IContentType) >>> c1_ctype.__name__ 'I' >>> class I1(I): ... pass >>> class I2(I1): ... pass >>> class I3(Interface): ... pass >>> @implementer(I1) ... class C1(object): ... pass >>> obj1 = C1() >>> c1_ctype = queryType(obj1, IContentType) >>> c1_ctype.__name__ 'I' >>> @implementer(I2) ... class C2(object): ... pass >>> obj2 = C2() >>> c2_ctype = queryType(obj2, IContentType) >>> c2_ctype.__name__ 'I' >>> @implementer(I3) ... class C3(object): ... pass >>> obj3 = C3() If Interface doesn't provide `IContentType`, `queryType` returns ``None``. >>> c3_ctype = queryType(obj3, IContentType) >>> c3_ctype >>> c3_ctype is None True >>> class I4(I): ... pass >>> directlyProvides(I4, IContentType) >>> @implementer(I4) ... class C4(object): ... pass >>> obj4 = C4() >>> c4_ctype = queryType(obj4, IContentType) >>> c4_ctype.__name__ 'I4' """ # Remove the security proxy, so that we can introspect the type of the # object's interfaces. naked = removeSecurityProxy(object) object_iro = providedBy(naked).__iro__ for iface in object_iro: if interface.providedBy(iface): return iface return None def queryContentType(object): """Returns the interface implemented by object which implements :class:`zope.app.content.interfaces.IContentType`. >>> from zope.interface import Interface, implementer, directlyProvides >>> class I(Interface): ... pass >>> directlyProvides(I, IContentType) >>> @implementer(I) ... class C(object): ... pass >>> obj = C() >>> c1_ctype = queryContentType(obj) >>> c1_ctype.__name__ 'I' """ return queryType(object, IContentType)
[ 29113, 29113, 7804, 4242, 2235, 198, 2, 198, 2, 15069, 357, 66, 8, 6244, 1168, 3008, 5693, 290, 25767, 669, 13, 198, 2, 1439, 6923, 33876, 13, 198, 2, 198, 2, 770, 3788, 318, 2426, 284, 262, 8617, 286, 262, 1168, 3008, 5094, 13789...
2.724626
1,271
#!/usr/bin/env python3 # encoding: utf-8 # # Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. # # This file is part of ewm-cloud-robotics # (see https://github.com/SAP/ewm-cloud-robotics). # # This file is licensed under the Apache Software License, v. 2 except as noted # otherwise in the LICENSE file (https://github.com/SAP/ewm-cloud-robotics/blob/master/LICENSE) # """Run the SAP EWM robot configurator.""" import sys import signal import traceback import logging import time from robcoewmrobotconfigurator.ewm_robot_sync import EWMRobotSync from robcoewmrobotconfigurator.robotconfigcontroller import RobotConfigurationController from robcoewmrobotconfigurator.robco_robot_api import RobCoRobotAPI _LOGGER = logging.getLogger(__name__) def run_robotconfigurator(): """Run one instance of the robot configurator.""" # Register handler to control main loop loop_control = MainLoopController() # Create CR watcher instances k8s_rb = RobCoRobotAPI() k8s_rc = RobotConfigurationController() # Create EWM robot syncer instance robotsync = EWMRobotSync(k8s_rc) # Register callback functions k8s_rb.register_callback('ConfigurationController', ['ADDED'], k8s_rc.robco_robot_cb) k8s_rc.register_callback( 'EWMRobotSync', ['ADDED', 'MODIFIED', 'REPROCESS'], robotsync.robotconfiguration_cb) # Start k8s_rb.run() k8s_rc.run(reprocess=True) _LOGGER.info('SAP EWM Robot Configurator started') try: # Looping while K8S watchers are running while loop_control.shutdown is False: # Refresh bearer token when using OAuth if robotsync.odataconfig.authorization == robotsync.odataconfig.AUTH_OAUTH: robotsync.odatahandler.refresh_access_token() # Check if K8S CR handler exception occured for k, exc in k8s_rb.thread_exceptions.items(): _LOGGER.error( 'Uncovered exception in "%s" thread of RobCoRobotAPI. Raising it in main ' 'thread', k) raise exc for k, exc in k8s_rc.thread_exceptions.items(): _LOGGER.error( 'Uncovered exception in "%s" thread of RobotConfigurationController. Raising ' 'it in main thread', k) raise exc # Sleep maximum 1.0 second loop_control.sleep(1.0) except KeyboardInterrupt: _LOGGER.info('Keyboard interrupt - terminating') except SystemExit: _LOGGER.info('System exit - terminating') finally: # Stop K8S CR watchers _LOGGER.info('Stopping K8S CR watchers') k8s_rb.stop_watcher() k8s_rc.stop_watcher() # Shutdown threadpool executor robotsync.executor.shutdown() if __name__ == '__main__': # Create root logger if running as main program ROOT_LOGGER = logging.getLogger() ROOT_LOGGER.setLevel(logging.INFO) # Create console handler and set level to info CH = logging.StreamHandler() CH.setLevel(logging.INFO) # Create formatter FORMATTER = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') # Add formatter to ch CH.setFormatter(FORMATTER) # Add ch to logger ROOT_LOGGER.addHandler(CH) # Run robot master try: run_robotconfigurator() except Exception: # pylint: disable=broad-except EXC_INFO = sys.exc_info() _LOGGER.critical( 'Unexpected error "%s" - "%s" - TRACEBACK: %s', EXC_INFO[0], EXC_INFO[1], traceback.format_exception(*EXC_INFO)) sys.exit('Application terminated with exception: "{}" - "{}"'.format( EXC_INFO[0], EXC_INFO[1]))
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 21004, 25, 3384, 69, 12, 23, 198, 2, 198, 2, 15069, 357, 66, 8, 13130, 48323, 7946, 393, 281, 48323, 17375, 1664, 13, 1439, 2489, 10395, 13, 198, 2, 198, 2, 770, 2393, 318...
2.401535
1,564
from . import config, widget # noqa
[ 6738, 764, 1330, 4566, 11, 26295, 220, 1303, 645, 20402, 198 ]
3.363636
11
from hwtest.shell_utils import run_command def test_linux_usb3hub(): """ Test for Linux Foundation 3.0 root hub in `lsusb` output """ resp = run_command(["lsusb"]) assert "1d6b:0003" in resp
[ 6738, 289, 86, 9288, 13, 29149, 62, 26791, 1330, 1057, 62, 21812, 628, 198, 4299, 1332, 62, 23289, 62, 43319, 18, 40140, 33529, 198, 220, 220, 220, 37227, 198, 220, 220, 220, 6208, 329, 7020, 5693, 513, 13, 15, 6808, 12575, 287, 460...
2.559524
84
# Copyright 2012-2014 The Meson development team # 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 backends import environment, mesonlib import build import mlog import dependencies from mesonlib import File from meson_install import InstallData from build import InvalidArguments from coredata import MesonException import os, sys, pickle, re import subprocess, shutil if mesonlib.is_windows(): quote_char = '"' execute_wrapper = 'cmd /c' else: quote_char = "'" execute_wrapper = ''
[ 2, 15069, 2321, 12, 4967, 383, 14937, 261, 2478, 1074, 198, 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, 13, ...
3.617329
277
"""Tests of cputime.py """ import unittest from reversi.strategies.common import CPU_TIME
[ 37811, 51, 3558, 286, 269, 1996, 524, 13, 9078, 198, 37811, 198, 198, 11748, 555, 715, 395, 198, 198, 6738, 10372, 72, 13, 2536, 2397, 444, 13, 11321, 1330, 9135, 62, 34694, 628 ]
2.818182
33
# -*- coding: utf-8 -*- """ReNS experiments - CIFAR10 Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1byZ4xTfCK2x1Rhkxpl-Vv4sqA-bo4bis # SETUP """ #@title Insatlling Pyorch # !pip install torch # !pip install torchvision #@title Import Dependencies import numpy as np import torch import torch.nn as nn import torchvision.datasets as dsets import torchvision.transforms as transforms from torch.autograd import Variable from tqdm import tqdm from typing import Optional, Union, Tuple, List, Sequence, Iterable import math from scipy.spatial.distance import euclidean from torch.nn.modules.utils import _pair from torchvision import models from sklearn.metrics import jaccard_score import matplotlib.pyplot as plt from models.models import RegularAutoEncoder, ModulatedAutoEncoder, PseudoRecAutoEncoder """# TRAINING""" batch_size = 32 num_epochs = 5 transform = transforms.Compose( [transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))]) # Load MNIST data. train_data = dsets.CIFAR10(root = './data', train = True, transform = transform, download = True) test_data = dsets.CIFAR10(root = './data', train = False, transform = transform) train_gen = torch.utils.data.DataLoader(dataset = train_data, batch_size = batch_size, shuffle = True) test_gen = torch.utils.data.DataLoader(dataset = test_data, batch_size = batch_size, shuffle = False) reflexor_size = 500 image_size = 32 channels = 3 # net = recurrentLayer(784, 784, 10, 5, 10, 0) net1 = RegularAutoEncoder(channels * image_size ** 2, channels * image_size ** 2, reflexor_size) net2 = ModulatedAutoEncoder(channels * image_size ** 2, channels * image_size ** 2, reflexor_size) net3 = PseudoRecAutoEncoder(channels * image_size ** 2, channels * image_size ** 2, reflexor_size) lr = .0001 # size of step loss_function = nn.MSELoss() # Unnormalize the image to display it # Commented out IPython magic to ensure Python compatibility. train_losses = [[],[],[]] test_losses = [[],[],[]] real_imgs = [[],[],[]] reconstructed_imgs = [[],[],[]] param_counts = np.ones(3) steps = [[],[],[]] for num, net in enumerate([net1, net2, net3]): optimizer = torch.optim.Adam( net.parameters(), lr=lr) param_counts[num] = (sum(p.numel() for p in net.parameters() if p.requires_grad)) for epoch in range(num_epochs): for i ,(images,labels) in enumerate(train_gen): #images = Variable(images.view(-1,28*28)) labels = Variable(images.view(-1,3 * image_size ** 2)) optimizer.zero_grad() outputs = net(images) loss = loss_function(outputs, labels) loss.backward() optimizer.step() if (i+1) % 300 == 0: temp_loss = loss.item() print('Epoch [%d/%d], Step [%d/%d], Loss: %.4f' %(epoch+1, num_epochs, i+1, len(train_data)//batch_size, temp_loss)) dupe = Variable(outputs[0].data, requires_grad=False) # plt.imshow(img_fix(images[0])) # plt.show() # plt.imshow(img_fix(dupe.view(3, image_size, image_size))) # plt.show() train_losses[num].append(temp_loss) steps[num].append((50000 * epoch) + ((i + 1) * batch_size)) real_imgs[num].append(img_fix(images[0])) reconstructed_imgs[num].append(img_fix(dupe.view(3, image_size, image_size))) # Test Data score = 0 total = 0 for images,labels in test_gen: #images = Variable(images.view(-1,784)) output = net(images) score += loss_function(output, images.view(-1, 3 * image_size ** 2)).item() test_losses[num].append((score)) plt.plot(steps[0], train_losses[0], label= "Baseline") plt.plot(steps[1], train_losses[1], label= "Modulated") plt.plot(steps[2], train_losses[2], label= "Recurrent with Modulation") plt.xlabel('Iteration') plt.ylabel('Loss') plt.title('Training loss history') plt.legend() plt.show() plt.plot(steps[0], test_losses[0], label= "Baseline") plt.plot(steps[1], test_losses[1], label= "Modulated") plt.plot(steps[2], test_losses[2], label= "Recurrent with Modulation") plt.xlabel('Iteration') plt.ylabel('Loss') plt.title('Testing loss history') plt.legend() plt.show() for num,count in enumerate(param_counts): param_counts[num] /= 1000 plt.bar(["Base", "Modulated", "ReNS"], param_counts) plt.xlabel('Model') plt.ylabel('# of thousands of Parameters') plt.show() from mpl_toolkits.axes_grid1 import ImageGrid num_smaples = len(real_imgs[0]) for num in [0,1,2]: fig = plt.figure(figsize=(20.,20.)) grid = ImageGrid(fig, 111, # similar to subplot(111) nrows_ncols=(2, num_smaples), # creates 2x2 grid of axes axes_pad=0.1, # pad between axes in inch. ) for ax, im in zip(grid, real_imgs[num]+reconstructed_imgs[num]): # Iterating over the grid returns the Axes. ax.imshow(im) ax.axis("off") plt.show()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 3041, 8035, 10256, 532, 327, 5064, 1503, 940, 198, 198, 38062, 4142, 7560, 416, 1623, 4820, 2870, 13, 198, 198, 20556, 2393, 318, 5140, 379, 198, 220, 220, 220, ...
2.320772
2,229
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2012 Nebula, 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. # FIXME(gabriel): Legacy imports for API compatibility. from django.forms import * # noqa from django.forms import widgets # Convenience imports for public API components. from horizon.forms.base import DateForm # noqa from horizon.forms.base import SelfHandlingForm # noqa from horizon.forms.base import SelfHandlingMixin # noqa from horizon.forms.fields import DynamicChoiceField # noqa from horizon.forms.fields import DynamicTypedChoiceField # noqa from horizon.forms.views import ModalFormMixin # noqa from horizon.forms.views import ModalFormView # noqa assert widgets assert SelfHandlingMixin assert SelfHandlingForm assert DateForm assert ModalFormView assert ModalFormMixin assert DynamicTypedChoiceField assert DynamicChoiceField
[ 2, 43907, 25, 7400, 11338, 28, 19, 6482, 10394, 28, 19, 2705, 8658, 11338, 28, 19, 198, 198, 2, 15069, 2321, 46915, 11, 3457, 13, 198, 2, 198, 2, 220, 220, 220, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 3...
3.482587
402
# 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 mock import oslo_messaging as messaging from heat.rpc import api as rpc_api from heat.rpc import listener_client as rpc_client from heat.tests import common
[ 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, 13, 198, 2, 921, 743, 7330, 257, 4866, 286, 262, 13789, 379, 198, 2,...
3.747368
190
from amadeus.client.decorator import Decorator
[ 6738, 716, 671, 385, 13, 16366, 13, 12501, 273, 1352, 1330, 4280, 273, 1352, 628 ]
3.2
15
import py import pytest from iniconfig import IniConfig, ParseError, __all__ as ALL from iniconfig import iscommentline from textwrap import dedent check_tokens = { 'section': ( '[section]', [(0, 'section', None, None)] ), 'value': ( 'value = 1', [(0, None, 'value', '1')] ), 'value in section': ( '[section]\nvalue=1', [(0, 'section', None, None), (1, 'section', 'value', '1')] ), 'value with continuation': ( 'names =\n Alice\n Bob', [(0, None, 'names', 'Alice\nBob')] ), 'value with aligned continuation': ( 'names = Alice\n' ' Bob', [(0, None, 'names', 'Alice\nBob')] ), 'blank line': ( '[section]\n\nvalue=1', [(0, 'section', None, None), (2, 'section', 'value', '1')] ), 'comment': ( '# comment', [] ), 'comment on value': ( 'value = 1', [(0, None, 'value', '1')] ), 'comment on section': ( '[section] #comment', [(0, 'section', None, None)] ), 'comment2': ( '; comment', [] ), 'comment2 on section': ( '[section] ;comment', [(0, 'section', None, None)] ), 'pseudo section syntax in value': ( 'name = value []', [(0, None, 'name', 'value []')] ), 'assignment in value': ( 'value = x = 3', [(0, None, 'value', 'x = 3')] ), 'use of colon for name-values': ( 'name: y', [(0, None, 'name', 'y')] ), 'use of colon without space': ( 'value:y=5', [(0, None, 'value', 'y=5')] ), 'equality gets precedence': ( 'value=xyz:5', [(0, None, 'value', 'xyz:5')] ), } def parse(input): # only for testing purposes - _parse() does not use state except path ini = object.__new__(IniConfig) ini.path = "sample" return ini._parse(input.splitlines(True)) def parse_a_error(input): return py.test.raises(ParseError, parse, input) def test_tokenize(input, expected): parsed = parse(input) assert parsed == expected def test_parse_empty(): parsed = parse("") assert not parsed ini = IniConfig("sample", "") assert not ini.sections def test_ParseError(): e = ParseError("filename", 0, "hello") assert str(e) == "filename:1: hello" def test_continuation_needs_perceeding_token(): excinfo = parse_a_error(' Foo') assert excinfo.value.lineno == 0 def test_continuation_cant_be_after_section(): excinfo = parse_a_error('[section]\n Foo') assert excinfo.value.lineno == 1 def test_section_cant_be_empty(): excinfo = parse_a_error('[]') assert excinfo.value.lineno == 0
[ 11748, 12972, 198, 11748, 12972, 9288, 198, 6738, 287, 4749, 5647, 1330, 554, 72, 16934, 11, 2547, 325, 12331, 11, 11593, 439, 834, 355, 11096, 198, 6738, 287, 4749, 5647, 1330, 318, 23893, 1370, 198, 6738, 2420, 37150, 1330, 4648, 298,...
2.205272
1,252
import os from subprocess import call from . import glob2 pwd = os.path.dirname(__file__) """ handling javajskparser AST """
[ 11748, 28686, 198, 6738, 850, 14681, 1330, 869, 198, 198, 6738, 764, 1330, 15095, 17, 198, 198, 79, 16993, 796, 28686, 13, 6978, 13, 15908, 3672, 7, 834, 7753, 834, 8, 198, 198, 37811, 198, 4993, 1359, 474, 615, 1228, 8135, 48610, 2...
2.782609
46
""" Patches views. | Copyright 2017-2021, Voxel51, Inc. | `voxel51.com <https://voxel51.com/>`_ | """ from copy import deepcopy import eta.core.utils as etau import fiftyone.core.aggregations as foa import fiftyone.core.dataset as fod import fiftyone.core.fields as fof import fiftyone.core.labels as fol import fiftyone.core.media as fom import fiftyone.core.sample as fos import fiftyone.core.view as fov _SINGLE_TYPES_MAP = { fol.Detections: fol.Detection, fol.Polylines: fol.Polyline, } _PATCHES_TYPES = (fol.Detections, fol.Polylines) _NO_MATCH_ID = "" def save(self, fields=None): """Overwrites the object patches in the source dataset with the contents of the view. If this view contains any additional fields that were not extracted from the source dataset, these fields are not saved. .. warning:: This will permanently delete any omitted, filtered, or otherwise modified patches from the source dataset. Args: fields (None): an optional field or list of fields to save. If specified, only these fields are overwritten """ if etau.is_str(fields): fields = [fields] super().save(fields=fields) if fields is None: fields = self._label_fields else: fields = [l for l in fields if l in self._label_fields] # # IMPORTANT: we sync the contents of `_patches_dataset`, not `self` # here because the `save()` call above updated the dataset, which means # this view may no longer have the same contents (e.g., if `skip()` is # involved) # self._sync_source_root(fields) def reload(self): self._root_dataset.reload() # # Regenerate the patches dataset # # This assumes that calling `load_view()` when the current patches # dataset has been deleted will cause a new one to be generated # self._patches_dataset.delete() _view = self._patches_stage.load_view(self._source_collection) self._patches_dataset = _view._patches_dataset def _sync_source_sample(self, sample): for field in self._label_fields: self._sync_source_sample_field(sample, field) class PatchesView(_PatchesView): """A :class:`fiftyone.core.view.DatasetView` of patches from a :class:`fiftyone.core.dataset.Dataset`. Patches views contain an ordered collection of patch samples, each of which contains a subset of a sample of the parent dataset corresponding to a single object or logical grouping of of objects. Patches retrieved from patches views are returned as :class:`PatchView` objects. Args: source_collection: the :class:`fiftyone.core.collections.SampleCollection` from which this view was created patches_stage: the :class:`fiftyone.core.stages.ToPatches` stage that defines how the patches were extracted patches_dataset: the :class:`fiftyone.core.dataset.Dataset` that serves the patches in this view """ _SAMPLE_CLS = PatchView def make_patches_dataset( sample_collection, field, keep_label_lists=False, name=None ): """Creates a dataset that contains one sample per object patch in the specified field of the collection. Fields other than ``field`` and the default sample fields will not be included in the returned dataset. A ``sample_id`` field will be added that records the sample ID from which each patch was taken. Args: sample_collection: a :class:`fiftyone.core.collections.SampleCollection` field: the patches field, which must be of type :class:`fiftyone.core.labels.Detections` or :class:`fiftyone.core.labels.Polylines` keep_label_lists (False): whether to store the patches in label list fields of the same type as the input collection rather than using their single label variants name (None): a name for the returned dataset Returns: a :class:`fiftyone.core.dataset.Dataset` """ if keep_label_lists: field_type = sample_collection._get_label_field_type(field) else: field_type = _get_single_label_field_type(sample_collection, field) dataset = fod.Dataset(name, _patches=True) dataset.media_type = fom.IMAGE dataset.add_sample_field( "sample_id", fof.ObjectIdField, db_field="_sample_id" ) dataset.add_sample_field( field, fof.EmbeddedDocumentField, embedded_doc_type=field_type ) patches_view = _make_patches_view( sample_collection, field, keep_label_lists=keep_label_lists ) _write_samples(dataset, patches_view) return dataset def _get_single_label_field_type(sample_collection, field): label_type = sample_collection._get_label_field_type(field) if label_type not in _SINGLE_TYPES_MAP: raise ValueError("Unsupported label field type %s" % label_type) return _SINGLE_TYPES_MAP[label_type] def make_evaluation_dataset(sample_collection, eval_key, name=None): """Creates a dataset based on the results of the evaluation with the given key that contains one sample for each true positive, false positive, and false negative example in the input collection, respectively. True positive examples will result in samples with both their ground truth and predicted fields populated, while false positive/negative examples will only have one of their corresponding predicted/ground truth fields populated, respectively. If multiple predictions are matched to a ground truth object (e.g., if the evaluation protocol includes a crowd attribute), then all matched predictions will be stored in the single sample along with the ground truth object. The returned dataset will also have top-level ``type`` and ``iou`` fields populated based on the evaluation results for that example, as well as a ``sample_id`` field recording the sample ID of the example, and a ``crowd`` field if the evaluation protocol defines a crowd attribute. .. note:: The returned dataset will contain patches for the contents of the input collection, which may differ from the view on which the ``eval_key`` evaluation was performed. This may exclude some labels that were evaluated and/or include labels that were not evaluated. If you would like to see patches for the exact view on which an evaluation was performed, first call :meth:`load_evaluation_view() <fiftyone.core.collections.SampleCollection.load_evaluation_view>` to load the view and then convert to patches. Args: sample_collection: a :class:`fiftyone.core.collections.SampleCollection` eval_key: an evaluation key that corresponds to the evaluation of ground truth/predicted fields that are of type :class:`fiftyone.core.labels.Detections` or :class:`fiftyone.core.labels.Polylines` name (None): a name for the returned dataset Returns: a :class:`fiftyone.core.dataset.Dataset` """ # Parse evaluation info eval_info = sample_collection.get_evaluation_info(eval_key) pred_field = eval_info.config.pred_field gt_field = eval_info.config.gt_field if hasattr(eval_info.config, "iscrowd"): crowd_attr = eval_info.config.iscrowd else: crowd_attr = None pred_type = sample_collection._get_label_field_type(pred_field) gt_type = sample_collection._get_label_field_type(gt_field) # Setup dataset with correct schema dataset = fod.Dataset(name, _patches=True) dataset.media_type = fom.IMAGE dataset.add_sample_field( pred_field, fof.EmbeddedDocumentField, embedded_doc_type=pred_type ) dataset.add_sample_field( gt_field, fof.EmbeddedDocumentField, embedded_doc_type=gt_type ) dataset.add_sample_field( "sample_id", fof.ObjectIdField, db_field="_sample_id" ) dataset.add_sample_field("type", fof.StringField) dataset.add_sample_field("iou", fof.FloatField) if crowd_attr is not None: dataset.add_sample_field("crowd", fof.BooleanField) # Add ground truth patches gt_view = _make_eval_view( sample_collection, eval_key, gt_field, crowd_attr=crowd_attr ) _write_samples(dataset, gt_view) # Merge matched predictions _merge_matched_labels(dataset, sample_collection, eval_key, pred_field) # Add unmatched predictions unmatched_pred_view = _make_eval_view( sample_collection, eval_key, pred_field, skip_matched=True ) _add_samples(dataset, unmatched_pred_view) return dataset def _make_patches_view(sample_collection, field, keep_label_lists=False): if sample_collection._is_frames: raise ValueError( "Creating patches views into frame views is not yet supported" ) if sample_collection._is_frame_field(field): raise ValueError( "Frame label patches cannot be directly extracted; you must first " "convert your video dataset to frames via `to_frames()`" ) label_type = sample_collection._get_label_field_type(field) if issubclass(label_type, _PATCHES_TYPES): list_field = field + "." + label_type._LABEL_LIST_FIELD else: raise ValueError( "Invalid label field type %s. Extracting patches is only " "supported for the following types: %s" % (label_type, _PATCHES_TYPES) ) pipeline = [ { "$project": { "_id": True, "_sample_id": "$_id", "_media_type": True, "filepath": True, "metadata": True, "tags": True, field + "._cls": True, list_field: True, } }, {"$unwind": "$" + list_field}, {"$set": {"_rand": {"$rand": {}}}}, {"$set": {"_id": "$" + list_field + "._id"}}, ] if keep_label_lists: pipeline.append({"$set": {list_field: ["$" + list_field]}}) else: pipeline.append({"$set": {field: "$" + list_field}}) return sample_collection.mongo(pipeline) def _make_eval_view( sample_collection, eval_key, field, skip_matched=False, crowd_attr=None ): eval_type = field + "." + eval_key eval_id = field + "." + eval_key + "_id" eval_iou = field + "." + eval_key + "_iou" view = _make_patches_view(sample_collection, field) if skip_matched: view = view.mongo( [ { "$match": { "$expr": { "$or": [ {"$eq": ["$" + eval_id, _NO_MATCH_ID]}, {"$not": {"$gt": ["$" + eval_id, None]}}, ] } } } ] ) view = view.mongo( [{"$set": {"type": "$" + eval_type, "iou": "$" + eval_iou}}] ) if crowd_attr is not None: crowd_path1 = "$" + field + "." + crowd_attr # @todo remove Attributes usage crowd_path2 = "$" + field + ".attributes." + crowd_attr + ".value" view = view.mongo( [ { "$set": { "crowd": { "$cond": { "if": {"$gt": [crowd_path1, None]}, "then": {"$toBool": crowd_path1}, "else": { "$cond": { "if": {"$gt": [crowd_path2, None]}, "then": {"$toBool": crowd_path2}, "else": None, } }, } } } } ] ) return _upgrade_labels(view, field) def _upgrade_labels(view, field): tmp_field = "_" + field label_type = view._get_label_field_type(field) return view.mongo( [ {"$set": {tmp_field: "$" + field}}, {"$unset": field}, { "$set": { field: { "_cls": label_type.__name__, label_type._LABEL_LIST_FIELD: ["$" + tmp_field], } } }, {"$unset": tmp_field}, ] ) def _merge_matched_labels(dataset, src_collection, eval_key, field): field_type = src_collection._get_label_field_type(field) list_field = field + "." + field_type._LABEL_LIST_FIELD eval_id = eval_key + "_id" eval_field = list_field + "." + eval_id pipeline = src_collection._pipeline(detach_frames=True) pipeline.extend( [ {"$project": {list_field: True}}, {"$unwind": "$" + list_field}, { "$match": { "$expr": { "$and": [ {"$gt": ["$" + eval_field, None]}, {"$ne": ["$" + eval_field, _NO_MATCH_ID]}, ] } } }, { "$group": { "_id": {"$toObjectId": "$" + eval_field}, "_labels": {"$push": "$" + list_field}, } }, { "$project": { field: { "_cls": field_type.__name__, field_type._LABEL_LIST_FIELD: "$_labels", } }, }, { "$merge": { "into": dataset._sample_collection_name, "on": "_id", "whenMatched": "merge", "whenNotMatched": "discard", } }, ] ) src_collection._dataset._aggregate(pipeline=pipeline, attach_frames=False) def _write_samples(dataset, src_collection): pipeline = src_collection._pipeline(detach_frames=True) pipeline.append({"$out": dataset._sample_collection_name}) src_collection._dataset._aggregate(pipeline=pipeline, attach_frames=False) def _add_samples(dataset, src_collection): pipeline = src_collection._pipeline(detach_frames=True) pipeline.append( { "$merge": { "into": dataset._sample_collection_name, "on": "_id", "whenMatched": "keepExisting", "whenNotMatched": "insert", } } ) src_collection._dataset._aggregate(pipeline=pipeline, attach_frames=False)
[ 37811, 198, 12130, 2052, 5009, 13, 198, 198, 91, 15069, 2177, 12, 1238, 2481, 11, 28035, 417, 4349, 11, 3457, 13, 198, 91, 4600, 85, 1140, 417, 4349, 13, 785, 1279, 5450, 1378, 85, 1140, 417, 4349, 13, 785, 15913, 63, 62, 198, 91,...
2.18028
6,917
#!/usr/bin/env python # -*- coding: utf-8 -*- """The setup script.""" from setuptools import setup, find_packages with open('README.rst') as readme_file: readme = readme_file.read() {%- set license_classifiers = { 'MIT license': 'License :: OSI Approved :: MIT License', 'BSD license': 'License :: OSI Approved :: BSD License', 'ISC license': 'License :: OSI Approved :: ISC License (ISCL)', 'Apache Software License 2.0': 'License :: OSI Approved :: Apache Software License', 'GNU General Public License v3': 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)' } %} # get the dependencies and installs with open(path.join(here, 'requirements.txt'), encoding='utf-8') as f: all_reqs = f.read().split('\n') install_requires = [x.strip() for x in all_reqs if 'git+' not in x] dependency_links = [x.strip().replace('git+', '') for x in all_reqs if x.startswith('git+')] tests_requirements = ['pytest'], setup_requirements = ['pytest-runner'] requirements = [ # package requirements go here ] setup( name='{{ cookiecutter.repo_name }}', version=__version__, description="{{ cookiecutter.project_short_description }}", long_description=readme, author="{{ cookiecutter.full_name.replace('\"', '\\\"') }}", author_email='{{ cookiecutter.email }}', url='https://github.com/{{ cookiecutter.github_username }}/{{ cookiecutter.repo_name }}', packages=find_packages(include=['{{ cookiecutter.repo_name }}'], exclude=('docs', 'tests*',)), {%- if cookiecutter.open_source_license in license_classifiers %} license="{{ cookiecutter.open_source_license }}", {%- endif %} install_requires=install_requires, dependency_links=dependency_links, setup_requires=setup_requirements, test_suite='tests', tests_require=test_requirements, keywords='{{ cookiecutter.repo_name }}', classifiers=[ 'Programming Language :: Python :: 3.6', ] )
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 198, 37811, 464, 9058, 4226, 526, 15931, 198, 198, 6738, 900, 37623, 10141, 1330, 9058, 11, 1064, 62, 43789, 628, 198, ...
2.755587
716
############################################################################## # # Copyright (c) 2002 Zope Foundation and Contributors. # All Rights Reserved. # # This software is subject to the provisions of the Zope Public License, # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # FOR A PARTICULAR PURPOSE. # ############################################################################## """Code to initialize the application server """ from __future__ import print_function __docformat__ = 'restructuredtext' import base64 import time import sys from pdb import Pdb from io import BytesIO from zope.publisher.publish import publish as _publish, debug_call from zope.publisher.browser import TestRequest, setDefaultSkin from zope.app.publication.browser import BrowserPublication from zope.app.appsetup import config, database try: from time import process_time as time_process_time # pragma: PY3 except ImportError: from time import clock as time_process_time # pragma: PY2 try: import urllib.parse as urllib # pragma: PY3 except ImportError: import urllib # pragma: PY2 try: text_type = unicode # pragma: PY2 except NameError: text_type = str # pragma: PY3
[ 29113, 29113, 7804, 4242, 2235, 198, 2, 198, 2, 15069, 357, 66, 8, 6244, 1168, 3008, 5693, 290, 25767, 669, 13, 198, 2, 1439, 6923, 33876, 13, 198, 2, 198, 2, 770, 3788, 318, 2426, 284, 262, 8617, 286, 262, 1168, 3008, 5094, 13789...
3.437055
421
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon May 18 22:42:54 2020 @author: mike """ import numpy as np import tensorflow as tf from tensorflow import keras from sklearn.model_selection import train_test_split from tensorflow.keras.applications import VGG16 from tensorflow.keras import layers from sklearn.preprocessing import OneHotEncoder from skimage.transform import resize import matplotlib.pyplot as plt train_data = np.load("train_data.npy") x_data = np.zeros((210,204,204,3)) y_data = np.zeros(210) for i in range(210): img = train_data[i,1:].reshape(1024,1024) img_resized = resize(img,(204,204)) y_data[i] = train_data[i,0] x_data[i,:,:,0] = img_resized.astype(int) x_data[i,:,:,1] = img_resized.astype(int) x_data[i,:,:,2] = img_resized.astype(int) x_train, x_test, y_train, y_test = train_test_split( x_data, y_data, test_size=0.2, random_state=42) y_train = OneHotEncoder().fit_transform(y_train.reshape(-1,1)).toarray() y_test = OneHotEncoder().fit_transform(y_test.reshape(-1,1)).toarray() base_model = VGG16(include_top=False, weights='vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5', input_shape=(204, 204, 3)) base_model.trainable = False inputs = tf.keras.Input(shape=(204, 204, 3)) x = base_model(inputs) x = tf.keras.layers.Flatten()(x) x = tf.keras.layers.Dense(256, activation='relu')(x) x = tf.keras.layers.Dense(64, activation='relu')(x) outputs = tf.keras.layers.Dense(2, activation='softmax')(x) model = keras.Model(inputs, outputs) model.summary() model.compile(optimizer=tf.keras.optimizers.SGD(learning_rate=0.001),loss="binary_crossentropy",metrics=["accuracy"]) model.fit(x_train, y_train, batch_size=16, epochs=5) pred = model.predict(x_train) score = model.evaluate(x_test, y_test, verbose=0) print(score[0],score[1])
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 37811, 198, 41972, 319, 2892, 1737, 1248, 2534, 25, 3682, 25, 4051, 12131, 198, 198, 31, 9800, 25, 285, 522, 198,...
2.372123
782
#!/usr/bin/python # # Copyright 2018-2020 Polyaxon, 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 pytest from marshmallow.exceptions import ValidationError from tests.utils import BaseTestCase, assert_equal_dict from polyaxon.polyflow.matrix import V1Hyperband from polyaxon.polyflow.optimization import V1Optimization, V1OptimizationMetric
[ 2, 48443, 14629, 14, 8800, 14, 29412, 198, 2, 198, 2, 15069, 2864, 12, 42334, 12280, 897, 261, 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, ...
3.589958
239
studendt1 = Student('James Kaka', '021074', 'M','Amethyst','16', '49') print(studendt1.getName()) studendt1.setName('James Gaga') print(studendt1.getName()) Student.PAUNanthem()
[ 198, 19149, 437, 83, 16, 796, 13613, 10786, 14731, 509, 8130, 3256, 705, 2999, 940, 4524, 3256, 705, 44, 41707, 5840, 44166, 41707, 1433, 3256, 705, 2920, 11537, 198, 4798, 7, 19149, 437, 83, 16, 13, 1136, 5376, 28955, 198, 19149, 437...
2.521127
71
from sqlalchemy.engine import reflection from clickhouse_sqlalchemy import Table, engines
[ 6738, 44161, 282, 26599, 13, 18392, 1330, 14580, 198, 198, 6738, 3904, 4803, 62, 25410, 282, 26599, 1330, 8655, 11, 11874, 628 ]
4.181818
22
""" Unit Tests for the pydisque module. Currently, most of these tests require a fresh instance of Disque to be valid and pass. """ import unittest import json import time import random import six from pydisque.client import Client from redis.exceptions import ResponseError if __name__ == '__main__': unittest.main()
[ 37811, 198, 26453, 30307, 329, 262, 279, 5173, 271, 4188, 8265, 13, 198, 198, 21327, 11, 749, 286, 777, 5254, 2421, 257, 4713, 4554, 286, 198, 7279, 4188, 284, 307, 4938, 290, 1208, 13, 198, 37811, 198, 198, 11748, 555, 715, 395, 19...
3.360825
97
# -*- coding: utf-8 -*- # """*********************************************************************************************""" # FileName [ runner.py ] # Synopsis [ main program that runs the 'Naive Bayes' and 'Decision Tree' training / testing ] # Author [ Ting-Wei Liu (Andi611) ] # Copyright [ Copyleft(c), NTUEE, NTU, Taiwan ] """*********************************************************************************************""" ############### # IMPORTATION # ############### import os import csv import argparse import numpy as np from data_loader import data_loader from classifiers import naive_bayes_runner from classifiers import decision_tree_runner ################## # CONFIGURATIONS # ################## ################## # ERROR HANDLING # ################## ################# # OUTPUT WRITER # ################# ######## # MAIN # ######## """ main function """ if __name__ == '__main__': main()
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 1303, 198, 37811, 17174, 17174, 8412, 4557, 35625, 37811, 198, 2, 220, 220, 9220, 5376, 220, 220, 220, 220, 685, 17490, 13, 9078, 2361, 198, 2, 220, 220, 16065, 24608, 220, ...
3.552239
268
import copy import numpy as np import pybullet as p from igibson.metrics.metric_base import MetricBase
[ 11748, 4866, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 15065, 1616, 355, 279, 198, 198, 6738, 45329, 571, 1559, 13, 4164, 10466, 13, 4164, 1173, 62, 8692, 1330, 3395, 1173, 14881, 628, 198 ]
2.972222
36
import sys from .main import ( _chunk_list, _get_unicode_range_hash, convert_unicode_range, get_120_unicode_ranges, get_unicode_ranges_from_text, generate_css, main, ) __all__ = [ "_chunk_list", "_get_unicode_range_hash", "convert_unicode_range", "get_120_unicode_ranges", "get_unicode_ranges_from_text", "generate_css", "main", ] if __name__ == "__main__": sys.exit(main())
[ 11748, 25064, 198, 6738, 764, 12417, 1330, 357, 198, 220, 220, 220, 4808, 354, 2954, 62, 4868, 11, 198, 220, 220, 220, 4808, 1136, 62, 46903, 1098, 62, 9521, 62, 17831, 11, 198, 220, 220, 220, 10385, 62, 46903, 1098, 62, 9521, 11, ...
2.115942
207
""" This module contains various base dialog base classes that can be used to create custom dialogs for the end user. These classes serve as the basis for the pre-defined static helper methods in the `Messagebox`, and `Querybox` container classes. """ import calendar import textwrap from datetime import datetime from tkinter import font import ttkbootstrap as ttk from ttkbootstrap import utility from ttkbootstrap.icons import Icon from ttkbootstrap.constants import * from tkinter import BaseWidget from ttkbootstrap.localization import MessageCatalog
[ 37811, 198, 220, 220, 220, 770, 8265, 4909, 2972, 2779, 17310, 2779, 6097, 326, 460, 307, 220, 198, 220, 220, 220, 973, 284, 2251, 2183, 17310, 82, 329, 262, 886, 2836, 13, 220, 628, 220, 220, 220, 2312, 6097, 4691, 355, 262, 4308, ...
3.76129
155
# -------------- #Importing header files import pandas as pd import matplotlib.pyplot as plt import seaborn as sns #Code starts here data = pd.read_csv(path) data.hist(['Rating']) data = data[data['Rating']<=5] data.hist(['Rating']) #Code ends here # -------------- # code starts here total_null = data.isnull().sum() percent_null = (total_null/data.isnull().count()) missing_data = pd.concat([total_null,percent_null],keys=['Total','Percent'],axis=1) print(missing_data) data.dropna(inplace=True) total_null_1 = data.isnull().sum() percent_null_1 = (total_null_1/data.isnull().count()) missing_data_1 = pd.concat([total_null_1,percent_null_1],keys=['Total','Percent'],axis=1) print(missing_data_1) # code ends here # -------------- #Code starts here plt.figure(figsize=(10,20)) catplot = sns.catplot(x = "Category", y = "Rating", data=data, kind="box",height=10) catplot.set_xticklabels(rotation=90) plt.title('Rating vs Category [BoxPlot]',size = 20) #Code ends here # -------------- #Importing header files from sklearn.preprocessing import MinMaxScaler, LabelEncoder #Code starts here print(data['Installs']) data['Installs'] = data['Installs'].str.replace('+','') data['Installs'] = data['Installs'].str.replace(',','') data['Installs'] = data['Installs'].astype('int32') le = LabelEncoder() data['Installs'] = le.fit_transform(data['Installs']) graph = sns.regplot(data['Installs'],data['Rating'],data=data) graph.set_title('Rating vs Installs [Boxplot]') plt.show() #Code ends here # -------------- #Code starts here print(data['Price'].value_counts()) data['Price'] = data['Price'].str.replace('$','') data['Price'] = data['Price'].astype('float32') graph2 = sns.regplot(data['Price'],data['Rating'],data=data) graph2.set_title('Rating vs Price [RegPlot]') #Code ends here # -------------- #Code starts here print(len(data['Genres'].unique()), "genres") data['Genres'] = data['Genres'].str.split(';').str[0] gr_mean = data[['Genres','Rating']].groupby(['Genres'],as_index=False).mean() print(gr_mean.describe()) gr_mean=gr_mean.sort_values('Rating') print(gr_mean.head(1)) print(gr_mean.head(1)) #Code ends here # -------------- #Code starts here data['Last Updated'] = pd.to_datetime(data['Last Updated']) data['Last Updated Days'] = (data['Last Updated'].max()-data['Last Updated']).dt.days plt.figure(figsize = (10,10)) sns.regplot(x="Last Updated Days", y="Rating",color='lightpink',data=data) plt.title('Rating vs Last Updated [Regplot]',size =20) #Code ends here
[ 2, 220, 26171, 198, 2, 20939, 278, 13639, 3696, 198, 11748, 19798, 292, 355, 279, 67, 198, 11748, 2603, 29487, 8019, 13, 9078, 29487, 355, 458, 83, 198, 11748, 384, 397, 1211, 355, 3013, 82, 628, 628, 198, 198, 2, 10669, 4940, 994, ...
2.757709
908
import argparse import operator import os import re import shutil import spacy import tempfile from nerds.utils import spans_to_tokens, get_logger def segment_text_to_sentences(text_file, sentence_splitter): """ Segment text into sentences. Text is provided by BRAT in .txt file. Args: text_file (str): the full path to the BRAT .txt file. sentence_splitter (spacy LM): SpaCy EN language model. Returns: sentences (list((int, int, str))): list of sentence spans. Spans are triples of (start_offset, end_offset, text), where offset is relative to the text. """ sentences = [] ftext = open(text_file, "r") for line in ftext: splits = sentence_splitter(line.strip()) for sent in splits.sents: sentences.append((sent.start_char, sent.end_char, sent.text)) ftext.close() return sentences def parse_text_annotations(ann_file): """ Parses BRAT annotations provided in the .ann file and converts them to annotation spans of (start_position, end_position, entity_class). Args: ann_file (str): full path to the BRAT .ann file. Returns: annotations (list((int, int, str))): list of annotation spans. Spans are triples of (start_offset, end_offset, entity_class) where offset is relative to the text. """ annots = [] fann = open(ann_file, "r") for line in fann: cols = re.split(r"\s+", line.strip()) if not cols[0].startswith("T"): continue annots.append((int(cols[2]), int(cols[3]), cols[1])) fann.close() return annots def apply_annotations(sentences, annotations, tokenizer): """ Apply annotation spans to the sentence spans to create a list of tokens and tags. Args: sentences (list((int, int, str))): list of sentence spans. annotations (list((int, int, str))): list of annotation spans. tokenizer (spacy LM): SpaCy EN language model. Returns: tokens_tags_list (list((list(str), list(str)))): list of list of token tag pairs. Each list of token-tag pairs corresponds to a single sentence. """ tokens_tags_list = [] for sent_start, sent_end, sent_text in sentences: sent_annots = [a for a in annotations if a[0] >= sent_start and a[1] <= sent_end] # convert document offsets to sentence offsets sent_annots = [(s[0] - sent_start, s[1] - sent_start, s[2]) for s in sent_annots] tokens, tags = spans_to_tokens(sent_text, sent_annots, tokenizer) tokens_tags_list.append(zip(tokens, tags)) return tokens_tags_list def convert_brat_to_iob(input_dir, output_file, nlp): """ Convenience Convertor function. Args: input_dir (str): the directory where the BRAT .txt and .ann files are located. output_file (str): the full path name of file to write output in IOB format to. nlp (SpaCy LM): reference to the SpaCy EN model. Returns: None. """ fout = open(output_file, "w") for text_file in os.listdir(input_dir): # only process .txt and .ann pairs in specified directory if not text_file.endswith(".txt"): continue annot_file = text_file[:-4] + ".ann" if not os.path.exists(os.path.join(input_dir, annot_file)): # do not process file if no corresponding .ann file continue # process file pair logger.info("Processing file: {:s}".format(text_file)) sentences = segment_text_to_sentences(os.path.join(input_dir, text_file), nlp) annotations = parse_text_annotations(os.path.join(input_dir, annot_file)) tokens_tags_list = apply_annotations(sentences, annotations, nlp) for tokens_tags in tokens_tags_list: for token, tag in tokens_tags: fout.write("{:s}\t{:s}\n".format(token, tag)) fout.write("\n") fout.close() def do_self_test(nlp): """ Simple self-test with small dataset to prove that this works okay. """ text = "Pierre Vinken, 61 years old, will join the board as a nonexecutive director, Nov. 29. Mr. Vinken is chairman of Elsevier N.V., the Dutch publishing group." annotations = [ "T1 PER 0 13 Pierre Vinken", "T2 PER 86 96 Mr. Vinken", "T3 DATE 15 27 61 years old", "T4 DATE 77 84 Nov. 29", "T5 ORG 112 125 Elsevier N.V.", "T6 NORP 131 136 Dutch" ] input_dir = tempfile.mkdtemp(dir="/tmp") ftext = open(os.path.join(input_dir, "test.txt"), "w") ftext.write(text) ftext.close() fann = open(os.path.join(input_dir, "test.ann"), "w") for line in annotations: fann.write(line + "\n") fann.close() output_file = os.path.join(input_dir, "test.iob") convert_brat_to_iob(input_dir, output_file, nlp) fout = open(output_file, "r") for line in fout: logger.warn(line.strip()) shutil.rmtree(input_dir) ################################ main ################################ # # usage: brat2iob.py [-h] [-i INPUT_DIR] [-o OUTPUT_FILE] [-t] # Script to convert BRAT annotations to IOB (NERDS) format. # optional arguments: # -h, --help show this help message and exit # -i INPUT_DIR, --input_dir INPUT_DIR # Directory to store BRAT .txt and .ann files. # -o OUTPUT_FILE, --output_file OUTPUT_FILE # Output file to write IOB output to. # -t, --test Runs self test. ###################################################################### parser = argparse.ArgumentParser( description="Script to convert BRAT annotations to IOB (NERDS) format.") parser.add_argument("-i", "--input_dir", help="Directory to store BRAT .txt and .ann files.") parser.add_argument("-o", "--output_file", help="Output file to write IOB output to.") parser.add_argument("-t", "--test", help="Runs self test.", action="store_true") args = parser.parse_args() logger = get_logger() input_dir = args.input_dir output_file = args.output_file self_test = args.test nlp = spacy.load("en") if self_test: logger.info("Executing self test...") do_self_test(nlp) else: logger.info("Reading BRAT .txt and .ann files from: {:s}".format(input_dir)) logger.info("Writing IOB tokens/tags to file: {:s}".format(output_file)) convert_brat_to_iob(input_dir, output_file, nlp)
[ 11748, 1822, 29572, 198, 11748, 10088, 198, 11748, 28686, 198, 11748, 302, 198, 11748, 4423, 346, 198, 11748, 599, 1590, 198, 11748, 20218, 7753, 198, 198, 6738, 47088, 13, 26791, 1330, 32727, 62, 1462, 62, 83, 482, 641, 11, 651, 62, ...
2.398037
2,751
""" Ocropus's magic PIL-numpy array conversion routines. They express slightly different behavior from PIL.Image.toarray(). """ import unicodedata import numpy as np from PIL import Image __all__ = ['pil2array', 'array2pil'] def is_bitonal(im: Image.Image) -> bool: """ Tests a PIL.Image for bitonality. Args: im (PIL.Image.Image): Image to test Returns: True if the image contains only two different color values. False otherwise. """ return im.getcolors(2) is not None and len(im.getcolors(2)) == 2 def is_printable(char: str) -> bool: """ Determines if a chode point is printable/visible when printed. Args: char (str): Input code point. Returns: True if printable, False otherwise. """ letters = ('LC', 'Ll', 'Lm', 'Lo', 'Lt', 'Lu') numbers = ('Nd', 'Nl', 'No') punctuation = ('Pc', 'Pd', 'Pe', 'Pf', 'Pi', 'Po', 'Ps') symbol = ('Sc', 'Sk', 'Sm', 'So') printable = letters + numbers + punctuation + symbol return unicodedata.category(char) in printable def make_printable(char: str) -> str: """ Takes a Unicode code point and return a printable representation of it. Args: char (str): Input code point Returns: Either the original code point, the name of the code point if it is a combining mark, whitespace etc., or the hex code if it is a control symbol. """ if not char or is_printable(char): return char elif unicodedata.category(char) in ('Cc', 'Cs', 'Co'): return '0x{:x}'.format(ord(char)) else: return unicodedata.name(char)
[ 37811, 198, 46, 31476, 385, 338, 5536, 350, 4146, 12, 77, 32152, 7177, 11315, 31878, 13, 1119, 4911, 4622, 198, 39799, 4069, 422, 350, 4146, 13, 5159, 13, 1462, 18747, 22446, 198, 37811, 198, 11748, 28000, 9043, 1045, 198, 11748, 299, ...
2.528875
658
import sys sys.path.insert(0,'..') from data.whale_data import exchnage_accounts from data.html_helper import check_if_address_name_exists from data.whale_eth_tx_data import * from data.whale_token_tx_data import identify_investor_type_token holding_account = "holding_account" deposit_account = 'deposit_account' withdraw_account = "withdraw_account" in_type = "IN" out_type = "OUT" all_acc_types = dict() for acc in exchnage_accounts: all_acc_types[acc] = exchange_type
[ 11748, 25064, 198, 17597, 13, 6978, 13, 28463, 7, 15, 4032, 492, 11537, 198, 6738, 1366, 13, 1929, 1000, 62, 7890, 1330, 409, 1349, 496, 62, 23317, 82, 198, 6738, 1366, 13, 6494, 62, 2978, 525, 1330, 2198, 62, 361, 62, 21975, 62, ...
2.790698
172
# @Time : 2020/11/14 # @Author : Junyi Li, Gaole He # @Email : lijunyi@ruc.edu.cn # UPDATE: # @Time : 2020/12/2, 2020/11/27, 2020/12/3, 2020/12/26 # @Author : Jinhao Jiang, Xiaoxuan Hu, Tianyi Tang, Jinhao Jiang # @Email : jiangjinhao@std.uestc.edu.cn, huxiaoxuan@ruc.edu.cn, steventang@ruc.edu.cn, jiangjinhao@std.uestc.edu.cn r""" textbox.trainer.trainer ################################ """ import os import torch import torch.optim as optim import numpy as np import matplotlib.pyplot as plt import copy import math from torch.utils.data import DataLoader from time import time from logging import getLogger from textbox.module.Optimizer.optim import ScheduledOptim from textbox.evaluator import NgramEvaluator, TranslationEvaluator, SummarizationEvaluator from textbox.utils import ensure_dir, early_stopping
[ 2, 2488, 7575, 220, 220, 1058, 12131, 14, 1157, 14, 1415, 198, 2, 2488, 13838, 1058, 7653, 48111, 7455, 11, 12822, 2305, 679, 198, 2, 2488, 15333, 220, 1058, 300, 2926, 403, 48111, 31, 622, 66, 13, 15532, 13, 31522, 198, 198, 2, 3...
2.791946
298
from ...models import Persona, Plugin from . import example, example_cache, example_ratelimit, example_with_args plugin = Plugin( name="rsserpent-plugin-builtin", author=Persona( name="queensferryme", link="https://github.com/queensferryme", email="queensferry.me@gmail.com", ), repository="https://github.com/RSSerpent/RSSerpent", prefix="/_", routers={ example.path: example.provider, example_cache.path: example_cache.provider, example_ratelimit.path: example_ratelimit.provider, example_with_args.path: example_with_args.provider, }, ) __all__ = ("plugin",)
[ 6738, 2644, 27530, 1330, 41581, 11, 42636, 198, 6738, 764, 1330, 1672, 11, 1672, 62, 23870, 11, 1672, 62, 4873, 32374, 11, 1672, 62, 4480, 62, 22046, 628, 198, 33803, 796, 42636, 7, 198, 220, 220, 220, 1438, 2625, 42216, 263, 16923, ...
2.48659
261
import pandas as pd # Define our header col_names = [ "year", "num_males_with_income", "male_median_income_curr_dollars", "male_median_income_2019_dollars", "num_females_with_income", "female_median_income_curr_dollars", "female_median_income_2019_dollars", ] # Load Asian census data XLS, skipping all headers dfa = pd.read_excel( r'p08a.xlsx', skiprows=8, # Make sure PD doesn't use header row for our DF header=None, # Define col names names=col_names, ) # Load White census data XLS, skipping all headers dfw = pd.read_excel( r'p08w.xlsx', skiprows=8, # Make sure PD doesn't use header row for our DF header=None, # Define cold names names=col_names ) # Splinter off rows into age group DFs for both sets of data dfa1524 = dfa.iloc[:20] dfa2534 = dfa.iloc[25:45] dfa3544 = dfa.iloc[50:70] dfa4554 = dfa.iloc[75:95] dfa5564 = dfa.iloc[100:120] dfa6574 = dfa.iloc[125:145] dfa75 = dfa.iloc[150:170] dfw1524 = dfw.iloc[:20] dfw2534 = dfw.iloc[25:45] dfw3544 = dfw.iloc[50:70] dfw4554 = dfw.iloc[75:95] dfw5564 = dfw.iloc[100:120] dfw6574 = dfw.iloc[125:145] dfw75 = dfw.iloc[150:170] # Add Age Range col to each DF dfa1524.insert(0, 'age_range', '15-24') dfa2534.insert(0, 'age_range', '25-34') dfa3544.insert(0, 'age_range', '35-44') dfa4554.insert(0, 'age_range', '45-54') dfa5564.insert(0, 'age_range', '55-64') dfa6574.insert(0, 'age_range', '65-74') dfa75.insert(0, 'age_range', 'Over 75') dfw1524.insert(0, 'age_range', '15-24') dfw2534.insert(0, 'age_range', '25-34') dfw3544.insert(0, 'age_range', '35-44') dfw4554.insert(0, 'age_range', '45-54') dfw5564.insert(0, 'age_range', '55-64') dfw6574.insert(0, 'age_range', '65-74') dfw75.insert(0, 'age_range', 'Over 75') # Stack cleaned DF's vertically dfa = pd.concat([ dfa1524, dfa2534, dfa3544, dfa4554, dfa5564, dfa6574, dfa75 ], axis=0) dfw = pd.concat([ dfw1524, dfw2534, dfw3544, dfw4554, dfw5564, dfw6574, dfw75 ], axis=0) # Add Race col dfa.insert(0, 'race', 'asian') dfw.insert(0, 'race', 'white') # Clean garbage chars in Year col using regex dfa['year'] = dfa['year'].replace(to_replace=r'(\s\(\d+\))', value='', regex=True) dfw['year'] = dfw['year'].replace(to_replace=r'(\s\(\d+\))', value='', regex=True) # Stack our cleaned + normalized data into a single DF df = pd.concat([ dfa, dfw ], axis=0) # Convert the DF col types to conform to our CensusRecord model df = df.astype({ "race": str, "age_range": str, "year": int, "num_males_with_income": int, "male_median_income_curr_dollars": float, "male_median_income_2019_dollars": float, "num_females_with_income": int, "female_median_income_curr_dollars": float, "female_median_income_2019_dollars": float, }) # Pickle the DF df.to_pickle("./res.pkl")
[ 11748, 19798, 292, 355, 279, 67, 198, 198, 2, 2896, 500, 674, 13639, 198, 4033, 62, 14933, 796, 685, 198, 220, 220, 220, 366, 1941, 1600, 198, 220, 220, 220, 366, 22510, 62, 76, 2040, 62, 4480, 62, 12519, 1600, 198, 220, 220, 220,...
2.109963
1,355
""" Dany jest cig okrelony wzorem: A[n+1] = (A[n] % 2) (3 A[n] + 1) + (1 A[n] % 2) A[n] / 2. Startujc z dowolnej liczby naturalnej > 1 cig ten osiga warto 1. Napisa program, ktry znajdzie wyraz pocztkowy z przedziau 2-10000 dla ktrego warto 1 jest osigalna po najwikszej liczbie krokw. """ a0 = 2 m = 1 for a0 in range(2, 10000): n = 0 while a0 != 1: a0 = (((a0 % 2) * (3 * a0 + 1)) + ((1 - (a0 % 2)) * (a0 / 2))) n += 1 if n > m: m = n a0 += 1 print(m)
[ 37811, 198, 35, 1092, 474, 395, 8594, 12876, 2411, 1647, 266, 89, 29625, 25, 317, 58, 77, 10, 16, 60, 796, 357, 32, 58, 77, 60, 4064, 362, 8, 220, 357, 18, 220, 317, 58, 77, 60, 1343, 352, 8, 1343, 357, 16, 220, 317, 58, 77,...
1.841328
271
""" ***************************************************************************** * H E A D E R I N F O R M A T I O N * * ***************************************************************************** Project Name: SysPy (System Python) http://cgi.di.uoa.gr/~evlog/syspy.html File Name: _var_declaration.py Created by: Evangelos Logaras ***************************************************************************** * C O P Y R I G H T N O T I C E * * ***************************************************************************** This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License, a copy of which is available from http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***************************************************************************** * D E S C R I P T I O N * * ***************************************************************************** Variable declaration when a variable assignment is tracked. """ from pdb import * def var_declaration(assign_lines_count, token_struct, assign_lines, signals, process_vars): """ FUNCTION: var_declaration(a int, b(), c[], d[], e[]) a: assign lines counter integer b: token's tupple c: list containing the VHDL code d: list containing the signal statements e: list containing Variable declaration when a variable assignment is tracked. """ # Python's variable declerations #---------------------------------------------------------------------------------------------------------------------------------- count0 = 0 count1 = 0 process_vars_d = [] vars0 = [] var0 = '' var1 = '' #---------------------------------------------------------------------------------------------------------------------------------- print("process_vars:", process_vars) # Erasing duplicated registrations in "process_vars[]" #---------------------------------------------------------------------------------------------------------------------------------- for i in range(len(process_vars)): vars0 = [] #flag_process_vars = 0 if ((process_vars[i][0] == "name_left") or (process_vars[i][0] == "name_right")): var0 = process_vars[i][1].replace('=', '') var0 = var0.replace('! ', '') var0 = var0.replace('>', '') var0 = var0.replace('<', '') var0 = var0.replace(' ', '') vars0.append(var0) elif (process_vars[i][0] == "name_right_binary_slice"): var0 = process_vars[i][1][0] vars0.append(var0) elif (process_vars[i][0] == "name_right_binary_slice_var0"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) elif (process_vars[i][0] == "name_right_binary_slice_var1"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][2] vars0.append(var0) elif (process_vars[i][0] == "name_right_binary_slice_var01"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) var0 = process_vars[i][1][2] vars0.append(var0) elif (process_vars[i][0] == "name_right_item"): var0 = process_vars[i][1][0] vars0.append(var0) elif (process_vars[i][0] == "name_right_item_var"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_item"): var0 = process_vars[i][1][0] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_item_var0"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_item_var1"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][2] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_item_var01"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) var0 = process_vars[i][1][2] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_slice"): var0 = process_vars[i][1][0] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_slice_var0"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_slice_var1"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][2] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_slice_var2"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][3] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_slice_var01"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) var0 = process_vars[i][1][2] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_slice_var02"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][1] vars0.append(var0) var0 = process_vars[i][1][3] vars0.append(var0) elif (process_vars[i][0] == "name_right_array_binary_slice_var12"): var0 = process_vars[i][1][0] vars0.append(var0) var0 = process_vars[i][1][2] vars0.append(var0) var0 = process_vars[i][1][3] vars0.append(var0) flag_process_vars = 0 for n in range(0, len(vars0)): for j in range(len(process_vars_d)): if ((process_vars_d[j][0] == "name_left") or (process_vars_d[j][0] == "name_right")): var1 = process_vars_d[j][1].replace('=', '') var1 = var1.replace('! ', '') var1 = var1.replace('>', '') var1 = var1.replace('<', '') var1 = var1.replace(' ', '') elif (process_vars_d[j][0] == "name_right_binary_slice"): var1 = process_vars_d[j][1][0] elif (process_vars_d[j][0] == "name_right_binary_slice_var0"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_binary_slice_var1"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_binary_slice_var01"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_item"): var1 = process_vars_d[j][1][0] elif (process_vars_d[j][0] == "name_right_item_var"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_item"): var1 = process_vars_d[j][1][0] elif (process_vars_d[j][0] == "name_right_array_binary_item_var0"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_item_var1"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_item_var01"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_slice"): var1 = process_vars_d[j][1][0] elif (process_vars_d[j][0] == "name_right_array_binary_slice_var0"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_slice_var1"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_slice_var2"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_slice_var01"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_slice_var02"): var1 = process_vars_d[j][1] elif (process_vars_d[j][0] == "name_right_array_binary_slice_var12"): var1 = process_vars_d[j][1] if (vars0[n] == var1): if (n == 0): flag_process_vars += 1 if (n == 1): flag_process_vars += 2 if (n == 2): flag_process_vars += 4 if ((process_vars[i][0] == "name_left") or (process_vars[i][0] == "name_right")): if (flag_process_vars == 0): process_vars_d.append(process_vars[i]) elif (process_vars[i][0] == "name_right_binary_slice"): if (flag_process_vars == 0): process_vars_d.append(process_vars[i]) elif (process_vars[i][0] == "name_right_binary_slice_var0"): if (flag_process_vars == 0): process_vars_d.append(["name_right_binary_slice_var0", process_vars[i][1][0]]) process_vars_d.append(["name_right_binary_slice_var0", process_vars[i][1][1]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_binary_slice_var0", process_vars[i][1][1]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_binary_slice_var0", process_vars[i][1][0]]) elif (flag_process_vars == 3): pass elif (process_vars[i][0] == "name_right_binary_slice_var1"): if (flag_process_vars == 0): process_vars_d.append(["name_right_binary_slice_var1", process_vars[i][1][0]]) process_vars_d.append(["name_right_binary_slice_var1", process_vars[i][1][2]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_binary_slice_var1", process_vars[i][1][2]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_binary_slice_var1", process_vars[i][1][0]]) elif (flag_process_vars == 4): pass elif (process_vars[i][0] == "name_right_binary_slice_var01"): if (flag_process_vars == 0): process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][1]]) process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][1]]) process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 3): process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 4): process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][1]]) elif (flag_process_vars == 5): process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][1]]) elif (flag_process_vars == 6): process_vars_d.append(["name_right_binary_slice_var01", process_vars[i][1][0]]) elif (flag_process_vars == 7): pass elif (process_vars[i][0] == "name_right_item"): if (flag_process_vars == 0): process_vars_d.append(process_vars[i]) elif (process_vars[i][0] == "name_right_item_var"): if (flag_process_vars == 0): process_vars_d.append(["name_right_item_var", process_vars[i][1][0]]) process_vars_d.append(["name_right_item_var", process_vars[i][1][1]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_item_var", process_vars[i][1][1]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_item_var", process_vars[i][1][0]]) elif (flag_process_vars == 3): pass elif (process_vars[i][0] == "name_right_array_binary_item"): if (flag_process_vars == 0): process_vars_d.append(process_vars[i]) elif (process_vars[i][0] == "name_right_array_binary_item_var0"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_item_var0", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_item_var0", process_vars[i][1][1]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_item_var0", process_vars[i][1][1]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_item_var0", process_vars[i][1][0]]) elif (flag_process_vars == 3): pass elif (process_vars[i][0] == "name_right_array_binary_item_var1"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_item_var1", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_item_var1", process_vars[i][1][2]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_item_var1", process_vars[i][1][2]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_item_var1", process_vars[i][1][0]]) elif (flag_process_vars == 3): pass elif (process_vars[i][0] == "name_right_array_binary_item_var01"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][1]]) process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][2]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][1]]) process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][2]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][2]]) elif (flag_process_vars == 3): process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][2]]) elif (flag_process_vars == 4): process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][1]]) elif (flag_process_vars == 5): process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][1]]) elif (flag_process_vars == 6): process_vars_d.append(["name_right_array_binary_item_var01", process_vars[i][1][0]]) elif (flag_process_vars == 7): pass elif (process_vars[i][0] == "name_right_array_binary_slice"): if (flag_process_vars == 0): process_vars_d.append(process_vars[i]) elif (process_vars[i][0] == "name_right_array_binary_slice_var0"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_slice_var0", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var0", process_vars[i][1][1]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_slice_var0", process_vars[i][1][1]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_slice_var0", process_vars[i][1][0]]) elif (flag_process_vars == 3): pass elif (process_vars[i][0] == "name_right_array_binary_slice_var1"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_slice_var1", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var1", process_vars[i][1][2]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_slice_var1", process_vars[i][1][2]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_slice_var1", process_vars[i][1][0]]) elif (flag_process_vars == 3): pass elif (process_vars[i][0] == "name_right_array_binary_slice_var2"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_slice_var2", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var2", process_vars[i][1][3]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_slice_var2", process_vars[i][1][3]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_slice_var2", process_vars[i][1][0]]) elif (flag_process_vars == 3): pass elif (process_vars[i][0] == "name_right_array_binary_slice_var01"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][1]]) process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][1]]) process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 3): process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][2]]) elif (flag_process_vars == 4): process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][1]]) elif (flag_process_vars == 5): process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][1]]) elif (flag_process_vars == 6): process_vars_d.append(["name_right_array_binary_slice_var01", process_vars[i][1][0]]) elif (flag_process_vars == 7): pass elif (process_vars[i][0] == "name_right_array_binary_slice_var02"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][1]]) process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][3]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][1]]) process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][3]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][3]]) elif (flag_process_vars == 3): process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][3]]) elif (flag_process_vars == 4): process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][1]]) elif (flag_process_vars == 5): process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][1]]) elif (flag_process_vars == 6): process_vars_d.append(["name_right_array_binary_slice_var02", process_vars[i][1][0]]) elif (flag_process_vars == 7): pass elif (process_vars[i][0] == "name_right_array_binary_slice_var12"): if (flag_process_vars == 0): process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][2]]) process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][3]]) elif (flag_process_vars == 1): process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][2]]) process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][3]]) elif (flag_process_vars == 2): process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][3]]) elif (flag_process_vars == 3): process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][3]]) elif (flag_process_vars == 4): process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][0]]) process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][2]]) elif (flag_process_vars == 5): process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][2]]) elif (flag_process_vars == 6): process_vars_d.append(["name_right_array_binary_slice_var12", process_vars[i][1][0]]) elif (flag_process_vars == 7): pass process_vars = process_vars_d #---------------------------------------------------------------------------------------------------------------------------------- j = assign_lines_count for m in range(0, len(process_vars)): if ((process_vars[m][0] == "name_left") or (process_vars[m][0] == "name_right")): t = process_vars[m][1].replace('=', '') t = t.replace(' ', '') elif (process_vars[m][0] == "name_right_binary_slice"): t = process_vars[m][1][0] elif (process_vars[m][0] == "name_right_binary_slice_var0"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_binary_slice_var1"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_binary_slice_var01"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_item"): t = process_vars[m][1][0] elif (process_vars[m][0] == "name_right_item_var"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_item"): t = process_vars[m][1][0] elif (process_vars[m][0] == "name_right_array_binary_item_var0"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_item_var1"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_item_var01"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_slice"): t = process_vars[m][1][0] elif (process_vars[m][0] == "name_right_array_binary_slice_var0"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_slice_var1"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_slice_var2"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_slice_var01"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_slice_var02"): t = process_vars[m][1] elif (process_vars[m][0] == "name_right_array_binary_slice_var12"): t = process_vars[m][1] for i in range (0, len(signals)): if (t == signals[i]['N']): if (signals[i]['D'] == 'v'): L = signals[i]['L'].__doc__ n = signals[i]['N'].__doc__ if (m == 0): sp = '' while 1: if (assign_lines[j][0] == "process_sens_list"): assign_lines[j][0] = assign_lines[j][0] + "_var" for k in range(0, assign_lines[j][4]): sp = sp + ' ' assign_lines[j][1] = assign_lines[j][1].replace("begin", '') assign_lines[j][1] = assign_lines[j][1] + "\n\n" + sp + "-- Variables" assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "-------------------------------------------------------------------" if (signals[i]['T'] == 'b'): if (L.find("int") == 0): if (n.find("list") == 0): for k in range(len(signals_intr[i]['N'])): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": std_logic;\n" elif (signals[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": std_logic := '" + signals[i]['V'] + "';\n" elif (n.find("str") == 0): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": std_logic;\n" elif (signals[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": std_logic := '" + signals[i]['V'] + "';\n" elif (L.find("list") == 0): if (n.find("list") == 0): for k in range(len(signals[i]['N'])): if (signals[i].has_key('V') == False): if (signals[i]['L'][0] > signals[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ");\n" else: assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ");\n" elif (signals[i].has_key('V') == True): if (signals_intr[i]['L'][0] > signals_intr[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ") := \"" + signals[i]['V'] + "\";\n" else: assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ") := '" + signals[i]['V'] + "';\n" elif (n.find("str") == 0): if (signals[i].has_key('V') == False): if (signals[i]['L'][0] > signals[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ");\n" else: assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ");\n" elif (signals[i].has_key('V') == True): if (signals[i]['L'][0] > signals[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ") := \"" + signals[i]['V'] + "\";\n" else: assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ") := '" + signals[i]['V'] + "';\n" break elif (signals[i]['T'] == "int"): if (n.find("str") == 0): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + ";\n" elif (signals[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + " := " + str(signals[i]['V']) + ";\n" elif (n.find("list") == 0): for k in range(len(signals[i]['N'])): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + ";\n" elif (signals_intr[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'][k] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + " := " + str(signals[i]['V']) + ";\n" break elif (signals[i]['T'] == "arrb"): if (n.find("str") == 0): if (signals[i]['L'][1][0] > signals[i]['L'][1][1]): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "type type" + str(count0) + " is array (" + str(signals[i]['L'][0][0]) + " to " + str(signals[i]['L'][0][1]) + ") of std_logic_vector(" + str(signals_intr[i]['L'][1][0]) + " downto " + str(signals_intr[i]['L'][1][1]) + ");\n" elif (signals[i]['L'][1][0] < signals[i]['L'][1][1]): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "type type" + str(count0) + " is array (" + str(signals[i]['L'][0][0]) + " to " + str(signals[i]['L'][0][1]) + ") of std_logic_vector(" + str(signals_intr[i]['L'][1][0]) + " to " + str(signals_intr[i]['L'][1][1]) + ");\n" if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": " + "type" + str(count0) + ";\n" elif (signals[i].has_key('V') == True): v = signals[i]['V'].__doc__ if (v.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": " + "type" + str(count0) + ": \"" + signals[i]['V'] + "\";\n" elif(v.find("list") == 0): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": " + "type" + str(count0) + ": {" for k in range(0, (signals[i]['L'][0][1] + 1)): if (k == signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + "\"" + signals[i]['V'][k] + "\"};\n" elif (k != signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + "\"" + signals[i]['V'][k] + "\", " count0 = count0 + 1 break elif (signals[i]['T'] == "arri"): if (n.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "type type" + str(count0) + " is array (" + str(signals[i]['L'][0][0]) + " to " + str(signals[i]['L'][0][1]) + ") of integer range " + str(signals[i]['L'][1][0]) + " to " + str(signals[i]['L'][1][1]) + ";\n" if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": " + "type" + str(count0) + ";\n" elif (signals[i].has_key('V') == True): v = signals[i]['V'].__doc__ if (v.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": " + "type" + str(count0) + ": " + str(signals[i]['V']) + ";\n" elif(v.find("list") == 0): assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "variable " + signals[i]['N'] + ": " + "type" + str(count0) + ": {" for k in range(0, (signals_intr[i]['L'][0][1] + 1)): if (k == signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'][k] + "};\n" elif (j != signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'][k] + ", " count0 = count0 + 1 break elif (signals[i]['T'] == 's'): v = signals[i]['V'].__doc__ assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "type state_type" + str(count1) + " is (" if (v.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'] + ");\n" elif (v.find("list") == 0): for k in range(len(signals[i]['V'])): if (k == (len(signals[i]['V']) - 1)): assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'][k] + ");\n" else: assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'][k] + ", " assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "signal " + args[i]['N'] + ": state_type" + str(count1) + ";\n" count1 = count1 + 1 break elif (j == 0): break j = j - 1 elif (m != 0): if (signals[i]['T'] == 'b'): if (L.find("int") == 0): if (n.find("list") == 0): for k in range(len(signals_intr[i]['N'])): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": std_logic;\n" elif (signals[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": std_logic := '" + signals[i]['V'] + "';\n" elif (n.find("str") == 0): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": std_logic;\n" elif (signals[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": std_logic := '" + signals[i]['V'] + "';\n" elif (L.find("list") == 0): if (n.find("list") == 0): for k in range(len(signals[i]['N'])): if (signals[i].has_key('V') == False): if (signals[i]['L'][0] > signals[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ");\n" else: assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ");\n" elif (signals[i].has_key('V') == True): if (signals_intr[i]['L'][0] > signals_intr[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ") := \"" + signals[i]['V'] + "\";\n" else: assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ") := '" + signals[i]['V'] + "';\n" elif (n.find("str") == 0): if (signals[i].has_key('V') == False): if (signals[i]['L'][0] > signals[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ");\n" else: assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ");\n" elif (signals[i].has_key('V') == True): if (signals[i]['L'][0] > signals[i]['L'][1]): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " downto " + str(int(signals[i]['L'][1])) + ") := \"" + signals[i]['V'] + "\";\n" else: assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": std_logic_vector(" + str(int(signals[i]['L'][0])) + " to " + str(int(signals[i]['L'][1])) + ") := '" + signals[i]['V'] + "';\n" elif (signals[i]['T'] == "int"): if (n.find("str") == 0): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + ";\n" elif (signals[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + " := " + str(signals[i]['V']) + ";\n" elif (n.find("list") == 0): for k in range(len(signals[i]['N'])): if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + ";\n" elif (signals_intr[i].has_key('V') == True): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'][k] + ": integer range " + str(signals[i]['L'][0]) + " to " + str(signals[i]['L'][1]) + " := " + str(signals[i]['V']) + ";\n" elif (signals[i]['T'] == "arrb"): if (n.find("str") == 0): if (signals[i]['L'][1][0] > signals[i]['L'][1][1]): assign_lines[j][1] = assign_lines[j][1] + sp + "type typev" + str(count0) + " is array (" + str(signals[i]['L'][0][0]) + " to " + str(signals[i]['L'][0][1]) + ") of std_logic_vector(" + str(signals[i]['L'][1][0]) + " downto " + str(signals[i]['L'][1][1]) + ");\n" elif (signals[i]['L'][1][0] < signals[i]['L'][1][1]): assign_lines[j][1] = assign_lines[j][1] + sp + "type typev" + str(count0) + " is array (" + str(signals[i]['L'][0][0]) + " to " + str(signals[i]['L'][0][1]) + ") of std_logic_vector(" + str(signals_intr[i]['L'][1][0]) + " to " + str(signals_intr[i]['L'][1][1]) + ");\n" if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": " + "typev" + str(count0) + ";\n" elif (signals[i].has_key('V') == True): v = signals[i]['V'].__doc__ if (v.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": " + "typev" + str(count0) + ": \"" + signals[i]['V'] + "\";\n" elif(v.find("list") == 0): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": " + "typev" + str(count0) + ": {" for k in range(0, (signals[i]['L'][0][1] + 1)): if (k == signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + "\"" + signals[i]['V'][k] + "\"};\n" elif (k != signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + "\"" + signals[i]['V'][k] + "\", " count0 = count0 + 1 elif (signals[i]['T'] == "arri"): if (n.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + sp + "type typev" + str(count0) + " is array (" + str(signals[i]['L'][0][0]) + " to " + str(signals[i]['L'][0][1]) + ") of integer range " + str(signals[i]['L'][1][0]) + " to " + str(signals[i]['L'][1][1]) + ";\n" if (signals[i].has_key('V') == False): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": " + "typev" + str(count0) + ";\n" elif (signals[i].has_key('V') == True): v = signals[i]['V'].__doc__ if (v.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": " + "typev" + str(count0) + ": " + str(signals[i]['V']) + ";\n" elif(v.find("list") == 0): assign_lines[j][1] = assign_lines[j][1] + sp + "variable " + signals[i]['N'] + ": " + "typev" + str(count0) + ": {" for k in range(0, (signals[i]['L'][0][1] + 1)): if (k == signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + str(signals[i]['V'][k]) + "};\n" elif (j != signals[i]['L'][0][1]): assign_lines[j][1] = assign_lines[j][1] + str(signals[i]['V'][k]) + ", " count0 = count0 + 1 elif (signals[i]['T'] == 's'): v = signals[i]['V'].__doc__ assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "type state_typev" + str(count1) + " is (" if (v.find("str") == 0): assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'] + ");\n" elif (v.find("list") == 0): for k in range(len(signals[i]['V'])): if (k == (len(signals[i]['V']) - 1)): assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'][k] + ");\n" else: assign_lines[j][1] = assign_lines[j][1] + signals[i]['V'][k] + ", " assign_lines[j][1] = assign_lines[j][1] + "\n" + sp + "signal " + args[i]['N'] + ": state_typev" + str(count1) + ";\n" count1 = count1 + 1 if (len(process_vars) > 0): assign_lines[j][1] = assign_lines[j][1] + sp + "-------------------------------------------------------------------" assign_lines[j][1] = assign_lines[j][1] + "\n\n" + sp + "begin\n\n"
[ 37811, 198, 17174, 17174, 4557, 35625, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, ...
1.515137
40,861
say_hi("Mike", "35") result = cube(4) # variable print(result)
[ 198, 198, 16706, 62, 5303, 7203, 16073, 1600, 366, 2327, 4943, 198, 198, 20274, 796, 23441, 7, 19, 8, 1303, 7885, 198, 4798, 7, 20274, 8, 628, 628, 198 ]
2.413793
29
import glob import json path_in = './airspaces/' path_out = './airspaces_processed/' filenames = [path.split('/')[-1] for path in glob.glob(path_in + '*')] remove = { 'france_fr.geojson': [ 314327, 314187, 314360, 314359, 314362, 314361, 314364, 314363, 314333, 314329, 314331, ], 'germany_de.geojson': [ 307563, 307638, 307639, 307640, ] } replacements = { 'france_fr.geojson': [ ['Bale10 119.35', 'Bale 10 TMA 130.9'], ['Bale1 119.35', 'Bale 1 TMA 130.9'], ['Bale2 119.35', 'Bale 2 TMA 130.9'], ['Bale3 119.35', 'Bale 3 TMA 130.9'], ['Bale4 119.35', 'Bale 4 TMA 130.9'], ['Bale5 119.35', 'Bale 5 TMA 130.9'], ['Bale5 119.35', 'Bale 5 TMA 130.9'], ['Bale6 119.35', 'Bale 6 TMA 130.9'], ['Bale7 119.35', 'Bale 7 TMA 130.9'], ['Bale8 119.35', 'Bale 8 TMA 130.9'], ['Bale9 119.35', 'Bale 9 TMA 130.9'], ['Bale AZ4T1 134.67', 'Bale T1 TMA HX 134.68'], ['Bale AZ4T2 134.67', 'Bale T2 TMA HX 134.68'], ['Bale AZ4T3 134.67', 'Bale T3 TMA HX 134.68'], ['CTR BALE', 'Bale CTR 118.3'] ], 'switzerland_ch.geojson': [ ['ZURICH 10 TMA 118.1', 'ZURICH 10 TMA 124.7'], ['ZURICH 11 TMA 118.1', 'ZURICH 11 TMA 124.7'], ['ZURICH 12 TMA 118.1', 'ZURICH 12 TMA 124.7'], ['ZURICH 13 TMA 118.1', 'ZURICH 13 TMA 124.7'], ['ZURICH 14 TMA 118.1', 'ZURICH 14 TMA HX 127.755'], ['ZURICH 15 TMA 118.1', 'ZURICH 15 TMA HX 127.755'], ['ZURICH 1 TMA 118.1', 'ZURICH 1 TMA 124.7'], ['ZURICH 2 CTR 118.1', 'ZURICH 2 CTR HX 118.975'], ['ZURICH 2 TMA 118.1', 'ZURICH 2 TMA 124.7'], ['ZURICH 3 TMA 118.1', 'ZURICH 3 TMA 124.7'], ['ZURICH 4A TMA 118.1', 'ZURICH 4A TMA 124.7'], ['ZURICH 4B TMA 118.1', 'ZURICH 4B TMA 124.7'], ['ZURICH 4C TMA 118.1', 'ZURICH 4C TMA 124.7'], ['ZURICH 5 TMA 118.1', 'ZURICH 5 TMA 124.7'], ['ZURICH 6 TMA 118.1', 'ZURICH 6 TMA 124.7'], ['ZURICH 7 TMA 118.1', 'ZURICH 7 TMA 124.7'], ['ZURICH 8 TMA 118.1', 'ZURICH 8 TMA 124.7'], ['ZURICH 9 TMA 118.1', 'ZURICH 9 TMA 124.7'], ['BERN 1 TMA 121.025', 'BERN 1 TMA HX 127.325'], ['BERN 2 TMA 121.025', 'BERN 2 TMA HX 127.325'], ['BERN CTR 121.025', 'BERN CTR HX 121.025'], ['EMMEN 1 CTR 120.425', 'EMMEN 1 CTR HX 120.425'], ['EMMEN 1 TMA 120.425', 'EMMEN 1 TMA HX 134.130'], ['EMMEN 2 CTR 120.425', 'EMMEN 2 CTR HX 120.425'], ['EMMEN 2 TMA 120.425', 'EMMEN 2 TMA HX 134.130'], ['EMMEN 3 TMA 120.425', 'EMMEN 3 TMA HX 134.130'], ['EMMEN 4 TMA 120.425', 'EMMEN 4 TMA HX 134.130'], ['EMMEN 5 TMA 120.425', 'EMMEN 5 TMA HX 134.130'], ['EMMEN 6 TMA 120.425', 'EMMEN 6 TMA HX 134.130'], ] } for filename in filenames: print(filename) with open(path_in + filename) as f: data = json.load(f) if filename in replacements: targets = [r[0] for r in replacements[filename]] for feature in data['features']: if feature['properties']['N'] in targets: print('replace ' + feature['properties']['N'] + '...') feature['properties']['N'] = next(x for x in replacements[filename] if x[0] == feature['properties']['N'])[1] if filename in remove: features_out = [f for f in data['features'] if int(f['properties']['ID']) not in remove[filename]] else: features_out = data['features'] print('removed ' + str(len(data['features']) - len(features_out)) + ' features') geojson = { 'type': 'FeatureCollection', 'features': features_out } print('write ' + filename + '...') with open(path_out + filename, 'w') as f: json.dump(geojson, f) all_features = [] for filename in filenames: print('read ' + filename + '...') with open(path_out + filename) as f: all_features += json.load(f)['features'] print('write airspaces.geojson...') with open('airspaces.geojson', 'w') as f: json.dump({ 'type': 'FeatureCollection', 'features': all_features }, f) print('done')
[ 11748, 15095, 198, 11748, 33918, 198, 198, 6978, 62, 259, 796, 705, 19571, 958, 2777, 2114, 14, 6, 198, 6978, 62, 448, 796, 705, 19571, 958, 2777, 2114, 62, 14681, 276, 14, 6, 198, 198, 10379, 268, 1047, 796, 685, 6978, 13, 35312, ...
1.920444
2,250
from AndroidSpider import url_manager, html_downloader, html_parser, html_output ''' Android HTML tab Extra module: BeautifulSoup ''' if __name__ == "__main__": rootUrl = "http://baike.baidu.com/item/Android" objSpider = SpiderMain() objSpider.craw(rootUrl)
[ 6738, 5565, 41294, 1330, 19016, 62, 37153, 11, 27711, 62, 15002, 263, 11, 27711, 62, 48610, 11, 27711, 62, 22915, 198, 198, 7061, 6, 198, 5565, 11532, 7400, 198, 198, 27726, 8265, 25, 198, 38413, 4135, 50, 10486, 198, 7061, 6, 198, ...
2.74
100
MUTATION = '''mutation {{ {mutation} }}''' def _verify_additional_type(additionaltype): """Check that the input to additionaltype is a list of strings. If it is empty, raise ValueError If it is a string, convert it to a list of strings.""" if additionaltype is None: return None if isinstance(additionaltype, str): additionaltype = [additionaltype] if len(additionaltype) == 0: raise ValueError("additionaltype must be a non-empty list") return additionaltype
[ 44, 3843, 6234, 796, 705, 7061, 76, 7094, 22935, 198, 220, 1391, 76, 7094, 92, 198, 11709, 7061, 6, 628, 198, 4299, 4808, 332, 1958, 62, 2860, 1859, 62, 4906, 7, 2860, 1859, 4906, 2599, 198, 220, 220, 220, 37227, 9787, 326, 262, 5...
2.888268
179
import boto import boto3 from config import Config dynamodb = boto3.resource('dynamodb', aws_access_key_id=Config.AWS_KEY, aws_secret_access_key=Config.AWS_SECRET_KEY, region_name=Config.REGION) table = dynamodb.Table('user_details') tables = boto3.resource('dynamodb', aws_access_key_id=Config.AWS_KEY, aws_secret_access_key=Config.AWS_SECRET_KEY, region_name=Config.REGION).Table('user_details') print(tables.creation_date_time) if __name__ == "__main__": main()
[ 11748, 275, 2069, 198, 11748, 275, 2069, 18, 198, 6738, 4566, 1330, 17056, 198, 198, 67, 4989, 375, 65, 796, 275, 2069, 18, 13, 31092, 10786, 67, 4989, 375, 65, 3256, 198, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220...
2
290
# TODO: implement algorithms in c++ or something to make them fast
[ 2, 16926, 46, 25, 3494, 16113, 287, 269, 4880, 393, 1223, 284, 787, 606, 3049, 201, 198, 201, 198 ]
3.684211
19
import os import unittest from Logger import Logger from gpsNavigation import gpsModule,gpsPoint if __name__ == '__main__': unittest.main()
[ 11748, 28686, 198, 11748, 555, 715, 395, 198, 6738, 5972, 1362, 1330, 5972, 1362, 198, 198, 6738, 308, 862, 30575, 7065, 1330, 308, 862, 26796, 11, 70, 862, 12727, 628, 198, 361, 11593, 3672, 834, 6624, 705, 834, 12417, 834, 10354, 19...
2.826923
52
from logging import warning from requests import get from .info import Info from .provider import Provider from .providers import get_provider
[ 6738, 18931, 1330, 6509, 198, 198, 6738, 7007, 1330, 651, 198, 198, 6738, 764, 10951, 1330, 14151, 198, 6738, 764, 15234, 1304, 1330, 32549, 198, 6738, 764, 15234, 4157, 1330, 651, 62, 15234, 1304, 628, 198 ]
4.083333
36
# -*- coding: utf-8 -*- # Generated by Django 1.10.4 on 2016-12-28 22:09 from django.db import migrations, models import django.db.models.deletion
[ 2, 532, 9, 12, 19617, 25, 3384, 69, 12, 23, 532, 9, 12, 198, 2, 2980, 515, 416, 37770, 352, 13, 940, 13, 19, 319, 1584, 12, 1065, 12, 2078, 2534, 25, 2931, 628, 198, 6738, 42625, 14208, 13, 9945, 1330, 15720, 602, 11, 4981, 19...
2.586207
58
from django.shortcuts import get_object_or_404, render from django.http import HttpResponseRedirect from django.urls import reverse from django.views import generic from django.utils import timezone from .models import Customer def add_customer(request): customer = Customer() customer.customer_firstname = request.POST['fname'] customer.customer_lastname = request.POST['lname'] customer.customer_address = request.POST['address'] customer.customer_city = request.POST['city'] customer.customer_zipcode = request.POST['zip'] customer.customer_state = request.POST['state'] customer.save() return HttpResponseRedirect(reverse('customers:index')) def delete_customer(request, customer_id): p = Customer.objects.get(pk=customer_id) p.delete() return HttpResponseRedirect(reverse('customers:index'))
[ 6738, 42625, 14208, 13, 19509, 23779, 1330, 651, 62, 15252, 62, 273, 62, 26429, 11, 8543, 198, 6738, 42625, 14208, 13, 4023, 1330, 367, 29281, 31077, 7738, 1060, 198, 6738, 42625, 14208, 13, 6371, 82, 1330, 9575, 198, 6738, 42625, 14208...
3.061151
278
# flake8: noqa # pylint: skip-file from __future__ import absolute_import, division, print_function from salt.ext.tornado.test.util import unittest
[ 2, 781, 539, 23, 25, 645, 20402, 198, 2, 279, 2645, 600, 25, 14267, 12, 7753, 198, 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 11, 7297, 11, 3601, 62, 8818, 198, 6738, 8268, 13, 2302, 13, 45910, 4533, 13, 9288, 13, 22602, 1330...
3.104167
48
"""Holds configurations to read and write with Spark to AWS S3.""" import os from typing import Any, Dict, List, Optional from pyspark.sql import DataFrame from butterfree.configs import environment from butterfree.configs.db import AbstractWriteConfig from butterfree.dataframe_service import extract_partition_values def get_path_with_partitions(self, key: str, dataframe: DataFrame) -> List: """Get options for AWS S3 from partitioned parquet file. Options will be a dictionary with the write and read configuration for Spark to AWS S3. Args: key: path to save data into AWS S3 bucket. dataframe: spark dataframe containing data from a feature set. Returns: A list of string for file-system backed data sources. """ path_list = [] dataframe_values = extract_partition_values( dataframe, partition_columns=["year", "month", "day"] ) for row in dataframe_values: path_list.append( f"{self.file_system}://{self.path}/{key}/year={row['year']}/" f"month={row['month']}/day={row['day']}" ) return path_list def translate(self, schema: List[Dict[str, Any]]) -> List[Dict[str, Any]]: """Translate feature set spark schema to the corresponding database.""" pass
[ 37811, 39, 10119, 25412, 284, 1100, 290, 3551, 351, 17732, 284, 30865, 311, 18, 526, 15931, 198, 198, 11748, 28686, 198, 6738, 19720, 1330, 4377, 11, 360, 713, 11, 7343, 11, 32233, 198, 198, 6738, 279, 893, 20928, 13, 25410, 1330, 606...
2.554529
541
#!/usr/bin/env python3 import sys sys.path.append('..') import specrel.geom as geom import specrel.spacetime.physical as phy import specrel.visualize as vis # Shared parameters include_grid = True include_legend = True tlim = (0, 2) xlim = (-2, 2) # A stationary point object stationary = phy.MovingObject(0, draw_options={'label': '$v = 0$'}) ## Alternate: # direction = (1, 0) # point = (0, 0) # stationary = geom.Line(direction, point, draw_options={'label': '$v = 0$'}) title='Stationary object' p = vis.stplot(stationary, title=title, tlim=tlim, xlim=xlim, grid=include_grid, legend=include_legend) p.save('2-objects_stationary_point.png') p.show() # A stationary point object, animated anim = vis.stanimate(stationary, title=title, tlim=tlim, xlim=xlim, grid=include_grid, legend=include_legend) anim.save('2-objects_stationary_point_anim.mp4') anim.show() # A stationary point object, animated with worldline anim = vis.stanimate_with_worldline(stationary, title=title, tlim=tlim, xlim=xlim, grid=include_grid, legend=include_legend, legend_loc='upper right') anim.save('2-objects_stationary_point_anim_worldline.mp4') anim.show() # A bunch of moving point objects, animated moving = phy.MovingObject(0, velocity=1/2, draw_options={'color': 'red', 'label': '$v = c/2$'}) light = phy.MovingObject(0, velocity=1, draw_options={'color': 'gold', 'label': '$v = c$'}) ftl = phy.MovingObject(0, velocity=3/2, draw_options={'color': 'cyan', 'label': '$v = 3c/2$'}) objects = geom.Collection([stationary, moving, light, ftl]) title = 'Various objects' anim = vis.stanimate_with_worldline(objects, title=title, current_time_color='magenta', tlim=tlim, xlim=xlim, grid=include_grid, legend=include_legend, legend_loc='upper left') anim.save('2-objects_moving_points.mp4') anim.show() # A moving meterstick meterstick = phy.MovingObject(-1/2, length=1, velocity=1/2, draw_options={'label': 'Meterstick'}) # # Alternate: # direction = (1, 1/2) # left = geom.Line(direction, (0, -1/2)) # right = geom.Line(direction, (0, 1/2)) # meterstick = geom.Ribbon(left, right, draw_options={'label': 'Meterstick'}) title = 'Moving meterstick ($v = c/2$)' anim = vis.stanimate_with_worldline(meterstick, title=title, tlim=tlim, xlim=xlim, grid=include_grid, legend=include_legend, legend_loc='upper left') anim.save('2-objects_moving_meterstick.mp4') anim.show()
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 11748, 25064, 198, 17597, 13, 6978, 13, 33295, 10786, 492, 11537, 198, 198, 11748, 1020, 2411, 13, 469, 296, 355, 4903, 296, 198, 11748, 1020, 2411, 13, 2777, 330, 8079, 13, 42854,...
2.65011
906
from baremetal import * from math import pi, sin, cos import sys from scale import scale from settings import * from ssb import ssb_polar import numpy as np from matplotlib import pyplot as plt if __name__ == "__main__" and "sim" in sys.argv: #mode am stim am stimulus=( np.sin(np.arange(1000)*2.0*pi*0.02)*1023+ np.sin(np.arange(1000)*2.0*pi*0.03)*1023 ) #test_modulator(stimulus, FM) #test_modulator(stimulus, FM) #test_modulator(stimulus, NBFM) test_modulator(stimulus, USB)
[ 6738, 6247, 28469, 1330, 1635, 198, 6738, 10688, 1330, 31028, 11, 7813, 11, 8615, 198, 11748, 25064, 198, 6738, 5046, 1330, 5046, 198, 6738, 6460, 1330, 1635, 198, 6738, 264, 36299, 1330, 264, 36299, 62, 79, 6192, 628, 198, 198, 11748, ...
2.376682
223
from __future__ import absolute_import from six.moves.urllib.parse import urlencode from django.test import RequestFactory from django.contrib.auth.models import AnonymousUser from sentry.auth.helper import handle_new_user from sentry.models import AuthProvider, InviteStatus, OrganizationMember from sentry.testutils import TestCase from sentry.utils.compat import mock
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 198, 6738, 2237, 13, 76, 5241, 13, 333, 297, 571, 13, 29572, 1330, 2956, 11925, 8189, 198, 6738, 42625, 14208, 13, 9288, 1330, 19390, 22810, 198, 6738, 42625, 14208, 13, 3642, 822, ...
3.666667
102
from broadcast_ping import BroadcastPing EVENT_TYPES = { "PING": BroadcastPing, }
[ 6738, 7025, 62, 13886, 1330, 44244, 49806, 198, 198, 20114, 3525, 62, 9936, 47, 1546, 796, 1391, 198, 220, 220, 220, 220, 220, 220, 220, 366, 47, 2751, 1298, 44244, 49806, 11, 198, 92, 198 ]
2.6
35
import datetime import requests from mbta_python.models import Stop, Direction, Schedule, Mode, \ TripSchedule, Alert, StopWithMode, Prediction HOST = "http://realtime.mbta.com/developer/api/v2"
[ 11748, 4818, 8079, 198, 11748, 7007, 198, 6738, 285, 65, 8326, 62, 29412, 13, 27530, 1330, 13707, 11, 41837, 11, 19281, 11, 10363, 11, 3467, 198, 220, 220, 220, 18383, 27054, 5950, 11, 23276, 11, 13707, 3152, 19076, 11, 46690, 628, 19...
3.075758
66
import argparse import glob import os import numpy as np import torch from sklearn.metrics import accuracy_score import models_torch as models import utils EXPERIMENT_DATA_DIR = "/tmp/mgr" if __name__ == "__main__": parser = argparse.ArgumentParser(description='Run Inference') parser.add_argument('model_type') parser.add_argument('--bins-histogram', default=50) parser.add_argument('--model-path', default=None) parser.add_argument('--device-type', default="cpu") # parser.add_argument('--image-path', default="images/") args = parser.parse_args() parameters_ = { "model_type": args.model_type, "bins_histogram": args.bins_histogram, "model_path": args.model_path, "device_type": args.device_type, # "image_path": args.image_path, } if parameters_["model_path"] is None: if args.model_type == "histogram": parameters_["model_path"] = "saved_models/BreastDensity_BaselineHistogramModel/model.p" if args.model_type == "cnn": parameters_["model_path"] = "saved_models/BreastDensity_BaselineBreastModel/model.p" predicted_values = [] real_values = [] predicted_values_two_classes = [] real_values_two_classes = [] two_classes_mapping = {1: 0, 2: 0, 3: 1, 4: 1} for dir in glob.glob(f"{EXPERIMENT_DATA_DIR}/*/"): parameters_["image_path"] = dir predicted_density = inference(parameters_) with open(os.path.join(dir, "density.txt")) as file: real_density = int(file.read()) print(f"Predicted density: {predicted_density}") print(f"Real density: {real_density}\n") print(f"Predicted density (2 cls): {two_classes_mapping[predicted_density]}") print(f"Real density (2 cls): {two_classes_mapping[real_density]}\n") predicted_values.append(predicted_density) real_values.append(real_density) predicted_values_two_classes.append(two_classes_mapping[predicted_density]) real_values_two_classes.append(two_classes_mapping[real_density]) print(f"Total accuracy: {accuracy_score(real_values, predicted_values)}") print(f"Total accuracy two classes: {accuracy_score(real_values_two_classes, predicted_values_two_classes)}") """ python density_model_torch_custom.py histogram python density_model_torch_custom.py cnn """
[ 11748, 1822, 29572, 198, 11748, 15095, 198, 11748, 28686, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 28034, 198, 6738, 1341, 35720, 13, 4164, 10466, 1330, 9922, 62, 26675, 198, 198, 11748, 4981, 62, 13165, 354, 355, 4981, 198, ...
2.547109
934
"""Computation of ensemble anomalies based on a desired value.""" import os import numpy as np from scipy import stats # User-defined packages from read_netcdf import read_iris, save_n_2d_fields from sel_season_area import sel_area, sel_season def ens_anom(filenames, dir_output, name_outputs, varname, numens, season, area, extreme): """Ensemble anomalies. Computation of the ensemble anomalies based on the desired value from the input variable (it can be the percentile, mean, maximum, standard deviation or trend) OUTPUT: NetCDF files of ensemble mean of climatology, selected value and anomaly maps. """ print('The name of the output files will be <variable>_{0}.txt' .format(name_outputs)) print('Number of ensemble members: {0}'.format(numens)) outfiles = [] # Reading the netCDF file of 3Dfield, for all the ensemble members var_ens = [] for ens in range(numens): ifile = filenames[ens] # print('ENSEMBLE MEMBER %s' %ens) var, varunits, lat, lon, dates, _ = read_iris(ifile) # Convertion from kg m-2 s-1 to mm/day if varunits == 'kg m-2 s-1': var = var * 86400 # there are 86400 seconds in a day varunits = 'mm/day' # Selecting a season (DJF,DJFM,NDJFM,JJA) var_season, _ = sel_season(var, dates, season) # Selecting only [latS-latN, lonW-lonE] box region var_area, lat_area, lon_area = sel_area(lat, lon, var_season, area) var_ens.append(var_area) if varunits == 'kg m-2 s-1': print('\nPrecipitation rate units were converted from kg m-2 s-1 ' 'to mm/day') print('The variable is {0} ({1})'.format(varname, varunits)) print('Original var shape: (time x lat x lon)={0}'.format(var.shape)) print('var shape after selecting season {0} and area {1}: ' '(time x lat x lon)={2}'.format(season, area, var_area.shape)) if extreme == 'mean': # Compute the time mean over the entire period, for each ens member varextreme_ens = [np.nanmean(var_ens[i], axis=0) for i in range(numens)] elif len(extreme.split("_")) == 2: # Compute the chosen percentile over the period, for each ens member quant = int(extreme.partition("th")[0]) varextreme_ens = [np.nanpercentile(var_ens[i], quant, axis=0) for i in range(numens)] elif extreme == 'maximum': # Compute the maximum value over the period, for each ensemble member varextreme_ens = [np.nanmax(var_ens[i], axis=0) for i in range(numens)] elif extreme == 'std': # Compute the standard deviation over the period, for each ens member varextreme_ens = [np.nanstd(var_ens[i], axis=0) for i in range(numens)] elif extreme == 'trend': # Compute the linear trend over the period, for each ensemble member trendmap = np.empty((var_ens[0].shape[1], var_ens[0].shape[2])) trendmap_ens = [] for i in range(numens): for jla in range(var_ens[0].shape[1]): for jlo in range(var_ens[0].shape[2]): slope, _, _, _, _ = \ stats.linregress(range(var_ens[0].shape[0]), var_ens[i][:, jla, jlo]) trendmap[jla, jlo] = slope trendmap_ens.append(trendmap.copy()) varextreme_ens = trendmap_ens varextreme_ens_np = np.array(varextreme_ens) print('Anomalies are computed with respect to the {0}'.format(extreme)) # Compute and save the anomalies with respect to the ensemble ens_anomalies = varextreme_ens_np - np.nanmean(varextreme_ens_np, axis=0) varsave = 'ens_anomalies' ofile = os.path.join(dir_output, 'ens_anomalies_{0}.nc' .format(name_outputs)) # print(ofile) print('ens_anomalies shape: (numens x lat x lon)={0}' .format(ens_anomalies.shape)) save_n_2d_fields(lat_area, lon_area, ens_anomalies, varsave, varunits, ofile) outfiles.append(ofile) # Compute and save the climatology vartimemean_ens = [np.mean(var_ens[i], axis=0) for i in range(numens)] ens_climatologies = np.array(vartimemean_ens) varsave = 'ens_climatologies' ofile = os.path.join(dir_output, 'ens_climatologies_{0}.nc' .format(name_outputs)) save_n_2d_fields(lat_area, lon_area, ens_climatologies, varsave, varunits, ofile) outfiles.append(ofile) ens_extreme = varextreme_ens_np varsave = 'ens_extreme' ofile = os.path.join(dir_output, 'ens_extreme_{0}.nc'.format(name_outputs)) save_n_2d_fields(lat_area, lon_area, ens_extreme, varsave, varunits, ofile) outfiles.append(ofile) return outfiles
[ 37811, 5377, 1996, 341, 286, 34549, 35907, 1912, 319, 257, 10348, 1988, 526, 15931, 198, 198, 11748, 28686, 198, 11748, 299, 32152, 355, 45941, 198, 6738, 629, 541, 88, 1330, 9756, 198, 198, 2, 11787, 12, 23211, 10392, 198, 6738, 1100, ...
2.230453
2,187
from django.db import models from django.utils.html import mark_safe, strip_tags from django.utils.text import slugify from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy from django.core.exceptions import ValidationError from django.db.models.signals import post_save, post_delete from django.dispatch import receiver from django.conf import settings from django.contrib.auth.hashers import get_hasher from django.db import transaction from django.urls import reverse from django.db.models import Q from tinymce import models as tinymce_models from colorfield.fields import ColorField import html class Permission(models.Model): organization = models.ForeignKey(Organization, on_delete=models.CASCADE, verbose_name=ugettext_lazy("Organization related to these permissions")) can_add_members = models.BooleanField(default=False) can_remove_members = models.BooleanField(default=False) can_create_petitions = models.BooleanField(default=False) can_modify_petitions = models.BooleanField(default=False) can_delete_petitions = models.BooleanField(default=False) can_create_templates = models.BooleanField(default=False) can_modify_templates = models.BooleanField(default=False) can_delete_templates = models.BooleanField(default=False) can_view_signatures = models.BooleanField(default=False) can_modify_signatures = models.BooleanField(default=False) can_delete_signatures = models.BooleanField(default=False) can_modify_permissions = models.BooleanField(default=False) class PytitionUser(models.Model): petitions = models.ManyToManyField(Petition, blank=True) organizations = models.ManyToManyField(Organization, related_name="members", blank=True) user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="pytitionuser") permissions = models.ManyToManyField(Permission, related_name="user", blank=True) invitations = models.ManyToManyField(Organization, related_name="invited", blank=True) petition_templates = models.ManyToManyField(PetitionTemplate, blank=True, through='TemplateOwnership', through_fields=['user', 'template'], verbose_name=ugettext_lazy("Petition templates")) default_template = models.ForeignKey(PetitionTemplate, blank=True, null=True, related_name='+', verbose_name=ugettext_lazy("Default petition template"), to_field='id', on_delete=models.SET_NULL) def __str__(self): return self.get_full_name def __repr__(self): return self.get_full_name class TemplateOwnership(models.Model): user = models.ForeignKey(PytitionUser, blank=True, null=True, on_delete=models.CASCADE) organization = models.ForeignKey(Organization, blank=True, null=True, on_delete=models.CASCADE) template = models.ForeignKey(PetitionTemplate, to_field='id', on_delete=models.CASCADE) #class Meta: # unique_together = (("user", "template"), ("organization", "template"))
[ 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 6738, 42625, 14208, 13, 26791, 13, 6494, 1330, 1317, 62, 21230, 11, 10283, 62, 31499, 198, 6738, 42625, 14208, 13, 26791, 13, 5239, 1330, 31065, 1958, 198, 6738, 42625, 14208, 13, 26791, 13...
2.716822
1,183
import csv from testdata import SOCIALHISTORY_FILE from testdata import rndDate from patient import Patient SMOKINGCODES = { '428041000124106': 'Current some day smoker', '266919005' : 'Never smoker', '449868002' : 'Current every day smoker', '266927001' : 'Unknown if ever smoked', '8517006' : 'Former smoker' }
[ 11748, 269, 21370, 198, 6738, 1332, 7890, 1330, 31430, 12576, 39, 42480, 62, 25664, 198, 6738, 1332, 7890, 1330, 374, 358, 10430, 198, 6738, 5827, 1330, 35550, 198, 198, 12310, 11380, 2751, 34, 3727, 1546, 796, 1391, 198, 220, 220, 220,...
2.48951
143
{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# dictionaries, look-up tables & key-value pairs\n", "# d = {} OR d = dict()\n", "#e.g. d = {\"George\": 24, \"Tom\": 32}\n", "\n", "d = {}\n", "\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "d[\"George\"] = 24" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "d[\"Tom\"] = 32\n", "d[\"Jenny\"] = 16" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'George': 24, 'Tom': 32, 'Jenny': 16}\n" ] } ], "source": [ "print(d)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'Jenny' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m<ipython-input-5-0bdfff196d23>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0md\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mJenny\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mNameError\u001b[0m: name 'Jenny' is not defined" ] } ], "source": [ "print(d[Jenny])" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "32\n" ] } ], "source": [ "print(d[\"Tom\"])" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "d[\"Jenny\"] = 20" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "20\n" ] } ], "source": [ "print(d[\"Jenny\"])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "# keys are strings or numbers \n", "\n", "d[10] = 100" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "100\n" ] } ], "source": [ "print(d[10])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# how to iterate over key-value pairs" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "key:\n", "George\n", "value:\n", "24\n", "\n", "key:\n", "Tom\n", "value:\n", "32\n", "\n", "key:\n", "Jenny\n", "value:\n", "20\n", "\n", "key:\n", "10\n", "value:\n", "100\n", "\n" ] } ], "source": [ " for key, value in d.items():\n", " print(\"key:\")\n", " print(key)\n", " print(\"value:\")\n", " print(value)\n", " print(\"\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }
[ 90, 198, 366, 46342, 1298, 685, 198, 220, 1391, 198, 220, 220, 366, 3846, 62, 4906, 1298, 366, 8189, 1600, 198, 220, 220, 366, 18558, 1009, 62, 9127, 1298, 352, 11, 198, 220, 220, 366, 38993, 1298, 1391, 5512, 198, 220, 220, 366, ...
1.867634
2,274
# Copyright 2013-2021 Lawrence Livermore National Security, LLC and other # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) import os import pytest from llnl.util.filesystem import mkdirp, touch import spack.config from spack.fetch_strategy import CacheURLFetchStrategy, NoCacheError from spack.stage import Stage
[ 2, 15069, 2211, 12, 1238, 2481, 13914, 45036, 3549, 2351, 4765, 11, 11419, 290, 584, 198, 2, 1338, 441, 4935, 34152, 13, 4091, 262, 1353, 12, 5715, 27975, 38162, 9947, 2393, 329, 3307, 13, 198, 2, 198, 2, 30628, 55, 12, 34156, 12, ...
3.302521
119
__author__ = 'hanhanw' import sys from pyspark import SparkConf, SparkContext from pyspark.sql.context import SQLContext from pyspark.sql.types import StructType, StructField, StringType, DoubleType conf = SparkConf().setAppName("temp range sql") sc = SparkContext(conf=conf) sqlContext = SQLContext(sc) assert sc.version >= '1.5.1' inputs1 = sys.argv[1] output = sys.argv[2] if __name__ == "__main__": main()
[ 834, 9800, 834, 796, 705, 7637, 7637, 86, 6, 198, 198, 11748, 25064, 198, 6738, 279, 893, 20928, 1330, 17732, 18546, 11, 17732, 21947, 198, 6738, 279, 893, 20928, 13, 25410, 13, 22866, 1330, 16363, 21947, 198, 6738, 279, 893, 20928, 1...
2.863946
147
from typing_extensions import Required #from sqlalchemy.sql.sqltypes import Boolean from graphene import ObjectType, String, Field, ID, List, DateTime, Mutation, Boolean, Int from models.EventsRelated.EventModel import EventModel from graphqltypes.Utils import extractSession
[ 6738, 19720, 62, 2302, 5736, 1330, 20906, 198, 198, 2, 6738, 44161, 282, 26599, 13, 25410, 13, 25410, 19199, 1330, 41146, 198, 6738, 42463, 1330, 9515, 6030, 11, 10903, 11, 7663, 11, 4522, 11, 7343, 11, 7536, 7575, 11, 337, 7094, 11, ...
3.971429
70
from __future__ import absolute_import # Copyright (c) 2010-2015 openpyxl from openpyxl.styles.colors import Color, BLACK, WHITE from openpyxl.utils.units import ( pixels_to_EMU, EMU_to_pixels, short_color, ) from openpyxl.compat import deprecated from openpyxl.xml.functions import Element, SubElement, tostring from openpyxl.xml.constants import ( DRAWING_NS, SHEET_DRAWING_NS, CHART_NS, CHART_DRAWING_NS, PKG_REL_NS ) from openpyxl.compat.strings import safe_string
[ 6738, 11593, 37443, 834, 1330, 4112, 62, 11748, 198, 2, 15069, 357, 66, 8, 3050, 12, 4626, 1280, 9078, 87, 75, 198, 198, 6738, 1280, 9078, 87, 75, 13, 47720, 13, 4033, 669, 1330, 5315, 11, 31963, 11, 44925, 198, 198, 6738, 1280, 9...
2.492611
203
from VcfQC import VcfQC from ReseqTrackDB import File from ReseqTrackDB import ReseqTrackDB import argparse import os import logging import datetime #get command line arguments parser = argparse.ArgumentParser(description='Script to subset a VCF by excluding the variants within the regions defined by a BED file') ''' Reseqtrack DB connection parameters ''' parser.add_argument('--hostname', type=str, required=True, help='Hostname for ReseqTrack DB' ) parser.add_argument('--username', type=str, required=True, help='User for ReseqTrack DB' ) parser.add_argument('--port', type=int, required=True, help='Port number in the ReseqTrack DB' ) parser.add_argument('--pwd', type=str, help='PWD for the ReseqTrack DB' ) parser.add_argument('--db', type=str, required=True, help='DB name in the ReseqTrack DB' ) parser.add_argument('--type', type=str, required=True, help='Type of the new VCF file' ) parser.add_argument('--vcftools_folder', type=str, required=True, help='Folder containing the VCFtools binary' ) parser.add_argument('--bgzip_folder', type=str, required=True, help='Folder containing the bgzip binary') parser.add_argument('--filename', type=str, required=True, help='Name (without the fullpath) of the VCF file that will be analysed. It assumes that the filename format is for example lc_bams.gatk.xxxx.vcf.gz, where lc_bams is the analysis group and gatk is the method used' ) parser.add_argument('--bed', type=str, required=True, help='BED file containing the coordinates to exclude' ) parser.add_argument('--outsuffix', type=str, required=True, help='Suffix for vcf output file. i.e. no_cms or no_offtarget' ) parser.add_argument('--outdir', type=str, required=True, help='Directory used to put the output files.' ) args = parser.parse_args() if __name__ == '__main__': if os.path.isdir(args.outdir) == False: raise Exception("Output dir does not exist: %s"%args.outdir) hostname=args.hostname username=args.username db=args.db port=args.port pwd=args.pwd reseqdb = ReseqTrackDB(host=hostname,user=username,port=port,pwd=pwd,db=db) file=reseqdb.fetch_file_by_filename(args.filename) #constructing the out filename now = datetime.datetime.now().strftime('%Y%m%d') bits= os.path.basename(file.name).split('.') outprefix=bits[0]+"."+bits[1]+"."+args.outsuffix+"."+now log_filename="subset_vcf_%s.log"% outprefix logger = logging.getLogger("subset_vcf") logger.setLevel(logging.INFO) # create the logging file handler fh = logging.FileHandler(log_filename) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fh.setFormatter(formatter) # add handler to logger object logger.addHandler(fh) logger.info("Program started") vcfQC = VcfQC(vcf=file.path,bgzip_folder=args.bgzip_folder,vcftools_folder=args.vcftools_folder) vcffile=vcfQC.subset_vcf(bed=args.bed,outprefix=outprefix,outdir=args.outdir,create_index=True) f=File(path=vcffile,type=args.type,host_id=1,withdrawn=0) f.store(reseqdb,do_md5=True) logger.info("Done!.")
[ 198, 6738, 569, 12993, 48, 34, 1330, 569, 12993, 48, 34, 198, 6738, 1874, 27363, 24802, 11012, 1330, 9220, 198, 6738, 1874, 27363, 24802, 11012, 1330, 1874, 27363, 24802, 11012, 198, 198, 11748, 1822, 29572, 198, 11748, 28686, 198, 11748,...
2.771556
1,125
import os from base import BaseHandler
[ 11748, 28686, 198, 198, 6738, 2779, 1330, 7308, 25060, 198 ]
4
10
# 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 mock from nova.compute import rpcapi as compute_rpcapi from nova.conductor.tasks import migrate from nova import objects from nova.scheduler import client as scheduler_client from nova.scheduler import utils as scheduler_utils from nova import test from nova.tests.unit.conductor.test_conductor import FakeContext from nova.tests.unit import fake_flavor from nova.tests.unit import fake_instance
[ 2, 220, 220, 220, 49962, 739, 262, 24843, 13789, 11, 10628, 362, 13, 15, 357, 1169, 366, 34156, 15341, 345, 743, 198, 2, 220, 220, 220, 407, 779, 428, 2393, 2845, 287, 11846, 351, 262, 13789, 13, 921, 743, 7330, 198, 2, 220, 220, ...
3.360825
291
import os
[ 11748, 28686, 198 ]
3.333333
3
from django.shortcuts import render from .models import Disk import os #def index(request): # module_dir = os.path.dirname(__file__) # file_path = os.path.join(module_dir, 'data.txt') # disk_list = open(file_path , 'r') # data = data_file.read() # context = {'disk_list': data} # return render(request, 'index.html', context)
[ 6738, 42625, 14208, 13, 19509, 23779, 1330, 8543, 198, 6738, 764, 27530, 1330, 31664, 198, 11748, 28686, 628, 198, 198, 2, 4299, 6376, 7, 25927, 2599, 198, 2, 220, 220, 220, 8265, 62, 15908, 796, 28686, 13, 6978, 13, 15908, 3672, 7, ...
2.589552
134
# Copyright Materialize, Inc. and contributors. All rights reserved. # # Use of this software is governed by the Business Source License # included in the LICENSE file at the root of this repository. # # As of the Change Date specified in that file, in accordance with # the Business Source License, use of this software will be governed # by the Apache License, Version 2.0. from textwrap import dedent from typing import List from materialize.checks.actions import Testdrive from materialize.checks.checks import Check
[ 2, 15069, 14633, 1096, 11, 3457, 13, 290, 20420, 13, 1439, 2489, 10395, 13, 198, 2, 198, 2, 5765, 286, 428, 3788, 318, 21825, 416, 262, 7320, 8090, 13789, 198, 2, 3017, 287, 262, 38559, 24290, 2393, 379, 262, 6808, 286, 428, 16099, ...
4.286885
122
import numpy as np import mujoco_py as mj from mujoco_py_renderer import SimulationError, XMLError, MujocoPyRenderer from mujoco_py import (MjSim, load_model_from_xml,functions, load_model_from_path, MjSimState, ignore_mujoco_warnings, load_model_from_mjb) from matplotlib import pyplot as plt import time xml = """ <mujoco model="example"> <compiler coordinate="global"/> <default> <geom rgba=".8 .6 .4 1"/> </default> <asset> <texture type="skybox" builtin="gradient" rgb1="1 1 1" rgb2=".6 .8 1" width="256" height="256"/> </asset> <worldbody> <light pos="0 1 1" dir="0 -1 -1" diffuse="1 1 1"/> <geom name="floor" pos="0 0 0" rgba="0.8 0.9 0.8 1" size="10 10 10" type="plane"/> <body> <site name="world" size="0.1" pos="0 0 0" /> <geom name="first_pole" type="capsule" fromto="0 0 0 0 0 0.5" size="0.04"/> <joint name='a' type="hinge" pos="0 0 0" axis="0 0 1" /> <body name="second_pole"> <inertial pos="0 0 0" mass="0.00000001" diaginertia="1e-008 1e-008 1e-008" /> <geom type="capsule" fromto="0 0 0.5 0.5 0 0.5" size="0.04" name="second_pole"/> <joint name='b' type="hinge" pos="0 0 0.5" axis="0 1 0"/> <body name='third_pole'> <inertial pos="0 0 0" mass="0.00000001" diaginertia="1e-008 1e-008 1e-008" /> <geom type="capsule" fromto="0.5 0 0.5 1 0 0.5" size="0.04" name="third_pole"/> <joint name='c' type="hinge" pos="0.5 0 0.5" axis="0 1 0"/> <site name="target" size="0.1" pos="1 0 0.5" /> <body name="mass"> <inertial pos="1 0 0.5" mass="1e-2" diaginertia="1e-008 1e-008 1e-008" /> <geom type="sphere" pos="1 0 0.5" size="0.2" name="mass"/> </body> </body> </body> </body> </worldbody> <actuator> <motor joint="a"/> <motor joint="b"/> <motor joint="c"/> </actuator> </mujoco> """ model = load_model_from_xml(xml) sim = MjSim(model) viewer = MujocoPyRenderer(sim) sim.reset() # After reset jacobians are all zeros sim.forward() target_jacp = np.zeros(3 * sim.model.nv) target_jacr= np.zeros(3 * sim.model.nv) F=np.array([0,0,-9.81*1e-2,0,0,0]).T #np.testing.assert_allclose(target_jacp, np.zeros(3 * sim.model.nv)) # After first forward, jacobians are real #sim.forward() K_diag=2000 C_diag=100 A_diag=1e-3 K=np.identity(3)*K_diag C=np.identity(3)*C_diag A=np.identity(3)*A_diag #K_diag=0.3 #C_diag=0.05 for i in range(3): K[i, i]=K_diag C[i,i]=C_diag A[i, i] = A_diag x_intial=sim.data.site_xpos[1] print(x_intial) x_desired=np.array([0,1,0.3]) v_intial=sim.data.site_xvelp[1] v_desired=np.array([0,0,0]) a_desired=np.array([0,0,0]) a_intial=np.array([0,0,0]) dt=sim.model.opt.timestep #sim.data.get_site_jacp('target', jacp=target_jacp) # Should be unchanged after steps (zero action) graph=[] for _ in range(100000): F[:3]=np.dot(K,x_desired-x_intial)+np.dot(C,v_desired-v_intial)+np.dot(A,a_desired-a_intial) H = np.zeros(sim.model.nv* sim.model.nv) functions.mj_fullM(sim.model, H, sim.data.qM) sim.data.get_site_jacp('target', jacp=target_jacp) sim.data.get_site_jacr('target', jacr=target_jacr) J_L = target_jacp.reshape((3, sim.model.nv)) J_A = target_jacr.reshape((3, sim.model.nv)) J = np.concatenate((J_L, J_A), axis=0) H_L =np.dot(np.linalg.pinv(J_L.T),np.dot(H.reshape(sim.model.nv, sim.model.nv), np.linalg.pinv(J_L))) H_all=np.dot(np.linalg.pinv(J.T),np.dot(H.reshape(sim.model.nv, sim.model.nv), np.linalg.pinv(J))) #F_a=np.dot(A,0.3-sim.data.qacc) #action = np.dot(J_L.T, np.dot(H_L, F[:3]))+sim.data.qfrc_bias action = sim.data.qfrc_bias+np.dot(H.reshape(3,3),np.dot(J_L.T,F[:3])) #print(action) #action = np.dot(J.T, F) sim.data.ctrl[:] = action sim.step() sim.forward() #print(np.max(action)) #print(sim.data.qacc) viewer.render() x_intial = sim.data.site_xpos[1] a_intial=(v_intial-sim.data.site_xvelp[1])/dt print(a_intial) v_intial = sim.data.site_xvelp[1] normal=np.linalg.norm(x_intial-x_desired) #print(normal) if normal<0.1: print("in") if x_desired[0]==0: x_desired = np.array([-1, 0, 0.5]) elif x_desired[0]==1: x_desired = np.array([0, 1, 0.3]) elif x_desired[0] == -1: x_desired = np.array([1, 0, 0.5]) graph.append(np.abs(x_intial-x_desired)) # sim.forward() print("the desired is {} and the intial is{}".format(x_desired,x_intial)) plt.plot(graph) plt.show()
[ 11748, 299, 32152, 355, 45941, 198, 11748, 285, 23577, 25634, 62, 9078, 355, 285, 73, 198, 6738, 285, 23577, 25634, 62, 9078, 62, 10920, 11882, 1330, 41798, 12331, 11, 1395, 44, 2538, 81, 1472, 11, 8252, 73, 25634, 20519, 49, 437, 118...
1.901426
2,455
import sys # package need to be installed, pip install docker import docker import time import yaml import os import xlwt auto = False private_registry = "202.114.10.146:9999/" # result result = [["tag", "finishTime", "size", "data"], ] def get_net_data(): netCard = "/proc/net/dev" fd = open(netCard, "r") for line in fd.readlines(): if line.find("enp0s3") >= 0: field = line.split() data = float(field[1]) / 1024.0 / 1024.0 fd.close() return data if __name__ == "__main__": if len(sys.argv) == 2: auto = True generator = Generator(os.path.split(os.path.realpath(__file__))[0]+"/image_versions.yaml") images = generator.generateFromProfile() puller = Puller(images) puller.pull() # create a workbook sheet workbook = xlwt.Workbook() sheet = workbook.add_sheet("run_time") for row in range(len(result)): for column in range(len(result[row])): sheet.write(row, column, result[row][column]) workbook.save(os.path.split(os.path.realpath(__file__))[0]+"/pull.xls")
[ 11748, 25064, 198, 2, 5301, 761, 284, 307, 6589, 11, 7347, 2721, 36253, 198, 11748, 36253, 220, 198, 11748, 640, 198, 11748, 331, 43695, 198, 11748, 28686, 198, 11748, 2124, 75, 46569, 198, 198, 23736, 796, 10352, 198, 198, 19734, 62, ...
2.393013
458
from jiminy.envs import vnc_env from jiminy.spaces import VNCActionSpace
[ 6738, 474, 320, 3541, 13, 268, 14259, 1330, 410, 10782, 62, 24330, 198, 6738, 474, 320, 3541, 13, 2777, 2114, 1330, 569, 7792, 12502, 14106, 628 ]
2.846154
26
import copy import logging import random from typing import List, Tuple import numpy as np import torch import wandb from torch.utils.data import ConcatDataset from fedml_api.standalone.fedavg.my_model_trainer import MyModelTrainer from fedml_api.standalone.federated_sgan.ac_gan_model_trainer import ACGANModelTrainer from fedml_api.standalone.federated_sgan.client import FedSSGANClient from fedml_api.standalone.federated_sgan.model_trainer import FedSSGANModelTrainer from fedml_api.standalone.utils.HeterogeneousModelBaseTrainerAPI import HeterogeneousModelBaseTrainerAPI
[ 11748, 4866, 198, 11748, 18931, 198, 11748, 4738, 198, 6738, 19720, 1330, 7343, 11, 309, 29291, 198, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 28034, 198, 11748, 11569, 65, 198, 6738, 28034, 13, 26791, 13, 7890, 1330, 1482, 9246, ...
3.20442
181
#!/usr/bin/env python3 import argparse from collections import Counter import pdb import pickle import re import sys import time import numpy as np import torch import torch.nn as nn from torch.autograd import Variable from torch import optim import torch.nn.functional as F import torch.multiprocessing as mp import data_producer from multiprocessing import set_start_method parser = argparse.ArgumentParser() parser.add_argument("--train", type=str, default="", help="training file") parser.add_argument("--vocab", type=str, default="", help="vocab pickle file") parser.add_argument("--save", type=str, default="csv.pth.tar", help="saved model filename") parser.add_argument("--size", type=int, default=300, help="word embedding dimension") parser.add_argument("--window", type=int, default=5, help="context window size") parser.add_argument("--sample", type=float, default=1e-5, help="subsample threshold") parser.add_argument("--negative", type=int, default=10, help="number of negative samples") parser.add_argument("--delta", type=float, default=0.15, help="create new sense for a type if similarity lower than this value.") parser.add_argument("--min_count", type=int, default=5, help="minimum frequency of a word") parser.add_argument("--processes", type=int, default=4, help="number of processes") parser.add_argument("--num_workers", type=int, default=6, help="number of workers for data processsing") parser.add_argument("--iter", type=int, default=3, help="number of iterations") parser.add_argument("--lr", type=float, default=-1.0, help="initial learning rate") parser.add_argument("--batch_size", type=int, default=100, help="(max) batch size") parser.add_argument("--cuda", action='store_true', default=False, help="enable cuda") parser.add_argument("--multi_proto", action='store_true', default=False, help="True: multi-prototype, False:single-prototype") MAX_SENT_LEN = 1000 # Build the vocabulary. # Initialize model. def init_net(args): if args.lr == -1.0: vars(args)['lr'] = 0.05 return CSV(args) def save_model(filename, model, args, word2idx): torch.save({ 'word2idx':word2idx, 'args':args, #'word2sense': model.word2sense, 'n_senses': model.n_senses, 'params': model.state_dict() }, filename) def load_model(filename): checkpoint = torch.load(filename) word2idx = checkpoint['word2idx'] args = checkpoint['args'] model = CSV(args) if args.cuda: model.cuda() model.global_embs.weight.data = checkpoint['params']['global_embs.weight'] model.sense_embs.weight.data = checkpoint['params']['sense_embs.weight'] model.ctx_weight.data = checkpoint['params']['ctx_weight'] model.word2sense = checkpoint['word2sense'] #model.word2sense.data = checkpoint['params']['word2sense'] #model.word_sense_cnts.data = checkpoint['params']['word_sense_cnts'] model.n_senses = checkpoint['n_senses'] return model, word2idx # Training if __name__ == '__main__': set_start_method('forkserver') args = parser.parse_args() print("Starting training using file %s" % args.train) train_file = open(args.train) train_file.seek(0, 2) vars(args)['file_size'] = train_file.tell() word_count_actual = mp.Value('L', 0) if args.vocab == '': word2idx, word_list, freq = build_vocab(args) else: with open(args.vocab, 'rb') as f: word2idx, word_list, freq, pos2idx, dep2id = pickle.load(f) word_count = sum([freq[k] for k in freq]) vars(args)['vocab_size'] = len(word2idx) vars(args)['train_words'] = word_count print("Vocab size: %ld" % len(word2idx)) print("Words in train file: %ld" % word_count) model = init_net(args) model.share_memory() if args.cuda: model.cuda() # stage 1, learn robust context representation. vars(args)['stage'] = 1 print("Stage 1") vars(args)['lr_anneal'] = True vars(args)['t_start'] = time.monotonic() processes = [] for p_id in range(args.processes): p = mp.Process(target=train_process, args=(p_id, word_count_actual, word2idx, word_list, freq, args, model)) p.start() processes.append(p) for p in processes: p.join() del processes print("\nStage 1, ", time.monotonic() - args.t_start, " secs ", word_count_actual.value) filename = args.save if not filename.endswith('.pth.tar'): filename += '.stage1.pth.tar' save_model(filename, model, args, word2idx) if args.multi_proto: # stage 2, create new sense in a non-parametric way. # Freeze model paramters except sense_embs, and use only 1 process to prevent race condition old_batch_size = vars(args)['batch_size'] model.global_embs.requires_grad = False model.ctx_weight.requires_grad = False model.sense_embs = model.sense_embs.cpu() vars(args)['stage'] = 2 vars(args)['batch_size'] = 5000 print("\nStage 2") word_count_actual.value = 0 vars(args)['t_start'] = time.monotonic() train_process_stage2(0, word_count_actual, word2idx, word_list, freq, args, model) if args.cuda: model.cuda() print("\nStage 2, ", time.monotonic() - args.t_start, " secs") print("Current # of senses: %d" % model.n_senses) pdb.set_trace() filename = args.save if not filename.endswith('.pth.tar'): filename += '.stage2.pth.tar' save_model(filename, model, args, word2idx) # stage 3, no more sense creation. vars(args)['lr'] = args.lr * 0.01 vars(args)['batch_size'] = old_batch_size model.global_embs.requires_grad = True model.ctx_weight.requires_grad = True vars(args)['stage'] = 3 print("\nBegin stage 3") word_count_actual.value = 0 vars(args)['t_start'] = time.monotonic() processes = [] for p_id in range(args.processes): p = mp.Process(target=train_process, args=(p_id, word_count_actual, word2idx, word_list, freq, args, model)) p.start() processes.append(p) for p in processes: p.join() print("\nStage 3, ", time.monotonic() - args.t_start, " secs") # save model filename = args.save if not filename.endswith('.pth.tar'): filename += '.stage3.pth.tar' save_model(filename, model, args, word2idx) print("")
[ 2, 48443, 14629, 14, 8800, 14, 24330, 21015, 18, 198, 198, 11748, 1822, 29572, 198, 6738, 17268, 1330, 15034, 198, 11748, 279, 9945, 198, 11748, 2298, 293, 198, 11748, 302, 198, 11748, 25064, 198, 11748, 640, 198, 198, 11748, 299, 32152...
2.375
2,808
sayi1 = int(input("1. Say: ")) sayi2 = int(input("2. Say: ")) sayi3 = int(input("3. Say: ")) sayi4 = int(input("4. Say: ")) sayi5 = int(input("5. Say: ")) sayilar=[]; sayilar.append(sayi1) sayilar.append(sayi2) sayilar.append(sayi3) sayilar.append(sayi4) sayilar.append(sayi5) sayilar.sort() print("En byk sayimiz..",sayilar[-1])
[ 16706, 72, 16, 796, 493, 7, 15414, 7203, 16, 13, 13816, 25, 366, 4008, 198, 16706, 72, 17, 796, 493, 7, 15414, 7203, 17, 13, 13816, 25, 366, 4008, 198, 16706, 72, 18, 796, 493, 7, 15414, 7203, 18, 13, 13816, 25, 366, 4008, 198, ...
2.155844
154
"""Deep Q learning graph The functions in this file can are used to create the following functions: ======= act ======== Function to chose an action given an observation Parameters ---------- observation: object Observation that can be feed into the output of make_obs_ph stochastic: bool if set to False all the actions are always deterministic (default False) update_eps_ph: float update epsilon a new value, if negative not update happens (default: no update) Returns ------- Tensor of dtype tf.int64 and shape (BATCH_SIZE,) with an action to be performed for every element of the batch. ======= train ======= Function that takes a transition (s,a,r,s') and optimizes Bellman equation's error: td_error = Q(s,a) - (r + gamma * max_a' Q(s', a')) loss = huber_loss[td_error] Parameters ---------- obs_t: object a batch of observations action: np.array actions that were selected upon seeing obs_t. dtype must be int32 and shape must be (batch_size,) reward: np.array immediate reward attained after executing those actions dtype must be float32 and shape must be (batch_size,) obs_tp1: object observations that followed obs_t done: np.array 1 if obs_t was the last observation in the episode and 0 otherwise obs_tp1 gets ignored, but must be of the valid shape. dtype must be float32 and shape must be (batch_size,) weight: np.array imporance weights for every element of the batch (gradient is multiplied by the importance weight) dtype must be float32 and shape must be (batch_size,) Returns ------- td_error: np.array a list of differences between Q(s,a) and the target in Bellman's equation. dtype is float32 and shape is (batch_size,) ======= update_target ======== copy the parameters from optimized Q function to the target Q function. In Q learning we actually optimize the following error: Q(s,a) - (r + gamma * max_a' Q'(s', a')) Where Q' is lagging behind Q to stablize the learning. For example for Atari Q' is set to Q once every 10000 updates training steps. """ import tensorflow as tf import baselines.common.tf_util as U import numpy as np def build_train_mf(make_obs_ph, q_func, num_actions, optimizer, grad_norm_clipping=None, gamma=1.0, scope="mfec", alpha=1.0, beta=1.0, theta=1.0, latent_dim=32, ib=True, reuse=None): """Creates the train function: Parameters ---------- make_obs_ph: str -> tf.placeholder or TfInput a function that takes a name and creates a placeholder of input with that name q_func: (tf.Variable, int, str, bool) -> tf.Variable the model that takes the following inputs: observation_in: object the output of observation placeholder num_actions: int number of actions scope: str reuse: bool should be passed to outer variable scope and returns a tensor of shape (batch_size, num_actions) with values of every action. num_actions: int number of actions reuse: bool whether or not to reuse the graph variables optimizer: tf.train.Optimizer optimizer to use for the Q-learning objective. grad_norm_clipping: float or None clip gradient norms to this value. If None no clipping is performed. gamma: float discount rate. double_q: bool if true will use Double Q Learning (https://arxiv.org/abs/1509.06461). In general it is a good idea to keep it enabled. scope: str or VariableScope optional scope for variable_scope. reuse: bool or None whether or not the variables should be reused. To be able to reuse the scope must be given. Returns ------- act: (tf.Variable, bool, float) -> tf.Variable function to select and action given observation. ` See the top of the file for details. train: (object, np.array, np.array, object, np.array, np.array) -> np.array optimize the error in Bellman's equation. ` See the top of the file for details. update_target: () -> () copy the parameters from optimized Q function to the target Q function. ` See the top of the file for details. debug: {str: function} a bunch of functions to print debug data like q_values. """ act_noise = tf.placeholder(tf.float32, [None, latent_dim], name="act_noise") act_f = build_act_mf(make_obs_ph, q_func, act_noise, num_actions, scope=scope, reuse=reuse) with tf.variable_scope(scope, reuse=reuse): # set up placeholders # EMDQN obs_vae_input = U.ensure_tf_input(make_obs_ph("obs_vae")) z_noise_vae = tf.placeholder(tf.float32, [None, latent_dim], name="z_noise_vae") inputs = [obs_vae_input,z_noise_vae] if ib: qec_input = tf.placeholder(tf.float32, [None], name='qec') inputs.append(qec_input) outputs = [] q_vae, q_deterministic_vae, v_mean_vae, v_logvar_vae, z_mean_vae, z_logvar_vae, recon_obs = q_func(obs_vae_input.get(), z_noise_vae, num_actions, scope="q_func", reuse=True) q_func_vars = U.scope_vars(U.absolute_scope_name("q_func")) encoder_loss = -1 + z_mean_vae ** 2 + tf.exp(z_logvar_vae) - z_logvar_vae total_loss = tf.reduce_mean(beta * encoder_loss) decoder_loss = tf.keras.losses.binary_crossentropy(tf.reshape(recon_obs, [-1]), tf.reshape( tf.dtypes.cast(obs_vae_input._placeholder, tf.float32), [-1])) print("here", z_mean_vae.shape, z_logvar_vae.shape, encoder_loss.shape, decoder_loss.shape) vae_loss = beta * encoder_loss + theta * decoder_loss outputs.append(encoder_loss) outputs.append(decoder_loss) outputs.append(vae_loss) total_loss += tf.reduce_mean(theta * decoder_loss) if ib: ib_loss = (v_mean_vae - tf.stop_gradient(tf.expand_dims(qec_input, 1))) ** 2 / tf.exp( v_logvar_vae) + v_logvar_vae print("here2", v_mean_vae.shape, tf.expand_dims(qec_input, 1).shape, v_logvar_vae.shape, ib_loss.shape) total_ib_loss = alpha * ib_loss + beta * encoder_loss outputs.append(total_ib_loss) total_loss += tf.reduce_mean(alpha * ib_loss) if grad_norm_clipping is not None: optimize_expr = U.minimize_and_clip(optimizer, total_loss, var_list=q_func_vars, clip_val=grad_norm_clipping) else: optimize_expr = optimizer.minimize(total_loss, var_list=q_func_vars) # Create callable functions # EMDQN total_loss_summary = tf.summary.scalar("total loss", total_loss) z_var_summary = tf.summary.scalar("z_var", tf.reduce_mean(tf.exp(z_logvar_vae))) encoder_loss_summary = tf.summary.scalar("encoder loss", tf.reduce_mean(encoder_loss)) decoder_loss_summary = tf.summary.scalar("decoder loss", tf.reduce_mean(decoder_loss)) summaries = [total_loss_summary, z_var_summary, encoder_loss_summary, decoder_loss_summary] if ib: ib_loss_summary = tf.summary.scalar("ib loss", tf.reduce_mean(ib_loss)) total_ib_loss_summary = tf.summary.scalar("total ib loss", tf.reduce_mean(total_ib_loss)) summaries.append(ib_loss_summary) summaries.append(total_ib_loss_summary) summary = tf.summary.merge(summaries) outputs.append(summary) train = U.function( inputs=inputs, outputs=[total_loss,summary], updates=[optimize_expr] ) return act_f, train
[ 37811, 29744, 1195, 4673, 4823, 198, 198, 464, 5499, 287, 428, 2393, 460, 389, 973, 284, 2251, 262, 1708, 5499, 25, 198, 198, 1421, 18604, 719, 29335, 18604, 628, 220, 220, 220, 15553, 284, 7690, 281, 2223, 1813, 281, 13432, 628, 220,...
2.292669
3,574
import sys sys.path.append('../') import LMR_config as cfg import LMR_prior import numpy as np import pytest
[ 11748, 25064, 198, 198, 17597, 13, 6978, 13, 33295, 10786, 40720, 11537, 198, 198, 11748, 406, 13599, 62, 11250, 355, 30218, 70, 198, 11748, 406, 13599, 62, 3448, 273, 198, 11748, 299, 32152, 355, 45941, 198, 11748, 12972, 9288, 628, 62...
2.72093
43
import os from dataloader.datasetDHF1K import DHF1K from torch.utils.data import DataLoader from utils.salgan_utils import save_model, get_lr_optimizer from utils.sendTelegram import send from utils.printer import param_print from utils.salgan_generator import create_model, add_bn from evaluation.fast_evaluation import compute_metrics import numpy as np import torch from torch.nn import AvgPool2d from torch.nn.modules.loss import BCELoss import torch.backends.cudnn as cudnn from torch.optim import SGD, Adam from torch.optim.lr_scheduler import ReduceLROnPlateau, StepLR from time import time from IPython import embed from tensorboard_logger import configure, log_value, log_histogram TRAIN = 'train' VAL = 'val' TEST = 'test' if __name__ == '__main__': import argparse parser = argparse.ArgumentParser() parser.add_argument("--path_out", default='sal_dhf1k_adamdepthcoordaugm2_frombestsaldepth', type=str, help="""set output path for the trained model""") parser.add_argument("--batch_size", default=12, type=int, help="""Set batch size""") parser.add_argument("--n_epochs", default=10, type=int, help="""Set total number of epochs""") parser.add_argument("--depth", default=False, type=bool, help="""Enable 4th channel with depth""") parser.add_argument("--augment", default=False, type=bool, help="""Enable data augmentation""") parser.add_argument("--coord", default=False, type=bool, help="""Enable coordconv""") parser.add_argument("--flow", default=False, type=bool, help="""Enable opticalflow""") parser.add_argument("--lr", type=float, default=0.00001, help="""Learning rate for training""") parser.add_argument("--patience", type=int, default=3, help="""Patience for learning rate scheduler (default 10)""") args = parser.parse_args() # set output path ========================================================== path_out = '../trained_models/batch12_/' + args.path_out if not os.path.exists(path_out): # create output path os.makedirs(path_out) # create output for models path_models = os.path.join(path_out, 'models') if not os.path.exists(path_models): os.makedirs(path_models) # tensorboard configure("{}".format(path_out), flush_secs=5) # data ===================================================================== batch_size = args.batch_size n_epochs = args.n_epochs lr = args.lr DEPTH = args.depth AUGMENT = args.augment COORD = args.coord FLOW = args.flow # Datasets for DHF1K ds_train = DHF1K(mode=TRAIN, transformation=True, depth=DEPTH, d_augm=AUGMENT, coord=COORD) ds_validate = DHF1K(mode=VAL, transformation=False, depth=DEPTH, d_augm=False, coord=COORD) # Dataloaders dataloader = { TRAIN: DataLoader(ds_train, batch_size=batch_size, shuffle=True, num_workers=2), VAL: DataLoader(ds_validate, batch_size=batch_size, shuffle=False, num_workers=2) } # POSSIBILITY OF CHOOSING GPU torch.cuda.set_device(1) # MODEL INITIALIZATION print("Init model...") vgg_weights = torch.load('../trained_models/salgan_baseline.pt')['state_dict'] model = create_model(3) # if DEPTH and COORD: # model = create_model(6) # for i in range(0,3): # vgg_weights = add_layer_weights(vgg_weights) # elif DEPTH: # model = create_model(4) # add_layer_weights(vgg_weights) # elif COORD: # model = create_model(5) # for i in range(0,2): # vgg_weights = add_layer_weights(vgg_weights) # else: model = create_model(3) # Instead of adding manually the layer of new weights, we could use strict=False model.load_state_dict(vgg_weights) # Add batch normalization to current model if needed model = add_bn(model) model.train() model.cuda() cudnn.benchmark = True # NOT WORKING UNMOUNTED DISK # If we have the two GPU's available we are going to use both # if torch.cuda.device_count() > 1: # print("Using ", torch.cuda.device_count(), "GPUs!") # model = torch.nn.DataParallel(model) # LOSS FUNCTION bce_loss = BCELoss() # FINE-TUNE WHOLE NETWORK OR JUST DECODER => uncomment / or different lr for each part # decoder_parameters = [] # base_params = [] # for i, (a, p) in enumerate(model.named_parameters()): # embed() # if i>25: # # print(i, a, p.shape) # decoder_parameters.append(p) # else: # base_params.append(p) # If you wanna train just the decoder put this # p.requires_grad = False # ADAM OPTIMIZER optimizer = Adam(model.parameters(), lr = lr, weight_decay=0.000001) # STOCHASTIC GRADIENT DESCENT OPTIMIZER # optimizer = SGD(model.parameters(), # lr = 0.00001, # momentum=0.9, # weight_decay=0.00001, # nesterov=True) # NUMBER OF TOTAL PARAMETERS # pytorch_total_params = sum(p.numel() for p in model.parameters()) # NUMBER OF TRAINABLE PARAMETERS trainable_parameters = sum(p.numel() for p in model.parameters() if p.requires_grad) print("Trainable parameters: ", trainable_parameters) send("Trainable parameters: " + str(trainable_parameters)) send("Experiment: " + args.path_out) # PRINT TABLE OF PARAMETERS param_print([path_out,"",DEPTH,AUGMENT,COORD,FLOW,batch_size,lr,n_epochs, trainable_parameters]) # set learning rate scheduler # ReduceLROnPlateau( # optimizer, # mode (str) 'min':lr es reduira quan la metrica no es redueixi mes, 'max' al contrari, # factor (float) factor de reduccio de la lr, # patience (int) num epochs sense millora a partir dels quals es redueix lr, # verbose (bool), # ) # scheduler = ReduceLROnPlateau(optimizer, # 'min', # patience=args.patience, # verbose=True) scheduler = StepLR(optimizer, step_size=3, gamma=0.1) best_loss=9999999 # main loop training ======================================================= for id_epoch in range(n_epochs): for mode in [VAL, TRAIN]: # select dataloader data_iterator = dataloader[mode] # # # saliency metrics # if mode ==VAL: # print("Evaluating metrics....") # # only do 100 images from validation # metrics = compute_metrics(model, 100, DEPTH, COORD) # # # log metric values # for metric in metrics.keys(): # log_value("Metrics/{}".format(metric), # metrics[metric], id_epoch) # # # get epoch loss # print("--> {} epoch {}".format(mode, id_epoch)) epoch_loss = train_eval(mode, model, optimizer, dataloader) lr = list(get_lr_optimizer(optimizer))[0] print("-----------") print("Done! {} epoch {} loss {} lr {}".format(mode, id_epoch, epoch_loss, lr)) send("{} epoch {}/{} loss {}".format(mode, id_epoch, n_epochs, epoch_loss)) print("\n") # record loss log_value("loss/{}".format(mode), epoch_loss, id_epoch) log_value("lr/{}".format(mode), lr, id_epoch) # for v in model.state_dict(): # log_histogram("Layer {}".format(v), model.state_dict()[v], id_epoch) if (id_epoch%2)==0: save_model(model, optimizer, id_epoch, path_out, name_model='{:03d}'.format(id_epoch)) # store model if val loss improves if mode==VAL: if best_loss > epoch_loss: # update loss best_loss = epoch_loss save_model(model, optimizer, id_epoch, path_out, name_model='best') # scheduler.step(epoch_loss) scheduler.step()
[ 11748, 28686, 198, 198, 6738, 4818, 282, 1170, 263, 13, 19608, 292, 316, 35, 29567, 16, 42, 1330, 23809, 37, 16, 42, 198, 6738, 28034, 13, 26791, 13, 7890, 1330, 6060, 17401, 198, 6738, 3384, 4487, 13, 21680, 1030, 62, 26791, 1330, ...
2.534835
2,842
# encoding: utf-8 from django.db import models from wagtail.wagtailcore.models import Page from wagtail.wagtailcore.fields import StreamField from wagtail.wagtailcore import blocks from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel from wagtail.wagtailimages.blocks import ImageChooserBlock
[ 220, 1303, 21004, 25, 3384, 69, 12, 23, 198, 198, 6738, 42625, 14208, 13, 9945, 1330, 4981, 198, 198, 6738, 266, 363, 13199, 13, 86, 363, 13199, 7295, 13, 27530, 1330, 7873, 198, 6738, 266, 363, 13199, 13, 86, 363, 13199, 7295, 13, ...
3.232323
99