prompt large_stringlengths 72 9.34k | completion large_stringlengths 0 7.61k |
|---|---|
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
<|fim_middle|>
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
:type p: str
... | return self.c == '.' or self.c == c |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
<|fim_middle|>
<|fim▁end|> | def isMatch(self, s, p):
"""
:type s: str
:type p: str
:rtype: bool
"""
rs = []
""":type: list[R]"""
for c in p:
if c == '*':
rs[-1].is_star = True
else:
rs.append(R(c))
lr = len(rs)
... |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
<|fim_middle|>
<|fim▁end|> | """
:type s: str
:type p: str
:rtype: bool
"""
rs = []
""":type: list[R]"""
for c in p:
if c == '*':
rs[-1].is_star = True
else:
rs.append(R(c))
lr = len(rs)
ls = len(s)
s +=... |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
... | rs[-1].is_star = True |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
... | rs.append(R(c)) |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
... | dp[i + 1][j] = dp[i][j]
if j and r.match(c):
dp[i + 1][j] |= dp[i + 1][j - 1] |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
... | dp[i + 1][j] |= dp[i + 1][j - 1] |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
... | if j and r.match(c):
dp[i + 1][j] = dp[i][j - 1] |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
... | dp[i + 1][j] = dp[i][j - 1] |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def <|fim_middle|>(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: str
... | __init__ |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def <|fim_middle|>(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def isMatch(self, s, p):
"""
:type s: s... | match |
<|file_name|>regular_expression_matching.py<|end_file_name|><|fim▁begin|>class R:
def __init__(self, c):
self.c = c
self.is_star = False
def match(self, c):
return self.c == '.' or self.c == c
class Solution(object):
def <|fim_middle|>(self, s, p):
"""
:type s: str... | isMatch |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | SKIP_REASON_CONNECTION = 'MySQL is not running or cannot connect'
MYSQL_CONNECTION_STRING = 'mysql://root@127.0.0.1/test' |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | Session = sessionmaker()
engine = create_engine(MYSQL_CONNECTION_STRING)
Session.configure(bind=engine)
metadata.create_all(engine)
try:
yield Session()
except:
pass |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | mysqldb_hooks.install_patches()
try:
yield
finally:
mysqldb_hooks.reset_patches() |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | try:
import MySQLdb
with MySQLdb.connect(host='127.0.0.1', user='root'):
pass
return True
except:
return False |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | assert span.operation_name == 'MySQLdb:' + operation
assert span.tags.get(tags.SPAN_KIND) == tags.SPAN_KIND_RPC_CLIENT
if parent:
assert span.parent_id == parent.context.span_id
assert span.context.trace_id == parent.context.trace_id
else:
assert span.parent_id is None |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | root_span = tracer.start_span('root-span')
# span recording works for regular operations within a context only
with span_in_context(root_span):
user = User(name='user', fullname='User', password='password')
session.add(user)
session.commit()
spans = tracer.recorder.get_spans()
... |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | assert span.parent_id == parent.context.span_id
assert span.context.trace_id == parent.context.trace_id |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | assert span.parent_id is None |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | session |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | patch_sqlalchemy |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | is_mysql_running |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | assert_span |
<|file_name|>test_mysqldb.py<|end_file_name|><|fim▁begin|>import sys
import pytest
from opentracing.ext import tags
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import mysqldb as mysqldb_hooks
from opentracing_instrumentation.request_conte... | test_db |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | for k in threads:
k.start()
time.sleep(0.1) # avoid simulator bugs |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | def f(s):
spc = player.get_action_space()
act = func([[s]])[0][0].argmax()
if random.random() < 0.001:
act = spc.sample()
if verbose:
print(act)
return act
return np.mean(player.play_one_episode(f)) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | spc = player.get_action_space()
act = func([[s]])[0][0].argmax()
if random.random() < 0.001:
act = spc.sample()
if verbose:
print(act)
return act |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | predfunc = OfflinePredictor(cfg)
while True:
score = play_one_episode(player, predfunc)
print("Total:", score) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | class Worker(StoppableThread, ShareSessionThread):
def __init__(self, func, queue):
super(Worker, self).__init__()
self._func = func
self.q = queue
def func(self, *args, **kwargs):
if self.stopped():
raise RuntimeError("stopped!")
... |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | def __init__(self, func, queue):
super(Worker, self).__init__()
self._func = func
self.q = queue
def func(self, *args, **kwargs):
if self.stopped():
raise RuntimeError("stopped!")
return self._func(*args, **kwargs)
def... |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | super(Worker, self).__init__()
self._func = func
self.q = queue |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | if self.stopped():
raise RuntimeError("stopped!")
return self._func(*args, **kwargs) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | with self.default_sess():
player = get_player_fn(train=False)
while not self.stopped():
try:
score = play_one_episode(player, self.func)
# print("Score, ", score)
except RuntimeError:
... |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | func = OfflinePredictor(cfg)
NR_PROC = min(multiprocessing.cpu_count() // 2, 8)
mean, max = eval_with_funcs([func] * NR_PROC, nr_eval, get_player_fn)
logger.info("Average Score: {}; Max Score: {}".format(mean, max)) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | def __init__(self, nr_eval, input_names, output_names, get_player_fn):
self.eval_episode = nr_eval
self.input_names = input_names
self.output_names = output_names
self.get_player_fn = get_player_fn
def _setup_graph(self):
NR_PROC = min(multiprocessing.cpu_count() // 2, 2... |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | self.eval_episode = nr_eval
self.input_names = input_names
self.output_names = output_names
self.get_player_fn = get_player_fn |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | NR_PROC = min(multiprocessing.cpu_count() // 2, 20)
self.pred_funcs = [self.trainer.get_predictor(
self.input_names, self.output_names)] * NR_PROC |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | t = time.time()
mean, max = eval_with_funcs(
self.pred_funcs, self.eval_episode, self.get_player_fn)
t = time.time() - t
if t > 10 * 60: # eval takes too long
self.eval_episode = int(self.eval_episode * 0.94)
self.trainer.monitors.put_scalar('mean_score',... |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | logger.info("Start evaluation: ")
for k in range(nr):
if k != 0:
player.restart_episode()
score = play_one_episode(player, predfunc)
print("{}/{}, score={}".format(k, nr, score)) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | act = spc.sample() |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | print(act) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | raise RuntimeError("stopped!") |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | return (stat.average, stat.max) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | self.eval_episode = int(self.eval_episode * 0.94) |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | player.restart_episode() |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | play_one_episode |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | f |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | play_model |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | eval_with_funcs |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | func |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | run |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | eval_model_multithread |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | __init__ |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | _setup_graph |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | _trigger |
<|file_name|>common.py<|end_file_name|><|fim▁begin|>#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: common.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import random
import time
import threading
import multiprocessing
import numpy as np
from tqdm import tqdm
from six.moves import queue
from tensorpack import *
fr... | play_n_episodes |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | self.callback = callback
message_manager.hook_prefix(self.message_prefix, self.callback) |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Decorator used to register message hooks."""
def __init__(self, message_name):
"""Store the message name."""
self.message_name = message_name
self.callback = None
def __call__(self, callback):
"""Store the callback and register the hook."""
self.callback = callba... |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Store the message name."""
self.message_name = message_name
self.callback = None |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Store the callback and register the hook."""
self.callback = callback
message_manager.hook_message(self.message_name, self.callback) |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Unregister the message hook."""
message_manager.unhook_message(self.message_name, self.callback) |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Decorator used to register message prefix hooks."""
def __init__(self, message_prefix):
"""Store the message prefix."""
self.message_prefix = message_prefix
self.callback = None
def __call__(self, callback):
"""Store the callback and register the hook."""
self.ca... |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Store the message prefix."""
self.message_prefix = message_prefix
self.callback = None |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Store the callback and register the hook."""
self.callback = callback
message_manager.hook_prefix(self.message_prefix, self.callback) |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | """Unregister the message prefix hook."""
message_manager.unhook_prefix(self.message_prefix, self.callback) |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | __init__ |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | __call__ |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | _unload_instance |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | __init__ |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | __call__ |
<|file_name|>hooks.py<|end_file_name|><|fim▁begin|># ../gungame/core/messages/hooks.py
"""Provides a way to hook GunGame messages."""
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Py... | _unload_instance |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | return ctypes.c_char_p(string.encode('utf-8'))
"""pandas""" |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | """Error thrown by xlearn trainer"""
pass |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | """Load xlearn shared library"""
lib_path = find_lib_path()
if len(lib_path) == 0:
return None
lib = ctypes.cdll.LoadLibrary(lib_path[0])
return lib |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | """Check the return value of C API call
This function will raise exception when error occurs.
Wrap every API call with this function
Parameters
----------
ret : int
return value from API calls
"""
if ret != 0:
msg = ""
# raise XLearnError()
_LIB.XLearnGe... |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | """Create ctypes char * from a Python string.
Parameters
----------
string : string type
Pyrhon string.
Returns
-------
str : c_char_p
A char pointer that can be passed to C API.
Examples
--------
>>> x = c_str("... |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | """Create ctypes char * from a Python string.
Parameters
----------
string : string type
Pyrhon string.
Returns
-------
str : c_char_p
A char pointer that can be passed to C API.
Examples
--------
>>> x = c_str("Hello... |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | """Dummy class for pandas.Series."""
pass |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | """Dummy class for pandas.DataFrame."""
pass |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | return None |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | msg = ""
# raise XLearnError()
_LIB.XLearnGetLastError.restype = ctypes.POINTER(ctypes.c_ubyte)
ptr = _LIB.XLearnGetLastError()
idx = 0
while(ptr[idx] != 0):
msg += chr(ptr[idx])
idx += 1
raise XLearnError(msg) |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | def c_str(string):
"""Create ctypes char * from a Python string.
Parameters
----------
string : string type
Pyrhon string.
Returns
-------
str : c_char_p
A char pointer that can be passed to C API.
Examples
--------
... |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | def c_str(string):
"""Create ctypes char * from a Python string.
Parameters
----------
string : string type
Pyrhon string.
Returns
-------
str : c_char_p
A char pointer that can be passed to C API.
Examples
--------
... |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | _load_lib |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | _check_call |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | c_str |
<|file_name|>base.py<|end_file_name|><|fim▁begin|># Copyright (c) 2018 by contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/lice... | c_str |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
for t... | |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
<|fim_middle|>
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
for this implementation, the input f should be the sigmoid
function value of your original input x.
... | """
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
<|fim_middle|>
def test_sigmoid_basic():
"""
Some simple tests to get... | """
Compute the gradient for the sigmoid function here. Note that
for this implementation, the input f should be the sigmoid
function value of your original input x.
"""
f = f * (1. - f)
return f |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
for t... | """
Some simple tests to get you started.
Warning: these are not exhaustive.
"""
print "Running basic tests..."
x = np.array([[1, 2], [-1, -2]])
f = sigmoid(x)
g = sigmoid_grad(f)
print f
assert np.amax(f - np.array([[0.73105858, 0.88079708],
[0.26894142, 0.11920292]]))... |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
for t... | """
Use this space to test your sigmoid implementation by running:
python q2_sigmoid.py
This function will not be called by the autograder, nor will
your tests be graded.
"""
print "Running your tests..."
### YOUR CODE HERE
raise NotImplementedError
### END YOUR CODE |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
for t... | test_sigmoid_basic();
#test_sigmoid() |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def <|fim_middle|>(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
... | sigmoid |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def <|fim_middle|>(f):
"""
Compute the gradient for the sigmoid function here. Note that
for... | sigmoid_grad |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
for t... | test_sigmoid_basic |
<|file_name|>q2_sigmoid.py<|end_file_name|><|fim▁begin|>import numpy as np
def sigmoid(x):
"""
Compute the sigmoid function for the input here.
"""
x = 1. / (1. + np.exp(-x))
return x
def sigmoid_grad(f):
"""
Compute the gradient for the sigmoid function here. Note that
for t... | test_sigmoid |
<|file_name|>generi_in_istituzioni.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*-
from collections import OrderedDict
import locale
from optparse import make_option
from verify.management.commands import VerifyBaseCommand
from verify.models import *
from verify.politici_models import *
from django.db.models im... |
def execute_verification(self, *args, **options):
self.csv_headers = ["ISTITUZIONE", "INCARICO", "N_DONNE", "N_UOMINI", "N_TOTALI", "PERC_DONNE", "PERC_UOMINI"] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.