input
stringlengths 11
7.65k
| target
stringlengths 22
8.26k
|
---|---|
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def get_date(self, p_tag):
""" Given a date tag, return a date object. """
string = self.tag_value(p_tag)
result = None
try:
result = date_string_to_date(string) if string else None
except ValueError:
pass
return result |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def start_date(self):
""" Returns a date object of the todo's start date. """
return self.get_date(config().tag_start()) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def due_date(self):
""" Returns a date object of the todo's due date. """
return self.get_date(config().tag_due()) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def is_active(self):
"""
Returns True when the start date is today or in the past and the
task has not yet been completed.
"""
start = self.start_date()
return not self.is_completed() and (not start or start <= date.today()) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def is_overdue(self):
"""
Returns True when the due date is in the past and the task has not
yet been completed.
"""
return not self.is_completed() and self.days_till_due() < 0 |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def days_till_due(self):
"""
Returns the number of days till the due date. Returns a negative number
of days when the due date is in the past.
Returns 0 when the task has no due date.
"""
due = self.due_date()
if due:
diff = due - date.today()
return diff.days
return 0 |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def main(self):
UI.OpenDialog(
VBox(
Heading("This Is a Heading."),
Label("This is a Label."),
PushButton("&OK")
)
)
UI.UserInput()
UI.CloseDialog() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
df2 = df[['A']]
df2['A'] += 10
return df2.A, df.A |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_scheme():
# does not raise NotImplementedError
UrlPath('/dev/null').touch() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
S1 = pd.Series(np.ones(n))
S2 = pd.Series(np.random.ranf(n))
df = pd.DataFrame({'A': S1, 'B': S2})
return df.A.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_scheme_not_supported():
with pytest.raises(NotImplementedError):
UrlPath('http:///tmp/test').touch() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
return df['A'][df['B']].values |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_scheme_not_listed():
with pytest.raises(NotImplementedError):
UrlPath('test:///tmp/test').touch() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
A = np.array([1., 2., 3.])
A[0] = np.nan
df = pd.DataFrame({'A': A})
B = df.A.fillna(5.0)
return B.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_file_additional():
assert UrlPath('.').resolve() == UrlPath.cwd() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
A = np.array([1., 2., 3.])
A[0] = np.nan
df = pd.DataFrame({'A': A})
df.A.fillna(5.0, inplace=True)
return df.A.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
A = np.array([1., 2., 3.])
A[0] = np.nan
df = pd.DataFrame({'A': A})
return df.A.mean() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
A = np.array([1., 2., 3.])
A[0] = 4.0
df = pd.DataFrame({'A': A})
return df.A.var() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
A = np.array([1., 2., 3.])
A[0] = 4.0
df = pd.DataFrame({'A': A})
return df.A.std() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(n)})
df['B'] = df.A.map(lambda a: 2 * a)
return df.B.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
df['B'] = df.A.map(lambda a: 2 * a)
return |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)})
Ac = df.A.cumsum()
return Ac.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)})
df.A.fillna(5.0, inplace=True)
DF = df.A.fillna(5.0)
s = DF.sum()
m = df.A.mean()
v = df.A.var()
t = df.A.std()
Ac = df.A.cumsum()
return Ac.sum() + s + m + v + t |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(0, n, 1, np.float64)})
return df.A.quantile(.25) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(0, n, 1, np.float32)})
df.A[0:100] = np.nan
df.A[200:331] = np.nan
return df.A.quantile(.25) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(0, n, 1, np.int32)})
return df.A.quantile(.25) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(A):
df = pd.DataFrame({'A': A})
return df.A.quantile(.25) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(n)})
df.A[2] = 0
return df.A.nunique() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
df = pq.read_table('example.parquet').to_pandas()
return df.four.nunique() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': ['aa', 'bb', 'aa', 'cc', 'cc']})
return df.A.nunique() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
df = pq.read_table('example.parquet').to_pandas()
return df.two.nunique() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
df = pq.read_table('example.parquet').to_pandas()
return (df.four.unique() == 3.0).sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
df = pq.read_table('example.parquet').to_pandas()
return (df.two.unique() == 'foo').sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(0, n, 1, np.float64)})
return df.A.describe() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
A = StringArray(['ABC', 'BB', 'ADEF'])
df = pd.DataFrame({'A': A})
B = df.A.str.contains('AB*', regex=True)
return B.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
A = StringArray(['ABC', 'BB', 'ADEF'])
df = pd.DataFrame({'A': A})
B = df.A.str.contains('BB', regex=False)
return B.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
return df.A.str.replace('AB*', 'EE', regex=True) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
return df.A.str.replace('AB', 'EE', regex=False) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
B = df.A.str.replace('AB*', 'EE', regex=True)
return B |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
return df.A.str.split() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
B = df.A.str.split(',')
df2 = pd.DataFrame({'B': B})
return df2[df2.B.str.len() > 1] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
return df.A.iloc[0] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
B = df.A.str.split(',')
C = pd.to_numeric(B.str.get(1), errors='coerce')
return C |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
A = df.A.str.split(',')
return pd.Series(list(itertools.chain(*A))) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
A = df.A.str.split(',')
B = pd.Series(list(itertools.chain(*A)))
return B |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
B = pd.to_numeric(df.A, errors='coerce')
return B |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(n), 'B': np.arange(n) + 1.0})
df1 = df[df.A > 5]
return len(df1.B) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(n), 'B': np.random.ranf(n)})
Ac = df.A.rolling(3).sum()
return Ac.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl_2(n):
df = pd.DataFrame({'A': np.arange(n) + 1.0, 'B': np.random.ranf(n)})
Ac = df.A.rolling(7).sum()
return Ac.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)})
df['moving average'] = df.A.rolling(window=5, center=True).mean()
return df['moving average'].sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)})
Ac = df.A.rolling(3, center=True).apply(lambda a: a[0] + 2 * a[1] + a[2])
return Ac.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(n) + 1.0, 'B': np.random.ranf(n)})
Ac = df.A.shift(1)
return Ac.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df = pd.DataFrame({'A': np.arange(n) + 1.0, 'B': np.random.ranf(n)})
Ac = df.A.pct_change(1)
return Ac.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
return df.B.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
C = df.B == 'two'
return C.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(df):
return df.B.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df1 = pd.DataFrame({'key1': np.arange(n), 'A': np.arange(n) + 1.0})
df2 = pd.DataFrame({'key2': n - np.arange(n), 'A': n + np.arange(n) + 1.0})
df3 = pd.concat([df1, df2])
return df3.A.sum() + df3.key2.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
df1 = pq.read_table('example.parquet').to_pandas()
df2 = pq.read_table('example.parquet').to_pandas()
A3 = pd.concat([df1, df2])
return (A3.two == 'foo').sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(n):
df1 = pd.DataFrame({'key1': np.arange(n), 'A': np.arange(n) + 1.0})
df2 = pd.DataFrame({'key2': n - np.arange(n), 'A': n + np.arange(n) + 1.0})
A3 = pd.concat([df1.A, df2.A])
return A3.sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl():
df1 = pq.read_table('example.parquet').to_pandas()
df2 = pq.read_table('example.parquet').to_pandas()
A3 = pd.concat([df1.two, df2.two])
return (A3 == 'foo').sum() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(nsyms):
max_num_days = 100
all_res = 0.0
for i in sdc.prange(nsyms):
s_open = 20 * np.ones(max_num_days)
s_low = 28 * np.ones(max_num_days)
s_close = 19 * np.ones(max_num_days)
df = pd.DataFrame({'Open': s_open, 'Low': s_low, 'Close': s_close})
df['Stdev'] = df['Close'].rolling(window=90).std()
df['Moving Average'] = df['Close'].rolling(window=20).mean()
df['Criteria1'] = (df['Open'] - df['Low'].shift(1)) < -df['Stdev']
df['Criteria2'] = df['Open'] > df['Moving Average']
df['BUY'] = df['Criteria1'] & df['Criteria2']
df['Pct Change'] = (df['Close'] - df['Open']) / df['Open']
df['Rets'] = df['Pct Change'][df['BUY']]
all_res += df['Rets'].mean()
return all_res |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_impl(A, B):
df = pd.DataFrame({'A': A, 'B': B})
df2 = df.groupby('A', as_index=False)['B'].sum()
# TODO: fix handling of df setitem to force match of array dists
# probably with a new node that is appended to the end of basic block
# df2['C'] = np.full(len(df2.B), 3, np.int8)
# TODO: full_like for Series
df2['C'] = np.full_like(df2.B.values, 3, np.int8)
return df2 |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_both():
"""Both f and g."""
p = are.above(2) & are.below(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def AddResultsOptions(parser):
group = optparse.OptionGroup(parser, 'Results options')
group.add_option('--chartjson', action='store_true',
help='Output Chart JSON. Ignores --output-format.')
group.add_option('--output-format', action='append', dest='output_formats',
choices=_OUTPUT_FORMAT_CHOICES, default=[],
help='Output format. Defaults to "%%default". '
'Can be %s.' % ', '.join(_OUTPUT_FORMAT_CHOICES))
group.add_option('-o', '--output',
dest='output_file',
default=None,
help='Redirects output to a file. Defaults to stdout.')
group.add_option('--output-dir', default=util.GetBaseDir(),
help='Where to save output data after the run.')
group.add_option('--output-trace-tag',
default='',
help='Append a tag to the key of each result trace. Use '
'with html, buildbot, csv-pivot-table output formats.')
group.add_option('--reset-results', action='store_true',
help='Delete all stored results.')
group.add_option('--upload-results', action='store_true',
help='Upload the results to cloud storage.')
group.add_option('--upload-bucket', default='internal',
choices=['public', 'partner', 'internal'],
help='Storage bucket to use for the uploaded results. '
'Defaults to internal. Supported values are: '
'public, partner, internal')
group.add_option('--results-label',
default=None,
help='Optional label to use for the results of a run .')
group.add_option('--suppress_gtest_report',
default=False,
help='Whether to suppress GTest progress report.')
parser.add_option_group(group) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_either():
"""Either f or g."""
p = are.above(3) | are.below(2)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, True, True] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def ProcessCommandLineArgs(parser, args):
# TODO(ariblue): Delete this flag entirely at some future data, when the
# existence of such a flag has been long forgotten.
if args.output_file:
parser.error('This flag is deprecated. Please use --output-dir instead.')
try:
os.makedirs(args.output_dir)
except OSError:
# Do nothing if the output directory already exists. Existing files will
# get overwritten.
pass
args.output_dir = os.path.expanduser(args.output_dir) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_equal_to():
"""Equal to y."""
p = are.equal_to(1)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, False, False] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _GetOutputStream(output_format, output_dir):
assert output_format in _OUTPUT_FORMAT_CHOICES, 'Must specify a valid format.'
assert output_format not in ('gtest', 'none'), (
'Cannot set stream for \'gtest\' or \'none\' output formats.')
if output_format == 'buildbot':
return sys.stdout
assert output_format in _OUTPUT_FILENAME_LOOKUP, (
'No known filename for the \'%s\' output format' % output_format)
output_file = os.path.join(output_dir, _OUTPUT_FILENAME_LOOKUP[output_format])
open(output_file, 'a').close() # Create file if it doesn't exist.
return open(output_file, 'r+') |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_above():
"""Greater than y."""
p = are.above(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _GetProgressReporter(output_skipped_tests_summary, suppress_gtest_report):
if suppress_gtest_report:
return progress_reporter.ProgressReporter()
return gtest_progress_reporter.GTestProgressReporter(
sys.stdout, output_skipped_tests_summary=output_skipped_tests_summary) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_below():
"""Less than y."""
p = are.not_below(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_above_or_equal_to():
"""Greater than or equal to y."""
p = are.above_or_equal_to(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_below_or_equal_to():
"""Less than or equal to y."""
p = are.not_below_or_equal_to(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_strictly_between():
"""Greater than y and less than z."""
p = are.strictly_between(2, 4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_between():
"""Greater than or equal to y and less than z."""
p = are.between(3, 4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def test_between_or_equal_to():
"""Greater than or equal to y and less than or equal to z."""
p = are.between_or_equal_to(3, 3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _apply_mask(y_true, sample_weight, masked_tokens, dtype):
if sample_weight is None:
sample_weight = tf.ones_like(y_true, dtype)
else:
sample_weight = tf.cast(sample_weight, dtype)
for token in masked_tokens:
mask = tf.cast(tf.not_equal(y_true, token), dtype)
sample_weight = sample_weight * mask
return sample_weight |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _copy_vars(v_list):
"""Copy variables in v_list."""
t_list = []
for v in v_list:
t_list.append(tf.identity(v))
return t_list |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def __init__(self, masked_tokens=None, name='num_tokens', dtype=tf.int64):
self._masked_tokens = masked_tokens or []
super().__init__(name, dtype) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _restore_vars(v_list, t_list):
"""Restore variables in v_list from t_list."""
ops = []
for v, t in zip(v_list, t_list):
ops.append(v.assign(t))
return ops |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def update_state(self, y_true, y_pred, sample_weight=None):
sample_weight = _apply_mask(y_true, sample_weight, self._masked_tokens,
self._dtype)
sample_weight = tf.reshape(sample_weight, [-1])
super().update_state(sample_weight) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _scale_vars(s, v_list):
"""Scale all variables in v_list by s."""
return [s * v for v in v_list] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def get_config(self):
config = super().get_config()
config['masked_tokens'] = tuple(self._masked_tokens)
return config |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _acc_grads(g_sum, g_w, g):
"""Accumulate gradients in g, weighted by g_w."""
return [g_sum_i + g_w * g_i for g_sum_i, g_i in zip(g_sum, g)] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def __init__(self, masked_tokens=None, name='accuracy', dtype=None):
self._masked_tokens = masked_tokens or []
super().__init__(name, dtype=dtype) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def _compute_reg_grads(gen_grads, disc_vars):
"""Compute gradients norm (this is an upper-bpund of the full-batch norm)."""
gen_norm = tf.accumulate_n([tf.reduce_sum(u * u) for u in gen_grads])
disc_reg_grads = tf.gradients(gen_norm, disc_vars)
return disc_reg_grads |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def update_state(self, y_true, y_pred, sample_weight=None):
sample_weight = _apply_mask(y_true, sample_weight, self._masked_tokens,
self._dtype)
num_classes = tf.shape(y_pred)[-1]
y_true = tf.reshape(y_true, [-1])
y_pred = tf.reshape(y_pred, [-1, num_classes])
sample_weight = tf.reshape(sample_weight, [-1])
super().update_state(y_true, y_pred, sample_weight) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def run_model(prior, images, model, disc_reg_weight):
"""Run the model with new data and samples.
Args:
prior: the noise source as the generator input.
images: images sampled from dataset.
model: a GAN model defined in gan.py.
disc_reg_weight: regularisation weight for discrmininator gradients.
Returns:
debug_ops: statistics from the model, see gan.py for more detials.
disc_grads: discriminator gradients.
gen_grads: generator gradients.
"""
generator_inputs = prior.sample(FLAGS.batch_size)
model_output = model.connect(images, generator_inputs)
optimization_components = model_output.optimization_components
disc_grads = tf.gradients(
optimization_components['disc'].loss,
optimization_components['disc'].vars)
gen_grads = tf.gradients(
optimization_components['gen'].loss,
optimization_components['gen'].vars)
if disc_reg_weight > 0.0:
reg_grads = _compute_reg_grads(gen_grads,
optimization_components['disc'].vars)
disc_grads = _acc_grads(disc_grads, disc_reg_weight, reg_grads)
debug_ops = model_output.debug_ops
return debug_ops, disc_grads, gen_grads |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def update_model(model, disc_grads, gen_grads, disc_opt, gen_opt,
global_step, update_scale):
"""Update model with gradients."""
disc_vars, gen_vars = model.get_variables()
with tf.control_dependencies(gen_grads + disc_grads):
disc_update_op = disc_opt.apply_gradients(
zip(_scale_vars(update_scale, disc_grads),
disc_vars))
gen_update_op = gen_opt.apply_gradients(
zip(_scale_vars(update_scale, gen_grads),
gen_vars),
global_step=global_step)
update_op = tf.group([disc_update_op, gen_update_op])
return update_op |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def sample_fn(x):
return utils.optimise_and_sample(x, module=model,
data=None, is_training=False)[0] |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def setUp(self):
super().setUp()
self.project1 = self.env["project.project"].create({"name": "Project 1"})
self.task1 = self.env["project.task"].create(
{"name": "name1", "project_id": self.project1.id}
)
self.subtask1 = self.env["project.task"].create(
{"name": "2", "project_id": self.project1.id, "parent_id": self.task1.id}
)
self.subtask2 = self.env["project.task"].create(
{"name": "3", "project_id": self.project1.id, "parent_id": self.task1.id}
) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def __init__(self, item_spacing=ITEM_SPACING, *args, **kwargs):
super().__init__(*args, **kwargs) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def __init__(self, nr, nc):
self.nr = nr
self.nc = nc |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def add_item(self, item):
self._vbox_items.pack_start(item.widget, expand=False, fill=False) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def inc_r(self, ind):
r, c = self.row_col(ind)
r += 1
if r == self.nr:
r = 0
if r == (self.nr - 1) and c == (self.nc - 1):
r = 0
return self.indx(r, c) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def reorder_item(self, item, position):
new_position = min(max(position, 0), len(self._items) - 1) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def dec_r(self, ind):
r, c = self.row_col(ind)
r -= 1
if r < 0:
r = self.nr - 1
if r == (self.nr - 1) and c == (self.nc - 1):
r = self.nr - 2
return self.indx(r, c) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def remove_item(self, item):
item_position = self._get_item_position(item)
if item_position < len(self._items) - 1:
next_item_position = item_position + 1
self._items[next_item_position].item_widget.grab_focus() |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def inc_c(self, ind):
r, c = self.row_col(ind)
c += 1
if c == self.nc:
c = 0
if r == (self.nr - 1) and c == (self.nc - 1):
c = 0
return self.indx(r, c) |
def dist(a, b):
return sum((i-j)**2 for i, j in zip(a, b)) | def clear(self):
for unused_ in range(len(self._items)):
self.remove_item(self._items[0]) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.