Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
test_training_step_scalar | (tmpdir) |
Tests that only training_step that returns a single scalar can be used
|
Tests that only training_step that returns a single scalar can be used
| def test_training_step_scalar(tmpdir):
"""
Tests that only training_step that returns a single scalar can be used
"""
model = DeterministicModel()
model.training_step = model.training_step__scalar_return
model.val_dataloader = None
trainer = Trainer(
default_root_dir=tmpdir,
... | [
"def",
"test_training_step_scalar",
"(",
"tmpdir",
")",
":",
"model",
"=",
"DeterministicModel",
"(",
")",
"model",
".",
"training_step",
"=",
"model",
".",
"training_step__scalar_return",
"model",
".",
"val_dataloader",
"=",
"None",
"trainer",
"=",
"Trainer",
"("... | [
27,
0
] | [
65,
51
] | python | en | ['en', 'error', 'th'] | False |
training_step_scalar_with_step_end | (tmpdir) |
Checks train_step with scalar only + training_step_end
|
Checks train_step with scalar only + training_step_end
| def training_step_scalar_with_step_end(tmpdir):
"""
Checks train_step with scalar only + training_step_end
"""
model = DeterministicModel()
model.training_step = model.training_step__scalar_return
model.training_step_end = model.training_step_end__scalar
model.val_dataloader = None
trai... | [
"def",
"training_step_scalar_with_step_end",
"(",
"tmpdir",
")",
":",
"model",
"=",
"DeterministicModel",
"(",
")",
"model",
".",
"training_step",
"=",
"model",
".",
"training_step__scalar_return",
"model",
".",
"training_step_end",
"=",
"model",
".",
"training_step_e... | [
68,
0
] | [
103,
51
] | python | en | ['en', 'error', 'th'] | False |
test_full_training_loop_scalar | (tmpdir) |
Checks train_step + training_step_end + training_epoch_end
(all with scalar return from train_step)
|
Checks train_step + training_step_end + training_epoch_end
(all with scalar return from train_step)
| def test_full_training_loop_scalar(tmpdir):
"""
Checks train_step + training_step_end + training_epoch_end
(all with scalar return from train_step)
"""
model = DeterministicModel()
model.training_step = model.training_step__scalar_return
model.training_step_end = model.training_step_end__sc... | [
"def",
"test_full_training_loop_scalar",
"(",
"tmpdir",
")",
":",
"model",
"=",
"DeterministicModel",
"(",
")",
"model",
".",
"training_step",
"=",
"model",
".",
"training_step__scalar_return",
"model",
".",
"training_step_end",
"=",
"model",
".",
"training_step_end__... | [
106,
0
] | [
152,
51
] | python | en | ['en', 'error', 'th'] | False |
test_train_step_epoch_end_scalar | (tmpdir) |
Checks train_step + training_epoch_end (NO training_step_end)
(with scalar return)
|
Checks train_step + training_epoch_end (NO training_step_end)
(with scalar return)
| def test_train_step_epoch_end_scalar(tmpdir):
"""
Checks train_step + training_epoch_end (NO training_step_end)
(with scalar return)
"""
model = DeterministicModel()
model.training_step = model.training_step__scalar_return
model.training_step_end = None
model.training_epoch_end = model.... | [
"def",
"test_train_step_epoch_end_scalar",
"(",
"tmpdir",
")",
":",
"model",
"=",
"DeterministicModel",
"(",
")",
"model",
".",
"training_step",
"=",
"model",
".",
"training_step__scalar_return",
"model",
".",
"training_step_end",
"=",
"None",
"model",
".",
"trainin... | [
155,
0
] | [
197,
51
] | python | en | ['en', 'error', 'th'] | False |
_get_movielens_path | () |
Get path to the movielens dataset file.
|
Get path to the movielens dataset file.
| def _get_movielens_path():
"""
Get path to the movielens dataset file.
"""
return os.path.join(os.path.dirname(os.path.abspath(__file__)),
'movielens.zip') | [
"def",
"_get_movielens_path",
"(",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"__file__",
")",
")",
",",
"'movielens.zip'",
")"
] | [
11,
0
] | [
17,
40
] | python | en | ['en', 'error', 'th'] | False |
_download_movielens | (dest_path) |
Download the dataset.
|
Download the dataset.
| def _download_movielens(dest_path):
"""
Download the dataset.
"""
url = 'http://files.grouplens.org/datasets/movielens/ml-100k.zip'
req = requests.get(url, stream=True)
with open(dest_path, 'wb') as fd:
for chunk in req.iter_content():
fd.write(chunk) | [
"def",
"_download_movielens",
"(",
"dest_path",
")",
":",
"url",
"=",
"'http://files.grouplens.org/datasets/movielens/ml-100k.zip'",
"req",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"stream",
"=",
"True",
")",
"with",
"open",
"(",
"dest_path",
",",
"'wb'",
"... | [
20,
0
] | [
30,
27
] | python | en | ['en', 'error', 'th'] | False |
_get_raw_movielens_data | () |
Return the raw lines of the train and test files.
|
Return the raw lines of the train and test files.
| def _get_raw_movielens_data():
"""
Return the raw lines of the train and test files.
"""
path = _get_movielens_path()
if not os.path.isfile(path):
_download_movielens(path)
with zipfile.ZipFile(path) as datafile:
return (datafile.read('ml-100k/ua.base').decode().split('\n'),
... | [
"def",
"_get_raw_movielens_data",
"(",
")",
":",
"path",
"=",
"_get_movielens_path",
"(",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")",
":",
"_download_movielens",
"(",
"path",
")",
"with",
"zipfile",
".",
"ZipFile",
"(",
"path",
... | [
33,
0
] | [
45,
70
] | python | en | ['en', 'error', 'th'] | False |
_parse | (data) |
Parse movielens dataset lines.
|
Parse movielens dataset lines.
| def _parse(data):
"""
Parse movielens dataset lines.
"""
for line in data:
if not line:
continue
uid, iid, rating, timestamp = [int(x) for x in line.split('\t')]
yield uid, iid, rating, timestamp | [
"def",
"_parse",
"(",
"data",
")",
":",
"for",
"line",
"in",
"data",
":",
"if",
"not",
"line",
":",
"continue",
"uid",
",",
"iid",
",",
"rating",
",",
"timestamp",
"=",
"[",
"int",
"(",
"x",
")",
"for",
"x",
"in",
"line",
".",
"split",
"(",
"'\... | [
48,
0
] | [
60,
41
] | python | en | ['en', 'error', 'th'] | False |
_build_interaction_matrix | (rows, cols, data) |
Build the training matrix (no_users, no_items),
with ratings >= 4.0 being marked as positive and
the rest as negative.
|
Build the training matrix (no_users, no_items),
with ratings >= 4.0 being marked as positive and
the rest as negative.
| def _build_interaction_matrix(rows, cols, data):
"""
Build the training matrix (no_users, no_items),
with ratings >= 4.0 being marked as positive and
the rest as negative.
"""
mat = sp.lil_matrix((rows, cols), dtype=np.int32)
for uid, iid, rating, timestamp in data:
if rating >= 4.... | [
"def",
"_build_interaction_matrix",
"(",
"rows",
",",
"cols",
",",
"data",
")",
":",
"mat",
"=",
"sp",
".",
"lil_matrix",
"(",
"(",
"rows",
",",
"cols",
")",
",",
"dtype",
"=",
"np",
".",
"int32",
")",
"for",
"uid",
",",
"iid",
",",
"rating",
",",
... | [
63,
0
] | [
78,
22
] | python | en | ['en', 'error', 'th'] | False |
_get_movie_raw_metadata | () |
Get raw lines of the genre file.
|
Get raw lines of the genre file.
| def _get_movie_raw_metadata():
"""
Get raw lines of the genre file.
"""
path = _get_movielens_path()
if not os.path.isfile(path):
_download_movielens(path)
with zipfile.ZipFile(path) as datafile:
return datafile.read('ml-100k/u.item').decode(errors='ignore').split('\n') | [
"def",
"_get_movie_raw_metadata",
"(",
")",
":",
"path",
"=",
"_get_movielens_path",
"(",
")",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"path",
")",
":",
"_download_movielens",
"(",
"path",
")",
"with",
"zipfile",
".",
"ZipFile",
"(",
"path",
... | [
81,
0
] | [
92,
82
] | python | en | ['en', 'error', 'th'] | False |
get_movielens_item_metadata | (use_item_ids) |
Build a matrix of genre features (no_items, no_features).
If use_item_ids is True, per-item features will also be used.
|
Build a matrix of genre features (no_items, no_features). | def get_movielens_item_metadata(use_item_ids):
"""
Build a matrix of genre features (no_items, no_features).
If use_item_ids is True, per-item features will also be used.
"""
features = {}
genre_set = set()
for line in _get_movie_raw_metadata():
if not line:
continue
... | [
"def",
"get_movielens_item_metadata",
"(",
"use_item_ids",
")",
":",
"features",
"=",
"{",
"}",
"genre_set",
"=",
"set",
"(",
")",
"for",
"line",
"in",
"_get_movie_raw_metadata",
"(",
")",
":",
"if",
"not",
"line",
":",
"continue",
"splt",
"=",
"line",
"."... | [
95,
0
] | [
134,
14
] | python | en | ['en', 'error', 'th'] | False |
get_movielens_data | () |
Return (train_interactions, test_interactions).
|
Return (train_interactions, test_interactions).
| def get_movielens_data():
"""
Return (train_interactions, test_interactions).
"""
train_data, test_data = _get_raw_movielens_data()
uids = set()
iids = set()
for uid, iid, rating, timestamp in itertools.chain(_parse(train_data),
_pars... | [
"def",
"get_movielens_data",
"(",
")",
":",
"train_data",
",",
"test_data",
"=",
"_get_raw_movielens_data",
"(",
")",
"uids",
"=",
"set",
"(",
")",
"iids",
"=",
"set",
"(",
")",
"for",
"uid",
",",
"iid",
",",
"rating",
",",
"timestamp",
"in",
"itertools"... | [
137,
0
] | [
156,
69
] | python | en | ['en', 'error', 'th'] | False |
test_multiple_optimizers_manual | (tmpdir) |
Tests that only training_step can be used
|
Tests that only training_step can be used
| def test_multiple_optimizers_manual(tmpdir):
"""
Tests that only training_step can be used
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
self.automatic_optimization = False
def training_step(self, batch, batch_idx, optimizer_idx):
... | [
"def",
"test_multiple_optimizers_manual",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automatic_optimization",
"=",
"False"... | [
31,
0
] | [
94,
112
] | python | en | ['en', 'error', 'th'] | False |
test_multiple_optimizers_manual_return | (tmpdir) |
Tests that only training_step can be used
|
Tests that only training_step can be used
| def test_multiple_optimizers_manual_return(tmpdir):
"""
Tests that only training_step can be used
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
self.automatic_optimization = False
def training_step(self, batch, batch_idx, optimizer_id... | [
"def",
"test_multiple_optimizers_manual_return",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automatic_optimization",
"=",
... | [
98,
0
] | [
163,
112
] | python | en | ['en', 'error', 'th'] | False |
test_multiple_optimizers_manual_return_and_log | (tmpdir) |
Tests that only training_step can be used
|
Tests that only training_step can be used
| def test_multiple_optimizers_manual_return_and_log(tmpdir):
"""
Tests that only training_step can be used
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
self.automatic_optimization = False
def training_step(self, batch, batch_idx, opti... | [
"def",
"test_multiple_optimizers_manual_return_and_log",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automatic_optimization",
... | [
167,
0
] | [
237,
29
] | python | en | ['en', 'error', 'th'] | False |
test_multiple_optimizers_manual_native_amp | (tmpdir) |
Tests that only training_step can be used
|
Tests that only training_step can be used
| def test_multiple_optimizers_manual_native_amp(tmpdir):
"""
Tests that only training_step can be used
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
self.automatic_optimization = False
def training_step(self, batch, batch_idx, optimize... | [
"def",
"test_multiple_optimizers_manual_native_amp",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automatic_optimization",
"="... | [
242,
0
] | [
307,
112
] | python | en | ['en', 'error', 'th'] | False |
test_multiple_optimizers_manual_apex | (tmpdir) |
Tests that only training_step can be used
|
Tests that only training_step can be used
| def test_multiple_optimizers_manual_apex(tmpdir):
"""
Tests that only training_step can be used
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
self.automatic_optimization = False
def training_step(self, batch, batch_idx, optimizer_idx)... | [
"def",
"test_multiple_optimizers_manual_apex",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automatic_optimization",
"=",
"F... | [
313,
0
] | [
384,
112
] | python | en | ['en', 'error', 'th'] | False |
test_manual_optimization_and_return_tensor | (tmpdir) |
This test verify that in `manual_optimization`
we don't add gradient when the user return loss in `training_step`
|
This test verify that in `manual_optimization`
we don't add gradient when the user return loss in `training_step`
| def test_manual_optimization_and_return_tensor(tmpdir):
"""
This test verify that in `manual_optimization`
we don't add gradient when the user return loss in `training_step`
"""
model = ManualOptimizationExtendedModel()
model.training_step_end = None
model.training_epoch_end = None
tra... | [
"def",
"test_manual_optimization_and_return_tensor",
"(",
"tmpdir",
")",
":",
"model",
"=",
"ManualOptimizationExtendedModel",
"(",
")",
"model",
".",
"training_step_end",
"=",
"None",
"model",
".",
"training_epoch_end",
"=",
"None",
"trainer",
"=",
"Trainer",
"(",
... | [
450,
0
] | [
471,
22
] | python | en | ['en', 'error', 'th'] | False |
test_manual_optimization_and_return_detached_tensor | (tmpdir) |
This test verify that in `manual_optimization`
we don't add gradient when the user return loss in `training_step`
When the tensor is detached, return MisConfiguration Error.
|
This test verify that in `manual_optimization`
we don't add gradient when the user return loss in `training_step`
When the tensor is detached, return MisConfiguration Error.
| def test_manual_optimization_and_return_detached_tensor(tmpdir):
"""
This test verify that in `manual_optimization`
we don't add gradient when the user return loss in `training_step`
When the tensor is detached, return MisConfiguration Error.
"""
model = ManualOptimizationExtendedModel()
mo... | [
"def",
"test_manual_optimization_and_return_detached_tensor",
"(",
"tmpdir",
")",
":",
"model",
"=",
"ManualOptimizationExtendedModel",
"(",
")",
"model",
".",
"detach",
"=",
"True",
"model",
".",
"training_step_end",
"=",
"None",
"model",
".",
"training_epoch_end",
"... | [
476,
0
] | [
501,
26
] | python | en | ['en', 'error', 'th'] | False |
test_manual_optimization_and_accumulated_gradient | (tmpdir) |
This test verify that in `automatic_optimization=False`,
step is being called only when we shouldn't accumulate.
|
This test verify that in `automatic_optimization=False`,
step is being called only when we shouldn't accumulate.
| def test_manual_optimization_and_accumulated_gradient(tmpdir):
"""
This test verify that in `automatic_optimization=False`,
step is being called only when we shouldn't accumulate.
"""
seed_everything(234)
class ExtendedModel(BoringModel):
count = 1
called = collections.defaultd... | [
"def",
"test_manual_optimization_and_accumulated_gradient",
"(",
"tmpdir",
")",
":",
"seed_everything",
"(",
"234",
")",
"class",
"ExtendedModel",
"(",
"BoringModel",
")",
":",
"count",
"=",
"1",
"called",
"=",
"collections",
".",
"defaultdict",
"(",
"int",
")",
... | [
505,
0
] | [
591,
22
] | python | en | ['en', 'error', 'th'] | False |
test_multiple_optimizers_step | (tmpdir) |
Tests that `step` works with several optimizers
|
Tests that `step` works with several optimizers
| def test_multiple_optimizers_step(tmpdir):
"""
Tests that `step` works with several optimizers
"""
class TestModel(BoringModel):
called = False
def __init__(self):
super().__init__()
self.automatic_optimization = False
def on_after_backward(self):
... | [
"def",
"test_multiple_optimizers_step",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"called",
"=",
"False",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automatic_opt... | [
596,
0
] | [
672,
23
] | python | en | ['en', 'error', 'th'] | False |
test_step_with_optimizer_closure | (tmpdir) |
Tests that `step` works with optimizer_closure
|
Tests that `step` works with optimizer_closure
| def test_step_with_optimizer_closure(tmpdir):
"""
Tests that `step` works with optimizer_closure
"""
class TestModel(BoringModel):
_losses = []
def __init__(self):
super().__init__()
self.automatic_optimization = False
def training_step(self, batch, ba... | [
"def",
"test_step_with_optimizer_closure",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"_losses",
"=",
"[",
"]",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automa... | [
676,
0
] | [
753,
113
] | python | en | ['en', 'error', 'th'] | False |
test_step_with_optimizer_closure_and_accumulated_grad | (tmpdir) |
Tests that `step` works with optimizer_closure and accumulated_grad
|
Tests that `step` works with optimizer_closure and accumulated_grad
| def test_step_with_optimizer_closure_and_accumulated_grad(tmpdir):
"""
Tests that `step` works with optimizer_closure and accumulated_grad
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
self.automatic_optimization = False
def training_... | [
"def",
"test_step_with_optimizer_closure_and_accumulated_grad",
"(",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"automatic_optimizat... | [
757,
0
] | [
816,
88
] | python | en | ['en', 'error', 'th'] | False |
test_step_with_optimizer_closure_and_extra_arguments | (step_mock, tmpdir) |
Tests that `step` works with optimizer_closure and extra arguments
|
Tests that `step` works with optimizer_closure and extra arguments
| def test_step_with_optimizer_closure_and_extra_arguments(step_mock, tmpdir):
"""
Tests that `step` works with optimizer_closure and extra arguments
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
self.automatic_optimization = False
def ... | [
"def",
"test_step_with_optimizer_closure_and_extra_arguments",
"(",
"step_mock",
",",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
... | [
821,
0
] | [
874,
46
] | python | en | ['en', 'error', 'th'] | False |
test_step_with_optimizer_closure_with_different_frequencies | (mock_sgd_step, mock_adam_step, tmpdir) |
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
|
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
| def test_step_with_optimizer_closure_with_different_frequencies(mock_sgd_step, mock_adam_step, tmpdir):
"""
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
"""
class TestModel(BoringModel):
def __init__(self):
super().__init__()
... | [
"def",
"test_step_with_optimizer_closure_with_different_frequencies",
"(",
"mock_sgd_step",
",",
"mock_adam_step",
",",
"tmpdir",
")",
":",
"class",
"TestModel",
"(",
"BoringModel",
")",
":",
"def",
"__init__",
"(",
"self",
")",
":",
"super",
"(",
")",
".",
"__ini... | [
880,
0
] | [
956,
51
] | python | en | ['en', 'error', 'th'] | False |
test_step_with_optimizer_closure_with_different_frequencies_ddp | (tmpdir) |
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
|
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
| def test_step_with_optimizer_closure_with_different_frequencies_ddp(tmpdir):
"""
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
"""
train_manual_optimization(tmpdir, "ddp") | [
"def",
"test_step_with_optimizer_closure_with_different_frequencies_ddp",
"(",
"tmpdir",
")",
":",
"train_manual_optimization",
"(",
"tmpdir",
",",
"\"ddp\"",
")"
] | [
1079,
0
] | [
1084,
44
] | python | en | ['en', 'error', 'th'] | False |
test_step_with_optimizer_closure_with_different_frequencies_ddp_spawn | (tmpdir) |
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
|
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
| def test_step_with_optimizer_closure_with_different_frequencies_ddp_spawn(tmpdir):
"""
Tests that `step` works with optimizer_closure and different accumulated_gradient frequency
"""
train_manual_optimization(tmpdir, "ddp_spawn") | [
"def",
"test_step_with_optimizer_closure_with_different_frequencies_ddp_spawn",
"(",
"tmpdir",
")",
":",
"train_manual_optimization",
"(",
"tmpdir",
",",
"\"ddp_spawn\"",
")"
] | [
1088,
0
] | [
1093,
50
] | python | en | ['en', 'error', 'th'] | False |
get_behavior_records | () |
Returns list of behavior records from db.
|
Returns list of behavior records from db.
| def get_behavior_records():
"""
Returns list of behavior records from db.
"""
return BehaviorRecord.query.all() | [
"def",
"get_behavior_records",
"(",
")",
":",
"return",
"BehaviorRecord",
".",
"query",
".",
"all",
"(",
")"
] | [
8,
0
] | [
12,
34
] | python | en | ['en', 'error', 'th'] | False |
get_behavior_record_values | (date: str) |
Gets Behavior Record values for a specific date.
|
Gets Behavior Record values for a specific date.
| def get_behavior_record_values(date: str):
"""
Gets Behavior Record values for a specific date.
"""
try:
rec = BehaviorRecord.query.filter_by(date=date).first()
# Catch nonexistent record for specified date and create one.
if rec is None:
print(f"-i- Adding new record for {date}")
rec = BehaviorRecord(... | [
"def",
"get_behavior_record_values",
"(",
"date",
":",
"str",
")",
":",
"try",
":",
"rec",
"=",
"BehaviorRecord",
".",
"query",
".",
"filter_by",
"(",
"date",
"=",
"date",
")",
".",
"first",
"(",
")",
"# Catch nonexistent record for specified date and create one."... | [
15,
0
] | [
35,
13
] | python | en | ['en', 'error', 'th'] | False |
get_led_status | () |
Sends a request to the arduino to get the current state of the LED's.
|
Sends a request to the arduino to get the current state of the LED's.
| def get_led_status():
"""
Sends a request to the arduino to get the current state of the LED's.
"""
url = f"http://192.168.1.188/current_led_state"
return json.loads(requests.get(url).text) | [
"def",
"get_led_status",
"(",
")",
":",
"url",
"=",
"f\"http://192.168.1.188/current_led_state\"",
"return",
"json",
".",
"loads",
"(",
"requests",
".",
"get",
"(",
"url",
")",
".",
"text",
")"
] | [
39,
0
] | [
45,
42
] | python | en | ['en', 'error', 'th'] | False |
adjust_led | (state_irgb) |
Sends a request to the arduino to adjust the leds.
|
Sends a request to the arduino to adjust the leds.
| def adjust_led(state_irgb):
"""
Sends a request to the arduino to adjust the leds.
"""
state = state_irgb.split()[0]
irgb = state_irgb.split()[1].upper()
url = f"http://192.168.1.188/led?state={state};irgb={irgb};"
return json.loads(requests.get(url).text) | [
"def",
"adjust_led",
"(",
"state_irgb",
")",
":",
"state",
"=",
"state_irgb",
".",
"split",
"(",
")",
"[",
"0",
"]",
"irgb",
"=",
"state_irgb",
".",
"split",
"(",
")",
"[",
"1",
"]",
".",
"upper",
"(",
")",
"url",
"=",
"f\"http://192.168.1.188/led?stat... | [
49,
0
] | [
56,
42
] | python | en | ['en', 'error', 'th'] | False |
trigger_school_alarm | (alarm_name) |
Sends a get request to the arduino to trigger the appropriate alarm.
|
Sends a get request to the arduino to trigger the appropriate alarm.
| def trigger_school_alarm(alarm_name):
"""
Sends a get request to the arduino to trigger the appropriate alarm.
"""
return jsonify(requests.get(f"http://192.168.1.188/alarm?name={alarm_name}").text) | [
"def",
"trigger_school_alarm",
"(",
"alarm_name",
")",
":",
"return",
"jsonify",
"(",
"requests",
".",
"get",
"(",
"f\"http://192.168.1.188/alarm?name={alarm_name}\"",
")",
".",
"text",
")"
] | [
60,
0
] | [
64,
83
] | python | en | ['en', 'error', 'th'] | False |
get_current_datetime | () |
Returns the current date & time to the arduino upon request.
|
Returns the current date & time to the arduino upon request.
| def get_current_datetime():
"""
Returns the current date & time to the arduino upon request.
"""
return get_datetime_string() | [
"def",
"get_current_datetime",
"(",
")",
":",
"return",
"get_datetime_string",
"(",
")"
] | [
68,
0
] | [
72,
29
] | python | en | ['en', 'error', 'th'] | False |
get_alarms_from_db | () |
Queries the database for all alarms currently in the database
|
Queries the database for all alarms currently in the database
| def get_alarms_from_db():
"""
Queries the database for all alarms currently in the database
"""
db_records = Alarm.query.all()
records = []
for rec in db_records:
temp_dict = rec.__dict__
temp_dict.pop(list(temp_dict.keys())[0])
records.append(temp_dict)
return jsonify(records) | [
"def",
"get_alarms_from_db",
"(",
")",
":",
"db_records",
"=",
"Alarm",
".",
"query",
".",
"all",
"(",
")",
"records",
"=",
"[",
"]",
"for",
"rec",
"in",
"db_records",
":",
"temp_dict",
"=",
"rec",
".",
"__dict__",
"temp_dict",
".",
"pop",
"(",
"list",... | [
76,
0
] | [
87,
24
] | python | en | ['en', 'error', 'th'] | False |
add_new_alarm | (alarm: Alarm) |
Stores an alarm model instance in the database.
@param alarm: New Alarm instance
@param alarm: alarm
|
Stores an alarm model instance in the database.
| def add_new_alarm(alarm: Alarm):
"""
Stores an alarm model instance in the database.
@param alarm: New Alarm instance
@param alarm: alarm
"""
db.session.add(alarm)
db.session.commit() | [
"def",
"add_new_alarm",
"(",
"alarm",
":",
"Alarm",
")",
":",
"db",
".",
"session",
".",
"add",
"(",
"alarm",
")",
"db",
".",
"session",
".",
"commit",
"(",
")"
] | [
91,
0
] | [
99,
20
] | python | en | ['en', 'error', 'th'] | False |
remove_alarm | (alarms: list) |
Removes one or more alarms from the database.
@param alarms: list of one or more alarms to remove by name
@type alarms: list
|
Removes one or more alarms from the database.
| def remove_alarm(alarms: list):
"""
Removes one or more alarms from the database.
@param alarms: list of one or more alarms to remove by name
@type alarms: list
"""
if alarms[0] == '_ALL_':
Alarm.query.delete()
else:
for alarm_name in alarms:
Alarm.query.filter_by(name=alarm_name).delete() | [
"def",
"remove_alarm",
"(",
"alarms",
":",
"list",
")",
":",
"if",
"alarms",
"[",
"0",
"]",
"==",
"'_ALL_'",
":",
"Alarm",
".",
"query",
".",
"delete",
"(",
")",
"else",
":",
"for",
"alarm_name",
"in",
"alarms",
":",
"Alarm",
".",
"query",
".",
"fi... | [
103,
0
] | [
114,
50
] | python | en | ['en', 'error', 'th'] | False |
update_behavior_points | (update_opt) |
Updates happy, sad, or bonus points for the current date behavior record.
@param update_opt: update option
@type update_opt: str
|
Updates happy, sad, or bonus points for the current date behavior record. | def update_behavior_points(update_opt):
"""
Updates happy, sad, or bonus points for the current date behavior record.
@param update_opt: update option
@type update_opt: str
"""
rec: BehaviorRecord
rec = get_behavior_record_values(get_date_string())
if update_opt != "-1":
if update_opt == "0":
rec.happy_po... | [
"def",
"update_behavior_points",
"(",
"update_opt",
")",
":",
"rec",
":",
"BehaviorRecord",
"rec",
"=",
"get_behavior_record_values",
"(",
"get_date_string",
"(",
")",
")",
"if",
"update_opt",
"!=",
"\"-1\"",
":",
"if",
"update_opt",
"==",
"\"0\"",
":",
"rec",
... | [
118,
0
] | [
143,
70
] | python | en | ['en', 'error', 'th'] | False |
render_homepage | () |
Starts homepage for the webapp.
|
Starts homepage for the webapp.
| def render_homepage():
"""
Starts homepage for the webapp.
"""
return render_template('homepage.html', alarms=Alarm.query.all()) | [
"def",
"render_homepage",
"(",
")",
":",
"return",
"render_template",
"(",
"'homepage.html'",
",",
"alarms",
"=",
"Alarm",
".",
"query",
".",
"all",
"(",
")",
")"
] | [
147,
0
] | [
152,
66
] | python | en | ['en', 'error', 'th'] | False |
is_block | (modules) | Check if is HRModule building block. | Check if is HRModule building block. | def is_block(modules):
"""Check if is HRModule building block."""
if isinstance(modules, (HRModule, )):
return True
return False | [
"def",
"is_block",
"(",
"modules",
")",
":",
"if",
"isinstance",
"(",
"modules",
",",
"(",
"HRModule",
",",
")",
")",
":",
"return",
"True",
"return",
"False"
] | [
8,
0
] | [
12,
16
] | python | en | ['en', 'en', 'en'] | True |
is_norm | (modules) | Check if is one of the norms. | Check if is one of the norms. | def is_norm(modules):
"""Check if is one of the norms."""
if isinstance(modules, (_BatchNorm, )):
return True
return False | [
"def",
"is_norm",
"(",
"modules",
")",
":",
"if",
"isinstance",
"(",
"modules",
",",
"(",
"_BatchNorm",
",",
")",
")",
":",
"return",
"True",
"return",
"False"
] | [
15,
0
] | [
19,
16
] | python | en | ['en', 'en', 'en'] | True |
all_zeros | (modules) | Check if the weight(and bias) is all zero. | Check if the weight(and bias) is all zero. | def all_zeros(modules):
"""Check if the weight(and bias) is all zero."""
weight_zero = torch.equal(modules.weight.data,
torch.zeros_like(modules.weight.data))
if hasattr(modules, 'bias'):
bias_zero = torch.equal(modules.bias.data,
torch.z... | [
"def",
"all_zeros",
"(",
"modules",
")",
":",
"weight_zero",
"=",
"torch",
".",
"equal",
"(",
"modules",
".",
"weight",
".",
"data",
",",
"torch",
".",
"zeros_like",
"(",
"modules",
".",
"weight",
".",
"data",
")",
")",
"if",
"hasattr",
"(",
"modules",... | [
22,
0
] | [
32,
36
] | python | en | ['en', 'en', 'en'] | True |
auto_move_data | (fn: Callable) |
Decorator for :class:`~pytorch_lightning.core.lightning.LightningModule` methods for which
input arguments should be moved automatically to the correct device.
It as no effect if applied to a method of an object that is not an instance of
:class:`~pytorch_lightning.core.lightning.LightningModule` and i... |
Decorator for :class:`~pytorch_lightning.core.lightning.LightningModule` methods for which
input arguments should be moved automatically to the correct device.
It as no effect if applied to a method of an object that is not an instance of
:class:`~pytorch_lightning.core.lightning.LightningModule` and i... | def auto_move_data(fn: Callable) -> Callable:
"""
Decorator for :class:`~pytorch_lightning.core.lightning.LightningModule` methods for which
input arguments should be moved automatically to the correct device.
It as no effect if applied to a method of an object that is not an instance of
:class:`~py... | [
"def",
"auto_move_data",
"(",
"fn",
":",
"Callable",
")",
"->",
"Callable",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"auto_transfer_args",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"from",
"pytorch_lightning",
".",
"core",
".",... | [
21,
0
] | [
63,
29
] | python | en | ['en', 'error', 'th'] | False |
parameter_validation | (fn: Callable) |
Decorator for :meth:`~pytorch_lightning.core.LightningModule.to` method.
Validates that the module parameter lengths match after moving to the device. It is useful
when tying weights on TPU's.
Args:
fn: ``.to`` method
Note:
TPU's require weights to be tied/shared after moving the ... |
Decorator for :meth:`~pytorch_lightning.core.LightningModule.to` method.
Validates that the module parameter lengths match after moving to the device. It is useful
when tying weights on TPU's. | def parameter_validation(fn: Callable) -> Callable:
"""
Decorator for :meth:`~pytorch_lightning.core.LightningModule.to` method.
Validates that the module parameter lengths match after moving to the device. It is useful
when tying weights on TPU's.
Args:
fn: ``.to`` method
Note:
... | [
"def",
"parameter_validation",
"(",
"fn",
":",
"Callable",
")",
"->",
"Callable",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"inner_fn",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"pre_layer_count",
"=",
"len",
"(",
"list",
"(",... | [
66,
0
] | [
102,
19
] | python | en | ['en', 'error', 'th'] | False |
series_to_supervised | (data, n_in=1, n_out=1, dropnan=True) |
Frame a time series as a supervised learning dataset.
Arguments:
^Idata: Sequence of observations as a list or NumPy array.
^In_in: Number of lag observations as input (X).
^In_out: Number of observations as output (y).
^Idropnan: Boolean whether or not to drop rows with NaN values.
Returns... |
Frame a time series as a supervised learning dataset.
Arguments:
^Idata: Sequence of observations as a list or NumPy array.
^In_in: Number of lag observations as input (X).
^In_out: Number of observations as output (y).
^Idropnan: Boolean whether or not to drop rows with NaN values.
Returns... | def series_to_supervised(data, n_in=1, n_out=1, dropnan=True):
"""
Frame a time series as a supervised learning dataset.
Arguments:
^Idata: Sequence of observations as a list or NumPy array.
^In_in: Number of lag observations as input (X).
^In_out: Number of observations as output (y).
^Idro... | [
"def",
"series_to_supervised",
"(",
"data",
",",
"n_in",
"=",
"1",
",",
"n_out",
"=",
"1",
",",
"dropnan",
"=",
"True",
")",
":",
"n_vars",
"=",
"1",
"if",
"type",
"(",
"data",
")",
"is",
"list",
"else",
"data",
".",
"shape",
"[",
"1",
"]",
"df",... | [
10,
0
] | [
41,
14
] | python | en | ['en', 'error', 'th'] | False |
create_input_features | (inputs) |
[labels, [features]]
|
[labels, [features]]
| def create_input_features(inputs):
"""
[labels, [features]]
"""
pad = ['TOKEN'] * SERIES_LENGTH
for index in range(len(inputs) - SERIES_LENGTH - 1):
yield [inputs[index], pad + inputs[max(0, index - SERIES_LENGTH ):index]]
pad = pad[1:] | [
"def",
"create_input_features",
"(",
"inputs",
")",
":",
"pad",
"=",
"[",
"'TOKEN'",
"]",
"*",
"SERIES_LENGTH",
"for",
"index",
"in",
"range",
"(",
"len",
"(",
"inputs",
")",
"-",
"SERIES_LENGTH",
"-",
"1",
")",
":",
"yield",
"[",
"inputs",
"[",
"index... | [
53,
0
] | [
60,
21
] | python | en | ['en', 'error', 'th'] | False |
zeroVector | (dimension) |
returns a zero-vector of size 'dimension'
|
returns a zero-vector of size 'dimension'
| def zeroVector(dimension):
"""
returns a zero-vector of size 'dimension'
"""
# precondition
assert (isinstance(dimension, int))
ans = []
for i in range(dimension):
ans.append(0)
return Vector(ans) | [
"def",
"zeroVector",
"(",
"dimension",
")",
":",
"# precondition",
"assert",
"(",
"isinstance",
"(",
"dimension",
",",
"int",
")",
")",
"ans",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"dimension",
")",
":",
"ans",
".",
"append",
"(",
"0",
")",
... | [
197,
0
] | [
206,
22
] | python | en | ['en', 'error', 'th'] | False |
unitBasisVector | (dimension, pos) |
returns a unit basis vector with a One
at index 'pos' (indexing at 0)
|
returns a unit basis vector with a One
at index 'pos' (indexing at 0)
| def unitBasisVector(dimension, pos):
"""
returns a unit basis vector with a One
at index 'pos' (indexing at 0)
"""
# precondition
assert (isinstance(dimension, int) and (isinstance(pos, int)))
ans = []
for i in range(dimension):
if i != pos:
ans.append(0)
... | [
"def",
"unitBasisVector",
"(",
"dimension",
",",
"pos",
")",
":",
"# precondition",
"assert",
"(",
"isinstance",
"(",
"dimension",
",",
"int",
")",
"and",
"(",
"isinstance",
"(",
"pos",
",",
"int",
")",
")",
")",
"ans",
"=",
"[",
"]",
"for",
"i",
"in... | [
209,
0
] | [
222,
22
] | python | en | ['en', 'error', 'th'] | False |
axpy | (scalar, x, y) |
input: a 'scalar' and two vectors 'x' and 'y'
output: a vector
computes the axpy operation
|
input: a 'scalar' and two vectors 'x' and 'y'
output: a vector
computes the axpy operation
| def axpy(scalar, x, y):
"""
input: a 'scalar' and two vectors 'x' and 'y'
output: a vector
computes the axpy operation
"""
# precondition
assert (isinstance(x, Vector) and (isinstance(y, Vector)) \
and (isinstance(scalar, int) or isinstance(scalar, float)))
return... | [
"def",
"axpy",
"(",
"scalar",
",",
"x",
",",
"y",
")",
":",
"# precondition",
"assert",
"(",
"isinstance",
"(",
"x",
",",
"Vector",
")",
"and",
"(",
"isinstance",
"(",
"y",
",",
"Vector",
")",
")",
"and",
"(",
"isinstance",
"(",
"scalar",
",",
"int... | [
225,
0
] | [
234,
27
] | python | en | ['en', 'error', 'th'] | False |
randomVector | (N, a, b) |
input: size (N) of the vector.
random range (a,b)
output: returns a random vector of size N, with
random integer components between 'a' and 'b'.
|
input: size (N) of the vector.
random range (a,b)
output: returns a random vector of size N, with
random integer components between 'a' and 'b'.
| def randomVector(N, a, b):
"""
input: size (N) of the vector.
random range (a,b)
output: returns a random vector of size N, with
random integer components between 'a' and 'b'.
"""
ans = zeroVector(N)
random.seed(None)
for i in range(N):
ans.cha... | [
"def",
"randomVector",
"(",
"N",
",",
"a",
",",
"b",
")",
":",
"ans",
"=",
"zeroVector",
"(",
"N",
")",
"random",
".",
"seed",
"(",
"None",
")",
"for",
"i",
"in",
"range",
"(",
"N",
")",
":",
"ans",
".",
"changeComponent",
"(",
"i",
",",
"rando... | [
237,
0
] | [
248,
14
] | python | en | ['en', 'error', 'th'] | False |
squareZeroMatrix | (N) |
returns a square zero-matrix of dimension NxN
|
returns a square zero-matrix of dimension NxN
| def squareZeroMatrix(N):
"""
returns a square zero-matrix of dimension NxN
"""
ans = []
for i in range(N):
row = []
for j in range(N):
row.append(0)
ans.append(row)
return Matrix(ans, N, N) | [
"def",
"squareZeroMatrix",
"(",
"N",
")",
":",
"ans",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"N",
")",
":",
"row",
"=",
"[",
"]",
"for",
"j",
"in",
"range",
"(",
"N",
")",
":",
"row",
".",
"append",
"(",
"0",
")",
"ans",
".",
"appen... | [
396,
0
] | [
406,
28
] | python | en | ['en', 'error', 'th'] | False |
randomMatrix | (W, H, a, b) |
returns a random matrix WxH with integer components
between 'a' and 'b'
|
returns a random matrix WxH with integer components
between 'a' and 'b'
| def randomMatrix(W, H, a, b):
"""
returns a random matrix WxH with integer components
between 'a' and 'b'
"""
matrix = []
random.seed(None)
for i in range(H):
row = []
for j in range(W):
row.append(random.randint(a, b))
matrix.append(row)
retur... | [
"def",
"randomMatrix",
"(",
"W",
",",
"H",
",",
"a",
",",
"b",
")",
":",
"matrix",
"=",
"[",
"]",
"random",
".",
"seed",
"(",
"None",
")",
"for",
"i",
"in",
"range",
"(",
"H",
")",
":",
"row",
"=",
"[",
"]",
"for",
"j",
"in",
"range",
"(",
... | [
409,
0
] | [
421,
31
] | python | en | ['en', 'error', 'th'] | False |
Vector.__init__ | (self, components) |
input: components or nothing
simple constructor for init the vector
|
input: components or nothing
simple constructor for init the vector
| def __init__(self, components):
"""
input: components or nothing
simple constructor for init the vector
"""
self.__components = components | [
"def",
"__init__",
"(",
"self",
",",
"components",
")",
":",
"self",
".",
"__components",
"=",
"components"
] | [
47,
4
] | [
52,
38
] | python | en | ['en', 'error', 'th'] | False |
Vector.set | (self, components) |
input: new components
changes the components of the vector.
replace the components with newer one.
|
input: new components
changes the components of the vector.
replace the components with newer one.
| def set(self, components):
"""
input: new components
changes the components of the vector.
replace the components with newer one.
"""
if len(components) > 0:
self.__components = components
else:
raise Exception("please give any ... | [
"def",
"set",
"(",
"self",
",",
"components",
")",
":",
"if",
"len",
"(",
"components",
")",
">",
"0",
":",
"self",
".",
"__components",
"=",
"components",
"else",
":",
"raise",
"Exception",
"(",
"\"please give any vector\"",
")"
] | [
54,
4
] | [
63,
53
] | python | en | ['en', 'error', 'th'] | False |
Vector.__str__ | (self) |
returns a string representation of the vector
|
returns a string representation of the vector
| def __str__(self):
"""
returns a string representation of the vector
"""
ans = "("
length = len(self.__components)
for i in range(length):
if i != length - 1:
ans += str(self.__components[i]) + ","
else:
ans += s... | [
"def",
"__str__",
"(",
"self",
")",
":",
"ans",
"=",
"\"(\"",
"length",
"=",
"len",
"(",
"self",
".",
"__components",
")",
"for",
"i",
"in",
"range",
"(",
"length",
")",
":",
"if",
"i",
"!=",
"length",
"-",
"1",
":",
"ans",
"+=",
"str",
"(",
"s... | [
65,
4
] | [
78,
18
] | python | en | ['en', 'error', 'th'] | False |
Vector.component | (self, i) |
input: index (start at 0)
output: the i-th component of the vector.
|
input: index (start at 0)
output: the i-th component of the vector.
| def component(self, i):
"""
input: index (start at 0)
output: the i-th component of the vector.
"""
if i < len(self.__components) and i >= 0:
return self.__components[i]
else:
raise Exception("index out of range") | [
"def",
"component",
"(",
"self",
",",
"i",
")",
":",
"if",
"i",
"<",
"len",
"(",
"self",
".",
"__components",
")",
"and",
"i",
">=",
"0",
":",
"return",
"self",
".",
"__components",
"[",
"i",
"]",
"else",
":",
"raise",
"Exception",
"(",
"\"index ou... | [
80,
4
] | [
88,
49
] | python | en | ['en', 'error', 'th'] | False |
Vector.size | (self) |
returns the size of the vector
|
returns the size of the vector
| def size(self):
"""
returns the size of the vector
"""
return len(self.__components) | [
"def",
"size",
"(",
"self",
")",
":",
"return",
"len",
"(",
"self",
".",
"__components",
")"
] | [
90,
4
] | [
94,
37
] | python | en | ['en', 'error', 'th'] | False |
Vector.eulidLength | (self) |
returns the eulidean length of the vector
|
returns the eulidean length of the vector
| def eulidLength(self):
"""
returns the eulidean length of the vector
"""
summe = 0
for c in self.__components:
summe += c ** 2
return math.sqrt(summe) | [
"def",
"eulidLength",
"(",
"self",
")",
":",
"summe",
"=",
"0",
"for",
"c",
"in",
"self",
".",
"__components",
":",
"summe",
"+=",
"c",
"**",
"2",
"return",
"math",
".",
"sqrt",
"(",
"summe",
")"
] | [
96,
4
] | [
103,
31
] | python | en | ['en', 'error', 'th'] | False |
Vector.__add__ | (self, other) |
input: other vector
assumes: other vector has the same size
returns a new vector that represents the sum.
|
input: other vector
assumes: other vector has the same size
returns a new vector that represents the sum.
| def __add__(self, other):
"""
input: other vector
assumes: other vector has the same size
returns a new vector that represents the sum.
"""
size = self.size()
result = []
if size == other.size():
for i in range(size):
... | [
"def",
"__add__",
"(",
"self",
",",
"other",
")",
":",
"size",
"=",
"self",
".",
"size",
"(",
")",
"result",
"=",
"[",
"]",
"if",
"size",
"==",
"other",
".",
"size",
"(",
")",
":",
"for",
"i",
"in",
"range",
"(",
"size",
")",
":",
"result",
"... | [
105,
4
] | [
118,
29
] | python | en | ['en', 'error', 'th'] | False |
Vector.__sub__ | (self, other) |
input: other vector
assumes: other vector has the same size
returns a new vector that represents the differenz.
|
input: other vector
assumes: other vector has the same size
returns a new vector that represents the differenz.
| def __sub__(self, other):
"""
input: other vector
assumes: other vector has the same size
returns a new vector that represents the differenz.
"""
size = self.size()
result = []
if size == other.size():
for i in range(size):
... | [
"def",
"__sub__",
"(",
"self",
",",
"other",
")",
":",
"size",
"=",
"self",
".",
"size",
"(",
")",
"result",
"=",
"[",
"]",
"if",
"size",
"==",
"other",
".",
"size",
"(",
")",
":",
"for",
"i",
"in",
"range",
"(",
"size",
")",
":",
"result",
"... | [
120,
4
] | [
133,
29
] | python | en | ['en', 'error', 'th'] | False |
Vector.__mul__ | (self, other) |
mul implements the scalar multiplication
and the dot-product
|
mul implements the scalar multiplication
and the dot-product
| def __mul__(self, other):
"""
mul implements the scalar multiplication
and the dot-product
"""
ans = []
if isinstance(other, float) or isinstance(other, int):
for c in self.__components:
ans.append(c * other)
elif (isinstance(o... | [
"def",
"__mul__",
"(",
"self",
",",
"other",
")",
":",
"ans",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"other",
",",
"float",
")",
"or",
"isinstance",
"(",
"other",
",",
"int",
")",
":",
"for",
"c",
"in",
"self",
".",
"__components",
":",
"ans",
"... | [
135,
4
] | [
152,
26
] | python | en | ['en', 'error', 'th'] | False |
Vector.copy | (self) |
copies this vector and returns it.
|
copies this vector and returns it.
| def copy(self):
"""
copies this vector and returns it.
"""
components = [x for x in self.__components]
return Vector(components) | [
"def",
"copy",
"(",
"self",
")",
":",
"components",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"__components",
"]",
"return",
"Vector",
"(",
"components",
")"
] | [
154,
4
] | [
159,
33
] | python | en | ['en', 'error', 'th'] | False |
Vector.changeComponent | (self, pos, value) |
input: an index (pos) and a value
changes the specified component (pos) with the
'value'
|
input: an index (pos) and a value
changes the specified component (pos) with the
'value'
| def changeComponent(self, pos, value):
"""
input: an index (pos) and a value
changes the specified component (pos) with the
'value'
"""
# precondition
assert (pos >= 0 and pos < len(self.__components))
self.__components[pos] = value | [
"def",
"changeComponent",
"(",
"self",
",",
"pos",
",",
"value",
")",
":",
"# precondition",
"assert",
"(",
"pos",
">=",
"0",
"and",
"pos",
"<",
"len",
"(",
"self",
".",
"__components",
")",
")",
"self",
".",
"__components",
"[",
"pos",
"]",
"=",
"va... | [
161,
4
] | [
169,
38
] | python | en | ['en', 'error', 'th'] | False |
Vector.norm | (self) |
normalizes this vector and returns it.
|
normalizes this vector and returns it.
| def norm(self):
"""
normalizes this vector and returns it.
"""
eLength = self.eulidLength()
quotient = 1.0 / eLength
for i in range(len(self.__components)):
self.__components[i] = self.__components[i] * quotient
return self | [
"def",
"norm",
"(",
"self",
")",
":",
"eLength",
"=",
"self",
".",
"eulidLength",
"(",
")",
"quotient",
"=",
"1.0",
"/",
"eLength",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"__components",
")",
")",
":",
"self",
".",
"__components",
... | [
171,
4
] | [
179,
19
] | python | en | ['en', 'error', 'th'] | False |
Vector.__eq__ | (self, other) |
returns true if the vectors are equal otherwise false.
|
returns true if the vectors are equal otherwise false.
| def __eq__(self, other):
"""
returns true if the vectors are equal otherwise false.
"""
ans = True
SIZE = self.size()
if (SIZE == other.size()):
for i in range(SIZE):
if self.__components[i] != other.component(i):
ans = ... | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":",
"ans",
"=",
"True",
"SIZE",
"=",
"self",
".",
"size",
"(",
")",
"if",
"(",
"SIZE",
"==",
"other",
".",
"size",
"(",
")",
")",
":",
"for",
"i",
"in",
"range",
"(",
"SIZE",
")",
":",
"if",
... | [
181,
4
] | [
194,
18
] | python | en | ['en', 'error', 'th'] | False |
Matrix.__init__ | (self, matrix, w, h) |
simple constructor for initialzes
the matrix with components.
|
simple constructor for initialzes
the matrix with components.
| def __init__(self, matrix, w, h):
"""
simple constructor for initialzes
the matrix with components.
"""
self.__matrix = matrix
self.__width = w
self.__height = h | [
"def",
"__init__",
"(",
"self",
",",
"matrix",
",",
"w",
",",
"h",
")",
":",
"self",
".",
"__matrix",
"=",
"matrix",
"self",
".",
"__width",
"=",
"w",
"self",
".",
"__height",
"=",
"h"
] | [
269,
4
] | [
276,
25
] | python | en | ['en', 'error', 'th'] | False |
Matrix.__str__ | (self) |
returns a string representation of this
matrix.
|
returns a string representation of this
matrix.
| def __str__(self):
"""
returns a string representation of this
matrix.
"""
ans = ""
for i in range(self.__height):
ans += "|"
for j in range(self.__width):
if j < self.__width - 1:
ans += str(self.__matri... | [
"def",
"__str__",
"(",
"self",
")",
":",
"ans",
"=",
"\"\"",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"__height",
")",
":",
"ans",
"+=",
"\"|\"",
"for",
"j",
"in",
"range",
"(",
"self",
".",
"__width",
")",
":",
"if",
"j",
"<",
"self",
".",... | [
278,
4
] | [
291,
18
] | python | en | ['en', 'error', 'th'] | False |
Matrix.changeComponent | (self, x, y, value) |
changes the x-y component of this matrix
|
changes the x-y component of this matrix
| def changeComponent(self, x, y, value):
"""
changes the x-y component of this matrix
"""
if x >= 0 and x < self.__height and y >= 0 and y < self.__width:
self.__matrix[x][y] = value
else:
raise Exception("changeComponent: indices out of bounds") | [
"def",
"changeComponent",
"(",
"self",
",",
"x",
",",
"y",
",",
"value",
")",
":",
"if",
"x",
">=",
"0",
"and",
"x",
"<",
"self",
".",
"__height",
"and",
"y",
">=",
"0",
"and",
"y",
"<",
"self",
".",
"__width",
":",
"self",
".",
"__matrix",
"["... | [
293,
4
] | [
300,
69
] | python | en | ['en', 'error', 'th'] | False |
Matrix.component | (self, x, y) |
returns the specified (x,y) component
|
returns the specified (x,y) component
| def component(self, x, y):
"""
returns the specified (x,y) component
"""
if x >= 0 and x < self.__height and y >= 0 and y < self.__width:
return self.__matrix[x][y]
else:
raise Exception("changeComponent: indices out of bounds") | [
"def",
"component",
"(",
"self",
",",
"x",
",",
"y",
")",
":",
"if",
"x",
">=",
"0",
"and",
"x",
"<",
"self",
".",
"__height",
"and",
"y",
">=",
"0",
"and",
"y",
"<",
"self",
".",
"__width",
":",
"return",
"self",
".",
"__matrix",
"[",
"x",
"... | [
302,
4
] | [
309,
69
] | python | en | ['en', 'error', 'th'] | False |
Matrix.width | (self) |
getter for the width
|
getter for the width
| def width(self):
"""
getter for the width
"""
return self.__width | [
"def",
"width",
"(",
"self",
")",
":",
"return",
"self",
".",
"__width"
] | [
311,
4
] | [
315,
27
] | python | en | ['en', 'error', 'th'] | False |
Matrix.height | (self) |
getter for the height
|
getter for the height
| def height(self):
"""
getter for the height
"""
return self.__height | [
"def",
"height",
"(",
"self",
")",
":",
"return",
"self",
".",
"__height"
] | [
317,
4
] | [
321,
28
] | python | en | ['en', 'error', 'th'] | False |
Matrix.__mul__ | (self, other) |
implements the matrix-vector multiplication.
implements the matrix-scalar multiplication
|
implements the matrix-vector multiplication.
implements the matrix-scalar multiplication
| def __mul__(self, other):
"""
implements the matrix-vector multiplication.
implements the matrix-scalar multiplication
"""
if isinstance(other, Vector): # vector-matrix
if (other.size() == self.__width):
ans = zeroVector(self.__height)
... | [
"def",
"__mul__",
"(",
"self",
",",
"other",
")",
":",
"if",
"isinstance",
"(",
"other",
",",
"Vector",
")",
":",
"# vector-matrix ",
"if",
"(",
"other",
".",
"size",
"(",
")",
"==",
"self",
".",
"__width",
")",
":",
"ans",
"=",
"zeroVector",
"(",
... | [
323,
4
] | [
348,
62
] | python | en | ['en', 'error', 'th'] | False |
Matrix.__add__ | (self, other) |
implements the matrix-addition.
|
implements the matrix-addition.
| def __add__(self, other):
"""
implements the matrix-addition.
"""
if (self.__width == other.width() and self.__height == other.height()):
matrix = []
for i in range(self.__height):
row = []
for j in range(self.__width):
... | [
"def",
"__add__",
"(",
"self",
",",
"other",
")",
":",
"if",
"(",
"self",
".",
"__width",
"==",
"other",
".",
"width",
"(",
")",
"and",
"self",
".",
"__height",
"==",
"other",
".",
"height",
"(",
")",
")",
":",
"matrix",
"=",
"[",
"]",
"for",
"... | [
350,
4
] | [
363,
67
] | python | en | ['en', 'error', 'th'] | False |
Matrix.__sub__ | (self, other) |
implements the matrix-subtraction.
|
implements the matrix-subtraction.
| def __sub__(self, other):
"""
implements the matrix-subtraction.
"""
if (self.__width == other.width() and self.__height == other.height()):
matrix = []
for i in range(self.__height):
row = []
for j in range(self.__width):
... | [
"def",
"__sub__",
"(",
"self",
",",
"other",
")",
":",
"if",
"(",
"self",
".",
"__width",
"==",
"other",
".",
"width",
"(",
")",
"and",
"self",
".",
"__height",
"==",
"other",
".",
"height",
"(",
")",
")",
":",
"matrix",
"=",
"[",
"]",
"for",
"... | [
365,
4
] | [
378,
67
] | python | en | ['en', 'error', 'th'] | False |
Matrix.__eq__ | (self, other) |
returns true if the matrices are equal otherwise false.
|
returns true if the matrices are equal otherwise false.
| def __eq__(self, other):
"""
returns true if the matrices are equal otherwise false.
"""
ans = True
if self.__width == other.width() and self.__height == other.height():
for i in range(self.__height):
for j in range(self.__width):
... | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":",
"ans",
"=",
"True",
"if",
"self",
".",
"__width",
"==",
"other",
".",
"width",
"(",
")",
"and",
"self",
".",
"__height",
"==",
"other",
".",
"height",
"(",
")",
":",
"for",
"i",
"in",
"range",... | [
380,
4
] | [
393,
18
] | python | en | ['en', 'error', 'th'] | False |
main | () |
Serialization composite test generator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Generates test source files for composite deserializers.
The files are generated, as they are extremely repetitive (tests for composite deserializer
for 0..9 sub-deserializers).
Usage:
launcher.py LOCATION_OF_OUTPUT_FILE
w... |
Serialization composite test generator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Generates test source files for composite deserializers.
The files are generated, as they are extremely repetitive (tests for composite deserializer
for 0..9 sub-deserializers). | def main():
"""
Serialization composite test generator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Generates test source files for composite deserializers.
The files are generated, as they are extremely repetitive (tests for composite deserializer
for 0..9 sub-deserializers).
Usage:
launcher.py LOCATION... | [
"def",
"main",
"(",
")",
":",
"serialization_composite_test_cc_file",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"sys",
".",
"argv",
"[",
"1",
"]",
")",
"generator",
".",
"generate_test_code",
"(",
"serialization_composite_test_cc_file",
")"
] | [
9,
0
] | [
27,
70
] | python | en | ['en', 'error', 'th'] | False |
AUROC.update | (self, preds: torch.Tensor, target: torch.Tensor) |
Update state with predictions and targets.
Args:
preds: Predictions from model (probabilities, or labels)
target: Ground truth labels
|
Update state with predictions and targets. | def update(self, preds: torch.Tensor, target: torch.Tensor):
"""
Update state with predictions and targets.
Args:
preds: Predictions from model (probabilities, or labels)
target: Ground truth labels
"""
preds, target, mode = _auroc_update(preds, target)
... | [
"def",
"update",
"(",
"self",
",",
"preds",
":",
"torch",
".",
"Tensor",
",",
"target",
":",
"torch",
".",
"Tensor",
")",
":",
"preds",
",",
"target",
",",
"mode",
"=",
"_auroc_update",
"(",
"preds",
",",
"target",
")",
"self",
".",
"preds",
".",
"... | [
138,
4
] | [
156,
24
] | python | en | ['en', 'error', 'th'] | False |
AUROC.compute | (self) |
Computes AUROC based on inputs passed in to ``update`` previously.
|
Computes AUROC based on inputs passed in to ``update`` previously.
| def compute(self) -> torch.Tensor:
"""
Computes AUROC based on inputs passed in to ``update`` previously.
"""
preds = torch.cat(self.preds, dim=0)
target = torch.cat(self.target, dim=0)
return _auroc_compute(
preds,
target,
self.mode,
... | [
"def",
"compute",
"(",
"self",
")",
"->",
"torch",
".",
"Tensor",
":",
"preds",
"=",
"torch",
".",
"cat",
"(",
"self",
".",
"preds",
",",
"dim",
"=",
"0",
")",
"target",
"=",
"torch",
".",
"cat",
"(",
"self",
".",
"target",
",",
"dim",
"=",
"0"... | [
158,
4
] | [
172,
9
] | python | en | ['en', 'error', 'th'] | False |
_newnames | (datatype, order) |
Given a datatype and an order object, return a new names tuple, with the
order indicated
|
Given a datatype and an order object, return a new names tuple, with the
order indicated
| def _newnames(datatype, order):
"""
Given a datatype and an order object, return a new names tuple, with the
order indicated
"""
oldnames = datatype.names
nameslist = list(oldnames)
if isinstance(order, (str, unicode)):
order = [order]
seen = set()
if isinstance(order, (list,... | [
"def",
"_newnames",
"(",
"datatype",
",",
"order",
")",
":",
"oldnames",
"=",
"datatype",
".",
"names",
"nameslist",
"=",
"list",
"(",
"oldnames",
")",
"if",
"isinstance",
"(",
"order",
",",
"(",
"str",
",",
"unicode",
")",
")",
":",
"order",
"=",
"[... | [
361,
0
] | [
382,
62
] | python | en | ['en', 'error', 'th'] | False |
_copy_fields | (ary) | Return copy of structured array with padding between fields removed.
Parameters
----------
ary : ndarray
Structured array from which to remove padding bytes
Returns
-------
ary_copy : ndarray
Copy of ary with padding bytes removed
| Return copy of structured array with padding between fields removed. | def _copy_fields(ary):
"""Return copy of structured array with padding between fields removed.
Parameters
----------
ary : ndarray
Structured array from which to remove padding bytes
Returns
-------
ary_copy : ndarray
Copy of ary with padding bytes removed
"""
dt = ar... | [
"def",
"_copy_fields",
"(",
"ary",
")",
":",
"dt",
"=",
"ary",
".",
"dtype",
"copy_dtype",
"=",
"{",
"'names'",
":",
"dt",
".",
"names",
",",
"'formats'",
":",
"[",
"dt",
".",
"fields",
"[",
"name",
"]",
"[",
"0",
"]",
"for",
"name",
"in",
"dt",
... | [
384,
0
] | [
400,
50
] | python | en | ['en', 'en', 'en'] | True |
_getfield_is_safe | (oldtype, newtype, offset) | Checks safety of getfield for object arrays.
As in _view_is_safe, we need to check that memory containing objects is not
reinterpreted as a non-object datatype and vice versa.
Parameters
----------
oldtype : data-type
Data type of the original ndarray.
newtype : data-type
Data... | Checks safety of getfield for object arrays. | def _getfield_is_safe(oldtype, newtype, offset):
""" Checks safety of getfield for object arrays.
As in _view_is_safe, we need to check that memory containing objects is not
reinterpreted as a non-object datatype and vice versa.
Parameters
----------
oldtype : data-type
Data type of th... | [
"def",
"_getfield_is_safe",
"(",
"oldtype",
",",
"newtype",
",",
"offset",
")",
":",
"if",
"newtype",
".",
"hasobject",
"or",
"oldtype",
".",
"hasobject",
":",
"if",
"offset",
"==",
"0",
"and",
"newtype",
"==",
"oldtype",
":",
"return",
"if",
"oldtype",
... | [
402,
0
] | [
432,
10
] | python | en | ['en', 'en', 'en'] | True |
_view_is_safe | (oldtype, newtype) | Checks safety of a view involving object arrays, for example when
doing::
np.zeros(10, dtype=oldtype).view(newtype)
Parameters
----------
oldtype : data-type
Data type of original ndarray
newtype : data-type
Data type of the view
Raises
------
TypeError
... | Checks safety of a view involving object arrays, for example when
doing:: | def _view_is_safe(oldtype, newtype):
""" Checks safety of a view involving object arrays, for example when
doing::
np.zeros(10, dtype=oldtype).view(newtype)
Parameters
----------
oldtype : data-type
Data type of original ndarray
newtype : data-type
Data type of the view... | [
"def",
"_view_is_safe",
"(",
"oldtype",
",",
"newtype",
")",
":",
"# if the types are equivalent, there is no problem.",
"# for example: dtype((np.record, 'i4,i4')) == dtype((np.void, 'i4,i4'))",
"if",
"oldtype",
"==",
"newtype",
":",
"return",
"if",
"newtype",
".",
"hasobject"... | [
434,
0
] | [
461,
10
] | python | en | ['en', 'en', 'en'] | True |
_fix_names | (field_spec) | Replace names which are None with the next unused f%d name | Replace names which are None with the next unused f%d name | def _fix_names(field_spec):
""" Replace names which are None with the next unused f%d name """
names = field_spec['names']
for i, name in enumerate(names):
if name is not None:
continue
j = 0
while True:
name = 'f{}'.format(j)
if name not in names... | [
"def",
"_fix_names",
"(",
"field_spec",
")",
":",
"names",
"=",
"field_spec",
"[",
"'names'",
"]",
"for",
"i",
",",
"name",
"in",
"enumerate",
"(",
"names",
")",
":",
"if",
"name",
"is",
"not",
"None",
":",
"continue",
"j",
"=",
"0",
"while",
"True",... | [
712,
0
] | [
725,
23
] | python | en | ['en', 'en', 'en'] | True |
_add_trailing_padding | (value, padding) | Inject the specified number of padding bytes at the end of a dtype | Inject the specified number of padding bytes at the end of a dtype | def _add_trailing_padding(value, padding):
"""Inject the specified number of padding bytes at the end of a dtype"""
if value.fields is None:
field_spec = dict(
names=['f0'],
formats=[value],
offsets=[0],
itemsize=value.itemsize
)
else:
... | [
"def",
"_add_trailing_padding",
"(",
"value",
",",
"padding",
")",
":",
"if",
"value",
".",
"fields",
"is",
"None",
":",
"field_spec",
"=",
"dict",
"(",
"names",
"=",
"[",
"'f0'",
"]",
",",
"formats",
"=",
"[",
"value",
"]",
",",
"offsets",
"=",
"[",... | [
727,
0
] | [
747,
28
] | python | en | ['en', 'en', 'en'] | True |
_gcd | (a, b) | Calculate the greatest common divisor of a and b | Calculate the greatest common divisor of a and b | def _gcd(a, b):
"""Calculate the greatest common divisor of a and b"""
while b:
a, b = b, a % b
return a | [
"def",
"_gcd",
"(",
"a",
",",
"b",
")",
":",
"while",
"b",
":",
"a",
",",
"b",
"=",
"b",
",",
"a",
"%",
"b",
"return",
"a"
] | [
755,
0
] | [
759,
12
] | python | en | ['en', 'en', 'en'] | True |
array_ufunc_errmsg_formatter | (dummy, ufunc, method, *inputs, **kwargs) | Format the error message for when __array_ufunc__ gives up. | Format the error message for when __array_ufunc__ gives up. | def array_ufunc_errmsg_formatter(dummy, ufunc, method, *inputs, **kwargs):
""" Format the error message for when __array_ufunc__ gives up. """
args_string = ', '.join(['{!r}'.format(arg) for arg in inputs] +
['{}={!r}'.format(k, v)
for k, v in kwargs.item... | [
"def",
"array_ufunc_errmsg_formatter",
"(",
"dummy",
",",
"ufunc",
",",
"method",
",",
"*",
"inputs",
",",
"*",
"*",
"kwargs",
")",
":",
"args_string",
"=",
"', '",
".",
"join",
"(",
"[",
"'{!r}'",
".",
"format",
"(",
"arg",
")",
"for",
"arg",
"in",
... | [
764,
0
] | [
773,
62
] | python | en | ['en', 'en', 'en'] | True |
array_function_errmsg_formatter | (public_api, types) | Format the error message for when __array_ufunc__ gives up. | Format the error message for when __array_ufunc__ gives up. | def array_function_errmsg_formatter(public_api, types):
""" Format the error message for when __array_ufunc__ gives up. """
func_name = '{}.{}'.format(public_api.__module__, public_api.__name__)
return ("no implementation found for '{}' on types that implement "
'__array_function__: {}'.format(f... | [
"def",
"array_function_errmsg_formatter",
"(",
"public_api",
",",
"types",
")",
":",
"func_name",
"=",
"'{}.{}'",
".",
"format",
"(",
"public_api",
".",
"__module__",
",",
"public_api",
".",
"__name__",
")",
"return",
"(",
"\"no implementation found for '{}' on types ... | [
776,
0
] | [
780,
68
] | python | en | ['en', 'en', 'en'] | True |
_ufunc_doc_signature_formatter | (ufunc) |
Builds a signature string which resembles PEP 457
This is used to construct the first line of the docstring
|
Builds a signature string which resembles PEP 457 | def _ufunc_doc_signature_formatter(ufunc):
"""
Builds a signature string which resembles PEP 457
This is used to construct the first line of the docstring
"""
# input arguments are simple
if ufunc.nin == 1:
in_args = 'x'
else:
in_args = ', '.join('x{}'.format(i+1) for i in ... | [
"def",
"_ufunc_doc_signature_formatter",
"(",
"ufunc",
")",
":",
"# input arguments are simple",
"if",
"ufunc",
".",
"nin",
"==",
"1",
":",
"in_args",
"=",
"'x'",
"else",
":",
"in_args",
"=",
"', '",
".",
"join",
"(",
"'x{}'",
".",
"format",
"(",
"i",
"+",... | [
783,
0
] | [
826,
5
] | python | en | ['en', 'error', 'th'] | False |
_ctypes.data_as | (self, obj) |
Return the data pointer cast to a particular c-types object.
For example, calling ``self._as_parameter_`` is equivalent to
``self.data_as(ctypes.c_void_p)``. Perhaps you want to use the data as a
pointer to a ctypes array of floating-point data:
``self.data_as(ctypes.POINTER(cty... |
Return the data pointer cast to a particular c-types object.
For example, calling ``self._as_parameter_`` is equivalent to
``self.data_as(ctypes.c_void_p)``. Perhaps you want to use the data as a
pointer to a ctypes array of floating-point data:
``self.data_as(ctypes.POINTER(cty... | def data_as(self, obj):
"""
Return the data pointer cast to a particular c-types object.
For example, calling ``self._as_parameter_`` is equivalent to
``self.data_as(ctypes.c_void_p)``. Perhaps you want to use the data as a
pointer to a ctypes array of floating-point data:
... | [
"def",
"data_as",
"(",
"self",
",",
"obj",
")",
":",
"# _ctypes.cast function causes a circular reference of self._data in",
"# self._data._objects. Attributes of self._data cannot be released",
"# until gc.collect is called. Make a copy of the pointer first then let",
"# it hold the array ref... | [
267,
4
] | [
284,
18
] | python | en | ['en', 'error', 'th'] | False |
_ctypes.shape_as | (self, obj) |
Return the shape tuple as an array of some other c-types
type. For example: ``self.shape_as(ctypes.c_short)``.
|
Return the shape tuple as an array of some other c-types
type. For example: ``self.shape_as(ctypes.c_short)``.
| def shape_as(self, obj):
"""
Return the shape tuple as an array of some other c-types
type. For example: ``self.shape_as(ctypes.c_short)``.
"""
if self._zerod:
return None
return (obj*self._arr.ndim)(*self._arr.shape) | [
"def",
"shape_as",
"(",
"self",
",",
"obj",
")",
":",
"if",
"self",
".",
"_zerod",
":",
"return",
"None",
"return",
"(",
"obj",
"*",
"self",
".",
"_arr",
".",
"ndim",
")",
"(",
"*",
"self",
".",
"_arr",
".",
"shape",
")"
] | [
286,
4
] | [
293,
53
] | python | en | ['en', 'error', 'th'] | False |
_ctypes.strides_as | (self, obj) |
Return the strides tuple as an array of some other
c-types type. For example: ``self.strides_as(ctypes.c_longlong)``.
|
Return the strides tuple as an array of some other
c-types type. For example: ``self.strides_as(ctypes.c_longlong)``.
| def strides_as(self, obj):
"""
Return the strides tuple as an array of some other
c-types type. For example: ``self.strides_as(ctypes.c_longlong)``.
"""
if self._zerod:
return None
return (obj*self._arr.ndim)(*self._arr.strides) | [
"def",
"strides_as",
"(",
"self",
",",
"obj",
")",
":",
"if",
"self",
".",
"_zerod",
":",
"return",
"None",
"return",
"(",
"obj",
"*",
"self",
".",
"_arr",
".",
"ndim",
")",
"(",
"*",
"self",
".",
"_arr",
".",
"strides",
")"
] | [
295,
4
] | [
302,
55
] | python | en | ['en', 'error', 'th'] | False |
_ctypes.data | (self) |
A pointer to the memory area of the array as a Python integer.
This memory area may contain data that is not aligned, or not in correct
byte-order. The memory area may not even be writeable. The array
flags and data-type of this array should be respected when passing this
attrib... |
A pointer to the memory area of the array as a Python integer.
This memory area may contain data that is not aligned, or not in correct
byte-order. The memory area may not even be writeable. The array
flags and data-type of this array should be respected when passing this
attrib... | def data(self):
"""
A pointer to the memory area of the array as a Python integer.
This memory area may contain data that is not aligned, or not in correct
byte-order. The memory area may not even be writeable. The array
flags and data-type of this array should be respected when ... | [
"def",
"data",
"(",
"self",
")",
":",
"return",
"self",
".",
"_data",
".",
"value"
] | [
305,
4
] | [
320,
31
] | python | en | ['en', 'error', 'th'] | False |
_ctypes.shape | (self) |
(c_intp*self.ndim): A ctypes array of length self.ndim where
the basetype is the C-integer corresponding to ``dtype('p')`` on this
platform. This base-type could be `ctypes.c_int`, `ctypes.c_long`, or
`ctypes.c_longlong` depending on the platform.
The c_intp type is defined acco... |
(c_intp*self.ndim): A ctypes array of length self.ndim where
the basetype is the C-integer corresponding to ``dtype('p')`` on this
platform. This base-type could be `ctypes.c_int`, `ctypes.c_long`, or
`ctypes.c_longlong` depending on the platform.
The c_intp type is defined acco... | def shape(self):
"""
(c_intp*self.ndim): A ctypes array of length self.ndim where
the basetype is the C-integer corresponding to ``dtype('p')`` on this
platform. This base-type could be `ctypes.c_int`, `ctypes.c_long`, or
`ctypes.c_longlong` depending on the platform.
The... | [
"def",
"shape",
"(",
"self",
")",
":",
"return",
"self",
".",
"shape_as",
"(",
"_getintp_ctype",
"(",
")",
")"
] | [
323,
4
] | [
332,
46
] | python | en | ['en', 'error', 'th'] | False |
_ctypes.strides | (self) |
(c_intp*self.ndim): A ctypes array of length self.ndim where
the basetype is the same as for the shape attribute. This ctypes array
contains the strides information from the underlying array. This strides
information is important for showing how many bytes must be jumped to
get ... |
(c_intp*self.ndim): A ctypes array of length self.ndim where
the basetype is the same as for the shape attribute. This ctypes array
contains the strides information from the underlying array. This strides
information is important for showing how many bytes must be jumped to
get ... | def strides(self):
"""
(c_intp*self.ndim): A ctypes array of length self.ndim where
the basetype is the same as for the shape attribute. This ctypes array
contains the strides information from the underlying array. This strides
information is important for showing how many bytes ... | [
"def",
"strides",
"(",
"self",
")",
":",
"return",
"self",
".",
"strides_as",
"(",
"_getintp_ctype",
"(",
")",
")"
] | [
335,
4
] | [
343,
48
] | python | en | ['en', 'error', 'th'] | False |
_ctypes._as_parameter_ | (self) |
Overrides the ctypes semi-magic method
Enables `c_func(some_array.ctypes)`
|
Overrides the ctypes semi-magic method | def _as_parameter_(self):
"""
Overrides the ctypes semi-magic method
Enables `c_func(some_array.ctypes)`
"""
return self.data_as(ctypes.c_void_p) | [
"def",
"_as_parameter_",
"(",
"self",
")",
":",
"return",
"self",
".",
"data_as",
"(",
"ctypes",
".",
"c_void_p",
")"
] | [
346,
4
] | [
352,
44
] | python | en | ['en', 'error', 'th'] | False |
_round_if_needed | (arr, dtype) |
Rounds arr inplace if destination dtype is integer.
Parameters
----------
arr : ndarray
Input array.
dtype : dtype
The dtype of the destination array.
|
Rounds arr inplace if destination dtype is integer. | def _round_if_needed(arr, dtype):
"""
Rounds arr inplace if destination dtype is integer.
Parameters
----------
arr : ndarray
Input array.
dtype : dtype
The dtype of the destination array.
"""
if np.issubdtype(dtype, np.integer):
arr.round(out=arr) | [
"def",
"_round_if_needed",
"(",
"arr",
",",
"dtype",
")",
":",
"if",
"np",
".",
"issubdtype",
"(",
"dtype",
",",
"np",
".",
"integer",
")",
":",
"arr",
".",
"round",
"(",
"out",
"=",
"arr",
")"
] | [
19,
0
] | [
31,
26
] | python | en | ['en', 'error', 'th'] | False |
_slice_at_axis | (sl, axis) |
Construct tuple of slices to slice an array in the given dimension.
Parameters
----------
sl : slice
The slice for the given dimension.
axis : int
The axis to which `sl` is applied. All other dimensions are left
"unsliced".
Returns
-------
sl : tuple of slices
... |
Construct tuple of slices to slice an array in the given dimension. | def _slice_at_axis(sl, axis):
"""
Construct tuple of slices to slice an array in the given dimension.
Parameters
----------
sl : slice
The slice for the given dimension.
axis : int
The axis to which `sl` is applied. All other dimensions are left
"unsliced".
Returns
... | [
"def",
"_slice_at_axis",
"(",
"sl",
",",
"axis",
")",
":",
"return",
"(",
"slice",
"(",
"None",
")",
",",
")",
"*",
"axis",
"+",
"(",
"sl",
",",
")",
"+",
"(",
"...",
",",
")"
] | [
34,
0
] | [
56,
49
] | python | en | ['en', 'error', 'th'] | False |
_view_roi | (array, original_area_slice, axis) |
Get a view of the current region of interest during iterative padding.
When padding multiple dimensions iteratively corner values are
unnecessarily overwritten multiple times. This function reduces the
working area for the first dimensions so that corners are excluded.
Parameters
----------
... |
Get a view of the current region of interest during iterative padding. | def _view_roi(array, original_area_slice, axis):
"""
Get a view of the current region of interest during iterative padding.
When padding multiple dimensions iteratively corner values are
unnecessarily overwritten multiple times. This function reduces the
working area for the first dimensions so tha... | [
"def",
"_view_roi",
"(",
"array",
",",
"original_area_slice",
",",
"axis",
")",
":",
"axis",
"+=",
"1",
"sl",
"=",
"(",
"slice",
"(",
"None",
")",
",",
")",
"*",
"axis",
"+",
"original_area_slice",
"[",
"axis",
":",
"]",
"return",
"array",
"[",
"sl",... | [
59,
0
] | [
84,
20
] | python | en | ['en', 'error', 'th'] | False |
_pad_simple | (array, pad_width, fill_value=None) |
Pad array on all sides with either a single value or undefined values.
Parameters
----------
array : ndarray
Array to grow.
pad_width : sequence of tuple[int, int]
Pad width on both sides for each dimension in `arr`.
fill_value : scalar, optional
If provided the padded ... |
Pad array on all sides with either a single value or undefined values. | def _pad_simple(array, pad_width, fill_value=None):
"""
Pad array on all sides with either a single value or undefined values.
Parameters
----------
array : ndarray
Array to grow.
pad_width : sequence of tuple[int, int]
Pad width on both sides for each dimension in `arr`.
fi... | [
"def",
"_pad_simple",
"(",
"array",
",",
"pad_width",
",",
"fill_value",
"=",
"None",
")",
":",
"# Allocate grown array",
"new_shape",
"=",
"tuple",
"(",
"left",
"+",
"size",
"+",
"right",
"for",
"size",
",",
"(",
"left",
",",
"right",
")",
"in",
"zip",
... | [
87,
0
] | [
127,
38
] | python | en | ['en', 'error', 'th'] | False |
_set_pad_area | (padded, axis, width_pair, value_pair) |
Set empty-padded area in given dimension.
Parameters
----------
padded : ndarray
Array with the pad area which is modified inplace.
axis : int
Dimension with the pad area to set.
width_pair : (int, int)
Pair of widths that mark the pad area on both sides in the given
... |
Set empty-padded area in given dimension. | def _set_pad_area(padded, axis, width_pair, value_pair):
"""
Set empty-padded area in given dimension.
Parameters
----------
padded : ndarray
Array with the pad area which is modified inplace.
axis : int
Dimension with the pad area to set.
width_pair : (int, int)
Pai... | [
"def",
"_set_pad_area",
"(",
"padded",
",",
"axis",
",",
"width_pair",
",",
"value_pair",
")",
":",
"left_slice",
"=",
"_slice_at_axis",
"(",
"slice",
"(",
"None",
",",
"width_pair",
"[",
"0",
"]",
")",
",",
"axis",
")",
"padded",
"[",
"left_slice",
"]",... | [
130,
0
] | [
152,
39
] | python | en | ['en', 'error', 'th'] | False |
_get_edges | (padded, axis, width_pair) |
Retrieve edge values from empty-padded array in given dimension.
Parameters
----------
padded : ndarray
Empty-padded array.
axis : int
Dimension in which the edges are considered.
width_pair : (int, int)
Pair of widths that mark the pad area on both sides in the given
... |
Retrieve edge values from empty-padded array in given dimension. | def _get_edges(padded, axis, width_pair):
"""
Retrieve edge values from empty-padded array in given dimension.
Parameters
----------
padded : ndarray
Empty-padded array.
axis : int
Dimension in which the edges are considered.
width_pair : (int, int)
Pair of widths th... | [
"def",
"_get_edges",
"(",
"padded",
",",
"axis",
",",
"width_pair",
")",
":",
"left_index",
"=",
"width_pair",
"[",
"0",
"]",
"left_slice",
"=",
"_slice_at_axis",
"(",
"slice",
"(",
"left_index",
",",
"left_index",
"+",
"1",
")",
",",
"axis",
")",
"left_... | [
155,
0
] | [
184,
32
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.