text_prompt stringlengths 157 13.1k | code_prompt stringlengths 7 19.8k ⌀ |
|---|---|
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def merge_google_napoleon_docs(prnt_doc=None, child_doc=None):
""" Merge two google-style docstrings into a single docstring, according to napoleon docstring sec... |
style = "google"
return merge_all_sections(parse_napoleon_doc(prnt_doc, style), parse_napoleon_doc(child_doc, style), style) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def merge_mesh( x1, ngroups1, conns1, x2, ngroups2, conns2, cmap, eps = 1e-8 ):
"""Merge two meshes in common coordinates found in x1, x2.""" |
n1 = x1.shape[0]
n2 = x2.shape[0]
err = nm.sum( nm.sum( nm.abs( x1[cmap[:,0],:-1] - x2[cmap[:,1],:-1] ) ) )
if abs( err ) > (10.0 * eps):
print 'nonmatching meshes!', err
raise ValueError
mask = nm.ones( (n2,), dtype = nm.int32 )
mask[cmap[:,1]] = 0
# print mask, nm.cumsum(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fix_double_nodes(coor, ngroups, conns, eps):
""" Detect and attempt fixing double nodes in a mesh. The double nodes are nodes having the same coordinates w.r... |
n_nod, dim = coor.shape
cmap = find_map( coor, nm.zeros( (0,dim) ), eps = eps, allow_double = True )
if cmap.size:
output('double nodes in input mesh!')
output('trying to fix...')
while cmap.size:
print cmap.size
# Just like in Variable.equation_mapping()..... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_min_edge_size(coor, conns):
""" Get the smallest edge length. """ |
mes = 1e16
for conn in conns:
n_ep = conn.shape[1]
for ir in range( n_ep ):
x1 = coor[conn[:,ir]]
for ic in range( ir + 1, n_ep ):
x2 = coor[conn[:,ic]]
aux = nm.sqrt( nm.sum( (x2 - x1)**2.0, axis = 1 ).min() )
mes = min( m... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_min_vertex_distance( coor, guess ):
"""Can miss the minimum, but is enough for our purposes.""" |
# Sort by x.
ix = nm.argsort( coor[:,0] )
scoor = coor[ix]
mvd = 1e16
# Get mvd in chunks potentially smaller than guess.
n_coor = coor.shape[0]
print n_coor
i0 = i1 = 0
x0 = scoor[i0,0]
while 1:
while ((scoor[i1,0] - x0) < guess) and (i1 < (n_coor - 1)):
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def make_mesh( coor, ngroups, conns, mesh_in ):
"""Create a mesh reusing mat_ids and descs of mesh_in.""" |
mat_ids = []
for ii, conn in enumerate( conns ):
mat_id = nm.empty( (conn.shape[0],), dtype = nm.int32 )
mat_id.fill( mesh_in.mat_ids[ii][0] )
mat_ids.append( mat_id )
mesh_out = Mesh.from_data( 'merged mesh', coor, ngroups, conns,
mat_ids, me... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def make_inverse_connectivity(conns, n_nod, ret_offsets=True):
""" For each mesh node referenced in the connectivity conns, make a list of elements it belongs to... |
from itertools import chain
iconn = [[] for ii in xrange( n_nod )]
n_els = [0] * n_nod
for ig, conn in enumerate( conns ):
for iel, row in enumerate( conn ):
for node in row:
iconn[node].extend([ig, iel])
n_els[node] += 1
n_els = nm.array(n_els,... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def from_surface( surf_faces, mesh_in ):
""" Create a mesh given a set of surface faces and the original mesh. """ |
aux = nm.concatenate([faces.ravel() for faces in surf_faces])
inod = nm.unique(aux)
n_nod = len( inod )
n_nod_m, dim = mesh_in.coors.shape
aux = nm.arange( n_nod, dtype=nm.int32 )
remap = nm.zeros( (n_nod_m,), nm.int32 )
remap[inod] = aux
mesh = Mesh( ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def from_file(filename=None, io='auto', prefix_dir=None, omit_facets=False):
""" Read a mesh from a file. Parameters filename : string or function or MeshIO inst... |
if isinstance(filename, Mesh):
return filename
if io == 'auto':
if filename is None:
output( 'filename or io must be specified!' )
raise ValueError
else:
io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def from_region(region, mesh_in, save_edges=False, save_faces=False, localize=False, is_surface=False):
""" Create a mesh corresponding to a given region. """ |
mesh = Mesh( mesh_in.name + "_reg" )
mesh.coors = mesh_in.coors.copy()
mesh.ngroups = mesh_in.ngroups.copy()
mesh.conns = []
mesh.descs = []
mesh.mat_ids = []
if not is_surface:
if region.has_cells():
for ig in region.igs:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def from_data( name, coors, ngroups, conns, mat_ids, descs, igs = None ):
""" Create a mesh from mesh data. """ |
if igs is None:
igs = range( len( conns ) )
mesh = Mesh(name)
mesh._set_data(coors = coors,
ngroups = ngroups,
conns = [conns[ig] for ig in igs],
mat_ids = [mat_ids[ig] for ig in igs],
descs ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def copy(self, name=None):
"""Make a deep copy of self. Parameters name : str Name of the copied mesh. """ |
return Struct.copy(self, deep=True, name=name) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _set_data(self, coors, ngroups, conns, mat_ids, descs, nodal_bcs=None):
""" Set mesh data. Parameters coors : array Coordinates of mesh nodes. ngroups : arra... |
self.coors = nm.ascontiguousarray(coors)
if ngroups is None:
self.ngroups = nm.zeros((self.coors.shape[0],), dtype=nm.int32)
else:
self.ngroups = nm.ascontiguousarray(ngroups)
self.conns = [nm.asarray(conn, dtype=nm.int32) for conn in conns]
self.mat_i... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def write(self, filename=None, io=None, coors=None, igs=None, out=None, float_format=None, **kwargs):
""" Write mesh + optional results in `out` to a file. Param... |
if filename is None:
filename = self.name + '.mesh'
if io is None:
io = self.io
if io is None:
io = 'auto'
if io == 'auto':
io = MeshIO.any_from_filename( filename )
if coors is None:
coors = self.coors
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_element_coors(self, ig=None):
""" Get the coordinates of vertices elements in group `ig`. Parameters ig : int, optional The element group. If None, the c... |
cc = self.coors
n_ep_max = self.n_e_ps.max()
coors = nm.empty((self.n_el, n_ep_max, self.dim), dtype=cc.dtype)
for ig, conn in enumerate(self.conns):
i1, i2 = self.el_offsets[ig], self.el_offsets[ig + 1]
coors[i1:i2, :conn.shape[1], :] = cc[conn]
return... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def transform_coors(self, mtx_t, ref_coors=None):
""" Transform coordinates of the mesh by the given transformation matrix. Parameters mtx_t : array The transfor... |
if ref_coors is None:
ref_coors = self.coors
if mtx_t.shape[1] > self.coors.shape[1]:
self.coors[:] = nm.dot(ref_coors, mtx_t[:,:-1].T) + mtx_t[:,-1]
else:
self.coors[:] = nm.dot(ref_coors, mtx_t.T) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def explode_groups(self, eps, return_emap=False):
""" Explode the mesh element groups by `eps`, i.e. split group interface nodes and shrink each group towards it... |
assert_(0.0 <= eps <= 1.0)
remap = nm.empty((self.n_nod,), dtype=nm.int32)
offset = 0
if return_emap:
rows, cols = [], []
coors = []
ngroups = []
conns = []
mat_ids = []
descs = []
for ig, conn in enumerate(self.conns):
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def join_conn_groups( conns, descs, mat_ids, concat = False ):
"""Join groups of the same element type.""" |
el = dict_from_keys_init( descs, list )
for ig, desc in enumerate( descs ):
el[desc].append( ig )
groups = [ii for ii in el.values() if ii]
## print el, groups
descs_out, conns_out, mat_ids_out = [], [], []
for group in groups:
n_ep = conns[group[0]].shape[1]
conn = n... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def convert_complex_output(out_in):
""" Convert complex values in the output dictionary `out_in` to pairs of real and imaginary parts. """ |
out = {}
for key, val in out_in.iteritems():
if val.data.dtype in complex_types:
rval = copy(val)
rval.data = val.data.real
out['real(%s)' % key] = rval
ival = copy(val)
ival.data = val.data.imag
out['imag(%s)' % key] = ival
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def guess_format( filename, ext, formats, io_table ):
""" Guess the format of filename, candidates are in formats. """ |
ok = False
for format in formats:
output( 'guessing %s' % format )
try:
ok = io_table[format].guess( filename )
except AttributeError:
pass
if ok: break
else:
raise NotImplementedError('cannot guess format of a *%s file!' % ext)
return f... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def any_from_filename(filename, prefix_dir=None):
""" Create a MeshIO instance according to the kind of `filename`. Parameters filename : str, function or MeshIO... |
if not isinstance(filename, basestr):
if isinstance(filename, MeshIO):
return filename
else:
return UserMeshIO(filename)
ext = op.splitext(filename)[1].lower()
try:
format = supported_formats[ext]
except KeyError:
raise ValueError('unsupported m... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def for_format(filename, format=None, writable=False, prefix_dir=None):
""" Create a MeshIO instance for file `filename` with forced `format`. Parameters filenam... |
ext = op.splitext(filename)[1].lower()
try:
_format = supported_formats[ext]
except KeyError:
_format = None
format = get_default(format, _format)
if format is None:
io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)
else:
if not isinstance(format,... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def read_data( self, step, filename = None ):
"""Point data only!""" |
filename = get_default( filename, self.filename )
out = {}
fd = open( self.filename, 'r' )
while 1:
line = skip_read_line(fd, no_eof=True).split()
if line[0] == 'POINT_DATA':
break
n_nod = int(line[1])
while 1:
line... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _read_section(self, f, integer=True):
""" Reads one section from the mesh3d file. float(), before returning Some examples how a section can look like: 2 1 2 ... |
if integer:
dtype=int
else:
dtype=float
l = self._read_line(f)
N = int(l)
rows = []
for i in range(N):
l = self._read_line(f)
row = nm.fromstring(l, sep=" ", dtype=dtype)
rows.append(row)
return nm.array... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create(cls):
""" Return always the same instance of the backend class """ |
if cls not in cls._instances:
cls._instances[cls] = cls()
return cls._instances[cls] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def peek(self):
""" Returns PeekableIterator.Nothing when the iterator is exhausted. """ |
try:
v = next(self._iter)
self._iter = itertools.chain((v,), self._iter)
return v
except StopIteration:
return PeekableIterator.Nothing |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _append_to_parent(self):
""" Causes this ephemeral table to be persisted on the TOMLFile. """ |
if self.__appended:
return
if self._parent is not None:
self._parent.append_fresh_table(self)
self.__appended = True |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def access_token(self, value, request):
""" Try to get the `AccessToken` associated with the provided token. *The provided value must pass `BearerHandler.validat... |
if self.validate(value, request) is not None:
return None
access_token = AccessToken.objects.for_token(value)
return access_token |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def validate(self, value, request):
""" Try to get the `AccessToken` associated with the given token. The return value is determined based n a few things: - If n... |
from django.http import HttpResponseBadRequest
from doac.http import HttpResponseUnauthorized
if not value:
response = HttpResponseBadRequest()
response["WWW-Authenticate"] = request_error_header(CredentialsNotProvided)
return response
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fetch_friends(self, user):
""" fetches the friends from twitter using the information on django-social-auth models user is an instance of UserSocialAuth Retu... |
# Fetch the token key and secret
if USING_ALLAUTH:
social_app = SocialApp.objects.get_current('twitter')
consumer_key = social_app.key
consumer_secret = social_app.secret
oauth_token = SocialToken.objects.get(account=user, app=social_app).token
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fetch_friend_ids(self, user):
""" fethces friend id's from twitter Return: collection of friend ids """ |
friends = self.fetch_friends(user)
friend_ids = []
for friend in friends:
friend_ids.append(friend.id)
return friend_ids |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def merge_section(key, prnt_sec, child_sec):
""" Synthesize a output numpy docstring section. Parameters key: str The numpy-section being merged. prnt_sec: Optio... |
if prnt_sec is None and child_sec is None:
return None
if key == "Short Summary":
header = ''
else:
header = "\n".join((key, "".join("-" for i in range(len(key))), ""))
if child_sec is None:
body = prnt_sec
else:
body = child_sec
return header + body |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def structure(table_toplevels):
""" Accepts an ordered sequence of TopLevel instances and returns a navigable object structure representation of the TOML file. "... |
table_toplevels = tuple(table_toplevels)
obj = NamedDict()
last_array_of_tables = None # The Name of the last array-of-tables header
for toplevel in table_toplevels:
if isinstance(toplevel, toplevels.AnonymousTable):
obj[''] = toplevel.table_element
elif isinsta... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def prune_old_authorization_codes():
""" Removes all unused and expired authorization codes from the database. """ |
from .compat import now
from .models import AuthorizationCode
AuthorizationCode.objects.with_expiration_before(now()).delete() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_handler(handler_name):
""" Imports the module for a DOAC handler based on the string representation of the module path that is provided. """ |
from .conf import options
handlers = options.handlers
for handler in handlers:
handler_path = handler.split(".")
name = handler_path[-2]
if handler_name == name:
handler_module = __import__(".".join(handler_path[:-1]), {}, {}, str(handler_path[-1]))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def request_error_header(exception):
""" Generates the error header for a request using a Bearer token based on a given OAuth exception. """ |
from .conf import options
header = "Bearer realm=\"%s\"" % (options.realm, )
if hasattr(exception, "error"):
header = header + ", error=\"%s\"" % (exception.error, )
if hasattr(exception, "reason"):
header = header + ", error_description=\"%s\"" % (exception.reason, )
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_default_pos(self, defaultPos):
"""Set the default starting location of our character.""" |
self.coords = defaultPos
self.velocity = r.Vector2()
self.desired_position = defaultPos
r.Ragnarok.get_world().Camera.pan = self.coords
r.Ragnarok.get_world().Camera.desired_pan = self.coords |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def __generate_location(self):
""" Reset the location of the cloud once it has left the viewable area of the screen. """ |
screen_width = world.get_backbuffer_size().X
self.movement_speed = random.randrange(10, 25)
# This line of code places the cloud to the right of the viewable screen, so it appears to
# gradually move in from the right instead of randomally appearing on some portion of the viewable
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def is_delimiter(line):
""" True if a line consists only of a single punctuation character.""" |
return bool(line) and line[0] in punctuation and line[0]*len(line) == line |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def parse_rest_doc(doc):
""" Extract the headers, delimiters, and text from reST-formatted docstrings. Parameters doc: Union[str, None] Returns ------- Dict[str,... |
class Section(object):
def __init__(self, header=None, body=None):
self.header = header # str
self.body = body # str
doc_sections = OrderedDict([('', Section(header=''))])
if not doc:
return doc_sections
doc = cleandoc(doc)
lines = iter(doc.splitlines())... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def merge_rest_docs(prnt_doc=None, child_doc=None):
""" See custom_inherit.style_store.reST for details. """ |
prnt_sections = parse_rest_doc(prnt_doc)
child_sections = parse_rest_doc(child_doc)
header = prnt_sections['']
prnt_sections.update(child_sections)
if not child_sections[''].body:
prnt_sections[''] = header
if not header.body:
prnt_sections.popitem(last=False)
retu... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def parse_strings(content="", filename=None):
"""Parse an apple .strings file and create a stringset with all entries in the file. See http://developer.apple.com... |
if filename is not None:
content = _get_content(filename=filename)
stringset = []
f = content
if f.startswith(u'\ufeff'):
f = f.lstrip(u'\ufeff')
#regex for finding all comments in a file
cp = r'(?:/\*(?P<comment>(?:[^*]|(?:\*+[^*/]))*\**)\*/)'
p = re.compile(r'(?:%s[ \t]*[... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def identify(file_elements):
""" Outputs an ordered sequence of instances of TopLevel types. Elements start with an optional TableElement, followed by zero or mo... |
if not file_elements:
return
_validate_file_elements(file_elements)
# An iterator over enumerate(the non-metadata) elements
iterator = PeekableIterator((element_i, element) for (element_i, element) in enumerate(file_elements)
if element.type != elements.TYPE_M... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def load_character(tile_map, gamescreen):
"""Create an instance of the main character and return it.""" |
tile_obj = thc.TileHeroCharacter(tile_map, gamescreen)
tile_obj.load_texture("..//Textures//character.png")
tile_obj.origin = r.Vector2(0, 0)
tile_obj.hazard_touched_method = hazard_touched_method
tile_obj.special_touched_method = special_touched_method
return tile_obj |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def auth_uri(self):
"""The authorzation URL that should be provided to the user""" |
return self.oauth.auth_uri(redirect_uri=self.redirect_uri, scope=self.scope) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def browse_dailydeviations(self):
"""Retrieves Daily Deviations""" |
response = self._req('/browse/dailydeviations')
deviations = []
for item in response['results']:
d = Deviation()
d.from_dict(item)
deviations.append(d)
return deviations |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def browse_userjournals(self, username, featured=False, offset=0, limit=10):
"""Fetch user journals from user :param username: name of user to retrieve journals ... |
response = self._req('/browse/user/journals', {
"username":username,
"featured":featured,
"offset":offset,
"limit":limit
})
deviations = []
for item in response['results']:
d = Deviation()
d.from_dict(item)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def browse_morelikethis_preview(self, seed):
"""Fetch More Like This preview result for a seed deviation :param seed: The deviationid to fetch more like """ |
response = self._req('/browse/morelikethis/preview', {
"seed":seed
})
returned_seed = response['seed']
author = User()
author.from_dict(response['author'])
more_from_artist = []
for item in response['more_from_artist']:
d = Deviation(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def browse(self, endpoint="hot", category_path="", seed="", q="", timerange="24hr", tag="", offset=0, limit=10):
"""Fetch deviations from public endpoints :param... |
if endpoint == "hot":
response = self._req('/browse/hot', {
"category_path":category_path,
"offset":offset,
"limit":limit
})
elif endpoint == "morelikethis":
if seed:
response = self._req('/browse/morel... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_categories(self, catpath="/"):
"""Fetch the categorytree :param catpath: The category to list children of """ |
response = self._req('/browse/categorytree', {
"catpath":catpath
})
categories = response['categories']
return categories |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def search_tags(self, tag_name):
"""Searches for tags :param tag_name: Partial tag name to get autocomplete suggestions for """ |
response = self._req('/browse/tags/search', {
"tag_name":tag_name
})
tags = list()
for item in response['results']:
tags.append(item['tag_name'])
return tags |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_deviation(self, deviationid):
"""Fetch a single deviation :param deviationid: The deviationid you want to fetch """ |
response = self._req('/deviation/{}'.format(deviationid))
d = Deviation()
d.from_dict(response)
return d |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def whofaved_deviation(self, deviationid, offset=0, limit=10):
"""Fetch a list of users who faved the deviation :param deviationid: The deviationid you want to f... |
response = self._req('/deviation/whofaved', get_data={
'deviationid' : deviationid,
'offset' : offset,
'limit' : limit
})
users = []
for item in response['results']:
u = {}
u['user'] = User()
u['user'].from_dict(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_deviation_metadata(self, deviationids, ext_submission=False, ext_camera=False, ext_stats=False, ext_collection=False):
"""Fetch deviation metadata for a ... |
response = self._req('/deviation/metadata', {
'ext_submission' : ext_submission,
'ext_camera' : ext_camera,
'ext_stats' : ext_stats,
'ext_collection' : ext_collection
},
post_data={
'deviationids[]' : deviationids
})
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_deviation_embeddedcontent(self, deviationid, offset_deviationid="", offset=0, limit=10):
"""Fetch content embedded in a deviation :param deviationid: The... |
response = self._req('/deviation/embeddedcontent', {
'deviationid' : deviationid,
'offset_deviationid' : offset_deviationid,
'offset' : 0,
'limit' : 0
})
deviations = []
for item in response['results']:
d = Deviatio... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_deviation_content(self, deviationid):
"""Fetch full data that is not included in the main devaition object The endpoint works with journals and literatur... |
response = self._req('/deviation/content', {
'deviationid':deviationid
})
content = {}
if "html" in response:
content['html'] = response['html']
if "css" in response:
content['css'] = response['css']
if "css_fonts" in resp... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_collections(self, username="", calculate_size=False, ext_preload=False, offset=0, limit=10):
"""Fetch collection folders :param username: The user to lis... |
if not username and self.standard_grant_type == "authorization_code":
response = self._req('/collections/folders', {
"calculate_size":calculate_size,
"ext_preload":ext_preload,
"offset":offset,
"limit":limit
})
els... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_collection(self, folderid, username="", offset=0, limit=10):
"""Fetch collection folder contents :param folderid: UUID of the folder to list :param usern... |
if not username and self.standard_grant_type == "authorization_code":
response = self._req('/collections/{}'.format(folderid), {
"offset":offset,
"limit":limit
})
else:
if not username:
raise DeviantartError("No userna... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fave(self, deviationid, folderid=""):
"""Add deviation to favourites :param deviationid: Id of the Deviation to favourite :param folderid: Optional UUID of t... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
post_data = {}
post_data['deviationid'] = deviationid
if folderid:
post_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_gallery_all(self, username='', offset=0, limit=10):
""" Get all of a user's deviations :param username: The user to query, defaults to current user :para... |
if not username:
raise DeviantartError('No username defined.')
response = self._req('/gallery/all', {'username': username,
'offset': offset,
'limit': limit})
deviations = []
for ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_user(self, username="", ext_collections=False, ext_galleries=False):
"""Get user profile information :param username: username to lookup profile of :para... |
if not username and self.standard_grant_type == "authorization_code":
response = self._req('/user/whoami')
u = User()
u.from_dict(response)
else:
if not username:
raise DeviantartError("No username defined.")
else:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_users(self, usernames):
"""Fetch user info for given usernames :param username: The usernames you want metadata for (max. 50) """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/user/whois', post_data={
"usernames":usernames
})
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def watch( self, username, watch={ "friend":True, "deviations":True, "journals":True, "forum_threads":True, "critiques":True, "scraps":True, "activity":True, "col... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/user/friends/watch/{}'.format(username), post_data={
"watch[friend]... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def unwatch(self, username):
"""Unwatch a user :param username: The username you want to unwatch """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/user/friends/unwatch/{}'.format(username))
return response['success'] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def is_watching(self, username):
"""Check if user is being watched by the given user :param username: Check if username is watching you """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/user/friends/watching/{}'.format(username))
return response['watching'... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def update_user(self, user_is_artist="", artist_level="", artist_specialty="", real_name="", tagline="", countryid="", website="", bio=""):
"""Update the users p... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
post_data = {}
if user_is_artist:
post_data["user_is_artist"] = user_is_artist
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_watchers(self, username, offset=0, limit=10):
"""Get the user's list of watchers :param username: The username you want to get a list of watchers of :par... |
response = self._req('/user/watchers/{}'.format(username), {
'offset' : offset,
'limit' : limit
})
watchers = []
for item in response['results']:
w = {}
w['user'] = User()
w['user'].from_dict(item['user'])
w['is_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_friends(self, username, offset=0, limit=10):
"""Get the users list of friends :param username: The username you want to get a list of friends of :param o... |
response = self._req('/user/friends/{}'.format(username), {
'offset' : offset,
'limit' : limit
})
friends = []
for item in response['results']:
f = {}
f['user'] = User()
f['user'].from_dict(item['user'])
f['is_wa... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_statuses(self, username, offset=0, limit=10):
"""Fetch status updates of a user :param username: The username you want to get a list of status updates fr... |
response = self._req('/user/statuses/', {
"username" : username,
'offset' : offset,
'limit' : limit
})
statuses = []
for item in response['results']:
s = Status()
s.from_dict(item)
statuses.append(s)
ret... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_status(self, statusid):
"""Fetch the status :param statusid: Status uuid """ |
response = self._req('/user/statuses/{}'.format(statusid))
s = Status()
s.from_dict(response)
return s |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def post_status(self, body="", id="", parentid="", stashid=""):
"""Post a status :param username: The body of the status :param id: The id of the object you wish... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/user/statuses/post', post_data={
"body":body,
"id":id,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_data(self, endpoint="privacy"):
"""Returns policies of DeviantArt""" |
if endpoint == "privacy":
response = self._req('/data/privacy')
elif endpoint == "submission":
response = self._req('/data/submission')
elif endpoint == "tos":
response = self._req('/data/tos')
else:
raise DeviantartError("Unknown endpoin... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_messages(self, folderid="", stack=1, cursor=""):
"""Feed of all messages :param folderid: The folder to fetch messages from, defaults to inbox :param sta... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/messages/feed', {
'folderid' : folderid,
'stack' : stac... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete_message(self, messageid="", folderid="", stackid=""):
"""Delete a message or a message stack :param folderid: The folder to delete the message from, d... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/messages/delete', post_data={
'folderid' : folderid,
'm... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_feedback(self, feedbacktype="comments", folderid="", stack=1, offset=0, limit=10):
"""Fetch feedback messages :param feedbacktype: Type of feedback messa... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/messages/feedback', {
'type' : feedbacktype,
'folderid'... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_feedback_in_stack(self, stackid, offset=0, limit=10):
"""Fetch feedback messages in a stack :param stackid: Id of the stack :param offset: the pagination... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/messages/feedback/{}'.format(stackid), {
'offset' : offset,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_note(self, noteid):
"""Fetch a single note :param folderid: The UUID of the note """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/notes/{}'.format(noteid))
return response |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def send_note(self, to, subject="", body="", noetid=""):
"""Send a note :param to: The username(s) that this note is to :param subject: The subject of the note :... |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/notes/send', post_data={
'to[]' : to,
'subject' : subje... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def move_notes(self, noteids, folderid):
"""Move notes to a folder :param noteids: The noteids to move :param folderid: The folderid to move notes to """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/notes/move', post_data={
'noteids[]' : noteids,
'folder... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete_notes(self, noteids):
"""Delete a note or notes :param noteids: The noteids to delete """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/notes/delete', post_data={
'noteids[]' : noteids
})
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rename_notes_folder(self, title, folderid):
"""Rename a folder :param title: New title of the folder :param folderid: The UUID of the folder to rename """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/notes/folders/rename/{}'.format(folderid), post_data={
'title' : ti... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete_notes_folder(self, folderid):
"""Delete note folder :param folderid: The UUID of the folder to delete """ |
if self.standard_grant_type is not "authorization_code":
raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.")
response = self._req('/notes/folders/remove/{}'.format(folderid))
return response |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _req(self, endpoint, get_data=dict(), post_data=dict()):
"""Helper method to make API calls :param endpoint: The endpoint to make the API call to :param get_... |
if get_data:
request_parameter = "{}?{}".format(endpoint, urlencode(get_data))
else:
request_parameter = endpoint
try:
encdata = urlencode(post_data, True).encode('utf-8')
response = self.oauth.request(request_parameter, data=encdata)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def revoke_tokens(self):
""" Revoke the authorization token and all tokens that were generated using it. """ |
self.is_active = False
self.save()
self.refresh_token.revoke_tokens() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def revoke_tokens(self):
""" Revokes the refresh token and all access tokens that were generated using it. """ |
self.is_active = False
self.save()
for access_token in self.access_tokens.all():
access_token.revoke() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def write(self, outfile, encoding):
"""Method override to create self-closing elements. https://docs.djangoproject.com/en/2.0/ref/utils/#django.utils.feedgenerat... |
try:
handler = EscapeFriendlyXMLGenerator(outfile, encoding, short_empty_elements=True)
except TypeError: # Python 2
handler = EscapeFriendlyXMLGenerator(outfile, encoding)
handler.startDocument()
handler.startElement('rss', self.rss_attributes())
handle... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def process_request(self, request):
""" Try to authenticate the user based on any given tokens that have been provided to the request object. This will try to de... |
request.auth_type = None
http_authorization = request.META.get("HTTP_AUTHORIZATION", None)
if not http_authorization:
return
auth = http_authorization.split()
self.auth_type = auth[0].lower()
self.auth_value = " ".join(aut... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def load_handler(self):
""" Load the detected handler. """ |
handler_path = self.handler_name.split(".")
handler_module = __import__(".".join(handler_path[:-1]), {}, {}, str(handler_path[-1]))
self.handler = getattr(handler_module, handler_path[-1])() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def validate_auth_type(self):
""" Validate the detected authorization type against the list of handlers. This will return the full module path to the detected ha... |
for handler in HANDLERS:
handler_type = handler.split(".")[-2]
if handler_type == self.auth_type:
self.handler_name = handler
return
self.handler_name = None |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def show_url(context, **kwargs):
"""Return the show feed URL with different protocol.""" |
if len(kwargs) != 2:
raise TemplateSyntaxError(_('"show_url" tag takes exactly two keyword arguments.'))
request = context['request']
current_site = get_current_site(request)
url = add_domain(current_site.domain, kwargs['url'])
return re.sub(r'https?:\/\/', '%s://' % kwargs['protocol'], url... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def loads(text):
""" Parses TOML text into a dict-like object and returns it. """ |
from prettytoml.parser import parse_tokens
from prettytoml.lexer import tokenize as lexer
from .file import TOMLFile
tokens = tuple(lexer(text, is_top_level=True))
elements = parse_tokens(tokens)
return TOMLFile(elements) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def dumps(value):
""" Dumps a data structure to TOML source code. The given value must be either a dict of dict values, a dict, or a TOML file constructed by thi... |
from contoml.file.file import TOMLFile
if not isinstance(value, TOMLFile):
raise RuntimeError("Can only dump a TOMLFile instance loaded by load() or loads()")
return value.dumps() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def dump(obj, file_path, prettify=False):
""" Dumps a data structure to the filesystem as TOML. The given value must be either a dict of dict values, a dict, or ... |
with open(file_path, 'w') as fp:
fp.write(dumps(obj)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rate(base, target, error_log=None):
"""Get current exchange rate. :param base: A base currency :param target: Convert to the target currency :param error_log... |
if base == target:
return decimal.Decimal(1.00)
services = [yahoo, fixer, ecb]
if error_log is None:
error_log = _error_log
for fn in services:
try:
return fn(base, target)
except Exception as e:
error_log(e)
return None |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def yahoo(base, target):
"""Parse data from Yahoo.""" |
api_url = 'http://download.finance.yahoo.com/d/quotes.csv'
resp = requests.get(
api_url,
params={
'e': '.csv',
'f': 'sl1d1t1',
's': '{0}{1}=X'.format(base, target)
},
timeout=1,
)
value = resp.text.split(',', 2)[1]
return decimal.D... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fixer(base, target):
"""Parse data from fixer.io.""" |
api_url = 'http://api.fixer.io/latest'
resp = requests.get(
api_url,
params={
'base': base,
'symbols': target,
},
timeout=1,
)
data = resp.json()
return decimal.Decimal(data['rates'][target]) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def ecb(base, target):
"""Parse data from European Central Bank.""" |
api_url = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
resp = requests.get(api_url, timeout=1)
text = resp.text
def _find_rate(symbol):
if symbol == 'EUR':
return decimal.Decimal(1.00)
m = re.findall(r"currency='%s' rate='([0-9\.]+)'" % symbol, text)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def dot(vec1, vec2):
"""Returns the dot product of two Vectors""" |
if isinstance(vec1, Vector3) and isinstance(vec2, Vector3):
return (vec1.x * vec2.x) + (vec1.y * vec2.y) + (vec1.z * vec2.z)
elif isinstance(vec1, Vector4) and isinstance(vec2, Vector4):
return (vec1.x * vec2.x) + (vec1.y * vec2.y) + (vec1.z * vec2.z) + (vec1.w * vec2.w)
else:
raise... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def angle(vec1, vec2):
"""Returns the angle between two vectors""" |
dot_vec = dot(vec1, vec2)
mag1 = vec1.length()
mag2 = vec2.length()
result = dot_vec / (mag1 * mag2)
return math.acos(result) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def project(vec1, vec2):
"""Project vector1 onto vector2.""" |
if isinstance(vec1, Vector3) and isinstance(vec2, Vector3) \
or isinstance(vec1, Vector4) and isinstance(vec2, Vector4):
return dot(vec1, vec2) / vec2.length() * vec2.normalize_copy()
else:
raise ValueError("vec1 and vec2 must be Vector3 or Vector4 objects.") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.