Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
388,900 | def update(self, response, **kwargs):
response_cls = self._get_instance(**kwargs)
if response_cls:
setattr(response_cls, self.column, self.accessor(response))
_action_and_commit(response_cls, session.add)
else:
self.get_or_create_from_legacy_response(... | If a record matching the instance already exists in the database, update
it, else create a new record. |
388,901 | def preferences_view(request):
user = request.user
if request.method == "POST":
logger.debug(dict(request.POST))
phone_formset, email_formset, website_formset, errors = save_personal_info(request, user)
if user.is_student:
preferred_pic_form = save_preferred_pic(request... | View and process updates to the preferences page. |
388,902 | def split_gtf(gtf, sample_size=None, out_dir=None):
if out_dir:
part1_fn = os.path.basename(os.path.splitext(gtf)[0]) + ".part1.gtf"
part2_fn = os.path.basename(os.path.splitext(gtf)[0]) + ".part2.gtf"
part1 = os.path.join(out_dir, part1_fn)
part2 = os.path.join(out_dir, part2_f... | split a GTF file into two equal parts, randomly selecting genes.
sample_size will select up to sample_size genes in total |
388,903 | def discretize(value, factor=100):
if not isinstance(value, Iterable):
return int(value * factor)
int_value = list(deepcopy(value))
for i in range(len(int_value)):
int_value[i] = int(int_value[i] * factor)
return int_value | Discretize the given value, pre-multiplying by the given factor |
388,904 | def build_ricecooker_json_tree(args, options, metadata_provider, json_tree_path):
LOGGER.info()
channeldir = args[]
if channeldir.endswith(os.path.sep):
channeldir.rstrip(os.path.sep)
channelparentdir, channeldirname = os.path.split(channeldir)
channelparentdir, channeldirname = os.pat... | Download all categories, subpages, modules, and resources from open.edu. |
388,905 | def sample(self):
lenghts = []
angles = []
coordinates = []
fix = []
sample_size = int(round(self.trajLen_borders[self.drawFrom(, self.getrand())]))
coordinates.append([0, 0])
fix.append(1)
while len(coordinates) < sample_size:
... | Draws a trajectory length, first coordinates, lengths, angles and
length-angle-difference pairs according to the empirical distribution.
Each call creates one complete trajectory. |
388,906 | def generate(self):
observed_arr = None
for result_tuple in self.__feature_generator.generate():
observed_arr = result_tuple[0]
break
if self.noise_sampler is not None:
self.noise_sampler.output_shape = observed_arr.shape
observe... | Draws samples from the `true` distribution.
Returns:
`np.ndarray` of samples. |
388,907 | def add_member_roles(self, guild_id: int, member_id: int, roles: List[int]):
current_roles = [role for role in self.get_guild_member_by_id(guild_id, member_id)[]]
roles.extend(current_roles)
new_list = list(set(roles))
self.set_member_roles(guild_id, member_id, new_list) | Add roles to a member
This method takes a list of **role ids** that you want to give to the user,
on top of whatever roles they may already have. This method will fetch
the user's current roles, and add to that list the roles passed in. The
user's resulting list of roles will not contai... |
388,908 | def ConsultarCortes(self, sep="||"):
"Retorna listado de cortes -carnes- (código, descripción)"
ret = self.client.consultarCortes(
auth={
: self.Token, : self.Sign,
: self.Cuit, },
)[]
sel... | Retorna listado de cortes -carnes- (código, descripción) |
388,909 | def _realsize(self):
current = self
size= 0
while current is not None:
size += current._parser.sizeof(current)
last = current
current = getattr(current, , None)
size += len(getattr(last, , b))
return size | Get the struct size without padding (or the "real size")
:returns: the "real size" in bytes |
388,910 | def update_wallet(self, wallet_name, limit):
request = {
: {
: str(limit),
}
}
return make_request(
.format(self.url, wallet_name),
method=,
body=request,
timeout=self.timeout,
client=sel... | Update a wallet with a new limit.
@param the name of the wallet.
@param the new value of the limit.
@return a success string from the plans server.
@raise ServerError via make_request. |
388,911 | def _build_archive(self, dir_path):
zip_path = os.path.join(dir_path, "import.zip")
archive = zipfile.ZipFile(zip_path, "w")
for filename in CSV_FILES:
filepath = os.path.join(dir_path, filename)
if os.path.exists(filepath):
archive.write(filepa... | Creates a zip archive from files in path. |
388,912 | def index_spacing(self, value):
if not isinstance(value, bool):
raise TypeError()
self._index_spacing = value | Validate and set the index_spacing flag. |
388,913 | def get_categories(self):
posts = self.get_posts(include_draft=True)
result = {}
for post in posts:
for category_name in set(post.categories):
result[category_name] = result.setdefault(
category_name,
Pair(0, 0)) + Pair... | Get all categories and post count of each category.
:return dict_item(category_name, Pair(count_all, count_published)) |
388,914 | def get_parallel_value_for_key(self, key):
if self._remotelib:
return self._remotelib.run_keyword(,
[key], {})
return _PabotLib.get_parallel_value_for_key(self, key) | Get the value for a key. If there is no value for the key then empty
string is returned. |
388,915 | def delete_namespaced_cron_job(self, name, namespace, **kwargs):
kwargs[] = True
if kwargs.get():
return self.delete_namespaced_cron_job_with_http_info(name, namespace, **kwargs)
else:
(data) = self.delete_namespaced_cron_job_with_http_info(name, namespace, *... | delete_namespaced_cron_job # noqa: E501
delete a CronJob # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.delete_namespaced_cron_job(name, namespace, async_req=True)
>>> resu... |
388,916 | def write_contents_to_file(self, entities, path_patterns=None,
contents=None, link_to=None,
content_mode=, conflicts=,
strict=False, domains=None, index=False,
index_domains=None):
... | Write arbitrary data to a file defined by the passed entities and
path patterns.
Args:
entities (dict): A dictionary of entities, with Entity names in
keys and values for the desired file in values.
path_patterns (list): Optional path patterns to use when buildin... |
388,917 | def _complete_batch_send(self, resp):
self._batch_send_d = None
self._req_attempts = 0
self._retry_interval = self._init_retry_interval
if isinstance(resp, Failure) and not resp.check(tid_CancelledError,
CancelledError):
... | Complete the processing of our batch send operation
Clear the deferred tracking our current batch processing
and reset our retry count and retry interval
Return none to eat any errors coming from up the deferred chain |
388,918 | def dict_of_numpyarray_to_dict_of_list(d):
for key,value in d.iteritems():
if isinstance(value,dict):
d[key] = dict_of_numpyarray_to_dict_of_list(value)
elif isinstance(value,np.ndarray):
d[key] = value.tolist()
return d | Convert dictionary containing numpy arrays to dictionary containing lists
Parameters
----------
d : dict
sli parameter name and value as dictionary key and value pairs
Returns
-------
d : dict
modified dictionary |
388,919 | def evaluate_accuracy(data_iterator, net):
acc = mx.metric.Accuracy()
for data, label in data_iterator:
output = net(data)
predictions = nd.argmax(output, axis=1)
predictions = predictions.reshape((-1, 1))
acc.update(preds=predictions, labels=label)
return acc.get()[1] | Function to evaluate accuracy of any data iterator passed to it as an argument |
388,920 | def start(self) -> None:
if self.config:
self.websocket = self.ws_client(
self.loop, self.session, self.host,
self.config.websocketport, self.async_session_handler)
self.websocket.start()
else:
_LOGGER.error() | Connect websocket to deCONZ. |
388,921 | def PhyDMSComprehensiveParser():
parser = ArgumentParserNoArgHelp(description=("Comprehensive phylogenetic "
"model comparison and detection of selection informed by deep "
"mutational scanning data. This program runs repeatedly "
"to compare substitution models and detect ... | Returns *argparse.ArgumentParser* for ``phdyms_comprehensive`` script. |
388,922 | def next(self):
while True:
self.cur_idx += 1
if self.__datasource.populate_iteration(self):
return self
raise StopIteration | Move to the next valid locus.
Will only return valid loci or exit via StopIteration exception |
388,923 | def _fix_typo(s):
subst, attr, mode = s
return m(subst, attr, script("t.-x.-s.y.-'")) | M:.-O:.-'M:.-wa.e.-'t.x.-s.y.-', => M:.-O:.-'M:.-wa.e.-'t.-x.-s.y.-', |
388,924 | def exit_and_fail(self, msg=None, out=None):
self.exit(result=PANTS_FAILED_EXIT_CODE, msg=msg, out=out) | Exits the runtime with a nonzero exit code, indicating failure.
:param msg: A string message to print to stderr or another custom file desciptor before exiting.
(Optional)
:param out: The file descriptor to emit `msg` to. (Optional) |
388,925 | def host_members(self):
host = self.host()
if host is None:
return
for member, full_member in host.members_objects:
yield full_member | Return the members of the host committee. |
388,926 | def xpathNextPreceding(self, cur):
if cur is None: cur__o = None
else: cur__o = cur._o
ret = libxml2mod.xmlXPathNextPreceding(self._o, cur__o)
if ret is None:raise xpathError()
__tmp = xmlNode(_obj=ret)
return __tmp | Traversal function for the "preceding" direction the
preceding axis contains all nodes in the same document as
the context node that are before the context node in
document order, excluding any ancestors and excluding
attribute nodes and namespace nodes; the nodes are ordered
... |
388,927 | def get_resource_group(access_token, subscription_id, rgname):
endpoint = .join([get_rm_endpoint(),
, subscription_id,
, rgname,
, RESOURCE_API])
return do_get(endpoint, access_token) | Get details about the named resource group.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
rgname (str): Azure resource group name.
Returns:
HTTP response. JSON body. |
388,928 | def auth(self):
if not self.store_handler.has_value():
params = {}
params["access_key"] = self.access_key
params["secret_key"] = self.secret_key
params["app_id"] = self.app_id
params["device_id"] = self.device_id
auth_url = self.ap... | Auth is used to call the AUTH API of CricketAPI.
Access token required for every request call to CricketAPI.
Auth functional will post user Cricket API app details to server
and return the access token.
Return:
Access token |
388,929 | def fcm_send_single_device_data_message(
registration_id,
condition=None,
collapse_key=None,
delay_while_idle=False,
time_to_live=None,
restricted_package_name=None,
low_priority=False,
dry_run=False,
data_message=None,
content_available=No... | Send push message to a single device
All arguments correspond to that defined in pyfcm/fcm.py.
Args:
registration_id (str): FCM device registration IDs.
data_message (dict): Data message payload to send alone or with the
notification message
Keyword Args:
collapse_key (... |
388,930 | def nltk_tree_to_logical_form(tree: Tree) -> str:
| Given an ``nltk.Tree`` representing the syntax tree that generates a logical form, this method
produces the actual (lisp-like) logical form, with all of the non-terminal symbols converted
into the correct number of parentheses.
This is used in the logic that converts action sequences back into logical form... |
388,931 | def as_lwp_str(self, ignore_discard=True, ignore_expires=True):
now = time.time()
r = []
for cookie in self:
if not ignore_discard and cookie.discard:
continue
if not ignore_expires and cookie.is_expired(now):
continue
... | Return cookies as a string of "\\n"-separated "Set-Cookie3" headers.
ignore_discard and ignore_expires: see docstring for FileCookieJar.save |
388,932 | def cmd_tracker_mode(self, args):
connection = self.find_connection()
if not connection:
print("No antenna tracker found")
return
mode_mapping = connection.mode_mapping()
if mode_mapping is None:
print()
return
if len(args)... | set arbitrary mode |
388,933 | def setnx(self, key, value):
fut = self.execute(b, key, value)
return wait_convert(fut, bool) | Set the value of a key, only if the key does not exist. |
388,934 | def set_check(self, name, state):
if self.child.is_alive():
self.parent_pipe.send(CheckItem(name, state)) | set a status value |
388,935 | def convert_to_unicode( tscii_input ):
output = list()
prev = None
prev2x = None
for char in tscii_input:
if ord(char) < 128 :
output.append( char )
prev = None
prev2x = None
elif ord(char) in TSCII_DIRECT_L... | convert a byte-ASCII encoded string into equivalent Unicode string
in the UTF-8 notation. |
388,936 | def banner(*lines, **kwargs):
sep = kwargs.get("sep", "*")
count = kwargs.get("width", globals()["WIDTH"])
out(sep * count)
if lines:
out(sep)
for line in lines:
out("{} {}".format(sep, line))
out(sep)
out(sep * count) | prints a banner
sep -- string -- the character that will be on the line on the top and bottom
and before any of the lines, defaults to *
count -- integer -- the line width, defaults to 80 |
388,937 | def is_subdir(a, b):
a, b = map(os.path.abspath, [a, b])
return os.path.commonpath([a, b]) == b | Return true if a is a subdirectory of b |
388,938 | def _sanitize_parameters(self):
if isinstance(self._additional_edges, (list, set, tuple)):
new_dict = defaultdict(list)
for s, d in self._additional_edges:
new_dict[s].append(d)
self._additional_edges = new_dict
elif isinstance(self... | Perform a sanity check on parameters passed in to CFG.__init__().
An AngrCFGError is raised if any parameter fails the sanity check.
:return: None |
388,939 | def mk_subsuper_association(m, r_subsup):
r_rel = one(r_subsup).R_REL[206]()
r_rto = one(r_subsup).R_SUPER[212].R_RTO[204]()
target_o_obj = one(r_rto).R_OIR[203].O_OBJ[201]()
for r_sub in many(r_subsup).R_SUB[213]():
r_rgo = one(r_sub).R_RGO[205]()
source_o_obj = one(r_rgo).R_... | Create pyxtuml associations from a sub/super association in BridgePoint. |
388,940 | def get_template_data(template_file):
if not pathlib.Path(template_file).exists():
raise ValueError("Template file not found at {}".format(template_file))
with open(template_file, ) as fp:
try:
return yaml_parse(fp.read())
except (ValueError, yaml.YAMLError) as ex:
... | Read the template file, parse it as JSON/YAML and return the template as a dictionary.
Parameters
----------
template_file : string
Path to the template to read
Returns
-------
Template data as a dictionary |
388,941 | def _parse_request(self, schema, req, locations):
if schema.many:
assert (
"json" in locations
), "schema.many=True is only supported for JSON location"
parsed = self.parse_arg(
name="json",
... | Return a parsed arguments dictionary for the current request. |
388,942 | def get_normal_draws(num_mixers,
num_draws,
num_vars,
seed=None):
assert all([isinstance(x, int) for x in [num_mixers, num_draws, num_vars]])
assert all([x > 0 for x in [num_mixers, num_draws, num_vars]])
if seed is not None:
a... | Parameters
----------
num_mixers : int.
Should be greater than zero. Denotes the number of observations for
which we are making draws from a normal distribution for. I.e. the
number of observations with randomly distributed coefficients.
num_draws : int.
Should be greater tha... |
388,943 | def create_and_register_access97_db(filename: str,
dsn: str,
description: str) -> bool:
fullfilename = os.path.abspath(filename)
create_string = fullfilename + " General"
return (create_user_dsn(access_driver, CREATE_DB3=creat... | (Windows only.)
Creates a Microsoft Access 97 database and registers it with ODBC.
Args:
filename: filename of the database to create
dsn: ODBC data source name to create
description: description of the database
Returns:
bool: was the DSN created? |
388,944 | def domain_create(auth=None, **kwargs):
*
cloud = get_operator_cloud(auth)
kwargs = _clean_kwargs(keep_name=True, **kwargs)
return cloud.create_domain(**kwargs) | Create a domain
CLI Example:
.. code-block:: bash
salt '*' keystoneng.domain_create name=domain1 |
388,945 | def Softmax(x, params, axis=-1, **kwargs):
del params, kwargs
return np.exp(x - backend.logsumexp(x, axis, keepdims=True)) | Apply softmax to x: exponentiate and normalize along the given axis. |
388,946 | def ParseRow(self, parser_mediator, row_offset, row):
timestamp = self._ParseTimestamp(parser_mediator, row)
if timestamp is None:
return
event_data = TrendMicroUrlEventData()
event_data.offset = row_offset
for field in (
, , ,
, ):
try:
value = int(ro... | Parses a line of the log file and produces events.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
row_offset (int): line number of the row.
row (dict[str, str]): fields of a single row, as specified in COLUM... |
388,947 | def _create_cell(args, cell_body):
name = args.get()
if name is None:
raise Exception("Pipeline name was not specified.")
pipeline_spec = google.datalab.utils.commands.parse_config(
cell_body, google.datalab.utils.commands.notebook_environment())
airflow_spec = google.datalab.contrib.pipeline._pipeli... | Implements the pipeline cell create magic used to create Pipeline objects.
The supported syntax is:
%%pipeline create <args>
[<inline YAML>]
Args:
args: the arguments following '%%pipeline create'.
cell_body: the contents of the cell |
388,948 | def remove_attr(self, attr):
self._stable = False
self.attrs.pop(attr, None)
return self | Removes an attribute. |
388,949 | def init_widget(self):
super(AndroidChronometer, self).init_widget()
w = self.widget
w.setOnChronometerTickListener(w.getId())
w.onChronometerTick.connect(self.on_chronometer_tick) | Initialize the underlying widget. |
388,950 | def getlist(self, section, option):
value_list = self.get(section, option)
values = []
for value_line in value_list.split():
for value in value_line.split():
value = value.strip()
if value:
values.append(value)
retu... | Read a list of strings.
The value of `section` and `option` is treated as a comma- and newline-
separated list of strings. Each value is stripped of whitespace.
Returns the list of strings. |
388,951 | def yn_prompt(text):
text = "\n"+ text + "\n( or ): "
while True:
answer = input(text).strip()
if answer != and answer != :
continue
elif answer == :
return True
elif answer == :
return False | Takes the text prompt, and presents it, takes only "y" or "n" for
answers, and returns True or False. Repeats itself on bad input. |
388,952 | def find_declaration(self):
if not self.is_plt:
binary_name = self.binary_name
if binary_name not in SIM_LIBRARIES:
return
else:
binary_name = None
edges = self.transition_graph.edges()
... | Find the most likely function declaration from the embedded collection of prototypes, set it to self.prototype,
and update self.calling_convention with the declaration.
:return: None |
388,953 | def _reset_problem_type(self):
if self._solve_count > 0:
integer_count = 0
for func in (self._cp.variables.get_num_binary,
self._cp.variables.get_num_integer,
self._cp.variables.get_num_semicontinuous,... | Reset problem type to whatever is appropriate. |
388,954 | def dict_contents(self, use_dict=None, as_class=None):
if _debug: _log.debug("dict_contents use_dict=%r as_class=%r", use_dict, as_class)
return str(self) | Return the contents of an object as a dict. |
388,955 | def rdf_source(self, aformat="turtle"):
if aformat and aformat not in self.SUPPORTED_FORMATS:
return "Sorry. Allowed formats are %s" % str(self.SUPPORTED_FORMATS)
if aformat == "dot":
return self.__serializedDot()
else:
return self.rdflib_graph.serialize(format=aformat) | Serialize graph using the format required |
388,956 | def find_xml_all(cls, url, markup, tag, pattern):
body = cls.find_xml(url, markup)
return body.find_all(tag, href=re.compile(pattern)) | find xml(list)
:param url: contents url
:param markup: markup provider
:param tag: find tag
:param pattern: xml file pattern
:return: BeautifulSoup object list |
388,957 | def seq_minibatches(inputs, targets, batch_size, seq_length, stride=1):
if len(inputs) != len(targets):
raise AssertionError("The length of inputs and targets should be equal")
n_loads = (batch_size * stride) + (seq_length - stride)
for start_idx in range(0, len(inputs) - n_loads + 1, (batch_... | Generate a generator that return a batch of sequence inputs and targets.
If `batch_size=100` and `seq_length=5`, one return will have 500 rows (examples).
Parameters
----------
inputs : numpy.array
The input features, every row is a example.
targets : numpy.array
The labels of input... |
388,958 | def filter_for_ignored_ext(result, ignored_ext, ignore_copying):
if ignore_copying:
log = LoggingMixin().log
regex_builder = r"^.*\.(%s$)$" % .join(ignored_ext)
ignored_extensions_regex = re.compile(regex_builder)
log.debug(
,
... | Will filter if instructed to do so the result to remove matching criteria
:param result: list of dicts returned by Snakebite ls
:type result: list[dict]
:param ignored_ext: list of ignored extensions
:type ignored_ext: list
:param ignore_copying: shall we ignore ?
:type ... |
388,959 | def save(self, ts):
with open(self, ) as f:
Timestamp.wrap(ts).dump(f) | Save timestamp to file. |
388,960 | def _cur_band_filled(self):
cur_band = self._hyperbands[self._state["band_idx"]]
return len(cur_band) == self._s_max_1 | Checks if the current band is filled.
The size of the current band should be equal to s_max_1 |
388,961 | def extract(cls, padded):
if padded.startswith("@{") and padded.endswith("}"):
return padded[2:len(padded)-1]
else:
return padded | Removes the surrounding "@{...}" from the name.
:param padded: the padded string
:type padded: str
:return: the extracted name
:rtype: str |
388,962 | def remove(self, data):
current_node = self._first_node
deleted = False
if self._size == 0:
return
if data == current_node.data():
if current_node.next() is None:
self._first_node = LinkedListNode(None, None)
... | Removes a data node from the list. If the list contains more than one
node having the same data that shall be removed, then the node having
the first occurrency of the data is removed.
:param data: the data to be removed in the new list node
:type data: object |
388,963 | def enqueue(self, item_type, item):
with self.enlock:
self.queue[item_type].append(item) | Queue a new data item, make item iterable |
388,964 | def astra_projector(vol_interp, astra_vol_geom, astra_proj_geom, ndim, impl):
if vol_interp not in (, ):
raise ValueError("`vol_interp` not understood"
.format(vol_interp))
impl = str(impl).lower()
if impl not in (, ):
raise ValueError("`impl` not understood"
... | Create an ASTRA projector configuration dictionary.
Parameters
----------
vol_interp : {'nearest', 'linear'}
Interpolation type of the volume discretization. This determines
the projection model that is chosen.
astra_vol_geom : dict
ASTRA volume geometry.
astra_proj_geom : d... |
388,965 | def capture_output(self, with_hook=True):
self.hooked =
def display_hook(obj):
self.hooked += self.safe_better_repr(obj)
self.last_obj = obj
stdout, stderr = sys.stdout, sys.stderr
if with_hook:
d_hook = sys.displayhook
... | Steal stream output, return them in string, restore them |
388,966 | def process_placeholder_image(self):
if self.placeholder_image_name:
return
placeholder_image_name = None
placeholder_image = self.placeholder_image
if placeholder_image:
if isinstance(placeholder_image, OnStoragePlaceholderImage):
name =... | Process the field's placeholder image.
Ensures the placeholder image has been saved to the same storage class
as the field in a top level folder with a name specified by
settings.VERSATILEIMAGEFIELD_SETTINGS['placeholder_directory_name']
This should be called by the VersatileImageFileD... |
388,967 | def search_related(self, request):
logger.debug("Cache Search Request")
if self.cache.is_empty() is True:
logger.debug("Empty Cache")
return None
result = []
items = list(self.cache.cache.items())
for key, item in items:
element = se... | extracting everything from the cache |
388,968 | def random_string(length=6, alphabet=string.ascii_letters+string.digits):
return .join([random.choice(alphabet) for i in xrange(length)]) | Return a random string of given length and alphabet.
Default alphabet is url-friendly (base62). |
388,969 | def authenticate_server(self, response):
log.debug("authenticate_server(): Authenticate header: {0}".format(
_negotiate_value(response)))
host = urlparse(response.url).hostname
try:
if self.cbt_struct:
result = kerberos.authGSSClie... | Uses GSSAPI to authenticate the server.
Returns True on success, False on failure. |
388,970 | def get_jobs_from_argument(self, raw_job_string):
jobs = []
if raw_job_string.startswith(":"):
job_keys = raw_job_string.strip(" :")
jobs.extend([job for job in self.jobs(job_keys)])
else:
assert "/" in raw_job_string, "Job Code {0} is improp... | return a list of jobs corresponding to the raw_job_string |
388,971 | def get_all_events(self):
self.all_events = {}
events = self.tree.execute("$.events.frames")
if events is None:
return
for e in events:
event_type = e.get()
frame_id = e.get()
try:
self.all_events[event_type].append... | Gather all event IDs in the REACH output by type.
These IDs are stored in the self.all_events dict. |
388,972 | def chisquare(n_ij, weighted):
if weighted:
m_ij = n_ij / n_ij
nan_mask = np.isnan(m_ij)
m_ij[nan_mask] = 0.000001
w_ij = m_ij
n_ij_col_sum = n_ij.sum(axis=1)
n_ij_row_sum = n_ij.sum(axis=0)
alpha, beta, eps = (1, 1, 1)
while eps > 10e-6:
... | Calculates the chisquare for a matrix of ind_v x dep_v
for the unweighted and SPSS weighted case |
388,973 | def Cp(self, T):
result = 0.0
for c, e in zip(self._coefficients, self._exponents):
result += c*T**e
return result | Calculate the heat capacity of the compound phase.
:param T: [K] temperature
:returns: [J/mol/K] Heat capacity. |
388,974 | def url_join(base, *args):
scheme, netloc, path, query, fragment = urlsplit(base)
path = path if len(path) else "/"
path = posixpath.join(path, *[( % x) for x in args])
return urlunsplit([scheme, netloc, path, query, fragment]) | Helper function to join an arbitrary number of url segments together. |
388,975 | def startGraph(self):
g = r.Graph()
g.namespace_manager.bind("rdf", r.namespace.RDF)
g.namespace_manager.bind("foaf", r.namespace.FOAF)
g.namespace_manager.bind("xsd", r.namespace.XSD)
g.namespace_manager.bind("opa", "http://purl.org/socialparticipation/opa/"... | Starts RDF graph and bing namespaces |
388,976 | def GetDirections(self, origin, destination, sensor = False, mode = None, waypoints = None, alternatives = None, avoid = None, language = None, units = None,
region = None, departure_time = None, arrival_time = None):
params = {
: origin,
: de... | Get Directions Service
Pls refer to the Google Maps Web API for the details of the remained parameters |
388,977 | def ToLatLng(self):
rad_lat = math.atan2(self.z, math.sqrt(self.x * self.x + self.y * self.y))
rad_lng = math.atan2(self.y, self.x)
return (rad_lat * 180.0 / math.pi, rad_lng * 180.0 / math.pi) | Returns that latitude and longitude that this point represents
under a spherical Earth model. |
388,978 | def bind(self, prefix, namespace, *args, **kwargs):
setattr(self, prefix, RdfNamespace(prefix, namespace, **kwargs))
if kwargs.pop(, True):
self.__make_dicts__ | Extends the function to add an attribute to the class for each
added namespace to allow for use of dot notation. All prefixes are
converted to lowercase
Args:
prefix: string of namespace name
namespace: rdflib.namespace instance
kwargs:
calc: whether... |
388,979 | def xi2_from_mass1_mass2_spin2x_spin2y(mass1, mass2, spin2x, spin2y):
q = q_from_mass1_mass2(mass1, mass2)
a1 = 2 + 3 * q / 2
a2 = 2 + 3 / (2 * q)
return a1 / (q**2 * a2) * chi_perp_from_spinx_spiny(spin2x, spin2y) | Returns the effective precession spin argument for the smaller mass.
This function assumes it's given spins of the secondary mass. |
388,980 | def log(self, branch, remote):
log_hook = self.settings[]
if log_hook:
if ON_WINDOWS:
with NamedTemporaryFile(
pr... | Call a log-command, if set by git-up.fetch.all. |
388,981 | def _prefetch_items(self,change):
if self.is_initialized:
view = self.item_view
upper_limit = view.iterable_index+view.iterable_fetch_size-view.iterable_prefetch
lower_limit = max(0,view.iterable_index+view.iterable_prefetch)
offset = int(vie... | When the current_row in the model changes (whether from scrolling) or
set by the application. Make sure the results are loaded! |
388,982 | def snap_to_nearest_config(x, tune_params):
params = []
for i, k in enumerate(tune_params.keys()):
values = numpy.array(tune_params[k])
idx = numpy.abs(values-x[i]).argmin()
params.append(int(values[idx]))
return params | helper func that for each param selects the closest actual value |
388,983 | def merge_parameters(parameters, date_time, macros, types_and_values):
merged_parameters = Query._airflow_macro_formats(date_time=date_time, macros=macros,
types_and_values=types_and_values)
if parameters:
if types_and_values:
parameters = ... | Merge Return a mapping from airflow macro names (prefixed with '_') to values
Args:
date_time: The timestamp at which the macro values need to be evaluated. This is only
applicable when types_and_values = True
macros: If true, the values in the returned dict are the macro strings (like '{{ ds... |
388,984 | def load_modules_alignak_configuration(self):
alignak_cfg = {}
for instance in self.modules_manager.instances:
if not hasattr(instance, ):
return
try:
logger.info("Getting Alignak global configuration from module ", instance.na... | Load Alignak configuration from the arbiter modules
If module implements get_alignak_configuration, call this function
:param raw_objects: raw objects we got from reading config files
:type raw_objects: dict
:return: None |
388,985 | def surface_of_section(orbit, plane_ix, interpolate=False):
w = orbit.w()
if w.ndim == 2:
w = w[...,None]
ndim,ntimes,norbits = w.shape
H_dim = ndim // 2
p_ix = plane_ix + H_dim
if interpolate:
raise NotImplementedError("Not yet implemented, sorry!")
all_sos = n... | Generate and return a surface of section from the given orbit.
.. warning::
This is an experimental function and the API may change.
Parameters
----------
orbit : `~gala.dynamics.Orbit`
plane_ix : int
Integer that represents the coordinate to record crossings in. For
examp... |
388,986 | def getinfo(self, member):
if isinstance(member, RarInfo):
fname = member.filename
else:
fname = member
if PATH_SEP == :
fname2 = fname.replace("\\", "/")
else:
fname2 = fname.replace("/", "\\")
try:
... | Return RarInfo for filename |
388,987 | def vlan_classifier_rule_class_type_proto_proto_proto_val(self, **kwargs):
config = ET.Element("config")
vlan = ET.SubElement(config, "vlan", xmlns="urn:brocade.com:mgmt:brocade-vlan")
classifier = ET.SubElement(vlan, "classifier")
rule = ET.SubElement(classifier, "rule")
... | Auto Generated Code |
388,988 | def on_nick(self, connection, event):
old_nickname = self.get_nickname(event)
old_color = self.nicknames.pop(old_nickname)
new_nickname = event.target()
message = "is now known as %s" % new_nickname
self.namespace.emit("message", old_nickname, message, old_color)
... | Someone changed their nickname - send the nicknames list to the
WebSocket. |
388,989 | def _check_available_data(archive, arc_type, day):
available_stations = []
if arc_type.lower() == :
wavefiles = glob.glob(os.path.join(archive, day.strftime(),
day.strftime(), ))
for wavefile in wavefiles:
header = read(wavefile, headon... | Function to check what stations are available in the archive for a given \
day.
:type archive: str
:param archive: The archive source
:type arc_type: str
:param arc_type: The type of archive, can be:
:type day: datetime.date
:param day: Date to retrieve data for
:returns: list of tuple... |
388,990 | def render_file(self, filename):
dirname, basename = split(filename)
with changedir(dirname):
infile = abspath(basename)
outfile = abspath( % basename)
self.docutils.publish_file(infile, outfile, self.styles)
return outfile | Convert a reST file to HTML. |
388,991 | def remove_config_to_machine_group(self, project_name, config_name, group_name):
headers = {}
params = {}
resource = "/machinegroups/" + group_name + "/configs/" + config_name
(resp, header) = self._send("DELETE", project_name, None, resource, params, headers)
retu... | remove a logtail config to a machine group
Unsuccessful opertaion will cause an LogException.
:type project_name: string
:param project_name: the Project name
:type config_name: string
:param config_name: the logtail config name to apply
:type group_n... |
388,992 | def build_values(name, values_mods):
values_file = os.path.join(name, )
with open(values_file) as f:
values = yaml.load(f)
for key, value in values_mods.items():
parts = key.split()
mod_obj = values
for p in parts:
mod_obj = mod_obj[p]
print(f"Updat... | Update name/values.yaml with modifications |
388,993 | def create_in_cluster(self):
try:
self.api.create_namespaced_service(self.namespace, self.body)
except ApiException as e:
raise ConuException(
"Exception when calling Kubernetes API - create_namespaced_service: {}\n".format(e))
logger.info(
... | call Kubernetes API and create this Service in cluster,
raise ConuExeption if the API call fails
:return: None |
388,994 | def intercept_(self):
if getattr(self, , None) is not None and self.booster != :
raise AttributeError(
.format(self.booster))
b = self.get_booster()
return np.array(json.loads(b.get_dump(dump_format=)[0])[]) | Intercept (bias) property
.. note:: Intercept is defined only for linear learners
Intercept (bias) is only defined when the linear model is chosen as base
learner (`booster=gblinear`). It is not defined for other base learner types, such
as tree learners (`booster=gbtree`).... |
388,995 | def delete_vmss(access_token, subscription_id, resource_group, vmss_name):
endpoint = .join([get_rm_endpoint(),
, subscription_id,
, resource_group,
, vmss_name,
, COMP_API])
return do_delete(endpoint, access_to... | Delete a virtual machine scale set.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vmss_name (str): Name of the virtual machine scale set.
Returns:
HTTP respons... |
388,996 | def csoftmax_for_slice(input):
[ten, u] = input
shape_t = ten.shape
shape_u = u.shape
ten -= tf.reduce_mean(ten)
q = tf.exp(ten)
active = tf.ones_like(u, dtype=tf.int32)
mass = tf.constant(0, dtype=tf.float32)
found = tf.constant(True, dtype=tf.bool)
def loop(q_, mask, mass_... | It is a implementation of the constrained softmax (csoftmax) for slice.
Based on the paper:
https://andre-martins.github.io/docs/emnlp2017_final.pdf "Learning What's Easy: Fully Differentiable Neural Easy-First Taggers" (page 4)
Args:
input: A list of [input tensor, cumulative attention].
... |
388,997 | def classify(self, n_jobs=-1, configure=None):
start = timeit.default_timer()
networks = self.networks
n = len(networks)
cpu = n_jobs if n_jobs > -1 else mp.cpu_count()
if cpu > 1:
lpart = int(np.ceil(n / float(cpu))) if n > cpu else 1
parts = n... | Returns input-output behaviors for the list of logical networks in the attribute :attr:`networks`
Example::
>>> from caspo import core, classify
>>> networks = core.LogicalNetworkList.from_csv('networks.csv')
>>> setup = core.Setup.from_json('setup.json')
>>> ... |
388,998 | def highlight(self, *args):
toEnable = (self._highlighter is None)
seconds = 3
color = "red"
if len(args) > 3:
raise TypeError("Unrecognized argument(s) for highlight()")
for arg in args:
if type(arg) == bool:
toEnable = arg
... | Highlights the region with a colored frame. Accepts the following parameters:
highlight([toEnable], [seconds], [color])
* toEnable (boolean): Enables or disables the overlay
* seconds (number): Seconds to show overlay
* color (string): Hex code ("#XXXXXX") or color name ("black... |
388,999 | def run(self):
if KSER_METRICS_ENABLED == "yes":
from prometheus_client import start_http_server
logger.info("Metric.Starting...")
start_http_server(
os.getenv("KSER_METRICS_PORT", 8888),
os.getenv("KSER_METRICS_ADDRESS", "0.0.0.0")
... | Run consumer |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.