content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def allVowelsA(word): """ allVowelsA is a function that changes all vowels to A. This function is a building block for a function that will count syllables by counting vowels. For that purpose, all vowels are equivalent. But, we want to remove consecutive duplicate vowels. Converting all...
f010afea28c6c10efb862d2beed52a6e1e17933e
16,626
def clang_find_attributes(node): """Finds attributes one level below the Clang node.""" return [n for n in node.get_children() if n.kind.is_attribute()]
a18483d8f5b19ce1b66abdbef76af5a98e420e21
16,627
import six def rows_from_table(table): """Given a tinyquery.Table, build an API-compatible rows object.""" result_rows = [] for i in six.moves.xrange(table.num_rows): field_values = [{'v': str(col.values[i])} for col in table.columns.values()] result_rows.append({ ...
e8aef81702eb4ce5a89a3c9bc4b0d3389c17ad54
16,628
import socket import struct def inet_aton(s): """Like `socket.inet_aton()` but returns an int.""" packed = socket.inet_aton(s) return struct.unpack('!I', packed)[0]
965388ca49c9f8472fc00f08af810e81bc7f0ff1
16,629
def regenerate_response(db_entry): """Unique message generator. Args: db_entry (dict?): Stored response from the database that has already been created. Returns: JSON string which contains the message response """ # Init a blank json response response_data = {'wallet_address': db...
fc60078fc09022811858554c50c5375bfd753f3e
16,630
from typing import Dict from typing import List import json def _pluck_listen_ids(aws_event: Dict) -> List[str]: """Pluck the listen ids from a batched sqs event. >>> _pluck_listen_ids({'Records': [{'body': '{"listen_id": "5"}'}]}) ['5'] """ message_bodies = [json.loads(record['body']) for record...
e7440915ab23207ae82d3cc3878037df7c8a00d1
16,632
def _unpack_index(i): """Unpack index and return exactly four elements. If index is more shallow than 4, return None for trailing dimensions. If index is deeper than 4, raise a KeyError. """ if len(i) > 4: raise KeyError( "Tried to index history with {} indices but only " ...
323a819107ac7c53c2b2abdabb46e573b620c7e9
16,633
import sys import torch def matches(modules, node, pattern, max_uses=sys.maxsize): """ Matches a node in fx against a pattern """ if isinstance(pattern, tuple): self_match, *arg_matches = pattern if self_match is getattr: assert len(pattern) == 2, 'Expecting getattr pattern to ...
47b64ccdd3627793a12329d25829970c037f0573
16,635
def does_intersect_rect(p, particles, padding, rect, is_3d = False): """ Returns true if particle p is sufficiently close or outside the rectangle (in 2d) or cuboid (in 3d) Parameters ---------- p : list Coordinates of center and radius of particle [x,y,z,r] particles : list List of center + ra...
a3300c17c6f9bf3d8f47efac0c94a222f6ee34ef
16,638
def alphanumericp(c): """Returns true if character is an alphabetic character or a numeric character; otherwise, returns false. """ return type(c) is str and c.isalpha() or c.isnumeric()
f6870d55471e8a96237c56e916df55c0f81266d9
16,639
import warnings def get_link_to_assembly(species_list): """ Get the path for assembly download from NCBI Select the most up-to-date Complete Genome of the each organisms and returns the FTP path for that one. ----------------------------------------------------------------- Argument: spe...
50c086d714786c67335715f4005ecd3eb1338e55
16,640
def session(request): """Load the database session for a given aiohttp request Internally, it just returns the value that was given as cleanup context by func:`krake.api.app.db_session`. Args: request (aiohttp.web.Request): HTTP request Returns: krake.database.Session: Database se...
897a3fc517d4f4a0773617769c60b9dc8fd29056
16,641
def get_labels(gdf): """ Returns geodataframe with 'labels' and 'columns' set according to most dense neighbours. Will loop through rows will complete once number of units have been reduced by ~50% Parameters: ----------- gdf : (gpd.GeoDataFrame) Dataframe in which units will be match...
88ac73b24be6fb68a169ff4cb9e66b4c99770b62
16,642
def upload_logs(): """ This is to get the webpage. """ return { 'page': 'upload_logs', 'raw_logs': '', }
f0238b73acb6a0f4716ea4daf0db11e0cd69e33d
16,643
def get_play_both(basketball: list, football: list): """given two lists return players that appear in both in O(N+M)""" basketball_map = {f"{player['first_name']} {player['last_name']}":True\ for player in basketball} overlapping = [] for player in football: key = f"{player['first_name']} {player['last_na...
3154b91e7e83a7bdc499d75f7ebe3bb610cf30aa
16,645
from datetime import datetime def utc_time(): """Make an utc_time with appended 'Z'""" return str(datetime.utcnow()) + 'Z'
0f718b656b337d3cd14cc023944221ed16fb84d2
16,647
from typing import Optional def to_safe_str_or_none(value: Optional[str]) -> Optional[str]: """Convert input to cleaned string or None.""" if value is None: return None v = str(value.strip()).replace('\r', '').replace('\n', '') return v or None
2946183f58aa51deb4deeb450296af95ca41f72e
16,648
def check_equal(param1, param2, msg="{},{}"): """Checks whether the two parameters are equal or not.""" if param1 != param2: raise ValueError(msg.format(param1, param2)) return param1
40f0058b41b937e6aecef1c035f934b05c9ac818
16,649
def hdr_str(s, x): """ Return header description strings """ if isinstance(x, str): return s r = [] try: for i, v in enumerate(x): r += [s + '(' + chr(ord('x') + i) + ')'] except Exception: r = s return r
06a3135953fd26fec196423efaf22c9390e035c1
16,650
def calculate_gc(seq): """ Returns percentage of G and C nucleotides in a DNA sequence. """ gc = 0 for base in seq: if base in "GCgc": gc += 1 else: gc = 1 return gc/len(seq) * 100
51048f70febf7309da1d2b4b8946315bdc31e939
16,651
def rename_coords_to_lon_and_lat(ds): """ Rename Dataset spatial coord names to: lat, lon """ if 'latitude' in ds.coords: ds = ds.rename({'latitude': 'lat'}) if 'longitude' in ds.coords: ds = ds.rename({'longitude': 'lon'}) elif 'long' in ds.coords: ds = ds.rename({'l...
8ba286e441f2a32a96fbbddc5c1112a6ed890f84
16,652
def mean(list): """ Given a list or tuple, will return the mean. Usage mean(list) """ sum = 0; for item in list: sum += item return(sum / len(list))
77d88f7386b53ab79eddfa459fa9c8f907961a9e
16,653
def read_pos_data(filename): """ Read data from file which looks like (sec, nsec, x, y, z) 0 8000000 -14 0 0.149843 1 12000000 -13.9997 -1.6e-05 0.117777 2 16000000 -13.9997 -1.9e-05 0.117841 """ arr = [] for line in open(filename): sec, nsec, x, y, z = [float(a) for ...
8f1a148e44033184cbd92cbb1f00de7e7d21e73f
16,654
def decode_response_version_from_config(confbytes: bytes) -> str: """Decode the string version from the bytearray response from Ledger device""" return "{}.{}.{}".format( confbytes[1], confbytes[2], confbytes[3], )
66dc0b71b2c9a22ca8198fb2a5ecbe69a7a0871b
16,656
import re import json def read_json (filename) : """ Comments in the form of # rest of line are stripped from json before parsing use like this:: import pprint pprint.pprint (read_json (sys.argv[1])) """ with open (filename) as f: content = '' # we...
8bd89325e8f3b486bb13790fc4c827427a435515
16,657
def cut_clockwise(positive_offset: bool, spindle_clockwise: bool, climb: bool): """ If all 3 are true, then cut must be done clockwise. Changing one to false, the cut must be done counter-clockwise. Changing two to false, the cut must be done clockwise. Changing all three to false, the cut must be d...
62a5c70ce723e8fc26e1cc9d8c0e7b167c031dc5
16,658
import pickle def read_binary_file(file_name): """reads binary file and returns the content""" with open(str(file_name), "rb") as bin_file: obj = pickle.load(bin_file) return obj
4d350edb97310df963fcd2bf3af67deb184f1cdb
16,659
def filter_selector(query): """ Selects filter :param query: :return: query including selected filter """ selected_filter = input("Available Filters: \n \ 1 = Clinical Trial \n \ 2 = Meta-Analysis \n \ 3 = Personal Narrative \n \ 4 = Preprint \n \ 5 = Randomized Controlled Tr...
0533c2fad16d1768e907ca3065fb3de8271784c4
16,660
from typing import Sequence from typing import Dict def create_fills_query(start_datetime: str, end_datetime: str, uuids: Sequence[str]) -> Dict: """Create a GetFills dictionary request. Args: start_datetime: UTC datetime as '%Y%-m%-dTHH:MM:SS' end_datetime: UTC datetime as '%Y-%m-%dTHH:MM:SS...
beb383badbe60d39f72185a8633155f797f98f4f
16,661
def get_request_id(request_json): """Get the request_id from the request """ request_id = request_json['requestInfo'].get('requestId') if not request_id: request_id = request_json['requestInfo'].get('requestID') return request_id
68b3e9e8a15d84d1042173b8fc8c480f996d616a
16,664
def parse_playlist_uri(uri): """ Takes a playlist uri and splits it to (user_id, playlist_id) """ playlistparts = uri.split(':') # Sample: spotify:user:lmljoe:playlist:0DXoY83tBvgWkd8QH49yAI if len(playlistparts) != 5: print('Invalid playlist id') exit() user_id = playlistpar...
23e7f36d4008f0e361a93e81289f302bf15cee81
16,665
def _ahull_sort_points(hull, points, p0, p1): """Compute the sub-hull using a sorted chain-hull algorithm""" dx, dy = p1 - p0 p0_x, p0_y = p0 def line_order(pt): return dx * (pt[0] - p0_x) + dy * (pt[1] - p0_y) points.sort(key=line_order) points.append(p1) stack = [p0] push = sta...
ca8e16a10db76146d63b1e431982d39f11235ec3
16,666
import inspect import logging def verify_parameters(code, kwargs, err_message): """ Used to verify the that the parameters in kwarg match the signature of the code. :param code: The code fragment's that has the signature to check. :param kwargs: The kwargs to look for :param err_message: An error ...
cd3c3542c41bb7ba0d3f8d7f250f44d743acb0a9
16,667
import socket def get_open_ports(number): """Get the number of open ports from the system. Args: number: number of ports Returns: list of open_ports """ ports = [] for i in range(number): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("", 0)) s.l...
972787bd26e7430ebbc6ad1f45dbf29b9e4aba00
16,671
def merge_dfs_by_index(df1, df2): """ Merge two pandas dataframe index-by-index. The dataframes have to share the same index name. Shared indexes will be merged without data loss. In case of conflicting entries a ValueError is raised. The merge operation is symmetric and does not depend on the ...
fe1558403ab2ee7a01b034788edd6ac413f77eaf
16,674
def bytes_to_little_int(data: bytearray) -> int: """Convert bytes to little int.""" return int.from_bytes(data, byteorder="little", signed=False)
bdca6a59b4036cce1bd9bc59a9096556d87b257b
16,675
def resolve_translation(instance, info, language_code): """Gets translation object from instance based on language code.""" return instance.translations.filter(language_code=language_code).first()
79737c123e09760fb1514bbfad7d73c385a4309a
16,676
def ris_ignoreValue_check(fieldsTuple, itemType_value): """ params: fieldsTuple, () itemType_value, str. return: fieldValue_dict """ # ris_element = fieldsTuple[0] ignore_value_list = fieldsTuple[2] fieldValue_dict = {} # for ignore_value in ignore_value_list: if...
be9bfdf2ae761e8309e1d9b9db33fee99c466cf0
16,678
import re def normalise_collection_url(url: str) -> str: """Remove anything after ID (e.g. `cp43213`) and change 'sciencemuseum.org.uk' to 'sciencemuseumgroup.org.uk'""" url = url.replace( "collection.sciencemuseum.org.uk", "collection.sciencemuseumgroup.org.uk" ) if "collection.sciencemuseu...
c58d095b446cdca3ff0292f5905166acb8b863b6
16,679
def init_parameters(parameter): """Auxiliary function to set the parameter dictionary Parameters ---------- parameter: dict See the above function NMFconv for further information Returns ------- parameter: dict """ parameter = dict() if not parameter else parameter para...
397a648b2ed799c5236fd8456874d739e7744974
16,681
def tonumber(v): """ Convert a value to int if its an int otherwise a float. """ try: v = int(v) except ValueError as e: v = float(v) return v
8b52ac3385b3ffc721af523799ef3a6da4e29060
16,682
def _param(param, value): """ create 'parameter=value' """ return "{0}={1}".format(param, value)
a64cedf88c20b774ffef23bb7caded4ed7975143
16,683
def array_madness(arr1: list, arr2: list) -> bool: """ This function returns True if the sum of the squares of each element in arr1 is strictly greater than the sum of the cubes of each element in arr2. """ if len(arr1) and len(arr2) >= 1: return True if sum([i**2 for i in arr1]) > sum([i**3 for i in ar...
67f4d2ca7bb51d0134336993c88928eca29b8383
16,684
def get_bcrypt_salt(hashed): """ Get the salt from on bcrypt hashed string """ return hashed[:29]
ce7f632ddb832548841b0daead4e8176899ac21d
16,685
def split_str_avoiding_square_brackets(s: str) -> list: """ Splits a string by comma, but skips commas inside square brackets. :param s: string to split :return: list of strings split by comma """ res = list() skipping = 0 last_idx = 0 for i, c in enumerate(s): if c == '[': ...
29dad952d9b8151bb2bad0f5c7338436251792b7
16,686
def _write_categories(categories_list): """ Parameters ---------- categories_list : list of str the list of category's names Returns ------- the categories' dictionary """ # create an empty categories' dictionary categories_dict = {"categori...
5af597f584c3b1a06a271cc6115398d9ef617668
16,687
import os import fnmatch def ls_r(path, fileext): """ Works like a shells `ls -r` syscall, but searches with a given file extensions (`fileext`) in mind **Positional Arguments:** path: - The base path from where we traverse the directory structure fileext: - The file extensio...
dce5a8f40bcf76336b33e5ab327bd985dbcd20a1
16,688
def sizeToTeam(size): """Given a size in kilobytes, returns the 512kb.club team (green/orange/blue), or "N/A" if size is too big for 512kb.club""" if size<100: return "green" elif size<250: return "orange" elif size<=512: return "blue" else: return "N/A"
a61f6a28f8f00cd05271684f715345b7fac4ed54
16,689
import time def time_seconds(): """ 获取当前时间seconds级计时值 :return: float值 eg. 1498381468.38095 """ return time.time()
90fee8f18bf6afc5dd9c6b5b6438051ec5d4ca3b
16,691
def product_consumption_rate(total_items, total_orders): """Returns the average number of units per order. Args: total_items (int): Total number of items of a SKU sold during a period. total_orders (int): Total number of orders during a period. Returns: Average number of units per ...
e5645a4703d0d9335abc6832da24b8a6b53c0c17
16,693
import json def read_cjson(path): """ Read a json file with #-comment lines """ with open(path) as f: lines = [line for line in f if not line.strip().startswith('#')] data = json.loads('\n'.join(lines)) return data
f0585820e56c5fa8ccbf9894a70b780b4ce00018
16,694
import logging def _get_pathway_scores_old( pathway_dict: dict ) -> dict: """Return pathway scores as a dictionary of scores :param pathway_dict: pathway dictionary as output by toDict :type: dict :return: dictionary of scores :rtype: dict """ __SCORE_KEYS = [ 'norm_fba_ob...
0a547552288dda6b4c4be4836389fe54cb2066f8
16,695
def evaluate_indiv(indiv, objective_dict): """Wrapper function for calculating the individual's fitness. See :class:`~hawks.objective.Objective` for implementation details. Args: indiv (:class:`~hawks.genotype.Genotype`): A single individual (i.e. a dataset). objective_dict (dict): Dictionary w...
b4d3ff64ace7c5fc9f67ef7d6860022d83e72457
16,696
def getSelectRedirect(params): """Returns the pick redirect for the specified entity. """ if params.get('args'): return '/%(url_name)s/pick?%(args)s' % params else: return '/%(url_name)s/pick' % params
1eae1150f180986b74ac2ec9bc31c3d3d1f566e1
16,698
import os def makeSubjIds(rdfname, mapfile=None, types=None): """Map subjects to ids rdfname - input RDF N-Tripples file name mapname - output id mapping file object or None types - resulting set of the loaded types if not None return subjstp - name: id mapping for the typed subjects idend - end of the...
b19c55a5ea4f868d5b674abc5c8f4a36592be337
16,700
def wrangle(X): """Wrangle train, validate, and test sets in the same way""" # Prevent SettingWithCopyWarning X = X.copy() # Fillna for other columns with most frquent values. Definitely with 1 (one) cols3 = ['Bedrooms', 'Beds', 'Bathrooms'] for col in cols3: X[col] = X[col].fillna...
47d40e613c6321d862b5c91f3bb99ef767e1907a
16,703
def feed(attribute, kwargs, dictionary, tab='\t'): """ Args: attribute (str): Attribute to be operated. kwargs (dict): generic parameters. dictionary (dict): default parameters dictionary. tab (str): '\t' or '\t\t', depend on orders of attribute. Return: (str) ""...
c8e0324c4081c0a2852e0eb1f218ebe99b81ccac
16,704
import glob import gzip import json def scrub_chunks(): """Collate a list of chunk paths into a single dictionary Keyword arguments: files -- list of paths to g-zipped chunks from `tmdb.py` """ files = glob.glob('chunks/*') if len(files) == 0 : raise SystemExit("No chunks found in `ch...
64b1052829b9e515aa358b4a7f31fd7580ab13f6
16,705
from datetime import datetime def complaint_list_query(self, begin_date=None, end_date=None, limit=10, offset=0, complainted_mchid=None): """查询投诉单列表 :param begin_date: 开始日期,投诉发生的开始日期,格式为YYYY-MM-DD。注意,查询日期跨度不超过30天,当前查询为实时查询。示例值:'2019-01-01' :param end_date: 结束日期,投诉发生的结束日期,格式为YYYY-MM-DD。注意,查询日期跨度不超过30天,当前查询...
21c598b1de662a2eb0f07c85020062a2bd611d8d
16,707
def wrap(char, wrapper): """Wrap a sequence in a custom string.""" return wrapper.format(char=char)
a86bbfb5f1b4ea373eb0a23b365c63ceed106159
16,708
import pickle import codecs def decode_df(str_encode): """ """ p1 = pickle.loads(codecs.decode(str_encode.encode(), "base64")) return p1
14f52ae2dc6dff4a53996a42657ee247d6f9ba33
16,710
import os def dirCheck(dirPath): """ Check whether the directory exists and if not make it. Parameters ---------- dirPath : str The path to the directory being checked. Returns ------- dirPath : str The path to the checked directory. """ if not...
ec0ad381961fae1f5660b89ae91b53559e6c4a86
16,711
def form_entity_types(ontotypes): """A method to form the numerical identifiers appropriately for further processing""" onto_types_l = set(ontotypes) onto_types_l = list(onto_types_l) # Sort the numerical identifiers # onto_types_l.sort() # Insert the '+' symbol between the identif...
e69fec7ca1cf78d20ad3cb1f995a26655ec94204
16,712
def combine_lists_recursive(list_of_lists): """Recursive combination function. This makes no attempt to avoid temporary copies""" if(len(list_of_lists) < 2): #Nothing to combine return list_of_lists elif(len(list_of_lists) == 2): list1 = list_of_lists[0] else: list1 = combine_lists_recursive(li...
ff77852cbea2a6b4176dc65a3640daa4f2f2bb9b
16,713
def is_string(func): """This decorator prevents the method from executing normally if the input is not a string.""" def wrapper(self, text): if type(text) is not str: return "'{}' is invalid. Input should be a string.".format(text) return func(self, text) return wrapper
9ac6c9a12c6f4dde7239af2c2ed05c81b3f1861c
16,715
def isIrrelevantManualRules(s, cdoc): """ Hand-crafted rules to remove paragraphs or entire documents from job advertisements :param s: String :param cdoc: List of parts of document (String) :returns: Boolean (ie. True if removal is needed), list of parts of documents (String), length of irrele...
772bc6f1f317d28119e16cc992eb668dfece6143
16,716
def _namedtuple_to_query(query, nt): """Return a filled-out query and arguments. The return value can be exploded and passed directly into execute. >>> query = 'INSERT INTO jobs ({}) VALUES ({});' >>> namedtuple_to_query(query, job) ('INSERT INTO jobs (`user`, `pages`) VALUES (%s, %s)', ('ckuehl',...
1db1dc9c90fe81dc262f1c1459ca7f0a0b725d9d
16,717
def x2bool(s): """Helper function to convert strings from the config to bool""" if isinstance(s, bool): return s elif isinstance(s, str): return s.lower() in ["1", "true"] raise ValueError()
2850c3ab0421619a087d88181f3b6e2c6ffa9e9a
16,718
def round_down(rounded, divider): """Round down an integer to a multiple of divider.""" return int(rounded) // divider * divider
cf9ea0a437d3246776bd80e03ed19f06827f68ce
16,719
import json import base64 import binascii def validate(arg): """ Validate input parameters for `left` and `right` :param arg: input from request :return: dictionary of {'data': base64encoded_stirng} if valid or False if not valid """ if not arg: return False if isinstan...
c10634020e402ffd7b39f657c405e6bcc7283031
16,721
def check_digit_luhn_mod_10(digits) -> int: """Luhn check verifies if 16 digits are a valid credit card or not. Args: digits ([str]): Credit card number Returns: [int]: Check digit """ reversed_digits = digits[::-1] calibrated_digits = [] for i, d in enumerate(reversed_digi...
77691a752b4db89141e9a791a1c596156dca4be3
16,722
import json def read_json_config(cfg): """Read a JSON configuration. First attempt to read as a JSON string. If that fails, assume that it is a JSON file and attempt to read contents from the file. Args: res: a config string or file path Returns: dict of config options """ ...
2268297273dbfb468e0a8391981b4795702ba0b7
16,723
def priceGetDeal(soup): """ Auxiliary price extraction function. Gets price of 'Deal of the Day'. """ price = soup.find('td', id='priceblock_dealprice', class_='a-color-price a-size-medium') price = price.text priceList = price.split() price = priceList[0] price = price.strip() price = price...
61bbe9d74628e3745e518cd8b74bceca9ae625f3
16,725
import string def idx_to_label(n: int) -> str: """Convert a number to a corresponding letter in the alphabet. In case the number is higher than the number of letters in the english alphabet, then a second character is appended. >>> For instance: >>>idx_to_label(0) >>> 'a' >>> idx_to_label...
67e4bba437016dddb6d90f286e1d65f2bfec8caf
16,728
def dict_contains(subdict, maindict): """ return True if the subdict is present with the sames values in dict. can be recursive. if maindict contains some key not in subdict it's ok. but if subdict has a key not in maindict or the value are not the same, it's a failure. >>> dict_contains(dict(a=1, ...
3c02145c7572f4c2d815213527effbfd7df93496
16,729
from typing import Any def cast_numeric_greater_than_zero( value: Any, value_name: str, required_type: type ) -> None: """ Checks that `value` is greater than zero and casts it to `required_type`. Raises an exception `value` not greater than zero. Args: value: numeric value to check ...
27f3b26d824863f1a94d4efe8c902cb84bc26c59
16,730
from typing import Iterable def filter_duplicate_key( line: bytes, line_number: int, marked_line_numbers: Iterable[int], ) -> bytes: """Return '' if first occurrence of the key otherwise return `line`.""" if marked_line_numbers and line_number == sorted(marked_line_numbers)[0]: return b"" ...
d592e718832f6d0c4718989d1a0fb96783c1508c
16,732
import copy import io import json def convert(data): """Convert a data to a graph structure""" if isinstance(data, (dict)): return copy.deepcopy(data) elif isinstance(data, str): # it's a json file path with open(data) as f: return convert(f) elif isinstance(data, io.TextI...
6e34bcdc5aa72289c3bb899c30ce92a272b13055
16,735
def get_people_values(people): """List person/observatory/site using explict retrieval of relevant values""" return [ (name, observatory, site) for name, site, observatory in people.values_list( "name", "site__name", "site__observatory__name" ) ]
6642515d80daa63346e043df05248121c0874ea7
16,736
def separate_elements(array): """splits the strings, delimited by whitespace in the provided list and adds each newly formed string to the returned list""" list_a = [] for element in array: list_a.extend(element.split(" ")) return list_a
1b0d8a4ea9d8255bbc70d90cdf963b98f61e38ea
16,740
import re def clean_text(text, *, replace='_'): """ Ensure input contains ONLY ASCII characters valid in filenames. Any other character will be replaced with 'replace'. Characters added in extras will be whitelisted in addiction to normal ASCII. Args: text: The text to clean. repl...
92d305e78d4883cea2e0a1c3da218284ad783b72
16,741
def greedy(circ, v, weight, options): """Defines a heuristic that results in greedy search, which focuses soley on minimizing the eval_func, and behaves somewhat similarly to depth first sarch.""" return options.eval_func(options.target, circ.matrix(v))
a9deb26009ec877cee2bf81c8c9f73114d268899
16,742
import sys def can_trace(): """Returns True if the user is an administrator on Windows. It is required for tracing to work. """ if sys.platform != 'win32': return True return bool(windll.shell32.IsUserAnAdmin())
6fbb54a8bed7af8483ced0d178cdfcbe2ce9ae0c
16,746
def compute_variances(grid): """Compute variance for each hyperparameters""" return grid[:, :, -1].var(axis=1)
a618e21b2d6290b60b1f9448acff941ad811fec6
16,747
def loadData(): """ 加载测试数据 """ return [[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]]
f143b1537198825a4fb85d656ca0772f2171fc48
16,748
from pathlib import Path def label_malformed(path: Path) -> Path: """ Renames the file at the given location to <original_filename>_MALFORMED. If such a file already exists, an incremented number is appended to the name until it can be created. The new file name is returned. Raises: `OSError` ...
12ca5ec240803127dd8aed7d13502c71a12f08ae
16,749
def get_child_parents(edges): """Puts each non-parent node together with its parents Parameters ---------- edges : list A list of tuples corresponding to the Bayesian network structure as described in the input file Returns ------- child_parents A dictionary with non-paren...
4b01a264ee1e2498c37f1fa0695f9430c207f04d
16,750
import random def get_random_from_distribution(minimum_value, distribution, increment=1): """Returns an integer from minimum_value to len(distribution)*increment, where the probability of any specific integer is determined by the probability distribution. """ x = random.random() result = minim...
0d3cde30c86ea8e230e3740123810d1e2d73d7ee
16,751
import numpy def gaussian2d(x, y, sigma_x, sigma_y, x0=0, y0=0, angle=0.0): """ Non-normalized 2D Gaussian function Parameters: * x, y : float or arrays Coordinates at which to calculate the Gaussian function * sigma_x, sigma_y : float Standard deviation in the x and y directions...
41a13e3799f611b9db02827113f537ae97d3cef8
16,752
def what_is_up(): """Initial message""" return 'Turing235 Project'
2ab9ed74f15f12b4f1e7291218c22b126690413a
16,753
def get_divisable(row): """Get numbers from row where one divides another without rest.""" for index, num in enumerate(row[:-1]): for other_num in row[index + 1:]: if num % other_num == 0 or other_num % num == 0: return sorted([num, other_num], reverse=True)
e7e6cb9936cd54df7cd0594168e53b8821cfbae6
16,755
def dms(degrees): """ Calculate degrees, minutes, seconds representation from decimal degrees. Parameters ---------- degrees : float Returns ------- (int, int, float) """ degrees_int = int(abs(degrees)) # integer degrees degrees_frac = abs(degrees) - degrees_int # fracti...
ef062ddc4d313c0e8376096952d0011c01d27825
16,756
def number_bigger_than_zero(s): """ Returns the Number representation of s if it is bigger than zero, else an error occurs :param s: Input string :return: Integer or None """ i = int(s) if i <= 0: raise ValueError("Value must be larger than 0") return i
a24d62a07964dea08d79392964073ac3ed84fbda
16,759
def is_genetic_effect(effect): """ Is this effect a genetic effect? :rtype: bool """ return effect in set(['additive', 'dominance', 'mitochondrial'])
9d79307f3f012b358b1b5c8347f7ba977be65aa1
16,760
def parenthesise(s, parens = True): """ Put parentheses around a string if requested. """ if parens: return '(%s)' % s else: return s
37a1abbb4a511eff9b9c63a79fafcc60331bee67
16,762
def delta_sr(processor_sr, aeronet_sr): """ Convention in ACIX I paper :param processor_sr: surface reflectance of the processor :param aeronet_sr: surface reflectance of the reference (aeronet based) :return: """ return processor_sr - aeronet_sr
60b3a69fd986044126cf95b8d87425334e472abe
16,763
from typing import Tuple import math def uniform_divide(total: float, mpp: float) -> Tuple[int, float]: """Return the minimum number of partitions and the quantity per partition that uniformly divide a given quantity :param total: The total quantity to divide :param mpp: Maximum quantity per partition ...
2cccebd710975b34ab7f3538516d8f4c60b18c87
16,764
import subprocess def _get_minor_gpu_device_numbers(): """ Returns: """ gpu_info = [] try: gpu_info = subprocess.check_output(["nvidia-smi", "--format=csv,noheader,nounits", "--query-gpu=pci.bus_id"]).decode() except: return gpu_info gpu_info = gpu_info.split('\n') d...
06eac15f9f15934083db4f75cd7b2161a4c594b4
16,765
import base64 def printable_encrypted_string(string): """ Зашифрованное сообщение не читабельно, т.к. содержит много непечатаемых символов таких как табуляция, новая строка и т.д. поэтому мы преобразуем это сообщение в строку в кодировке base64 """ message_bytes = string.encode("ascii") ba...
0451a2670408da7ab50227a09d7ff8358891fd49
16,768
def add_trailing_zero(df_vendor_gt, anchor_key): """ This function will amend the single temporary ground truth data frame record at runtime :param df_vendor_gt: The single temporary ground truth data frame record :param anchor_key: The field we are currently processing :return: The amended datafram...
7191c17f1f2795ec04218b9e1611c194569df8ff
16,769