content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
import torch def max_over_grammatrix(inputs, l1, l2): """ :param inputs: [T2 * T1 * B * D] :param l1: :param l2: :return: """ batch_size = inputs.size(2) max_out_list = [] for b in range(batch_size): b_gram_matrix = inputs[:l2[b], :l1[b], b, :] dim = b_gram_matrix.s...
e2f4ad15a942d5222ed0607f75a1f85a6f3b98b5
23,606
def children(letter, x, y): """Gives the indices of the "children" of the variables describing the neighbours of a cell, according to the scheme described by Knuth""" assert letter in ["a", "b", "c", "d", "e", "f", "g"], "Letter does not have children in Knuth's scheme" if letter == "a": return ("b"...
3b6ea470003581a93f1a32f01228f00837cfc3b3
23,608
def in_cksum_done(s): """Fold and return Internet checksum.""" while (s >> 16): s = (s >> 16) + (s & 0xffff) return (~s & 0xffff)
25011c254e89179fe4232ad0ecfa0a847bf0b30b
23,609
import requests def cvr_to_q(cvr): """Convert CVR to Wikidata ID. Parameters ---------- cvr : str or int CVR identifier. Returns ------- q : str or None Strings with Wikidata IDs. None is returned if the CVR is not found. Examples -------- >>> cvr_to_q("10007...
287896d4193fd1427fdcf03f729b979488210c71
23,611
import ast def empty_list(lineno=None, col=None): """Creates the AST node for an empty list.""" return ast.List(elts=[], ctx=ast.Load(), lineno=lineno, col_offset=col)
2def486baf5537d2754312c6234a7908c4aa46dd
23,612
import numpy def participation_index(W,Ci): """ based on participation_coefficient.m from MATLAB Brain Connectivity Toolbox W: adjacency matrix Ci: community labels """ ## n=length(W); %number of vertices n=len(Ci) ## Ko=sum(W,2); ...
75110a1b5792d175d319407c46b2b29109dfe3fc
23,613
import torch def quat2rotmat(quat: torch.Tensor) -> torch.Tensor: """From a rotation matrix from a unit length quaternion Note that quaternion ordering is 'wxyz'. """ assert quat.shape[-1] == 4 qw, qx, qy, qz = quat[..., 0], quat[..., 1], quat[..., 2], quat[..., 3] qx2, qy2, qz2 = qx * qx, qy ...
d27590acc4124ef3b8e1c322c6d2faf8ceecb321
23,614
import argparse def get_options(cmd_args=None): """ Argument Parser. """ parser = argparse.ArgumentParser( prog='generateParkingAreaRerouters.py', usage='%(prog)s [options]', description='Generate parking area rerouters from the parking area definition.') parser.add_argument( '-a',...
a2a622e61a32452d2adb12b25aff61fb33c32733
23,617
def flip_transpose(arr): """ Flip a 2D-list (i.e. transpose). """ m = len(arr) n = len(arr[0]) res = [[-1 for _ in range(n)] for _ in range(m)] for i in range(m): for j in range(n): res[i][j] = arr[j][i] return res
ad0bb8b1e3a67cc0323425b5cba26d66665336e0
23,618
from typing import Dict from typing import Union def filter_level0( pairs: Dict[str, str]) -> Dict[str, Union[str, Dict[str, str]]]: """ Filter out key, value pairs for form parent.child: value""" result = {} for k, v in pairs.items(): key_parts = k.split('.') if len(key_parts) >...
a8aa3ee0b2a9e7714ee4dcf7bc1f505702e77d27
23,619
def _mean(items): """Return average (aka mean) for sequence of items.""" return sum(items) / len(items)
49fd8e1b42e3b454103074b512e32c1c443f974f
23,620
import shutil import os def unpack_smplh(smplh_dir): """`smplx.create` expects pkl files to be in `smplh` directory""" # unpack `smplh.tar.xz` target = smplh_dir / "smplh" archive_file = smplh_dir / "smplh.tar.xz" if not target.exists(): target.mkdir(exist_ok=True) shutil.unpack_ar...
0a36312795acfa90bd73a643b809769b013b4b4f
23,621
import logging def safe_get(ds, key): """Safely gets the tag value if present from the Dataset and logs failure. The safe get method of dict works for str, but not the hex key. The added benefit of this funtion is that it logs the failure to get the keyed value. Args: ds (Dataset): pydicom D...
15d3640410e7af9924fba512ca1c6da83a26b9f0
23,622
import random def rand_pl(m: int) -> int: """ Random integer distributed by a power law in the limit of the parameter m E.g.: With m = 2 returns 1 80% of the time returns 2 20% of the time With m = 3 returns 1 73.47% of the time returns 2 18.37% of the time returns 3 8.16% ...
ab48cf84ba3cf1d62ffcac0d2e702e7936d573b2
23,623
def createWhereCondition(attributes): """ Creates the where portion of filtering conditions. (So far, can only be used reliably for PlayerStats, but, it should work for most tables.) :param attributes: dict :return: str NEEDS AGGREGATION """ where = " WHERE " orderBy = "" ...
b175cd287dbcade622a8b47b700c7a6e0ab02234
23,624
def format_duration(secs): """ >>> format_duration(0) '00:00' >>> format_duration(1) '00:01' >>> format_duration(100) '01:40' >>> format_duration(10000) '02:46:40' >>> format_duration(1000000) '277:46:40' >>> format_duration(0.0) '00:00.000' >>> format_duration(0....
444a65d11f54b090f9d03252c3720ef2dabb3062
23,625
import os import shutil def form_results(results_path='./Results', model_type=None, dataset=None): """ Forms folders for each run to store the tensorboard files, saved models and the log files. :return: three string pointing to tensorboard, saved models and log paths respectively. """ if not os.pa...
107803807d37f427fdc7340a7d365e529c616f9a
23,626
from typing import Optional def fmac_cisco(mac: str) -> Optional[str]: """ Given a string representation of a MAC address in a common format, return it in Cisco format. """ # Fast-like remove ":", ".", and "-" in one go mac = mac.translate({58: None, 45: None, 46: None}).lower() if len(mac) !=...
4c1eb0a0f2b5dcf715c2653a224a18ecf979ac4b
23,627
def plusminus(n): """Get a number of +s or -s corresponding to n's value. If n == 0, returns "". Arg: n: An int Returns: A str, possibly empty. """ return ("-", "+")[n > 0] * abs(n)
26ddf2f90fff6ad3a24aca5ff8e3d3e26c2a7a2e
23,628
def get_console_domain(region: str) -> str: """ Get the domain for the AWS management console based on the region """ if region.startswith('us-gov'): return "console.amazonaws-us-gov.com" if region.startswith('cn'): return "console.amazonaws.cn" if region.startswith('us-iso'): ...
05c3f313616b4d71a59e4d0bdf5151e509939d87
23,629
def world_point_to_pixel(x, y, intr): """ Feed a point through the OpenCV distortion model to get :param x: :param y: :param intr: :return: """ r2 = x * x + y * y radial_distort = (1 + intr.k1 * r2 + intr.k2 * r2 * r2 + intr.k3 * r2 * r2 * r2) x_distort = x * radial_distort + (2...
debb763ef22970a6744fe8cd91df3f19e8c7ce4b
23,631
def _translate_virVcpuState(state): """ Return human readable virtual vpu state string. """ states = {} states[0] = 'Offline' states[1] = 'Running' states[2] = 'Blocked' states[3] = 'Last' return states[state]
1e65b55b946413e0a684f37cfd83fc2bf7f51761
23,632
import re def IsCommitPosition(regex_match): """Checks if match is correct revision(Cp number) format.""" matched_re = re.match(r'^[0-9]{6}$', regex_match) if matched_re: return True return False
b659215fb5107a5303b91d1d9fe9f4f368a1c280
23,633
def circulation_patron_exists(patron_pid): """Check if user exists.""" return True
0617d16e19269ce62b44bb341e857ffe67da364d
23,634
import re def build_doc_index(doc): """ Given a document string, construct index. Args: doc - a string to be indexed Returns: a dictionary with key being each distinct word in the doc string and value being a list of positions where this word occurs """ doc = doc.lower() ...
5fa34a3b9978b40d846e4a6d3da60c5a7da0633d
23,636
from dateutil import tz from datetime import datetime def tofrom_utc(timestamp, parseformat, from_utc=True): """ Convert a timestamp to/from UTC time :param str timestamp: Date/time to modify :param str parseformat: Format of the timestamp to parse :param bool from_utc: True if source stamp is UT...
feaf28653500bf9df58f73e86d19690098f1951d
23,637
def is_list_like(value): """Whether value is tuple or list""" return isinstance(value, (tuple, list))
71bbb42fff718e5f8ce7186116941cd9a6cd6465
23,639
def reorder_array(array, old_ids, new_ids): """Reorders a numpy array based on two lists of ids. The old_ids contains the ids of the elements currently in array. new_ids is the desired order. Elements and sizes must match! """ if type(old_ids) not in [list, tuple]: old_ids = list(old_ids) #...
365789b959a785985c0e4d071c674069a2221949
23,640
import os import subprocess def get_program_dir(program): """Get directory path of the external program. :param program: name of program, e.g. 'ls' or 'cat' :returns: None if it wasn't found, '/path/to/it/' if found """ devnull = open(os.devnull, 'w') try: path = subprocess.check_outp...
25be5c66b505ab622ca0702fbe1d486a107c20f9
23,642
from unittest.mock import Mock def fake_oauth_token(token, token_secret): """Return a mock OAuth token object.""" return Mock(key=token, secret=token_secret)
608d2aaf1163f35091b9f221043fab2d16af7fb3
23,643
def calc_sum_mem_dict(mem_dict): """ Calculates sum of values stored in memory. :param mem_dict: dictionary with memory address as key and stored value as value :return: int """ return sum(mem_dict.values())
de0ac4f2fc5f04d7e2e1bd8edd73fef2fd5f0b50
23,644
def get_weights(cbf): """Retrieve the latest gain corrections and their corresponding update times.""" weights, times = {}, {} for sensor_name in cbf.sensor: if sensor_name.endswith('_gain_correction_per_channel'): sensor = cbf.sensor[sensor_name] input_name = sensor_name.spl...
84887af7eda90fccb46242051a0f5b1d91a8e983
23,645
def allowed_image(filename): """ Check each uploaded image to ensure a permissible filetype and filename Takes full filename as input, returns boolean if filename passes the check """ allowed_img_ext = ["JPEG", "JPG", "HEIC"] # Ensure file has a . in the name if not "." in filename: ...
6dfdd37587ffa7abd98209c2cb965e78d808c229
23,646
def merge(default, config): """ Override default dict with config dict. """ merged = default.copy() merged.update({ k: v for k,v in config.items() if v and not v=='prompt'}) return merged
be204000174ea69007b536a2309b56b144cde5be
23,648
def batch_checker(predicted_quizzes): """ This function checks the batch of quizzes for that those are right or wrong. Parameter --------- predicted_quizzes (np.array), shape (?, 9, 9) Return ------ checked_quizzes : list of True or False for each quiz in predicted_quizzes ...
c86ae0c00cc5828b65ea991cf05e0274b8b676f6
23,649
import logging import yaml def get_yaml_config(config_file): """Return configuration from YAML file. :param config_file: Configuration file name :type config_file: string :returns: Dictionary of configuration :rtype: dict """ # Note in its original form get_mojo_config it would do a searc...
07d90588b753a8ddecbca681a94f7ef5ca25fc27
23,650
def cut_list(listing): """creates another list of words between ".." and nests it at the original place""" anf = [] end = [] for i in range(len(listing)): # finds where ".. begins and ends .." if len(listing[i]) > 1: # used to hamdle single " if listing [i][0] == '"' an...
415c3af8cc66961589cb85f26e60242d043e0d29
23,651
def get_player(): """ Add player is a function which takes the top 100 players of team and solo and concatenate them into a bigger list. It only accepts one name once in case a player plays both. Then we are sending the list to the input field for the user to select players. :return: a list of all a...
2a20ab01242cd75446812874dd4862638c37fbed
23,654
def parse_nx(nx_object, directed): """ Core parser for networkx objects Args: a networkx graph """ return (nx_object, None)
b973e73bcdbd3d98ca96d5dcebc17cb4e92ad600
23,655
def avg(vals, count=None): """ Returns the average value Args: vals: List of numbers to calculate average from. count: Int of total count that vals was part of. Returns: Float average value throughout a count. """ sum = 0 for v in vals: sum += v if count is...
dbb7d7d9cacb635b702c842aeaeb55194f7fcb50
23,656
def sum_swap_sorted(a, b): """O(A + B) time and O(1) space.""" if len(a) == 0: raise ValueError("array a must not be empty") if len(b) == 0: raise ValueError("array b must not be empty") sum_a = sum(a) sum_b = sum(b) # exit if difference is odd; sums cannot be balanced! if (s...
717922fb2f62ce120f62c36738cf63d80bd1f926
23,658
def north_south_drift(lat, lon): """North south trend depending linearly on latitude.""" return lat
f716c353b947f2d7079d7da663e46da5da9f0cab
23,659
import os def normpath(path): """Normalize a path. Parameters ---------- path : str The path to normalize. Returns ------- npath : str The normalized path. """ if "~" in path: out = os.path.abspath(os.path.expanduser(path)) else: out = os.pat...
ea051cada6fd855e72b6f36a892bbdf04fe11463
23,660
def format_file_name(input_file, output_file = None): """ Determine the name of the file to write to disk. If the user has specified an output file name and extension, use this to write the file. If they haven't, append "_no_grave" onto the name of the input file and add the .h5m extension. In...
bd13b2d3b5957df67f1a7d14a6189a12fe4ba3e8
23,661
def _convert_to_minutes(time_in): """ :in: time_in (str) HH:MM format; UTC :out: _minutes_out (int) minutes from midnight that day (00:00) """ hours_str, minutes_str = time_in.split(':') hours, minutes = int(hours_str), int(minutes_str) return hours*60 + minutes
4713194b337857fa98660beee5c18359b3cf6701
23,662
async def combine_records(record_a, record_b, join_fields=None): """ Combines unique information from two records into 1. Args: record_a (``dictionary``): New airtable record. record_b (``dictionary``): Old airtable record (This will be dictate the ``id``) Kwargs: join_fields (`...
324d6683870b87bed54f2ec94b1d7363b99d295e
23,664
def expand(self, nrepeat="", hindex="", icsys="", sctang="", phase="", **kwargs): """Displays the results of a modal cyclic symmetry analysis. APDL Command: EXPAND Parameters ---------- nrepeat Number of sector repetitions for expansion. The default is 0 (no expansion). ...
56045aa943d0e0ad14c3262430e52debe874bb28
23,665
def part1_and_2(lines, draw_diagonal=False): """ Part1: Consider only horizontal and vertical lines. Part2: Consider horizontal, vertical, *and* diagonal lines. All diagonal lines will be exactly 45 degrees At how many points do at least two lines overlap? """ # create the empty grap...
92501f82ab84a0b7dcbbc13b74ac5a8189fdf518
23,666
from typing import Optional from typing import Union from typing import Tuple def _normalize_keep(keep: Optional[Union[str, Tuple[Optional[str], Optional[str]]]]) -> Tuple[Optional[str], Optional[str]]: """Convert a value passed for the 'keep' parameter to a normalized form.""" if keep is None: return...
4e91c1c25ffab6b0488e37105d1a2ca5d5b3f849
23,667
def concatranknames(group): """helper function""" group['autnames'] = "%s" % ', '.join(group['namerank'][group['country'] == 'AUT']) return group
1999aa2473cc14816d26d2283a466de38652859a
23,668
import sys import argparse def parse_args(): """Pass command line arguments""" if not sys.argv[1:]: sys.argv.append('-h') parser = argparse.ArgumentParser(description='parse command line options for input') # input files parser.add_argument('-x', '--xlsx', help='xls...
933268db5c790350f4eaf91000f83694cd47e640
23,669
def validate_dict(in_dict, **kwargs): """ Returns Boolean of whether given dict conforms to type specifications given in kwargs. """ if not isinstance(in_dict, dict): raise ValueError('requires a dictionary') for key, value in kwargs.items(): if key == 'required': for requ...
2b816a440437272c1c84b8abf55d78ddbea29912
23,670
import copy def copy_face_features(feats: list): """ Performs deep copy of feats :param feats: list of features :return: deep-copied features """ return copy.deepcopy(feats)
47c37b528bbb63fe8d123bb8ebcf619d033ee310
23,671
def _get_dict_from_longtolongmap(proto_map): """ Convert the ProtoLongToLongMap_pb2 type to a simple dict. """ if len(proto_map.keys.elements) != len(proto_map.values.elements): raise IndexError('array length mismatch') new_dict = {} for key, value in zip(proto_map.keys.elements, proto_m...
07502282c5d000a74d0b24eace4dffcbe3dd81ae
23,672
import torch def gram_matrix(x): """ Calculates the Gram matrix for the feature maps contained in x. Parameters: x: feature maps Returns: G: gram matrix """ b, c, h, w = x.size() F = x.view(b, c, h * w) G = torch.bmm(F, F.transpose(1, 2)) G.div_(h * w) ...
69789d925fcd84d3d9dff93f70e41c1f8ae9d3e6
23,673
def search(d, key, default=None): """Return a dict containing to the specified key in the (possibly nested) within dictionary d. If there is no item with that key, return default. """ stack = [d] while stack: cur_d = stack[-1] stack.pop() for k, v in cur_d.items(): ...
cd96fda8462b4fe6904f138cc3fc25a83faca802
23,674
def _count_running_workers(cluster): """ Local replacement for the late `._count_active_workers` class method """ return len(cluster.scheduler_info.get('workers'))
f4d23f0ac7b5ecf07b67cd0c9050c6e1d743e902
23,675
def reverse_label(single_npy): """ reverse the normal/abnormal label for shanghaitech :return: """ reverse_npy=1-single_npy reverse_npy=reverse_npy[1:-1] return reverse_npy
e8529fde8cbcd13b0114d6d4d0a1d29972cc2c87
23,676
import locale import codecs def get_locale_codec(): """ Is Very Very Useful :return: """ return codecs.lookup(locale.getpreferredencoding()).name
dae9877892856f2c5565b3bcbc3801200e94fb40
23,677
def compute_route_cost(dist, route): """Compute the cost of a route.""" N = len(route) assert N == len(dist) + 1 assert route[0] == route[-1] cost = 0 for i in range(1, len(route)): u = route[i - 1] v = route[i] c = dist[u][v] assert c != 0 cost += c r...
8a1f8ce83ac0f2f990dbed08019fa04a97b1b725
23,678
import re def _prefix_only_url_replace_regex(pattern): """ Match urls in quotes pulling out the fields from pattern """ return re.compile(""" (?x) # flags=re.VERBOSE (?P<quote>\\\\?['"]) # the opening quotes {} (?P=quote) # the f...
ba095fa91f26a37e212d0f60639bfdd569111928
23,679
def compute_cis(series, confidence_level): """ Compute confidence intervals given cf level """ sorted_perfs = series.sort_values() lower_index = int(confidence_level/2 * len(sorted_perfs)) - 1 upper_index = int((1 - confidence_level/2) * len(sorted_perfs)) - 1 lower = sorted_perfs.iloc[lower...
34451cbb9b4fb3160243a09c748ab6c1c1f8843b
23,680
def is_hello_message(message: str) -> bool: """Checks if a message is a hello message.""" if "Hello" in message: return True return False
1acebc9ee74d05e3e1bb9913f68a6aaf6b48faa2
23,681
def get_markers_args_using_get_marker(node, mark_name): """Deprecated on pytest>=3.6""" return getattr(node.get_marker(mark_name), 'args', ())
7a2e0affb7d338cff60aae0bbaeb886700c06b1e
23,683
import os def load_ids_from_text_files(directory, training_set): """Given a directory where raw ProteinNet records are stored along with .ids files, reads and returns the contents of those files. Effectively returns a list of IDs associated with the training, validation, and test sets. """ wi...
fe79fb7d204cceddda313ff3914f66e577ecd963
23,684
def find_output_value(name, outputs): """ Finds a specific output within a collection. """ return next( output['value'] for output in outputs if output['name'] == name )
29ab594f969757ce9e8aab79ced58b285b9e49c2
23,686
def get_score_strings(path): """get scores from test output file, which lists per line the predicted and original scores: predicted: [0.3563531] - orig: 0.3676470588235294 predicted: [0.737128] - orig: 0.7205882352941176 """ of = open(path) lines=of.readlines() scores=lines[:-1] #last line i...
3ae2262db1012824d28ae59964ec54ea37aa8dac
23,687
import random import json def generate_random_client(field, **kwargs): """ Generate clients from 0 to 3 entries. If field is not required, return an empty result. Args: field: The field object. Keyword Arguments: only_required: The argument to generate only required fields. ...
c27845923e64c8e1075ff893508750c2bbb661a2
23,688
import hashlib def get_sha256_hash(key, size=None): """ Provide a SHA256 hash based on the supplied key values. :param key: An iterable of key values. :param size: The size of the returned hash. Defaults to full hash. If size provided is greater than the hash size the full hash is returned. ...
311c751d5c64eb9bef3a297760922654958d58cc
23,689
def _queue_number_order_priority(v): """Returns the number to be used as a comparison for priority. Lower values are more important. The queue priority is the lowest 31 bits, of which the top 9 bits are the task priority, and the rest is the timestamp which may overflow in the task priority. """ return v.q...
fd32678eb1984d2fcf9392467722cc43f72f64d9
23,690
def create_segment_allele_counts(segment_data, allele_data): """ Create a table of total and allele specific segment counts Args: segment_data (pandas.DataFrame): counts of reads in segments allele_data (pandas.DataFrame): counts of reads in segment haplotype blocks with phasing Returns: ...
f27b8e925d58ea70806c90ad2d3d5144e7690812
23,691
def update_trace_vector(agent, method, state, action=None): """Updates agent's trace vector (z) with then current state (or state-action pair) using to the given method. Returns the updated vector.""" assert method in ['replace', 'replace_reset', 'accumulating'], 'Invalid trace update method.' # Trace...
6ce4cd27e91dfca044b94c9b12a3aabdc788a5e5
23,692
def parse_state(value): """ Parse state from LEA code. """ return value[0:2]
8814cc94785674f411afe7ba54802891babb20a7
23,694
import math def get_ue_sig_power(ue_ap_distance): """ Function to calculate signal power between the UE and AP """ # To avoid ZeroDivisionError if ue_ap_distance: distance = (10 * math.log10(1 / math.pow(ue_ap_distance, 2))) # discretizing the distance distance /= 10 ...
1239e60153c397871e7a8b37d1b48bba39f41bee
23,695
def get_from_box_model(self, name): """ Property getter for all attributes that come from the box model. """ return getattr(self._box_model, name)
183ed25a55dd9b8c0ac6b8082f7be99a1ff78c25
23,696
import re def extract_timestamp(line): """Extract timestamp from log item. :param line: log item. :type line: str :return: timestamp or empty string :rtype: str """ rex = r"(\d{4}\-\d\d\-\d\d\s\d\d:\d\d:\d\d[\,\d]*[\s\w]*)" match = re.search(rex, line) if match: return mat...
2f8efdb9bdc95bf511d2f225ab42e3e489a61677
23,698
import os def get_resources_directory(): """Get imagebuilder resources directory.""" current_dir = os.path.dirname(os.path.abspath(__file__)) return os.path.join(current_dir, "..", "pcluster", "resources")
139664f6dbe540c12225625eb39e54220c7b42aa
23,699
def test_multi_plugin_sending(basicApp, EmptyPlugin): """ Nearly some test as "test_signal_handling_via_plugins", but with an adjustable amount of plugins for sending and receiving. Registers receivers before the signal gets registers itself and afterwards. Checks if all receivers get correctly cal...
6ac9a88cd4d37d79f86f057fc8f3c8b1049b5b65
23,700
from typing import Union def is_not_selected(*args: Union[str, None]) -> bool: """Check if field not seleced.""" for arg in args: if arg in ("", None): return True return False
ece53a2dafbed06bc4635e0193305e405b68c21c
23,701
def is_unique(sentence): """ 1.1 Is Unique: Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? Complexity: O(n) time, O(n) space """ h = set([]) for c in sentence: if c in h: return False h.add...
5c69a4217803c7ab88bb20b641dcd8726d29cb1e
23,702
import binascii def str2bytes(s: str) -> str: """Converts string to hex representations. :param str s: A string to convert :return: Hexadecimal string :rtype: str """ assert isinstance(s, str), 'Expected string got {}'.format(s) ss = str(binascii.hexlify(s.encode()))[1:] return ss.rep...
f616dc0c34208aa789acfbeff8b84baacac61487
23,703
def get_most_similar_factors(n): """Factorize n into two numbers. Returns the best pair, in the sense that the numbers are the closest to each other.""" i = int(n**0.5 + 0.5) while n % i != 0: i -= 1 return i, n/i
ea45874901031a95ba103b5f6bf89c743d8f65c3
23,705
import numpy def mp1(p, f, h): """Return the 1st order energy.""" ec1 = numpy.tensordot(h, p, axes=([0, 1], [0, 1])) ec2 = numpy.tensordot(f, p, axes=([0, 1], [0, 1])) return 0.5*(ec1 - ec2)
40bf1008a36574381e436cfef236c9845c5e225e
23,706
import click def get_short_help_str(command, limit=45): """ Gets short help for the command or makes it by shortening the long help string. """ return command.short_help or command.help and click.utils.make_default_short_help(command.help, limit) or ''
e123db3a912f1da13b7afd94fb8759a18237c36b
23,707
def countMorphemes(morphlist): """ Cuenta el número de ocurrencias de cada label :param morphlist: Lista de bio-labels :return: Diccionario con las labesl como llave y el número de ocurrencias como valor """ counts = {} for morpheme in morphlist: label = morpheme[0][2:] coun...
6cd4aa59b7c41cc416693c3287297570b94197fe
23,710
def sort_file(fh): """ sort the contents of a file handle. """ lst = list(fh.readlines()) lst.sort() return lst
8a8bf189e4294414024285187c66cd303dad2768
23,711
import functools def make_html(func): """Wraps text in html tags""" @functools.wraps(func) def wrapper(*args, **kwargs): return '<strong>' + func(*args, **kwargs) + '</strong>' return wrapper
42ee87d1f33fa9aca8acf8e1751399b2a2fbc45e
23,712
def str_to_int(s): """ Work around for converting str to int in numba. See https://github.com/numba/numba/issues/5650 """ result: int = 0 final_index: int = len(s) - 1 for i, v in enumerate(s): result += (ord(v) - 48) * (10 ** (final_index - i)) return result
4192b8c9cb7930778d04a6e15da7967c210e1a96
23,713
def has_no_end_date(effect): """ has no end date""" return not effect.instance.end
e6023fc531f38069f01d41c2b53e49f676700f2b
23,715
from typing import Union from typing import Dict from typing import Any def dict_to_txt(dict_val: Union[str, Dict[str, Any]]) -> str: """ Return string as "key:val; key2:val2" pairs from `dict_val`. Parameters ---------- dict_val : Union[str, Dict[str, Any]] Dict of key/val pairs ...
116aeb9236466e71db5f84651d4cb36d3da05422
23,716
from pathlib import Path from typing import TextIO import gzip def tsv_opener(path: Path) -> TextIO: """ Open a TSV (either text file or gzip-compressed text file). Args: path : The path to the TSV file. """ if path.suffix == ".gz": fh = gzip.open(path, "rt") else: fh = ...
7e5186138f9331e27b35458dc0f33b268dc48582
23,717
def reg_iou(x1, y1, x2, y2, dx1, dy1, dx2, dy2): """Bounding box regression function""" pred_x1 = x1 + dx1 pred_y1 = y1 + dy1 pred_x2 = x2 + dx2 pred_y2 = y2 + dy2 return pred_x1, pred_y1, pred_x2, pred_y2
3ea7229136800f448d3731209c63bbeec4aab81d
23,718
def gpsWeekCheck(t): """Makes sure the time is in the interval [-302400 302400] seconds, which corresponds to number of seconds in the GPS week""" if t > 302400.: t = t - 604800. elif t < -302400.: t = t + 604800. return t
acec8cff009f8dac53363a4686d869f4d5054b8d
23,719
import six import binascii def _uvarint(buf): """Reads a varint from a bytes buffer and returns the value and # bytes""" x = 0 s = 0 for i, b_str in enumerate(buf): if six.PY3: b = b_str else: b = int(binascii.b2a_hex(b_str), 16) if b < 0x80: ...
825921b72501436ca52dff498c76c43c0f5f48ca
23,720
import shutil import os def patch_rom(src, dst, patch_data): """Patch src with the contents of patch_data, saving to dst.""" succeeded = True # If we can work on a copy, copy the ROM so we can work on it if src != dst: shutil.copyfile(src, dst) with open(dst, "r+b") as f: for of...
c62c5a22fccbe7a1d7d66b914a9305c166c27a69
23,721
import torch def get_default_config(): """The default configs.""" use_cuda = torch.cuda.is_available() save_model = False # node_state_dim = 32 # number of features for a node # graph_rep_dim = 128 # number of features of a graph representation # graph_embedding_net_config = dict( # ...
ac340f7d2886a168c349e48bb1b3daa0bf48307e
23,723
def findWellsWithGivenTopsCurves( wells, wells_with_all_given_tops, wellsWithNeededCurvesList_real ): """ NOTE: THIS FUNCTION MAY NOT BE USED DUE TO OTHER CHANGES IN THE CODE. It was created to deal with wanting to find the intersection of a list of wells with SITEID only and a list of wells with UWI on...
6f76cdb3866a0b87f3231aae09158bd788dea47e
23,724
def binarize_ic50(ic50, ic50_threshold): """ Binarize ic50 based on a threshold """ if ic50 <= ic50_threshold: return 1 return 0
d1512f790dfad4fb3f85f4757184ceb7d21fc56a
23,725
def filter_rows_by_value(data, min): """Select rows where each value is greater than the given min threshhold.""" rows = data[data > min].dropna().astype(int) return rows
ec49892ea47256fe8d80063c2cdbcd161872ceb7
23,727
def integer(number, *args): """In Python 3 int() is broken. >>> int(bytearray(b'1_0')) Traceback (most recent call last): ... ValueError: """ num = int(number, *args) if isinstance(number, str) and '_' in number or isinstance(number, (bytes, bytearray)) and b' ' in number: raise ValueError() return num
e24f208db97be51ee535ad93cb795958848dd18f
23,728