repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
loli/medpy | medpy/metric/binary.py | jc | def jc(result, reference):
"""
Jaccard coefficient
Computes the Jaccard coefficient between the binary objects in two images.
Parameters
----------
result: array_like
Input data containing objects. Can be any type but will be converted
into binary: background wh... | python | def jc(result, reference):
"""
Jaccard coefficient
Computes the Jaccard coefficient between the binary objects in two images.
Parameters
----------
result: array_like
Input data containing objects. Can be any type but will be converted
into binary: background wh... | [
"def",
"jc",
"(",
"result",
",",
"reference",
")",
":",
"result",
"=",
"numpy",
".",
"atleast_1d",
"(",
"result",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"reference",
"=",
"numpy",
".",
"atleast_1d",
"(",
"reference",
".",
"astype",
"(",
... | Jaccard coefficient
Computes the Jaccard coefficient between the binary objects in two images.
Parameters
----------
result: array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
refe... | [
"Jaccard",
"coefficient",
"Computes",
"the",
"Jaccard",
"coefficient",
"between",
"the",
"binary",
"objects",
"in",
"two",
"images",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"Input",
"data",
"containing",
"objects",
".",
"Can",
"be",
"any",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L83-L116 |
loli/medpy | medpy/metric/binary.py | precision | def precision(result, reference):
"""
Precison.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing object... | python | def precision(result, reference):
"""
Precison.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing object... | [
"def",
"precision",
"(",
"result",
",",
"reference",
")",
":",
"result",
"=",
"numpy",
".",
"atleast_1d",
"(",
"result",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"reference",
"=",
"numpy",
".",
"atleast_1d",
"(",
"reference",
".",
"astype",
... | Precison.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing objects. Can be any type but will be converted
... | [
"Precison",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"Input",
"data",
"containing",
"objects",
".",
"Can",
"be",
"any",
"type",
"but",
"will",
"be",
"converted",
"into",
"binary",
":",
"background",
"where",
"0",
"object",
"everywhere",
"e... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L118-L163 |
loli/medpy | medpy/metric/binary.py | recall | def recall(result, reference):
"""
Recall.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing objects. Ca... | python | def recall(result, reference):
"""
Recall.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing objects. Ca... | [
"def",
"recall",
"(",
"result",
",",
"reference",
")",
":",
"result",
"=",
"numpy",
".",
"atleast_1d",
"(",
"result",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"reference",
"=",
"numpy",
".",
"atleast_1d",
"(",
"reference",
".",
"astype",
"("... | Recall.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing objects. Can be any type but will be converted
... | [
"Recall",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"Input",
"data",
"containing",
"objects",
".",
"Can",
"be",
"any",
"type",
"but",
"will",
"be",
"converted",
"into",
"binary",
":",
"background",
"where",
"0",
"object",
"everywhere",
"els... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L165-L210 |
loli/medpy | medpy/metric/binary.py | specificity | def specificity(result, reference):
"""
Specificity.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing o... | python | def specificity(result, reference):
"""
Specificity.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing o... | [
"def",
"specificity",
"(",
"result",
",",
"reference",
")",
":",
"result",
"=",
"numpy",
".",
"atleast_1d",
"(",
"result",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"reference",
"=",
"numpy",
".",
"atleast_1d",
"(",
"reference",
".",
"astype",
... | Specificity.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhere else.
reference : array_like
Input data containing objects. Can be any type but will be converted
... | [
"Specificity",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"Input",
"data",
"containing",
"objects",
".",
"Can",
"be",
"any",
"type",
"but",
"will",
"be",
"converted",
"into",
"binary",
":",
"background",
"where",
"0",
"object",
"everywhere",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L223-L268 |
loli/medpy | medpy/metric/binary.py | hd | def hd(result, reference, voxelspacing=None, connectivity=1):
"""
Hausdorff Distance.
Computes the (symmetric) Hausdorff Distance (HD) between the binary objects in two
images. It is defined as the maximum surface distance between the objects.
Parameters
----------
result : array_l... | python | def hd(result, reference, voxelspacing=None, connectivity=1):
"""
Hausdorff Distance.
Computes the (symmetric) Hausdorff Distance (HD) between the binary objects in two
images. It is defined as the maximum surface distance between the objects.
Parameters
----------
result : array_l... | [
"def",
"hd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"hd1",
"=",
"__surface_distances",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
",",
"connectivity",
")",
".",
"max",
"(",
"... | Hausdorff Distance.
Computes the (symmetric) Hausdorff Distance (HD) between the binary objects in two
images. It is defined as the maximum surface distance between the objects.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be con... | [
"Hausdorff",
"Distance",
".",
"Computes",
"the",
"(",
"symmetric",
")",
"Hausdorff",
"Distance",
"(",
"HD",
")",
"between",
"the",
"binary",
"objects",
"in",
"two",
"images",
".",
"It",
"is",
"defined",
"as",
"the",
"maximum",
"surface",
"distance",
"between... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L306-L351 |
loli/medpy | medpy/metric/binary.py | hd95 | def hd95(result, reference, voxelspacing=None, connectivity=1):
"""
95th percentile of the Hausdorff Distance.
Computes the 95th percentile of the (symmetric) Hausdorff Distance (HD) between the binary objects in two
images. Compared to the Hausdorff Distance, this metric is slightly more stable to sma... | python | def hd95(result, reference, voxelspacing=None, connectivity=1):
"""
95th percentile of the Hausdorff Distance.
Computes the 95th percentile of the (symmetric) Hausdorff Distance (HD) between the binary objects in two
images. Compared to the Hausdorff Distance, this metric is slightly more stable to sma... | [
"def",
"hd95",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"hd1",
"=",
"__surface_distances",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
",",
"connectivity",
")",
"hd2",
"=",
"__sur... | 95th percentile of the Hausdorff Distance.
Computes the 95th percentile of the (symmetric) Hausdorff Distance (HD) between the binary objects in two
images. Compared to the Hausdorff Distance, this metric is slightly more stable to small outliers and is
commonly used in Biomedical Segmentation challenges.
... | [
"95th",
"percentile",
"of",
"the",
"Hausdorff",
"Distance",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L354-L399 |
loli/medpy | medpy/metric/binary.py | assd | def assd(result, reference, voxelspacing=None, connectivity=1):
"""
Average symmetric surface distance.
Computes the average symmetric surface distance (ASD) between the binary objects in
two images.
Parameters
----------
result : array_like
Input data containing objects. C... | python | def assd(result, reference, voxelspacing=None, connectivity=1):
"""
Average symmetric surface distance.
Computes the average symmetric surface distance (ASD) between the binary objects in
two images.
Parameters
----------
result : array_like
Input data containing objects. C... | [
"def",
"assd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"assd",
"=",
"numpy",
".",
"mean",
"(",
"(",
"asd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
",",
"connectivity",
")... | Average symmetric surface distance.
Computes the average symmetric surface distance (ASD) between the binary objects in
two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0... | [
"Average",
"symmetric",
"surface",
"distance",
".",
"Computes",
"the",
"average",
"symmetric",
"surface",
"distance",
"(",
"ASD",
")",
"between",
"the",
"binary",
"objects",
"in",
"two",
"images",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"In... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L402-L454 |
loli/medpy | medpy/metric/binary.py | asd | def asd(result, reference, voxelspacing=None, connectivity=1):
"""
Average surface distance metric.
Computes the average surface distance (ASD) between the binary objects in two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but... | python | def asd(result, reference, voxelspacing=None, connectivity=1):
"""
Average surface distance metric.
Computes the average surface distance (ASD) between the binary objects in two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but... | [
"def",
"asd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"sds",
"=",
"__surface_distances",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
",",
"connectivity",
")",
"asd",
"=",
"sds",
... | Average surface distance metric.
Computes the average surface distance (ASD) between the binary objects in two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where 0, object everywhe... | [
"Average",
"surface",
"distance",
"metric",
".",
"Computes",
"the",
"average",
"surface",
"distance",
"(",
"ASD",
")",
"between",
"the",
"binary",
"objects",
"in",
"two",
"images",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"Input",
"data",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L456-L563 |
loli/medpy | medpy/metric/binary.py | ravd | def ravd(result, reference):
"""
Relative absolute volume difference.
Compute the relative absolute volume difference between the (joined) binary objects
in the two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be ... | python | def ravd(result, reference):
"""
Relative absolute volume difference.
Compute the relative absolute volume difference between the (joined) binary objects
in the two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be ... | [
"def",
"ravd",
"(",
"result",
",",
"reference",
")",
":",
"result",
"=",
"numpy",
".",
"atleast_1d",
"(",
"result",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"reference",
"=",
"numpy",
".",
"atleast_1d",
"(",
"reference",
".",
"astype",
"(",
... | Relative absolute volume difference.
Compute the relative absolute volume difference between the (joined) binary objects
in the two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background... | [
"Relative",
"absolute",
"volume",
"difference",
".",
"Compute",
"the",
"relative",
"absolute",
"volume",
"difference",
"between",
"the",
"(",
"joined",
")",
"binary",
"objects",
"in",
"the",
"two",
"images",
".",
"Parameters",
"----------",
"result",
":",
"array... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L565-L650 |
loli/medpy | medpy/metric/binary.py | volume_correlation | def volume_correlation(results, references):
r"""
Volume correlation.
Computes the linear correlation in binary object volume between the
contents of the successive binary images supplied. Measured through
the Pearson product-moment correlation coefficient.
Parameters
----------
... | python | def volume_correlation(results, references):
r"""
Volume correlation.
Computes the linear correlation in binary object volume between the
contents of the successive binary images supplied. Measured through
the Pearson product-moment correlation coefficient.
Parameters
----------
... | [
"def",
"volume_correlation",
"(",
"results",
",",
"references",
")",
":",
"results",
"=",
"numpy",
".",
"atleast_2d",
"(",
"numpy",
".",
"array",
"(",
"results",
")",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"references",
"=",
"numpy",
".",
... | r"""
Volume correlation.
Computes the linear correlation in binary object volume between the
contents of the successive binary images supplied. Measured through
the Pearson product-moment correlation coefficient.
Parameters
----------
results : sequence of array_like
Order... | [
"r",
"Volume",
"correlation",
".",
"Computes",
"the",
"linear",
"correlation",
"in",
"binary",
"object",
"volume",
"between",
"the",
"contents",
"of",
"the",
"successive",
"binary",
"images",
"supplied",
".",
"Measured",
"through",
"the",
"Pearson",
"product",
"... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L652-L684 |
loli/medpy | medpy/metric/binary.py | volume_change_correlation | def volume_change_correlation(results, references):
r"""
Volume change correlation.
Computes the linear correlation of change in binary object volume between
the contents of the successive binary images supplied. Measured through
the Pearson product-moment correlation coefficient.
Par... | python | def volume_change_correlation(results, references):
r"""
Volume change correlation.
Computes the linear correlation of change in binary object volume between
the contents of the successive binary images supplied. Measured through
the Pearson product-moment correlation coefficient.
Par... | [
"def",
"volume_change_correlation",
"(",
"results",
",",
"references",
")",
":",
"results",
"=",
"numpy",
".",
"atleast_2d",
"(",
"numpy",
".",
"array",
"(",
"results",
")",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"references",
"=",
"numpy",
... | r"""
Volume change correlation.
Computes the linear correlation of change in binary object volume between
the contents of the successive binary images supplied. Measured through
the Pearson product-moment correlation coefficient.
Parameters
----------
results : sequence of array_l... | [
"r",
"Volume",
"change",
"correlation",
".",
"Computes",
"the",
"linear",
"correlation",
"of",
"change",
"in",
"binary",
"object",
"volume",
"between",
"the",
"contents",
"of",
"the",
"successive",
"binary",
"images",
"supplied",
".",
"Measured",
"through",
"the... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L686-L721 |
loli/medpy | medpy/metric/binary.py | obj_assd | def obj_assd(result, reference, voxelspacing=None, connectivity=1):
"""
Average symmetric surface distance.
Computes the average symmetric surface distance (ASSD) between the binary objects in
two images.
Parameters
----------
result : array_like
Input data containing objec... | python | def obj_assd(result, reference, voxelspacing=None, connectivity=1):
"""
Average symmetric surface distance.
Computes the average symmetric surface distance (ASSD) between the binary objects in
two images.
Parameters
----------
result : array_like
Input data containing objec... | [
"def",
"obj_assd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"assd",
"=",
"numpy",
".",
"mean",
"(",
"(",
"obj_asd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
",",
"connectivit... | Average symmetric surface distance.
Computes the average symmetric surface distance (ASSD) between the binary objects in
two images.
Parameters
----------
result : array_like
Input data containing objects. Can be any type but will be converted
into binary: background where ... | [
"Average",
"symmetric",
"surface",
"distance",
".",
"Computes",
"the",
"average",
"symmetric",
"surface",
"distance",
"(",
"ASSD",
")",
"between",
"the",
"binary",
"objects",
"in",
"two",
"images",
".",
"Parameters",
"----------",
"result",
":",
"array_like",
"I... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L723-L775 |
loli/medpy | medpy/metric/binary.py | obj_asd | def obj_asd(result, reference, voxelspacing=None, connectivity=1):
"""
Average surface distance between objects.
First correspondences between distinct binary objects in reference and result are
established. Then the average surface distance is only computed between corresponding
objects. Corre... | python | def obj_asd(result, reference, voxelspacing=None, connectivity=1):
"""
Average surface distance between objects.
First correspondences between distinct binary objects in reference and result are
established. Then the average surface distance is only computed between corresponding
objects. Corre... | [
"def",
"obj_asd",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"sds",
"=",
"list",
"(",
")",
"labelmap1",
",",
"labelmap2",
",",
"_a",
",",
"_b",
",",
"mapping",
"=",
"__distinct_binary_objec... | Average surface distance between objects.
First correspondences between distinct binary objects in reference and result are
established. Then the average surface distance is only computed between corresponding
objects. Correspondence is defined as unique and at least one voxel overlap.
Paramet... | [
"Average",
"surface",
"distance",
"between",
"objects",
".",
"First",
"correspondences",
"between",
"distinct",
"binary",
"objects",
"in",
"reference",
"and",
"result",
"are",
"established",
".",
"Then",
"the",
"average",
"surface",
"distance",
"is",
"only",
"comp... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L778-L918 |
loli/medpy | medpy/metric/binary.py | obj_fpr | def obj_fpr(result, reference, connectivity=1):
"""
The false positive rate of distinct binary object detection.
The false positive rates gives a percentage measure of how many distinct binary
objects in the second array do not exists in the first array. A partial overlap
(of minimum one voxel)... | python | def obj_fpr(result, reference, connectivity=1):
"""
The false positive rate of distinct binary object detection.
The false positive rates gives a percentage measure of how many distinct binary
objects in the second array do not exists in the first array. A partial overlap
(of minimum one voxel)... | [
"def",
"obj_fpr",
"(",
"result",
",",
"reference",
",",
"connectivity",
"=",
"1",
")",
":",
"_",
",",
"_",
",",
"_",
",",
"n_obj_reference",
",",
"mapping",
"=",
"__distinct_binary_object_correspondences",
"(",
"reference",
",",
"result",
",",
"connectivity",
... | The false positive rate of distinct binary object detection.
The false positive rates gives a percentage measure of how many distinct binary
objects in the second array do not exists in the first array. A partial overlap
(of minimum one voxel) is here considered sufficient.
In cases where two ... | [
"The",
"false",
"positive",
"rate",
"of",
"distinct",
"binary",
"object",
"detection",
".",
"The",
"false",
"positive",
"rates",
"gives",
"a",
"percentage",
"measure",
"of",
"how",
"many",
"distinct",
"binary",
"objects",
"in",
"the",
"second",
"array",
"do",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L920-L1029 |
loli/medpy | medpy/metric/binary.py | obj_tpr | def obj_tpr(result, reference, connectivity=1):
"""
The true positive rate of distinct binary object detection.
The true positive rates gives a percentage measure of how many distinct binary
objects in the first array also exists in the second array. A partial overlap
(of minimum one voxel) is ... | python | def obj_tpr(result, reference, connectivity=1):
"""
The true positive rate of distinct binary object detection.
The true positive rates gives a percentage measure of how many distinct binary
objects in the first array also exists in the second array. A partial overlap
(of minimum one voxel) is ... | [
"def",
"obj_tpr",
"(",
"result",
",",
"reference",
",",
"connectivity",
"=",
"1",
")",
":",
"_",
",",
"_",
",",
"n_obj_result",
",",
"_",
",",
"mapping",
"=",
"__distinct_binary_object_correspondences",
"(",
"reference",
",",
"result",
",",
"connectivity",
"... | The true positive rate of distinct binary object detection.
The true positive rates gives a percentage measure of how many distinct binary
objects in the first array also exists in the second array. A partial overlap
(of minimum one voxel) is here considered sufficient.
In cases where two dist... | [
"The",
"true",
"positive",
"rate",
"of",
"distinct",
"binary",
"object",
"detection",
".",
"The",
"true",
"positive",
"rates",
"gives",
"a",
"percentage",
"measure",
"of",
"how",
"many",
"distinct",
"binary",
"objects",
"in",
"the",
"first",
"array",
"also",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L1031-L1139 |
loli/medpy | medpy/metric/binary.py | __distinct_binary_object_correspondences | def __distinct_binary_object_correspondences(reference, result, connectivity=1):
"""
Determines all distinct (where connectivity is defined by the connectivity parameter
passed to scipy's `generate_binary_structure`) binary objects in both of the input
parameters and returns a 1to1 mapping from the labe... | python | def __distinct_binary_object_correspondences(reference, result, connectivity=1):
"""
Determines all distinct (where connectivity is defined by the connectivity parameter
passed to scipy's `generate_binary_structure`) binary objects in both of the input
parameters and returns a 1to1 mapping from the labe... | [
"def",
"__distinct_binary_object_correspondences",
"(",
"reference",
",",
"result",
",",
"connectivity",
"=",
"1",
")",
":",
"result",
"=",
"numpy",
".",
"atleast_1d",
"(",
"result",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"reference",
"=",
"nump... | Determines all distinct (where connectivity is defined by the connectivity parameter
passed to scipy's `generate_binary_structure`) binary objects in both of the input
parameters and returns a 1to1 mapping from the labelled objects in reference to the
corresponding (whereas a one-voxel overlap suffices for ... | [
"Determines",
"all",
"distinct",
"(",
"where",
"connectivity",
"is",
"defined",
"by",
"the",
"connectivity",
"parameter",
"passed",
"to",
"scipy",
"s",
"generate_binary_structure",
")",
"binary",
"objects",
"in",
"both",
"of",
"the",
"input",
"parameters",
"and",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L1141-L1193 |
loli/medpy | medpy/metric/binary.py | __surface_distances | def __surface_distances(result, reference, voxelspacing=None, connectivity=1):
"""
The distances between the surface voxel of binary objects in result and their
nearest partner surface voxel of a binary object in reference.
"""
result = numpy.atleast_1d(result.astype(numpy.bool))
reference = num... | python | def __surface_distances(result, reference, voxelspacing=None, connectivity=1):
"""
The distances between the surface voxel of binary objects in result and their
nearest partner surface voxel of a binary object in reference.
"""
result = numpy.atleast_1d(result.astype(numpy.bool))
reference = num... | [
"def",
"__surface_distances",
"(",
"result",
",",
"reference",
",",
"voxelspacing",
"=",
"None",
",",
"connectivity",
"=",
"1",
")",
":",
"result",
"=",
"numpy",
".",
"atleast_1d",
"(",
"result",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
")",
"refer... | The distances between the surface voxel of binary objects in result and their
nearest partner surface voxel of a binary object in reference. | [
"The",
"distances",
"between",
"the",
"surface",
"voxel",
"of",
"binary",
"objects",
"in",
"result",
"and",
"their",
"nearest",
"partner",
"surface",
"voxel",
"of",
"a",
"binary",
"object",
"in",
"reference",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L1195-L1227 |
loli/medpy | medpy/metric/binary.py | __combine_windows | def __combine_windows(w1, w2):
"""
Joins two windows (defined by tuple of slices) such that their maximum
combined extend is covered by the new returned window.
"""
res = []
for s1, s2 in zip(w1, w2):
res.append(slice(min(s1.start, s2.start), max(s1.stop, s2.stop)))
return tuple(res) | python | def __combine_windows(w1, w2):
"""
Joins two windows (defined by tuple of slices) such that their maximum
combined extend is covered by the new returned window.
"""
res = []
for s1, s2 in zip(w1, w2):
res.append(slice(min(s1.start, s2.start), max(s1.stop, s2.stop)))
return tuple(res) | [
"def",
"__combine_windows",
"(",
"w1",
",",
"w2",
")",
":",
"res",
"=",
"[",
"]",
"for",
"s1",
",",
"s2",
"in",
"zip",
"(",
"w1",
",",
"w2",
")",
":",
"res",
".",
"append",
"(",
"slice",
"(",
"min",
"(",
"s1",
".",
"start",
",",
"s2",
".",
... | Joins two windows (defined by tuple of slices) such that their maximum
combined extend is covered by the new returned window. | [
"Joins",
"two",
"windows",
"(",
"defined",
"by",
"tuple",
"of",
"slices",
")",
"such",
"that",
"their",
"maximum",
"combined",
"extend",
"is",
"covered",
"by",
"the",
"new",
"returned",
"window",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/binary.py#L1229-L1237 |
loli/medpy | medpy/iterators/patchwise.py | SlidingWindowIterator.applyslicer | def applyslicer(self, array, slicer, cval = None):
r"""
Apply a slicer returned by the iterator to a new array of the same
dimensionality as the one used to initialize the iterator.
Notes
-----
If ``array`` has more dimensions than ``slicer`` and ``pmask``, the f... | python | def applyslicer(self, array, slicer, cval = None):
r"""
Apply a slicer returned by the iterator to a new array of the same
dimensionality as the one used to initialize the iterator.
Notes
-----
If ``array`` has more dimensions than ``slicer`` and ``pmask``, the f... | [
"def",
"applyslicer",
"(",
"self",
",",
"array",
",",
"slicer",
",",
"cval",
"=",
"None",
")",
":",
"if",
"cval",
"is",
"None",
":",
"cval",
"=",
"self",
".",
"cval",
"_padding",
"=",
"self",
".",
"padding",
"+",
"[",
"(",
"0",
",",
"0",
")",
"... | r"""
Apply a slicer returned by the iterator to a new array of the same
dimensionality as the one used to initialize the iterator.
Notes
-----
If ``array`` has more dimensions than ``slicer`` and ``pmask``, the first ones
are sliced.
Parameters
... | [
"r",
"Apply",
"a",
"slicer",
"returned",
"by",
"the",
"iterator",
"to",
"a",
"new",
"array",
"of",
"the",
"same",
"dimensionality",
"as",
"the",
"one",
"used",
"to",
"initialize",
"the",
"iterator",
".",
"Notes",
"-----",
"If",
"array",
"has",
"more",
"d... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/iterators/patchwise.py#L121-L150 |
loli/medpy | medpy/iterators/patchwise.py | CentredPatchIterator.applyslicer | def applyslicer(array, slicer, pmask, cval = 0):
r"""
Apply a slicer returned by the iterator to a new array of the same
dimensionality as the one used to initialize the iterator.
Notes
-----
If ``array`` has more dimensions than ``slicer`` and ``pmask``, the fir... | python | def applyslicer(array, slicer, pmask, cval = 0):
r"""
Apply a slicer returned by the iterator to a new array of the same
dimensionality as the one used to initialize the iterator.
Notes
-----
If ``array`` has more dimensions than ``slicer`` and ``pmask``, the fir... | [
"def",
"applyslicer",
"(",
"array",
",",
"slicer",
",",
"pmask",
",",
"cval",
"=",
"0",
")",
":",
"l",
"=",
"len",
"(",
"slicer",
")",
"patch",
"=",
"numpy",
".",
"zeros",
"(",
"list",
"(",
"pmask",
".",
"shape",
"[",
":",
"l",
"]",
")",
"+",
... | r"""
Apply a slicer returned by the iterator to a new array of the same
dimensionality as the one used to initialize the iterator.
Notes
-----
If ``array`` has more dimensions than ``slicer`` and ``pmask``, the first ones
are sliced.
Parameters
... | [
"r",
"Apply",
"a",
"slicer",
"returned",
"by",
"the",
"iterator",
"to",
"a",
"new",
"array",
"of",
"the",
"same",
"dimensionality",
"as",
"the",
"one",
"used",
"to",
"initialize",
"the",
"iterator",
".",
"Notes",
"-----",
"If",
"array",
"has",
"more",
"d... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/iterators/patchwise.py#L320-L358 |
loli/medpy | medpy/iterators/patchwise.py | CentredPatchIterator.assembleimage | def assembleimage(patches, pmasks, gridids):
r"""
Assemble an image from a number of patches, patch masks and their grid ids.
Parameters
----------
patches : sequence
Sequence of patches.
pmasks : sequence
Sequence of associated patch mask... | python | def assembleimage(patches, pmasks, gridids):
r"""
Assemble an image from a number of patches, patch masks and their grid ids.
Parameters
----------
patches : sequence
Sequence of patches.
pmasks : sequence
Sequence of associated patch mask... | [
"def",
"assembleimage",
"(",
"patches",
",",
"pmasks",
",",
"gridids",
")",
":",
"for",
"d",
"in",
"range",
"(",
"patches",
"[",
"0",
"]",
".",
"ndim",
")",
":",
"groups",
"=",
"{",
"}",
"for",
"patch",
",",
"pmask",
",",
"gridid",
"in",
"zip",
"... | r"""
Assemble an image from a number of patches, patch masks and their grid ids.
Parameters
----------
patches : sequence
Sequence of patches.
pmasks : sequence
Sequence of associated patch masks.
gridids
Sequence of associated... | [
"r",
"Assemble",
"an",
"image",
"from",
"a",
"number",
"of",
"patches",
"patch",
"masks",
"and",
"their",
"grid",
"ids",
".",
"Parameters",
"----------",
"patches",
":",
"sequence",
"Sequence",
"of",
"patches",
".",
"pmasks",
":",
"sequence",
"Sequence",
"of... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/iterators/patchwise.py#L361-L420 |
loli/medpy | medpy/filter/binary.py | size_threshold | def size_threshold(img, thr, comp='lt', structure = None):
r"""
Removes binary objects from an image identified by a size threshold.
The unconnected binary objects in an image are identified and all removed
whose size compares (e.g. less-than) to a supplied threshold value.
The threshold `... | python | def size_threshold(img, thr, comp='lt', structure = None):
r"""
Removes binary objects from an image identified by a size threshold.
The unconnected binary objects in an image are identified and all removed
whose size compares (e.g. less-than) to a supplied threshold value.
The threshold `... | [
"def",
"size_threshold",
"(",
"img",
",",
"thr",
",",
"comp",
"=",
"'lt'",
",",
"structure",
"=",
"None",
")",
":",
"operators",
"=",
"{",
"'lt'",
":",
"lt",
",",
"'le'",
":",
"le",
",",
"'gt'",
":",
"gt",
",",
"'ge'",
":",
"ge",
",",
"'eq'",
"... | r"""
Removes binary objects from an image identified by a size threshold.
The unconnected binary objects in an image are identified and all removed
whose size compares (e.g. less-than) to a supplied threshold value.
The threshold ``thr`` can be any positive integer value. The comparison operat... | [
"r",
"Removes",
"binary",
"objects",
"from",
"an",
"image",
"identified",
"by",
"a",
"size",
"threshold",
".",
"The",
"unconnected",
"binary",
"objects",
"in",
"an",
"image",
"are",
"identified",
"and",
"all",
"removed",
"whose",
"size",
"compares",
"(",
"e"... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/filter/binary.py#L31-L86 |
loli/medpy | medpy/filter/binary.py | largest_connected_component | def largest_connected_component(img, structure = None):
r"""
Select the largest connected binary component in an image.
Treats all zero values in the input image as background and all others as foreground.
The return value is an binary array of equal dimensions as the input array with TRUE
valu... | python | def largest_connected_component(img, structure = None):
r"""
Select the largest connected binary component in an image.
Treats all zero values in the input image as background and all others as foreground.
The return value is an binary array of equal dimensions as the input array with TRUE
valu... | [
"def",
"largest_connected_component",
"(",
"img",
",",
"structure",
"=",
"None",
")",
":",
"labeled_array",
",",
"num_features",
"=",
"label",
"(",
"img",
",",
"structure",
")",
"component_sizes",
"=",
"[",
"numpy",
".",
"count_nonzero",
"(",
"labeled_array",
... | r"""
Select the largest connected binary component in an image.
Treats all zero values in the input image as background and all others as foreground.
The return value is an binary array of equal dimensions as the input array with TRUE
values where the largest connected component is situated.
... | [
"r",
"Select",
"the",
"largest",
"connected",
"binary",
"component",
"in",
"an",
"image",
".",
"Treats",
"all",
"zero",
"values",
"in",
"the",
"input",
"image",
"as",
"background",
"and",
"all",
"others",
"as",
"foreground",
".",
"The",
"return",
"value",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/filter/binary.py#L88-L116 |
loli/medpy | medpy/filter/binary.py | bounding_box | def bounding_box(img):
r"""
Return the bounding box incorporating all non-zero values in the image.
Parameters
----------
img : array_like
An array containing non-zero objects.
Returns
-------
bbox : a list of slicer objects defining the bounding box
"""
loc... | python | def bounding_box(img):
r"""
Return the bounding box incorporating all non-zero values in the image.
Parameters
----------
img : array_like
An array containing non-zero objects.
Returns
-------
bbox : a list of slicer objects defining the bounding box
"""
loc... | [
"def",
"bounding_box",
"(",
"img",
")",
":",
"locations",
"=",
"numpy",
".",
"argwhere",
"(",
"img",
")",
"mins",
"=",
"locations",
".",
"min",
"(",
"0",
")",
"maxs",
"=",
"locations",
".",
"max",
"(",
"0",
")",
"+",
"1",
"return",
"[",
"slice",
... | r"""
Return the bounding box incorporating all non-zero values in the image.
Parameters
----------
img : array_like
An array containing non-zero objects.
Returns
-------
bbox : a list of slicer objects defining the bounding box | [
"r",
"Return",
"the",
"bounding",
"box",
"incorporating",
"all",
"non",
"-",
"zero",
"values",
"in",
"the",
"image",
".",
"Parameters",
"----------",
"img",
":",
"array_like",
"An",
"array",
"containing",
"non",
"-",
"zero",
"objects",
".",
"Returns",
"-----... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/filter/binary.py#L118-L134 |
loli/medpy | bin/medpy_binary_resampling.py | shape_based_slice_interpolation | def shape_based_slice_interpolation(img, dim, nslices):
"""
Adds `nslices` slices between all slices of the binary image `img` along dimension
`dim` respecting the original slice values to be situated in the middle of each
slice. Extrapolation situations are handled by simple repeating.
Interpo... | python | def shape_based_slice_interpolation(img, dim, nslices):
"""
Adds `nslices` slices between all slices of the binary image `img` along dimension
`dim` respecting the original slice values to be situated in the middle of each
slice. Extrapolation situations are handled by simple repeating.
Interpo... | [
"def",
"shape_based_slice_interpolation",
"(",
"img",
",",
"dim",
",",
"nslices",
")",
":",
"# check arguments",
"if",
"not",
"0",
"==",
"nslices",
"%",
"2",
":",
"raise",
"ValueError",
"(",
"'nslices must be an even number'",
")",
"out",
"=",
"None",
"slicer",
... | Adds `nslices` slices between all slices of the binary image `img` along dimension
`dim` respecting the original slice values to be situated in the middle of each
slice. Extrapolation situations are handled by simple repeating.
Interpolation of new slices is performed using shape based interpolation.
... | [
"Adds",
"nslices",
"slices",
"between",
"all",
"slices",
"of",
"the",
"binary",
"image",
"img",
"along",
"dimension",
"dim",
"respecting",
"the",
"original",
"slice",
"values",
"to",
"be",
"situated",
"in",
"the",
"middle",
"of",
"each",
"slice",
".",
"Extra... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/bin/medpy_binary_resampling.py#L118-L169 |
loli/medpy | bin/medpy_binary_resampling.py | shape_based_slice_insertation_object_wise | def shape_based_slice_insertation_object_wise(sl1, sl2, dim, nslices, order=3):
"""
Wrapper to apply `shape_based_slice_insertation()` for each binary object
separately to ensure correct extrapolation behaviour.
"""
out = None
sandwich = numpy.concatenate((sl1[numpy.newaxis], sl2[numpy.newaxis])... | python | def shape_based_slice_insertation_object_wise(sl1, sl2, dim, nslices, order=3):
"""
Wrapper to apply `shape_based_slice_insertation()` for each binary object
separately to ensure correct extrapolation behaviour.
"""
out = None
sandwich = numpy.concatenate((sl1[numpy.newaxis], sl2[numpy.newaxis])... | [
"def",
"shape_based_slice_insertation_object_wise",
"(",
"sl1",
",",
"sl2",
",",
"dim",
",",
"nslices",
",",
"order",
"=",
"3",
")",
":",
"out",
"=",
"None",
"sandwich",
"=",
"numpy",
".",
"concatenate",
"(",
"(",
"sl1",
"[",
"numpy",
".",
"newaxis",
"]"... | Wrapper to apply `shape_based_slice_insertation()` for each binary object
separately to ensure correct extrapolation behaviour. | [
"Wrapper",
"to",
"apply",
"shape_based_slice_insertation",
"()",
"for",
"each",
"binary",
"object",
"separately",
"to",
"ensure",
"correct",
"extrapolation",
"behaviour",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/bin/medpy_binary_resampling.py#L171-L186 |
loli/medpy | bin/medpy_binary_resampling.py | shape_based_slice_insertation | def shape_based_slice_insertation(sl1, sl2, dim, nslices, order=3):
"""
Insert `nslices` new slices between `sl1` and `sl2` along dimension `dim` using shape
based binary interpolation.
Extrapolation is handled adding `nslices`/2 step-wise eroded copies of the last slice
in each direction.
... | python | def shape_based_slice_insertation(sl1, sl2, dim, nslices, order=3):
"""
Insert `nslices` new slices between `sl1` and `sl2` along dimension `dim` using shape
based binary interpolation.
Extrapolation is handled adding `nslices`/2 step-wise eroded copies of the last slice
in each direction.
... | [
"def",
"shape_based_slice_insertation",
"(",
"sl1",
",",
"sl2",
",",
"dim",
",",
"nslices",
",",
"order",
"=",
"3",
")",
":",
"sl1",
"=",
"sl1",
".",
"astype",
"(",
"numpy",
".",
"bool",
")",
"sl2",
"=",
"sl2",
".",
"astype",
"(",
"numpy",
".",
"bo... | Insert `nslices` new slices between `sl1` and `sl2` along dimension `dim` using shape
based binary interpolation.
Extrapolation is handled adding `nslices`/2 step-wise eroded copies of the last slice
in each direction.
Parameters
----------
sl1 : array_like
First slice. Treated... | [
"Insert",
"nslices",
"new",
"slices",
"between",
"sl1",
"and",
"sl2",
"along",
"dimension",
"dim",
"using",
"shape",
"based",
"binary",
"interpolation",
".",
"Extrapolation",
"is",
"handled",
"adding",
"nslices",
"/",
"2",
"step",
"-",
"wise",
"eroded",
"copie... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/bin/medpy_binary_resampling.py#L188-L250 |
loli/medpy | bin/medpy_binary_resampling.py | getArguments | def getArguments(parser):
"Provides additional validation of the arguments collected by argparse."
args = parser.parse_args()
if args.order < 0 or args.order > 5:
parser.error('The order has to be a number between 0 and 5.')
return args | python | def getArguments(parser):
"Provides additional validation of the arguments collected by argparse."
args = parser.parse_args()
if args.order < 0 or args.order > 5:
parser.error('The order has to be a number between 0 and 5.')
return args | [
"def",
"getArguments",
"(",
"parser",
")",
":",
"args",
"=",
"parser",
".",
"parse_args",
"(",
")",
"if",
"args",
".",
"order",
"<",
"0",
"or",
"args",
".",
"order",
">",
"5",
":",
"parser",
".",
"error",
"(",
"'The order has to be a number between 0 and 5... | Provides additional validation of the arguments collected by argparse. | [
"Provides",
"additional",
"validation",
"of",
"the",
"arguments",
"collected",
"by",
"argparse",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/bin/medpy_binary_resampling.py#L252-L257 |
loli/medpy | bin/medpy_intensity_range_standardization.py | getArguments | def getArguments(parser):
"Provides additional validation of the arguments collected by argparse."
args = parser.parse_args()
# check mutual exlusive and reaquired arguments
if args.lmodel and args.smodel:
parser.error('only one of --load-model and --save-model can be supplied, as they deci... | python | def getArguments(parser):
"Provides additional validation of the arguments collected by argparse."
args = parser.parse_args()
# check mutual exlusive and reaquired arguments
if args.lmodel and args.smodel:
parser.error('only one of --load-model and --save-model can be supplied, as they deci... | [
"def",
"getArguments",
"(",
"parser",
")",
":",
"args",
"=",
"parser",
".",
"parse_args",
"(",
")",
"# check mutual exlusive and reaquired arguments",
"if",
"args",
".",
"lmodel",
"and",
"args",
".",
"smodel",
":",
"parser",
".",
"error",
"(",
"'only one of --lo... | Provides additional validation of the arguments collected by argparse. | [
"Provides",
"additional",
"validation",
"of",
"the",
"arguments",
"collected",
"by",
"argparse",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/bin/medpy_intensity_range_standardization.py#L133-L166 |
loli/medpy | bin/medpy_intensity_range_standardization.py | getParser | def getParser():
"Creates and returns the argparse parser object."
parser = argparse.ArgumentParser(description=__description__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('images', nargs='+', help='The images used for training (in the learning case) or to transform (in the tr... | python | def getParser():
"Creates and returns the argparse parser object."
parser = argparse.ArgumentParser(description=__description__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('images', nargs='+', help='The images used for training (in the learning case) or to transform (in the tr... | [
"def",
"getParser",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"__description__",
",",
"formatter_class",
"=",
"argparse",
".",
"RawDescriptionHelpFormatter",
")",
"parser",
".",
"add_argument",
"(",
"'images'",
",",
... | Creates and returns the argparse parser object. | [
"Creates",
"and",
"returns",
"the",
"argparse",
"parser",
"object",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/bin/medpy_intensity_range_standardization.py#L168-L191 |
loli/medpy | medpy/metric/histogram.py | minowski | def minowski(h1, h2, p = 2): # 46..45..14,11..43..44 / 45 us for p=int(-inf..-24..-1,1..24..inf) / float @array, +20 us @list \w 100 bins
r"""
Minowski distance.
With :math:`p=2` equal to the Euclidean distance, with :math:`p=1` equal to the Manhattan distance,
and the Chebyshev distance implementa... | python | def minowski(h1, h2, p = 2): # 46..45..14,11..43..44 / 45 us for p=int(-inf..-24..-1,1..24..inf) / float @array, +20 us @list \w 100 bins
r"""
Minowski distance.
With :math:`p=2` equal to the Euclidean distance, with :math:`p=1` equal to the Manhattan distance,
and the Chebyshev distance implementa... | [
"def",
"minowski",
"(",
"h1",
",",
"h2",
",",
"p",
"=",
"2",
")",
":",
"# 46..45..14,11..43..44 / 45 us for p=int(-inf..-24..-1,1..24..inf) / float @array, +20 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"if",
"0",
... | r"""
Minowski distance.
With :math:`p=2` equal to the Euclidean distance, with :math:`p=1` equal to the Manhattan distance,
and the Chebyshev distance implementation represents the case of :math:`p=\pm inf`.
The Minowksi distance between two histograms :math:`H` and :math:`H'` of size :math:`m... | [
"r",
"Minowski",
"distance",
".",
"With",
":",
"math",
":",
"p",
"=",
"2",
"equal",
"to",
"the",
"Euclidean",
"distance",
"with",
":",
"math",
":",
"p",
"=",
"1",
"equal",
"to",
"the",
"Manhattan",
"distance",
"and",
"the",
"Chebyshev",
"distance",
"im... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L34-L93 |
loli/medpy | medpy/metric/histogram.py | __minowski_low_positive_integer_p | def __minowski_low_positive_integer_p(h1, h2, p = 2): # 11..43 us for p = 1..24 \w 100 bins
"""
A faster implementation of the Minowski distance for positive integer < 25.
@note do not use this function directly, but the general @link minowski() method.
@note the passed histograms must be scipy arrays.
... | python | def __minowski_low_positive_integer_p(h1, h2, p = 2): # 11..43 us for p = 1..24 \w 100 bins
"""
A faster implementation of the Minowski distance for positive integer < 25.
@note do not use this function directly, but the general @link minowski() method.
@note the passed histograms must be scipy arrays.
... | [
"def",
"__minowski_low_positive_integer_p",
"(",
"h1",
",",
"h2",
",",
"p",
"=",
"2",
")",
":",
"# 11..43 us for p = 1..24 \\w 100 bins",
"mult",
"=",
"scipy",
".",
"absolute",
"(",
"h1",
"-",
"h2",
")",
"dif",
"=",
"mult",
"for",
"_",
"in",
"range",
"(",
... | A faster implementation of the Minowski distance for positive integer < 25.
@note do not use this function directly, but the general @link minowski() method.
@note the passed histograms must be scipy arrays. | [
"A",
"faster",
"implementation",
"of",
"the",
"Minowski",
"distance",
"for",
"positive",
"integer",
"<",
"25",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L95-L104 |
loli/medpy | medpy/metric/histogram.py | manhattan | def manhattan(h1, h2): # # 7 us @array, 31 us @list \w 100 bins
r"""
Equal to Minowski distance with :math:`p=1`.
See also
--------
minowski
"""
h1, h2 = __prepare_histogram(h1, h2)
return scipy.sum(scipy.absolute(h1 - h2)) | python | def manhattan(h1, h2): # # 7 us @array, 31 us @list \w 100 bins
r"""
Equal to Minowski distance with :math:`p=1`.
See also
--------
minowski
"""
h1, h2 = __prepare_histogram(h1, h2)
return scipy.sum(scipy.absolute(h1 - h2)) | [
"def",
"manhattan",
"(",
"h1",
",",
"h2",
")",
":",
"# # 7 us @array, 31 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"return",
"scipy",
".",
"sum",
"(",
"scipy",
".",
"absolute",
"(",
"h1",
"-",
"h2",
"... | r"""
Equal to Minowski distance with :math:`p=1`.
See also
--------
minowski | [
"r",
"Equal",
"to",
"Minowski",
"distance",
"with",
":",
"math",
":",
"p",
"=",
"1",
".",
"See",
"also",
"--------",
"minowski"
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L117-L126 |
loli/medpy | medpy/metric/histogram.py | euclidean | def euclidean(h1, h2): # 9 us @array, 33 us @list \w 100 bins
r"""
Equal to Minowski distance with :math:`p=2`.
See also
--------
minowski
"""
h1, h2 = __prepare_histogram(h1, h2)
return math.sqrt(scipy.sum(scipy.square(scipy.absolute(h1 - h2)))) | python | def euclidean(h1, h2): # 9 us @array, 33 us @list \w 100 bins
r"""
Equal to Minowski distance with :math:`p=2`.
See also
--------
minowski
"""
h1, h2 = __prepare_histogram(h1, h2)
return math.sqrt(scipy.sum(scipy.square(scipy.absolute(h1 - h2)))) | [
"def",
"euclidean",
"(",
"h1",
",",
"h2",
")",
":",
"# 9 us @array, 33 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"return",
"math",
".",
"sqrt",
"(",
"scipy",
".",
"sum",
"(",
"scipy",
".",
"square",
"... | r"""
Equal to Minowski distance with :math:`p=2`.
See also
--------
minowski | [
"r",
"Equal",
"to",
"Minowski",
"distance",
"with",
":",
"math",
":",
"p",
"=",
"2",
".",
"See",
"also",
"--------",
"minowski"
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L128-L137 |
loli/medpy | medpy/metric/histogram.py | chebyshev | def chebyshev(h1, h2): # 12 us @array, 36 us @list \w 100 bins
r"""
Chebyshev distance.
Also Tchebychev distance, Maximum or :math:`L_{\infty}` metric; equal to Minowski
distance with :math:`p=+\infty`. For the case of :math:`p=-\infty`, use `chebyshev_neg`.
The Chebyshev distance between ... | python | def chebyshev(h1, h2): # 12 us @array, 36 us @list \w 100 bins
r"""
Chebyshev distance.
Also Tchebychev distance, Maximum or :math:`L_{\infty}` metric; equal to Minowski
distance with :math:`p=+\infty`. For the case of :math:`p=-\infty`, use `chebyshev_neg`.
The Chebyshev distance between ... | [
"def",
"chebyshev",
"(",
"h1",
",",
"h2",
")",
":",
"# 12 us @array, 36 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"return",
"max",
"(",
"scipy",
".",
"absolute",
"(",
"h1",
"-",
"h2",
")",
")"
] | r"""
Chebyshev distance.
Also Tchebychev distance, Maximum or :math:`L_{\infty}` metric; equal to Minowski
distance with :math:`p=+\infty`. For the case of :math:`p=-\infty`, use `chebyshev_neg`.
The Chebyshev distance between two histograms :math:`H` and :math:`H'` of size :math:`m` is
de... | [
"r",
"Chebyshev",
"distance",
".",
"Also",
"Tchebychev",
"distance",
"Maximum",
"or",
":",
"math",
":",
"L_",
"{",
"\\",
"infty",
"}",
"metric",
";",
"equal",
"to",
"Minowski",
"distance",
"with",
":",
"math",
":",
"p",
"=",
"+",
"\\",
"infty",
".",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L139-L190 |
loli/medpy | medpy/metric/histogram.py | chebyshev_neg | def chebyshev_neg(h1, h2): # 12 us @array, 36 us @list \w 100 bins
r"""
Chebyshev negative distance.
Also Tchebychev distance, Minimum or :math:`L_{-\infty}` metric; equal to Minowski
distance with :math:`p=-\infty`. For the case of :math:`p=+\infty`, use `chebyshev`.
The Chebyshev distanc... | python | def chebyshev_neg(h1, h2): # 12 us @array, 36 us @list \w 100 bins
r"""
Chebyshev negative distance.
Also Tchebychev distance, Minimum or :math:`L_{-\infty}` metric; equal to Minowski
distance with :math:`p=-\infty`. For the case of :math:`p=+\infty`, use `chebyshev`.
The Chebyshev distanc... | [
"def",
"chebyshev_neg",
"(",
"h1",
",",
"h2",
")",
":",
"# 12 us @array, 36 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"return",
"min",
"(",
"scipy",
".",
"absolute",
"(",
"h1",
"-",
"h2",
")",
")"
] | r"""
Chebyshev negative distance.
Also Tchebychev distance, Minimum or :math:`L_{-\infty}` metric; equal to Minowski
distance with :math:`p=-\infty`. For the case of :math:`p=+\infty`, use `chebyshev`.
The Chebyshev distance between two histograms :math:`H` and :math:`H'` of size :math:`m` is
... | [
"r",
"Chebyshev",
"negative",
"distance",
".",
"Also",
"Tchebychev",
"distance",
"Minimum",
"or",
":",
"math",
":",
"L_",
"{",
"-",
"\\",
"infty",
"}",
"metric",
";",
"equal",
"to",
"Minowski",
"distance",
"with",
":",
"math",
":",
"p",
"=",
"-",
"\\",... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L192-L243 |
loli/medpy | medpy/metric/histogram.py | histogram_intersection | def histogram_intersection(h1, h2): # 6 us @array, 30 us @list \w 100 bins
r"""
Calculate the common part of two histograms.
The histogram intersection between two histograms :math:`H` and :math:`H'` of size :math:`m` is
defined as:
.. math::
d_{\cap}(H, H') = \sum_{m=1}^M\min... | python | def histogram_intersection(h1, h2): # 6 us @array, 30 us @list \w 100 bins
r"""
Calculate the common part of two histograms.
The histogram intersection between two histograms :math:`H` and :math:`H'` of size :math:`m` is
defined as:
.. math::
d_{\cap}(H, H') = \sum_{m=1}^M\min... | [
"def",
"histogram_intersection",
"(",
"h1",
",",
"h2",
")",
":",
"# 6 us @array, 30 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"return",
"scipy",
".",
"sum",
"(",
"scipy",
".",
"minimum",
"(",
"h1",
",",
... | r"""
Calculate the common part of two histograms.
The histogram intersection between two histograms :math:`H` and :math:`H'` of size :math:`m` is
defined as:
.. math::
d_{\cap}(H, H') = \sum_{m=1}^M\min(H_m, H'_m)
*Attributes:*
- a real metric
*Attributes fo... | [
"r",
"Calculate",
"the",
"common",
"part",
"of",
"two",
"histograms",
".",
"The",
"histogram",
"intersection",
"between",
"two",
"histograms",
":",
"math",
":",
"H",
"and",
":",
"math",
":",
"H",
"of",
"size",
":",
"math",
":",
"m",
"is",
"defined",
"a... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L245-L287 |
loli/medpy | medpy/metric/histogram.py | relative_deviation | def relative_deviation(h1, h2): # 18 us @array, 42 us @list \w 100 bins
r"""
Calculate the deviation between two histograms.
The relative deviation between two histograms :math:`H` and :math:`H'` of size :math:`m` is
defined as:
.. math::
d_{rd}(H, H') =
\frac{
... | python | def relative_deviation(h1, h2): # 18 us @array, 42 us @list \w 100 bins
r"""
Calculate the deviation between two histograms.
The relative deviation between two histograms :math:`H` and :math:`H'` of size :math:`m` is
defined as:
.. math::
d_{rd}(H, H') =
\frac{
... | [
"def",
"relative_deviation",
"(",
"h1",
",",
"h2",
")",
":",
"# 18 us @array, 42 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"numerator",
"=",
"math",
".",
"sqrt",
"(",
"scipy",
".",
"sum",
"(",
"scipy",
... | r"""
Calculate the deviation between two histograms.
The relative deviation between two histograms :math:`H` and :math:`H'` of size :math:`m` is
defined as:
.. math::
d_{rd}(H, H') =
\frac{
\sqrt{\sum_{m=1}^M(H_m - H'_m)^2}
}{
... | [
"r",
"Calculate",
"the",
"deviation",
"between",
"two",
"histograms",
".",
"The",
"relative",
"deviation",
"between",
"two",
"histograms",
":",
"math",
":",
"H",
"and",
":",
"math",
":",
"H",
"of",
"size",
":",
"math",
":",
"m",
"is",
"defined",
"as",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L332-L387 |
loli/medpy | medpy/metric/histogram.py | relative_bin_deviation | def relative_bin_deviation(h1, h2): # 79 us @array, 104 us @list \w 100 bins
r"""
Calculate the bin-wise deviation between two histograms.
The relative bin deviation between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::
d_{rbd}(H, H') = \su... | python | def relative_bin_deviation(h1, h2): # 79 us @array, 104 us @list \w 100 bins
r"""
Calculate the bin-wise deviation between two histograms.
The relative bin deviation between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::
d_{rbd}(H, H') = \su... | [
"def",
"relative_bin_deviation",
"(",
"h1",
",",
"h2",
")",
":",
"# 79 us @array, 104 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"numerator",
"=",
"scipy",
".",
"sqrt",
"(",
"scipy",
".",
"square",
"(",
"h... | r"""
Calculate the bin-wise deviation between two histograms.
The relative bin deviation between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::
d_{rbd}(H, H') = \sum_{m=1}^M
\frac{
\sqrt{(H_m - H'_m)^2}
... | [
"r",
"Calculate",
"the",
"bin",
"-",
"wise",
"deviation",
"between",
"two",
"histograms",
".",
"The",
"relative",
"bin",
"deviation",
"between",
"two",
"histograms",
":",
"math",
":",
"H",
"and",
":",
"math",
":",
"H",
"of",
"size",
":",
"math",
":",
"... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L389-L448 |
loli/medpy | medpy/metric/histogram.py | chi_square | def chi_square(h1, h2): # 23 us @array, 49 us @list \w 100
r"""
Chi-square distance.
Measure how unlikely it is that one distribution (histogram) was drawn from the
other. The Chi-square distance between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::... | python | def chi_square(h1, h2): # 23 us @array, 49 us @list \w 100
r"""
Chi-square distance.
Measure how unlikely it is that one distribution (histogram) was drawn from the
other. The Chi-square distance between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::... | [
"def",
"chi_square",
"(",
"h1",
",",
"h2",
")",
":",
"# 23 us @array, 49 us @list \\w 100",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"old_err_state",
"=",
"scipy",
".",
"seterr",
"(",
"invalid",
"=",
"'ignore'",
")",
"# divide ... | r"""
Chi-square distance.
Measure how unlikely it is that one distribution (histogram) was drawn from the
other. The Chi-square distance between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::
d_{\chi^2}(H, H') = \sum_{m=1}^M
\fra... | [
"r",
"Chi",
"-",
"square",
"distance",
".",
"Measure",
"how",
"unlikely",
"it",
"is",
"that",
"one",
"distribution",
"(",
"histogram",
")",
"was",
"drawn",
"from",
"the",
"other",
".",
"The",
"Chi",
"-",
"square",
"distance",
"between",
"two",
"histograms"... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L450-L504 |
loli/medpy | medpy/metric/histogram.py | kullback_leibler | def kullback_leibler(h1, h2): # 83 us @array, 109 us @list \w 100 bins
r"""
Kullback-Leibler divergence.
Compute how inefficient it would to be code one histogram into another.
Actually computes :math:`\frac{d_{KL}(h1, h2) + d_{KL}(h2, h1)}{2}` to achieve symmetry.
The Kullback-Leibler div... | python | def kullback_leibler(h1, h2): # 83 us @array, 109 us @list \w 100 bins
r"""
Kullback-Leibler divergence.
Compute how inefficient it would to be code one histogram into another.
Actually computes :math:`\frac{d_{KL}(h1, h2) + d_{KL}(h2, h1)}{2}` to achieve symmetry.
The Kullback-Leibler div... | [
"def",
"kullback_leibler",
"(",
"h1",
",",
"h2",
")",
":",
"# 83 us @array, 109 us @list \\w 100 bins",
"old_err_state",
"=",
"scipy",
".",
"seterr",
"(",
"divide",
"=",
"'raise'",
")",
"try",
":",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
... | r"""
Kullback-Leibler divergence.
Compute how inefficient it would to be code one histogram into another.
Actually computes :math:`\frac{d_{KL}(h1, h2) + d_{KL}(h2, h1)}{2}` to achieve symmetry.
The Kullback-Leibler divergence between two histograms :math:`H` and :math:`H'` of size
:math:`... | [
"r",
"Kullback",
"-",
"Leibler",
"divergence",
".",
"Compute",
"how",
"inefficient",
"it",
"would",
"to",
"be",
"code",
"one",
"histogram",
"into",
"another",
".",
"Actually",
"computes",
":",
"math",
":",
"\\",
"frac",
"{",
"d_",
"{",
"KL",
"}",
"(",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L507-L560 |
loli/medpy | medpy/metric/histogram.py | __kullback_leibler | def __kullback_leibler(h1, h2): # 36.3 us
"""
The actual KL implementation. @see kullback_leibler() for details.
Expects the histograms to be of type scipy.ndarray.
"""
result = h1.astype(scipy.float_)
mask = h1 != 0
result[mask] = scipy.multiply(h1[mask], scipy.log(h1[mask] / h2[mask]))
... | python | def __kullback_leibler(h1, h2): # 36.3 us
"""
The actual KL implementation. @see kullback_leibler() for details.
Expects the histograms to be of type scipy.ndarray.
"""
result = h1.astype(scipy.float_)
mask = h1 != 0
result[mask] = scipy.multiply(h1[mask], scipy.log(h1[mask] / h2[mask]))
... | [
"def",
"__kullback_leibler",
"(",
"h1",
",",
"h2",
")",
":",
"# 36.3 us",
"result",
"=",
"h1",
".",
"astype",
"(",
"scipy",
".",
"float_",
")",
"mask",
"=",
"h1",
"!=",
"0",
"result",
"[",
"mask",
"]",
"=",
"scipy",
".",
"multiply",
"(",
"h1",
"[",... | The actual KL implementation. @see kullback_leibler() for details.
Expects the histograms to be of type scipy.ndarray. | [
"The",
"actual",
"KL",
"implementation",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L562-L570 |
loli/medpy | medpy/metric/histogram.py | jensen_shannon | def jensen_shannon(h1, h2): # 85 us @array, 110 us @list \w 100 bins
r"""
Jensen-Shannon divergence.
A symmetric and numerically more stable empirical extension of the Kullback-Leibler
divergence.
The Jensen Shannon divergence between two histograms :math:`H` and :math:`H'` of size
:ma... | python | def jensen_shannon(h1, h2): # 85 us @array, 110 us @list \w 100 bins
r"""
Jensen-Shannon divergence.
A symmetric and numerically more stable empirical extension of the Kullback-Leibler
divergence.
The Jensen Shannon divergence between two histograms :math:`H` and :math:`H'` of size
:ma... | [
"def",
"jensen_shannon",
"(",
"h1",
",",
"h2",
")",
":",
"# 85 us @array, 110 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"s",
"=",
"(",
"h1",
"+",
"h2",
")",
"/",
"2.",
"return",
"__kullback_leibler",
"(... | r"""
Jensen-Shannon divergence.
A symmetric and numerically more stable empirical extension of the Kullback-Leibler
divergence.
The Jensen Shannon divergence between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::
d_{JSD}(H, H') =
... | [
"r",
"Jensen",
"-",
"Shannon",
"divergence",
".",
"A",
"symmetric",
"and",
"numerically",
"more",
"stable",
"empirical",
"extension",
"of",
"the",
"Kullback",
"-",
"Leibler",
"divergence",
".",
"The",
"Jensen",
"Shannon",
"divergence",
"between",
"two",
"histogr... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L572-L625 |
loli/medpy | medpy/metric/histogram.py | fidelity_based | def fidelity_based(h1, h2): # 25 us @array, 51 us @list \w 100 bins
r"""
Fidelity based distance.
Also Bhattacharyya distance; see also the extensions `noelle_1` to `noelle_5`.
The metric between two histograms :math:`H` and :math:`H'` of size :math:`m` is defined as:
.. math::
... | python | def fidelity_based(h1, h2): # 25 us @array, 51 us @list \w 100 bins
r"""
Fidelity based distance.
Also Bhattacharyya distance; see also the extensions `noelle_1` to `noelle_5`.
The metric between two histograms :math:`H` and :math:`H'` of size :math:`m` is defined as:
.. math::
... | [
"def",
"fidelity_based",
"(",
"h1",
",",
"h2",
")",
":",
"# 25 us @array, 51 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"result",
"=",
"scipy",
".",
"sum",
"(",
"scipy",
".",
"sqrt",
"(",
"h1",
"*",
"h... | r"""
Fidelity based distance.
Also Bhattacharyya distance; see also the extensions `noelle_1` to `noelle_5`.
The metric between two histograms :math:`H` and :math:`H'` of size :math:`m` is defined as:
.. math::
d_{F}(H, H') = \sum_{m=1}^M\sqrt{H_m * H'_m}
*Attri... | [
"r",
"Fidelity",
"based",
"distance",
".",
"Also",
"Bhattacharyya",
"distance",
";",
"see",
"also",
"the",
"extensions",
"noelle_1",
"to",
"noelle_5",
".",
"The",
"metric",
"between",
"two",
"histograms",
":",
"math",
":",
"H",
"and",
":",
"math",
":",
"H"... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L627-L679 |
loli/medpy | medpy/metric/histogram.py | noelle_4 | def noelle_4(h1, h2): # 26 us @array, 52 us @list \w 100 bins
r"""
Extension of `fidelity_based` proposed by [1]_.
.. math::
d_{\arccos F}(H, H') = \frac{2}{\pi} \arccos d_{F}(H, H')
See `fidelity_based` for the definition of :math:`d_{F}(H, H')`.
*Attributes:*
... | python | def noelle_4(h1, h2): # 26 us @array, 52 us @list \w 100 bins
r"""
Extension of `fidelity_based` proposed by [1]_.
.. math::
d_{\arccos F}(H, H') = \frac{2}{\pi} \arccos d_{F}(H, H')
See `fidelity_based` for the definition of :math:`d_{F}(H, H')`.
*Attributes:*
... | [
"def",
"noelle_4",
"(",
"h1",
",",
"h2",
")",
":",
"# 26 us @array, 52 us @list \\w 100 bins",
"return",
"2.",
"/",
"math",
".",
"pi",
"*",
"math",
".",
"acos",
"(",
"fidelity_based",
"(",
"h1",
",",
"h2",
")",
")"
] | r"""
Extension of `fidelity_based` proposed by [1]_.
.. math::
d_{\arccos F}(H, H') = \frac{2}{\pi} \arccos d_{F}(H, H')
See `fidelity_based` for the definition of :math:`d_{F}(H, H')`.
*Attributes:*
- metric
*Attributes for normalized histograms:*
... | [
"r",
"Extension",
"of",
"fidelity_based",
"proposed",
"by",
"[",
"1",
"]",
"_",
".",
"..",
"math",
"::",
"d_",
"{",
"\\",
"arccos",
"F",
"}",
"(",
"H",
"H",
")",
"=",
"\\",
"frac",
"{",
"2",
"}",
"{",
"\\",
"pi",
"}",
"\\",
"arccos",
"d_",
"{... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L819-L863 |
loli/medpy | medpy/metric/histogram.py | noelle_5 | def noelle_5(h1, h2): # 26 us @array, 52 us @list \w 100 bins
r"""
Extension of `fidelity_based` proposed by [1]_.
.. math::
d_{\sin F}(H, H') = \sqrt{1 -d_{F}^2(H, H')}
See `fidelity_based` for the definition of :math:`d_{F}(H, H')`.
*Attributes:*
- metr... | python | def noelle_5(h1, h2): # 26 us @array, 52 us @list \w 100 bins
r"""
Extension of `fidelity_based` proposed by [1]_.
.. math::
d_{\sin F}(H, H') = \sqrt{1 -d_{F}^2(H, H')}
See `fidelity_based` for the definition of :math:`d_{F}(H, H')`.
*Attributes:*
- metr... | [
"def",
"noelle_5",
"(",
"h1",
",",
"h2",
")",
":",
"# 26 us @array, 52 us @list \\w 100 bins",
"return",
"math",
".",
"sqrt",
"(",
"1",
"-",
"math",
".",
"pow",
"(",
"fidelity_based",
"(",
"h1",
",",
"h2",
")",
",",
"2",
")",
")"
] | r"""
Extension of `fidelity_based` proposed by [1]_.
.. math::
d_{\sin F}(H, H') = \sqrt{1 -d_{F}^2(H, H')}
See `fidelity_based` for the definition of :math:`d_{F}(H, H')`.
*Attributes:*
- metric
*Attributes for normalized histograms:*
- :math:`... | [
"r",
"Extension",
"of",
"fidelity_based",
"proposed",
"by",
"[",
"1",
"]",
"_",
".",
"..",
"math",
"::",
"d_",
"{",
"\\",
"sin",
"F",
"}",
"(",
"H",
"H",
")",
"=",
"\\",
"sqrt",
"{",
"1",
"-",
"d_",
"{",
"F",
"}",
"^2",
"(",
"H",
"H",
")",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L865-L909 |
loli/medpy | medpy/metric/histogram.py | cosine_alt | def cosine_alt(h1, h2): # 17 us @array, 42 us @list \w 100 bins
r"""
Alternative implementation of the `cosine` distance measure.
Notes
-----
Under development.
"""
h1, h2 = __prepare_histogram(h1, h2)
return -1 * float(scipy.sum(h1 * h2)) / (scipy.sum(scipy.power(h1, 2)) * scipy.su... | python | def cosine_alt(h1, h2): # 17 us @array, 42 us @list \w 100 bins
r"""
Alternative implementation of the `cosine` distance measure.
Notes
-----
Under development.
"""
h1, h2 = __prepare_histogram(h1, h2)
return -1 * float(scipy.sum(h1 * h2)) / (scipy.sum(scipy.power(h1, 2)) * scipy.su... | [
"def",
"cosine_alt",
"(",
"h1",
",",
"h2",
")",
":",
"# 17 us @array, 42 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"return",
"-",
"1",
"*",
"float",
"(",
"scipy",
".",
"sum",
"(",
"h1",
"*",
"h2",
"... | r"""
Alternative implementation of the `cosine` distance measure.
Notes
-----
Under development. | [
"r",
"Alternative",
"implementation",
"of",
"the",
"cosine",
"distance",
"measure",
".",
"Notes",
"-----",
"Under",
"development",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L912-L921 |
loli/medpy | medpy/metric/histogram.py | cosine | def cosine(h1, h2): # 17 us @array, 42 us @list \w 100 bins
r"""
Cosine simmilarity.
Compute the angle between the two histograms in vector space irrespective of their
length. The cosine similarity between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math... | python | def cosine(h1, h2): # 17 us @array, 42 us @list \w 100 bins
r"""
Cosine simmilarity.
Compute the angle between the two histograms in vector space irrespective of their
length. The cosine similarity between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math... | [
"def",
"cosine",
"(",
"h1",
",",
"h2",
")",
":",
"# 17 us @array, 42 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"return",
"scipy",
".",
"sum",
"(",
"h1",
"*",
"h2",
")",
"/",
"math",
".",
"sqrt",
"("... | r"""
Cosine simmilarity.
Compute the angle between the two histograms in vector space irrespective of their
length. The cosine similarity between two histograms :math:`H` and :math:`H'` of size
:math:`m` is defined as:
.. math::
d_{\cos}(H, H') = \cos\alpha = \frac{H * H'}{\|H... | [
"r",
"Cosine",
"simmilarity",
".",
"Compute",
"the",
"angle",
"between",
"the",
"two",
"histograms",
"in",
"vector",
"space",
"irrespective",
"of",
"their",
"length",
".",
"The",
"cosine",
"similarity",
"between",
"two",
"histograms",
":",
"math",
":",
"H",
... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L923-L975 |
loli/medpy | medpy/metric/histogram.py | correlate | def correlate(h1, h2): # 31 us @array, 55 us @list \w 100 bins
r"""
Correlation between two histograms.
The histogram correlation between two histograms :math:`H` and :math:`H'` of size :math:`m`
is defined as:
.. math::
d_{corr}(H, H') =
\frac{
\sum_{m=1}... | python | def correlate(h1, h2): # 31 us @array, 55 us @list \w 100 bins
r"""
Correlation between two histograms.
The histogram correlation between two histograms :math:`H` and :math:`H'` of size :math:`m`
is defined as:
.. math::
d_{corr}(H, H') =
\frac{
\sum_{m=1}... | [
"def",
"correlate",
"(",
"h1",
",",
"h2",
")",
":",
"# 31 us @array, 55 us @list \\w 100 bins",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"h1m",
"=",
"h1",
"-",
"scipy",
".",
"sum",
"(",
"h1",
")",
"/",
"float",
"(",
"h1",... | r"""
Correlation between two histograms.
The histogram correlation between two histograms :math:`H` and :math:`H'` of size :math:`m`
is defined as:
.. math::
d_{corr}(H, H') =
\frac{
\sum_{m=1}^M (H_m-\bar{H}) \cdot (H'_m-\bar{H'})
}{
\sqrt... | [
"r",
"Correlation",
"between",
"two",
"histograms",
".",
"The",
"histogram",
"correlation",
"between",
"two",
"histograms",
":",
"math",
":",
"H",
"and",
":",
"math",
":",
"H",
"of",
"size",
":",
"math",
":",
"m",
"is",
"defined",
"as",
":",
"..",
"mat... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L1067-L1127 |
loli/medpy | medpy/metric/histogram.py | quadratic_forms | def quadratic_forms(h1, h2):
r"""
Quadrativ forms metric.
Notes
-----
UNDER DEVELOPMENT
This distance measure shows very strange behaviour. The expression
transpose(h1-h2) * A * (h1-h2) yields egative values that can not be processed by the
square root. Some examples::
... | python | def quadratic_forms(h1, h2):
r"""
Quadrativ forms metric.
Notes
-----
UNDER DEVELOPMENT
This distance measure shows very strange behaviour. The expression
transpose(h1-h2) * A * (h1-h2) yields egative values that can not be processed by the
square root. Some examples::
... | [
"def",
"quadratic_forms",
"(",
"h1",
",",
"h2",
")",
":",
"h1",
",",
"h2",
"=",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
"A",
"=",
"__quadratic_forms_matrix_euclidean",
"(",
"h1",
",",
"h2",
")",
"return",
"math",
".",
"sqrt",
"(",
"(",
"h1",
... | r"""
Quadrativ forms metric.
Notes
-----
UNDER DEVELOPMENT
This distance measure shows very strange behaviour. The expression
transpose(h1-h2) * A * (h1-h2) yields egative values that can not be processed by the
square root. Some examples::
h1 h2 ... | [
"r",
"Quadrativ",
"forms",
"metric",
".",
"Notes",
"-----",
"UNDER",
"DEVELOPMENT",
"This",
"distance",
"measure",
"shows",
"very",
"strange",
"behaviour",
".",
"The",
"expression",
"transpose",
"(",
"h1",
"-",
"h2",
")",
"*",
"A",
"*",
"(",
"h1",
"-",
"... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L1185-L1215 |
loli/medpy | medpy/metric/histogram.py | __quadratic_forms_matrix_euclidean | def __quadratic_forms_matrix_euclidean(h1, h2):
r"""
Compute the bin-similarity matrix for the quadratic form distance measure.
The matric :math:`A` for two histograms :math:`H` and :math:`H'` of size :math:`m` and
:math:`n` respectively is defined as
.. math::
A_{m,n} = 1 - \frac{... | python | def __quadratic_forms_matrix_euclidean(h1, h2):
r"""
Compute the bin-similarity matrix for the quadratic form distance measure.
The matric :math:`A` for two histograms :math:`H` and :math:`H'` of size :math:`m` and
:math:`n` respectively is defined as
.. math::
A_{m,n} = 1 - \frac{... | [
"def",
"__quadratic_forms_matrix_euclidean",
"(",
"h1",
",",
"h2",
")",
":",
"A",
"=",
"scipy",
".",
"repeat",
"(",
"h2",
"[",
":",
",",
"scipy",
".",
"newaxis",
"]",
",",
"h1",
".",
"size",
",",
"1",
")",
"# repeat second array to form a matrix",
"A",
"... | r"""
Compute the bin-similarity matrix for the quadratic form distance measure.
The matric :math:`A` for two histograms :math:`H` and :math:`H'` of size :math:`m` and
:math:`n` respectively is defined as
.. math::
A_{m,n} = 1 - \frac{d_2(H_m, {H'}_n)}{d_{max}}
with
..... | [
"r",
"Compute",
"the",
"bin",
"-",
"similarity",
"matrix",
"for",
"the",
"quadratic",
"form",
"distance",
"measure",
".",
"The",
"matric",
":",
"math",
":",
"A",
"for",
"two",
"histograms",
":",
"math",
":",
"H",
"and",
":",
"math",
":",
"H",
"of",
"... | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L1217-L1239 |
loli/medpy | medpy/metric/histogram.py | __prepare_histogram | def __prepare_histogram(h1, h2):
"""Convert the histograms to scipy.ndarrays if required."""
h1 = h1 if scipy.ndarray == type(h1) else scipy.asarray(h1)
h2 = h2 if scipy.ndarray == type(h2) else scipy.asarray(h2)
if h1.shape != h2.shape or h1.size != h2.size:
raise ValueError('h1 and h2 must be ... | python | def __prepare_histogram(h1, h2):
"""Convert the histograms to scipy.ndarrays if required."""
h1 = h1 if scipy.ndarray == type(h1) else scipy.asarray(h1)
h2 = h2 if scipy.ndarray == type(h2) else scipy.asarray(h2)
if h1.shape != h2.shape or h1.size != h2.size:
raise ValueError('h1 and h2 must be ... | [
"def",
"__prepare_histogram",
"(",
"h1",
",",
"h2",
")",
":",
"h1",
"=",
"h1",
"if",
"scipy",
".",
"ndarray",
"==",
"type",
"(",
"h1",
")",
"else",
"scipy",
".",
"asarray",
"(",
"h1",
")",
"h2",
"=",
"h2",
"if",
"scipy",
".",
"ndarray",
"==",
"ty... | Convert the histograms to scipy.ndarrays if required. | [
"Convert",
"the",
"histograms",
"to",
"scipy",
".",
"ndarrays",
"if",
"required",
"."
] | train | https://github.com/loli/medpy/blob/95216b9e22e7ce301f0edf953ee2a2f1b6c6aee5/medpy/metric/histogram.py#L1246-L1252 |
minrk/findspark | findspark.py | find | def find():
"""Find a local spark installation.
Will first check the SPARK_HOME env variable, and otherwise
search common installation locations, e.g. from homebrew
"""
spark_home = os.environ.get('SPARK_HOME', None)
if not spark_home:
for path in [
'/usr/local/opt/apache-s... | python | def find():
"""Find a local spark installation.
Will first check the SPARK_HOME env variable, and otherwise
search common installation locations, e.g. from homebrew
"""
spark_home = os.environ.get('SPARK_HOME', None)
if not spark_home:
for path in [
'/usr/local/opt/apache-s... | [
"def",
"find",
"(",
")",
":",
"spark_home",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'SPARK_HOME'",
",",
"None",
")",
"if",
"not",
"spark_home",
":",
"for",
"path",
"in",
"[",
"'/usr/local/opt/apache-spark/libexec'",
",",
"# OS X Homebrew",
"'/usr/lib/spar... | Find a local spark installation.
Will first check the SPARK_HOME env variable, and otherwise
search common installation locations, e.g. from homebrew | [
"Find",
"a",
"local",
"spark",
"installation",
"."
] | train | https://github.com/minrk/findspark/blob/20c945d5136269ca56b1341786c49087faa7c75e/findspark.py#L14-L38 |
minrk/findspark | findspark.py | change_rc | def change_rc(spark_home, spark_python, py4j):
"""Persists changes to environment by changing shell config.
Adds lines to .bashrc to set environment variables
including the adding of dependencies to the system path. Will only
edit this file if they already exist. Currently only works for bash.
Par... | python | def change_rc(spark_home, spark_python, py4j):
"""Persists changes to environment by changing shell config.
Adds lines to .bashrc to set environment variables
including the adding of dependencies to the system path. Will only
edit this file if they already exist. Currently only works for bash.
Par... | [
"def",
"change_rc",
"(",
"spark_home",
",",
"spark_python",
",",
"py4j",
")",
":",
"bashrc_location",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~/.bashrc\"",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"bashrc_location",
")",
":",
"with",
... | Persists changes to environment by changing shell config.
Adds lines to .bashrc to set environment variables
including the adding of dependencies to the system path. Will only
edit this file if they already exist. Currently only works for bash.
Parameters
----------
spark_home : str
Pa... | [
"Persists",
"changes",
"to",
"environment",
"by",
"changing",
"shell",
"config",
"."
] | train | https://github.com/minrk/findspark/blob/20c945d5136269ca56b1341786c49087faa7c75e/findspark.py#L41-L65 |
minrk/findspark | findspark.py | edit_ipython_profile | def edit_ipython_profile(spark_home, spark_python, py4j):
"""Adds a startup file to the current IPython profile to import pyspark.
The startup file sets the required environment variables and imports pyspark.
Parameters
----------
spark_home : str
Path to Spark installation.
spark_pyth... | python | def edit_ipython_profile(spark_home, spark_python, py4j):
"""Adds a startup file to the current IPython profile to import pyspark.
The startup file sets the required environment variables and imports pyspark.
Parameters
----------
spark_home : str
Path to Spark installation.
spark_pyth... | [
"def",
"edit_ipython_profile",
"(",
"spark_home",
",",
"spark_python",
",",
"py4j",
")",
":",
"from",
"IPython",
"import",
"get_ipython",
"ip",
"=",
"get_ipython",
"(",
")",
"if",
"ip",
":",
"profile_dir",
"=",
"ip",
".",
"profile_dir",
".",
"location",
"els... | Adds a startup file to the current IPython profile to import pyspark.
The startup file sets the required environment variables and imports pyspark.
Parameters
----------
spark_home : str
Path to Spark installation.
spark_python : str
Path to python subdirectory of Spark installatio... | [
"Adds",
"a",
"startup",
"file",
"to",
"the",
"current",
"IPython",
"profile",
"to",
"import",
"pyspark",
"."
] | train | https://github.com/minrk/findspark/blob/20c945d5136269ca56b1341786c49087faa7c75e/findspark.py#L68-L98 |
minrk/findspark | findspark.py | init | def init(spark_home=None, python_path=None, edit_rc=False, edit_profile=False):
"""Make pyspark importable.
Sets environment variables and adds dependencies to sys.path.
If no Spark location is provided, will try to find an installation.
Parameters
----------
spark_home : str, optional, defaul... | python | def init(spark_home=None, python_path=None, edit_rc=False, edit_profile=False):
"""Make pyspark importable.
Sets environment variables and adds dependencies to sys.path.
If no Spark location is provided, will try to find an installation.
Parameters
----------
spark_home : str, optional, defaul... | [
"def",
"init",
"(",
"spark_home",
"=",
"None",
",",
"python_path",
"=",
"None",
",",
"edit_rc",
"=",
"False",
",",
"edit_profile",
"=",
"False",
")",
":",
"if",
"not",
"spark_home",
":",
"spark_home",
"=",
"find",
"(",
")",
"if",
"not",
"python_path",
... | Make pyspark importable.
Sets environment variables and adds dependencies to sys.path.
If no Spark location is provided, will try to find an installation.
Parameters
----------
spark_home : str, optional, default = None
Path to Spark installation, will try to find automatically
if ... | [
"Make",
"pyspark",
"importable",
"."
] | train | https://github.com/minrk/findspark/blob/20c945d5136269ca56b1341786c49087faa7c75e/findspark.py#L101-L147 |
minrk/findspark | findspark.py | _add_to_submit_args | def _add_to_submit_args(s):
"""Adds string s to the PYSPARK_SUBMIT_ARGS env var"""
new_args = os.environ.get("PYSPARK_SUBMIT_ARGS", "") + (" %s" % s)
os.environ["PYSPARK_SUBMIT_ARGS"] = new_args
return new_args | python | def _add_to_submit_args(s):
"""Adds string s to the PYSPARK_SUBMIT_ARGS env var"""
new_args = os.environ.get("PYSPARK_SUBMIT_ARGS", "") + (" %s" % s)
os.environ["PYSPARK_SUBMIT_ARGS"] = new_args
return new_args | [
"def",
"_add_to_submit_args",
"(",
"s",
")",
":",
"new_args",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"\"PYSPARK_SUBMIT_ARGS\"",
",",
"\"\"",
")",
"+",
"(",
"\" %s\"",
"%",
"s",
")",
"os",
".",
"environ",
"[",
"\"PYSPARK_SUBMIT_ARGS\"",
"]",
"=",
"ne... | Adds string s to the PYSPARK_SUBMIT_ARGS env var | [
"Adds",
"string",
"s",
"to",
"the",
"PYSPARK_SUBMIT_ARGS",
"env",
"var"
] | train | https://github.com/minrk/findspark/blob/20c945d5136269ca56b1341786c49087faa7c75e/findspark.py#L149-L153 |
minrk/findspark | findspark.py | add_packages | def add_packages(packages):
"""Add external packages to the pyspark interpreter.
Set the PYSPARK_SUBMIT_ARGS properly.
Parameters
----------
packages: list of package names in string format
"""
#if the parameter is a string, convert to a single element list
if isinstance(packages,str)... | python | def add_packages(packages):
"""Add external packages to the pyspark interpreter.
Set the PYSPARK_SUBMIT_ARGS properly.
Parameters
----------
packages: list of package names in string format
"""
#if the parameter is a string, convert to a single element list
if isinstance(packages,str)... | [
"def",
"add_packages",
"(",
"packages",
")",
":",
"#if the parameter is a string, convert to a single element list",
"if",
"isinstance",
"(",
"packages",
",",
"str",
")",
":",
"packages",
"=",
"[",
"packages",
"]",
"_add_to_submit_args",
"(",
"\"--packages \"",
"+",
"... | Add external packages to the pyspark interpreter.
Set the PYSPARK_SUBMIT_ARGS properly.
Parameters
----------
packages: list of package names in string format | [
"Add",
"external",
"packages",
"to",
"the",
"pyspark",
"interpreter",
"."
] | train | https://github.com/minrk/findspark/blob/20c945d5136269ca56b1341786c49087faa7c75e/findspark.py#L155-L169 |
minrk/findspark | findspark.py | add_jars | def add_jars(jars):
"""Add external jars to the pyspark interpreter.
Set the PYSPARK_SUBMIT_ARGS properly.
Parameters
----------
jars: list of path to jars in string format
"""
#if the parameter is a string, convert to a single element list
if isinstance(jars,str):
jars = [jar... | python | def add_jars(jars):
"""Add external jars to the pyspark interpreter.
Set the PYSPARK_SUBMIT_ARGS properly.
Parameters
----------
jars: list of path to jars in string format
"""
#if the parameter is a string, convert to a single element list
if isinstance(jars,str):
jars = [jar... | [
"def",
"add_jars",
"(",
"jars",
")",
":",
"#if the parameter is a string, convert to a single element list",
"if",
"isinstance",
"(",
"jars",
",",
"str",
")",
":",
"jars",
"=",
"[",
"jars",
"]",
"_add_to_submit_args",
"(",
"\"--jars \"",
"+",
"\",\"",
".",
"join",... | Add external jars to the pyspark interpreter.
Set the PYSPARK_SUBMIT_ARGS properly.
Parameters
----------
jars: list of path to jars in string format | [
"Add",
"external",
"jars",
"to",
"the",
"pyspark",
"interpreter",
"."
] | train | https://github.com/minrk/findspark/blob/20c945d5136269ca56b1341786c49087faa7c75e/findspark.py#L171-L185 |
sdispater/cleo | cleo/parser.py | Parser.parse | def parse(cls, expression):
"""
Parse the given console command definition into a dict.
:param expression: The expression to parse
:type expression: str
:rtype: dict
"""
parsed = {"name": None, "arguments": [], "options": []}
if not expression.strip():
... | python | def parse(cls, expression):
"""
Parse the given console command definition into a dict.
:param expression: The expression to parse
:type expression: str
:rtype: dict
"""
parsed = {"name": None, "arguments": [], "options": []}
if not expression.strip():
... | [
"def",
"parse",
"(",
"cls",
",",
"expression",
")",
":",
"parsed",
"=",
"{",
"\"name\"",
":",
"None",
",",
"\"arguments\"",
":",
"[",
"]",
",",
"\"options\"",
":",
"[",
"]",
"}",
"if",
"not",
"expression",
".",
"strip",
"(",
")",
":",
"raise",
"Val... | Parse the given console command definition into a dict.
:param expression: The expression to parse
:type expression: str
:rtype: dict | [
"Parse",
"the",
"given",
"console",
"command",
"definition",
"into",
"a",
"dict",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/parser.py#L16-L45 |
sdispater/cleo | cleo/parser.py | Parser._parameters | def _parameters(cls, tokens):
"""
Extract all of the parameters from the tokens.
:param tokens: The tokens to extract the parameters from
:type tokens: list
:rtype: dict
"""
arguments = []
options = []
for token in tokens:
if not tok... | python | def _parameters(cls, tokens):
"""
Extract all of the parameters from the tokens.
:param tokens: The tokens to extract the parameters from
:type tokens: list
:rtype: dict
"""
arguments = []
options = []
for token in tokens:
if not tok... | [
"def",
"_parameters",
"(",
"cls",
",",
"tokens",
")",
":",
"arguments",
"=",
"[",
"]",
"options",
"=",
"[",
"]",
"for",
"token",
"in",
"tokens",
":",
"if",
"not",
"token",
".",
"startswith",
"(",
"\"--\"",
")",
":",
"arguments",
".",
"append",
"(",
... | Extract all of the parameters from the tokens.
:param tokens: The tokens to extract the parameters from
:type tokens: list
:rtype: dict | [
"Extract",
"all",
"of",
"the",
"parameters",
"from",
"the",
"tokens",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/parser.py#L48-L66 |
sdispater/cleo | cleo/parser.py | Parser._parse_argument | def _parse_argument(cls, token):
"""
Parse an argument expression.
:param token: The argument expression
:type token: str
:rtype: InputArgument
"""
description = ""
validator = None
if " : " in token:
token, description = tuple(token... | python | def _parse_argument(cls, token):
"""
Parse an argument expression.
:param token: The argument expression
:type token: str
:rtype: InputArgument
"""
description = ""
validator = None
if " : " in token:
token, description = tuple(token... | [
"def",
"_parse_argument",
"(",
"cls",
",",
"token",
")",
":",
"description",
"=",
"\"\"",
"validator",
"=",
"None",
"if",
"\" : \"",
"in",
"token",
":",
"token",
",",
"description",
"=",
"tuple",
"(",
"token",
".",
"split",
"(",
"\" : \"",
",",
"2",
")... | Parse an argument expression.
:param token: The argument expression
:type token: str
:rtype: InputArgument | [
"Parse",
"an",
"argument",
"expression",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/parser.py#L69-L117 |
sdispater/cleo | cleo/parser.py | Parser._parse_option | def _parse_option(cls, token):
"""
Parse an option expression.
:param token: The option expression
:type token: str
:rtype: InputOption
"""
description = ""
validator = None
if " : " in token:
token, description = tuple(token.split("... | python | def _parse_option(cls, token):
"""
Parse an option expression.
:param token: The option expression
:type token: str
:rtype: InputOption
"""
description = ""
validator = None
if " : " in token:
token, description = tuple(token.split("... | [
"def",
"_parse_option",
"(",
"cls",
",",
"token",
")",
":",
"description",
"=",
"\"\"",
"validator",
"=",
"None",
"if",
"\" : \"",
"in",
"token",
":",
"token",
",",
"description",
"=",
"tuple",
"(",
"token",
".",
"split",
"(",
"\" : \"",
",",
"2",
")",... | Parse an option expression.
:param token: The option expression
:type token: str
:rtype: InputOption | [
"Parse",
"an",
"option",
"expression",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/parser.py#L120-L186 |
sdispater/cleo | cleo/application.py | Application.add | def add(self, command): # type: (BaseCommand) -> Application
"""
Adds a command object.
"""
self.add_command(command.config)
command.set_application(self)
return self | python | def add(self, command): # type: (BaseCommand) -> Application
"""
Adds a command object.
"""
self.add_command(command.config)
command.set_application(self)
return self | [
"def",
"add",
"(",
"self",
",",
"command",
")",
":",
"# type: (BaseCommand) -> Application",
"self",
".",
"add_command",
"(",
"command",
".",
"config",
")",
"command",
".",
"set_application",
"(",
"self",
")",
"return",
"self"
] | Adds a command object. | [
"Adds",
"a",
"command",
"object",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/application.py#L38-L45 |
sdispater/cleo | cleo/commands/command.py | Command._configure_using_fluent_definition | def _configure_using_fluent_definition(self):
"""
Configure the console command using a fluent definition.
"""
definition = Parser.parse(self.signature)
self._config.set_name(definition["name"])
for name, flags, description, default in definition["arguments"]:
... | python | def _configure_using_fluent_definition(self):
"""
Configure the console command using a fluent definition.
"""
definition = Parser.parse(self.signature)
self._config.set_name(definition["name"])
for name, flags, description, default in definition["arguments"]:
... | [
"def",
"_configure_using_fluent_definition",
"(",
"self",
")",
":",
"definition",
"=",
"Parser",
".",
"parse",
"(",
"self",
".",
"signature",
")",
"self",
".",
"_config",
".",
"set_name",
"(",
"definition",
"[",
"\"name\"",
"]",
")",
"for",
"name",
",",
"f... | Configure the console command using a fluent definition. | [
"Configure",
"the",
"console",
"command",
"using",
"a",
"fluent",
"definition",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L71-L83 |
sdispater/cleo | cleo/commands/command.py | Command.call | def call(self, name, args=None): # type: (str, Optional[str]) -> int
"""
Call another command.
"""
if args is None:
args = ""
args = StringArgs(args)
command = self.application.get_command(name)
return command.run(args, self.io) | python | def call(self, name, args=None): # type: (str, Optional[str]) -> int
"""
Call another command.
"""
if args is None:
args = ""
args = StringArgs(args)
command = self.application.get_command(name)
return command.run(args, self.io) | [
"def",
"call",
"(",
"self",
",",
"name",
",",
"args",
"=",
"None",
")",
":",
"# type: (str, Optional[str]) -> int",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"\"\"",
"args",
"=",
"StringArgs",
"(",
"args",
")",
"command",
"=",
"self",
".",
"applicati... | Call another command. | [
"Call",
"another",
"command",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L100-L110 |
sdispater/cleo | cleo/commands/command.py | Command.call_silent | def call_silent(self, name, args=None): # type: (str, Optional[str]) -> int
"""
Call another command.
"""
if args is None:
args = ""
args = StringArgs(args)
command = self.application.get_command(name)
return command.run(args, NullIO()) | python | def call_silent(self, name, args=None): # type: (str, Optional[str]) -> int
"""
Call another command.
"""
if args is None:
args = ""
args = StringArgs(args)
command = self.application.get_command(name)
return command.run(args, NullIO()) | [
"def",
"call_silent",
"(",
"self",
",",
"name",
",",
"args",
"=",
"None",
")",
":",
"# type: (str, Optional[str]) -> int",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"\"\"",
"args",
"=",
"StringArgs",
"(",
"args",
")",
"command",
"=",
"self",
".",
"ap... | Call another command. | [
"Call",
"another",
"command",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L112-L122 |
sdispater/cleo | cleo/commands/command.py | Command.argument | def argument(self, key=None):
"""
Get the value of a command argument.
"""
if key is None:
return self._args.arguments()
return self._args.argument(key) | python | def argument(self, key=None):
"""
Get the value of a command argument.
"""
if key is None:
return self._args.arguments()
return self._args.argument(key) | [
"def",
"argument",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"if",
"key",
"is",
"None",
":",
"return",
"self",
".",
"_args",
".",
"arguments",
"(",
")",
"return",
"self",
".",
"_args",
".",
"argument",
"(",
"key",
")"
] | Get the value of a command argument. | [
"Get",
"the",
"value",
"of",
"a",
"command",
"argument",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L124-L131 |
sdispater/cleo | cleo/commands/command.py | Command.option | def option(self, key=None):
"""
Get the value of a command option.
"""
if key is None:
return self._args.options()
return self._args.option(key) | python | def option(self, key=None):
"""
Get the value of a command option.
"""
if key is None:
return self._args.options()
return self._args.option(key) | [
"def",
"option",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"if",
"key",
"is",
"None",
":",
"return",
"self",
".",
"_args",
".",
"options",
"(",
")",
"return",
"self",
".",
"_args",
".",
"option",
"(",
"key",
")"
] | Get the value of a command option. | [
"Get",
"the",
"value",
"of",
"a",
"command",
"option",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L133-L140 |
sdispater/cleo | cleo/commands/command.py | Command.confirm | def confirm(self, question, default=False, true_answer_regex="(?i)^y"):
"""
Confirm a question with the user.
"""
return self._io.confirm(question, default, true_answer_regex) | python | def confirm(self, question, default=False, true_answer_regex="(?i)^y"):
"""
Confirm a question with the user.
"""
return self._io.confirm(question, default, true_answer_regex) | [
"def",
"confirm",
"(",
"self",
",",
"question",
",",
"default",
"=",
"False",
",",
"true_answer_regex",
"=",
"\"(?i)^y\"",
")",
":",
"return",
"self",
".",
"_io",
".",
"confirm",
"(",
"question",
",",
"default",
",",
"true_answer_regex",
")"
] | Confirm a question with the user. | [
"Confirm",
"a",
"question",
"with",
"the",
"user",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L142-L146 |
sdispater/cleo | cleo/commands/command.py | Command.ask | def ask(self, question, default=None):
"""
Prompt the user for input.
"""
if isinstance(question, Question):
return self._io.ask_question(question)
return self._io.ask(question, default) | python | def ask(self, question, default=None):
"""
Prompt the user for input.
"""
if isinstance(question, Question):
return self._io.ask_question(question)
return self._io.ask(question, default) | [
"def",
"ask",
"(",
"self",
",",
"question",
",",
"default",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"question",
",",
"Question",
")",
":",
"return",
"self",
".",
"_io",
".",
"ask_question",
"(",
"question",
")",
"return",
"self",
".",
"_io",
... | Prompt the user for input. | [
"Prompt",
"the",
"user",
"for",
"input",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L148-L155 |
sdispater/cleo | cleo/commands/command.py | Command.choice | def choice(self, question, choices, default=None, attempts=None, multiple=False):
"""
Give the user a single choice from an list of answers.
"""
question = ChoiceQuestion(question, choices, default)
question.set_max_attempts(attempts)
question.set_multi_select(multiple)
... | python | def choice(self, question, choices, default=None, attempts=None, multiple=False):
"""
Give the user a single choice from an list of answers.
"""
question = ChoiceQuestion(question, choices, default)
question.set_max_attempts(attempts)
question.set_multi_select(multiple)
... | [
"def",
"choice",
"(",
"self",
",",
"question",
",",
"choices",
",",
"default",
"=",
"None",
",",
"attempts",
"=",
"None",
",",
"multiple",
"=",
"False",
")",
":",
"question",
"=",
"ChoiceQuestion",
"(",
"question",
",",
"choices",
",",
"default",
")",
... | Give the user a single choice from an list of answers. | [
"Give",
"the",
"user",
"a",
"single",
"choice",
"from",
"an",
"list",
"of",
"answers",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L163-L172 |
sdispater/cleo | cleo/commands/command.py | Command.create_question | def create_question(self, question, type=None, **kwargs):
"""
Returns a Question of specified type.
"""
if not type:
return Question(question, **kwargs)
if type == "choice":
return ChoiceQuestion(question, **kwargs)
if type == "confirmation":
... | python | def create_question(self, question, type=None, **kwargs):
"""
Returns a Question of specified type.
"""
if not type:
return Question(question, **kwargs)
if type == "choice":
return ChoiceQuestion(question, **kwargs)
if type == "confirmation":
... | [
"def",
"create_question",
"(",
"self",
",",
"question",
",",
"type",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"type",
":",
"return",
"Question",
"(",
"question",
",",
"*",
"*",
"kwargs",
")",
"if",
"type",
"==",
"\"choice\"",
":",... | Returns a Question of specified type. | [
"Returns",
"a",
"Question",
"of",
"specified",
"type",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L174-L185 |
sdispater/cleo | cleo/commands/command.py | Command.table | def table(self, header=None, rows=None, style=None):
"""
Return a Table instance.
"""
if style is not None:
style = self.TABLE_STYLES[style]
table = Table(style)
if header:
table.set_header_row(header)
if rows:
table.set_rows... | python | def table(self, header=None, rows=None, style=None):
"""
Return a Table instance.
"""
if style is not None:
style = self.TABLE_STYLES[style]
table = Table(style)
if header:
table.set_header_row(header)
if rows:
table.set_rows... | [
"def",
"table",
"(",
"self",
",",
"header",
"=",
"None",
",",
"rows",
"=",
"None",
",",
"style",
"=",
"None",
")",
":",
"if",
"style",
"is",
"not",
"None",
":",
"style",
"=",
"self",
".",
"TABLE_STYLES",
"[",
"style",
"]",
"table",
"=",
"Table",
... | Return a Table instance. | [
"Return",
"a",
"Table",
"instance",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L187-L202 |
sdispater/cleo | cleo/commands/command.py | Command.render_table | def render_table(self, headers, rows, style=None):
"""
Format input to textual table.
"""
table = self.table(headers, rows, style)
table.render(self._io) | python | def render_table(self, headers, rows, style=None):
"""
Format input to textual table.
"""
table = self.table(headers, rows, style)
table.render(self._io) | [
"def",
"render_table",
"(",
"self",
",",
"headers",
",",
"rows",
",",
"style",
"=",
"None",
")",
":",
"table",
"=",
"self",
".",
"table",
"(",
"headers",
",",
"rows",
",",
"style",
")",
"table",
".",
"render",
"(",
"self",
".",
"_io",
")"
] | Format input to textual table. | [
"Format",
"input",
"to",
"textual",
"table",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L204-L210 |
sdispater/cleo | cleo/commands/command.py | Command.write | def write(self, text, style=None):
"""
Writes a string without a new line.
Useful if you want to use overwrite().
"""
if style:
styled = "<%s>%s</>" % (style, text)
else:
styled = text
self._io.write(styled) | python | def write(self, text, style=None):
"""
Writes a string without a new line.
Useful if you want to use overwrite().
"""
if style:
styled = "<%s>%s</>" % (style, text)
else:
styled = text
self._io.write(styled) | [
"def",
"write",
"(",
"self",
",",
"text",
",",
"style",
"=",
"None",
")",
":",
"if",
"style",
":",
"styled",
"=",
"\"<%s>%s</>\"",
"%",
"(",
"style",
",",
"text",
")",
"else",
":",
"styled",
"=",
"text",
"self",
".",
"_io",
".",
"write",
"(",
"st... | Writes a string without a new line.
Useful if you want to use overwrite(). | [
"Writes",
"a",
"string",
"without",
"a",
"new",
"line",
".",
"Useful",
"if",
"you",
"want",
"to",
"use",
"overwrite",
"()",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L212-L222 |
sdispater/cleo | cleo/commands/command.py | Command.line | def line(self, text, style=None, verbosity=None):
"""
Write a string as information output.
"""
if style:
styled = "<%s>%s</>" % (style, text)
else:
styled = text
self._io.write_line(styled, verbosity) | python | def line(self, text, style=None, verbosity=None):
"""
Write a string as information output.
"""
if style:
styled = "<%s>%s</>" % (style, text)
else:
styled = text
self._io.write_line(styled, verbosity) | [
"def",
"line",
"(",
"self",
",",
"text",
",",
"style",
"=",
"None",
",",
"verbosity",
"=",
"None",
")",
":",
"if",
"style",
":",
"styled",
"=",
"\"<%s>%s</>\"",
"%",
"(",
"style",
",",
"text",
")",
"else",
":",
"styled",
"=",
"text",
"self",
".",
... | Write a string as information output. | [
"Write",
"a",
"string",
"as",
"information",
"output",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L224-L233 |
sdispater/cleo | cleo/commands/command.py | Command.line_error | def line_error(self, text, style=None, verbosity=None):
"""
Write a string as information output to stderr.
"""
if style:
styled = "<%s>%s</>" % (style, text)
else:
styled = text
self._io.error_line(styled, verbosity) | python | def line_error(self, text, style=None, verbosity=None):
"""
Write a string as information output to stderr.
"""
if style:
styled = "<%s>%s</>" % (style, text)
else:
styled = text
self._io.error_line(styled, verbosity) | [
"def",
"line_error",
"(",
"self",
",",
"text",
",",
"style",
"=",
"None",
",",
"verbosity",
"=",
"None",
")",
":",
"if",
"style",
":",
"styled",
"=",
"\"<%s>%s</>\"",
"%",
"(",
"style",
",",
"text",
")",
"else",
":",
"styled",
"=",
"text",
"self",
... | Write a string as information output to stderr. | [
"Write",
"a",
"string",
"as",
"information",
"output",
"to",
"stderr",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L235-L244 |
sdispater/cleo | cleo/commands/command.py | Command.progress_indicator | def progress_indicator(self, fmt=None, interval=100, values=None):
"""
Creates a new progress indicator.
"""
return ProgressIndicator(self.io, fmt, interval, values) | python | def progress_indicator(self, fmt=None, interval=100, values=None):
"""
Creates a new progress indicator.
"""
return ProgressIndicator(self.io, fmt, interval, values) | [
"def",
"progress_indicator",
"(",
"self",
",",
"fmt",
"=",
"None",
",",
"interval",
"=",
"100",
",",
"values",
"=",
"None",
")",
":",
"return",
"ProgressIndicator",
"(",
"self",
".",
"io",
",",
"fmt",
",",
"interval",
",",
"values",
")"
] | Creates a new progress indicator. | [
"Creates",
"a",
"new",
"progress",
"indicator",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L284-L288 |
sdispater/cleo | cleo/commands/command.py | Command.spin | def spin(self, start_message, end_message, fmt=None, interval=100, values=None):
"""
Automatically spin a progress indicator.
"""
spinner = ProgressIndicator(self.io, fmt, interval, values)
return spinner.auto(start_message, end_message) | python | def spin(self, start_message, end_message, fmt=None, interval=100, values=None):
"""
Automatically spin a progress indicator.
"""
spinner = ProgressIndicator(self.io, fmt, interval, values)
return spinner.auto(start_message, end_message) | [
"def",
"spin",
"(",
"self",
",",
"start_message",
",",
"end_message",
",",
"fmt",
"=",
"None",
",",
"interval",
"=",
"100",
",",
"values",
"=",
"None",
")",
":",
"spinner",
"=",
"ProgressIndicator",
"(",
"self",
".",
"io",
",",
"fmt",
",",
"interval",
... | Automatically spin a progress indicator. | [
"Automatically",
"spin",
"a",
"progress",
"indicator",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L290-L296 |
sdispater/cleo | cleo/commands/command.py | Command.add_style | def add_style(self, name, fg=None, bg=None, options=None):
"""
Adds a new style
"""
style = Style(name)
if fg is not None:
style.fg(fg)
if bg is not None:
style.bg(bg)
if options is not None:
if "bold" in options:
... | python | def add_style(self, name, fg=None, bg=None, options=None):
"""
Adds a new style
"""
style = Style(name)
if fg is not None:
style.fg(fg)
if bg is not None:
style.bg(bg)
if options is not None:
if "bold" in options:
... | [
"def",
"add_style",
"(",
"self",
",",
"name",
",",
"fg",
"=",
"None",
",",
"bg",
"=",
"None",
",",
"options",
"=",
"None",
")",
":",
"style",
"=",
"Style",
"(",
"name",
")",
"if",
"fg",
"is",
"not",
"None",
":",
"style",
".",
"fg",
"(",
"fg",
... | Adds a new style | [
"Adds",
"a",
"new",
"style"
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L298-L317 |
sdispater/cleo | cleo/commands/command.py | Command.overwrite | def overwrite(self, text, size=None):
"""
Overwrites the current line.
It will not add a new line so use line('')
if necessary.
"""
self._io.overwrite(text, size=size) | python | def overwrite(self, text, size=None):
"""
Overwrites the current line.
It will not add a new line so use line('')
if necessary.
"""
self._io.overwrite(text, size=size) | [
"def",
"overwrite",
"(",
"self",
",",
"text",
",",
"size",
"=",
"None",
")",
":",
"self",
".",
"_io",
".",
"overwrite",
"(",
"text",
",",
"size",
"=",
"size",
")"
] | Overwrites the current line.
It will not add a new line so use line('')
if necessary. | [
"Overwrites",
"the",
"current",
"line",
"."
] | train | https://github.com/sdispater/cleo/blob/cf44ac2eba2d6435516501e47e5521ee2da9115a/cleo/commands/command.py#L319-L326 |
Mergifyio/git-pull-request | git_pull_request/__init__.py | get_login_password | def get_login_password(site_name="github.com",
netrc_file="~/.netrc",
git_credential_file="~/.git-credentials"):
"""Read a .netrc file and return login/password for LWN."""
try:
n = netrc.netrc(os.path.expanduser(netrc_file))
except OSError:
pass... | python | def get_login_password(site_name="github.com",
netrc_file="~/.netrc",
git_credential_file="~/.git-credentials"):
"""Read a .netrc file and return login/password for LWN."""
try:
n = netrc.netrc(os.path.expanduser(netrc_file))
except OSError:
pass... | [
"def",
"get_login_password",
"(",
"site_name",
"=",
"\"github.com\"",
",",
"netrc_file",
"=",
"\"~/.netrc\"",
",",
"git_credential_file",
"=",
"\"~/.git-credentials\"",
")",
":",
"try",
":",
"n",
"=",
"netrc",
".",
"netrc",
"(",
"os",
".",
"path",
".",
"expand... | Read a .netrc file and return login/password for LWN. | [
"Read",
"a",
".",
"netrc",
"file",
"and",
"return",
"login",
"/",
"password",
"for",
"LWN",
"."
] | train | https://github.com/Mergifyio/git-pull-request/blob/58dbe3325b3dfada02482a32223fb36ebb193248/git_pull_request/__init__.py#L51-L73 |
Mergifyio/git-pull-request | git_pull_request/__init__.py | get_github_hostname_user_repo_from_url | def get_github_hostname_user_repo_from_url(url):
"""Return hostname, user and repository to fork from.
:param url: The URL to parse
:return: hostname, user, repository
"""
parsed = parse.urlparse(url)
if parsed.netloc == '':
# Probably ssh
host, sep, path = parsed.path.partition... | python | def get_github_hostname_user_repo_from_url(url):
"""Return hostname, user and repository to fork from.
:param url: The URL to parse
:return: hostname, user, repository
"""
parsed = parse.urlparse(url)
if parsed.netloc == '':
# Probably ssh
host, sep, path = parsed.path.partition... | [
"def",
"get_github_hostname_user_repo_from_url",
"(",
"url",
")",
":",
"parsed",
"=",
"parse",
".",
"urlparse",
"(",
"url",
")",
"if",
"parsed",
".",
"netloc",
"==",
"''",
":",
"# Probably ssh",
"host",
",",
"sep",
",",
"path",
"=",
"parsed",
".",
"path",
... | Return hostname, user and repository to fork from.
:param url: The URL to parse
:return: hostname, user, repository | [
"Return",
"hostname",
"user",
"and",
"repository",
"to",
"fork",
"from",
"."
] | train | https://github.com/Mergifyio/git-pull-request/blob/58dbe3325b3dfada02482a32223fb36ebb193248/git_pull_request/__init__.py#L114-L130 |
Mergifyio/git-pull-request | git_pull_request/__init__.py | git_get_title_and_message | def git_get_title_and_message(begin, end):
"""Get title and message summary for patches between 2 commits.
:param begin: first commit to look at
:param end: last commit to look at
:return: number of commits, title, message
"""
titles = git_get_log_titles(begin, end)
title = "Pull request fo... | python | def git_get_title_and_message(begin, end):
"""Get title and message summary for patches between 2 commits.
:param begin: first commit to look at
:param end: last commit to look at
:return: number of commits, title, message
"""
titles = git_get_log_titles(begin, end)
title = "Pull request fo... | [
"def",
"git_get_title_and_message",
"(",
"begin",
",",
"end",
")",
":",
"titles",
"=",
"git_get_log_titles",
"(",
"begin",
",",
"end",
")",
"title",
"=",
"\"Pull request for \"",
"+",
"end",
"if",
"len",
"(",
"titles",
")",
"==",
"1",
":",
"title",
"=",
... | Get title and message summary for patches between 2 commits.
:param begin: first commit to look at
:param end: last commit to look at
:return: number of commits, title, message | [
"Get",
"title",
"and",
"message",
"summary",
"for",
"patches",
"between",
"2",
"commits",
"."
] | train | https://github.com/Mergifyio/git-pull-request/blob/58dbe3325b3dfada02482a32223fb36ebb193248/git_pull_request/__init__.py#L160-L180 |
zhebrak/raftos | raftos/state.py | validate_term | def validate_term(func):
"""Compares current term and request term:
if current term is stale:
update current term & become follower
if received term is stale:
respond with False
"""
@functools.wraps(func)
def on_receive_function(self, data):
if self.stora... | python | def validate_term(func):
"""Compares current term and request term:
if current term is stale:
update current term & become follower
if received term is stale:
respond with False
"""
@functools.wraps(func)
def on_receive_function(self, data):
if self.stora... | [
"def",
"validate_term",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"on_receive_function",
"(",
"self",
",",
"data",
")",
":",
"if",
"self",
".",
"storage",
".",
"term",
"<",
"data",
"[",
"'term'",
"]",
":",
"self"... | Compares current term and request term:
if current term is stale:
update current term & become follower
if received term is stale:
respond with False | [
"Compares",
"current",
"term",
"and",
"request",
"term",
":",
"if",
"current",
"term",
"is",
"stale",
":",
"update",
"current",
"term",
"&",
"become",
"follower",
"if",
"received",
"term",
"is",
"stale",
":",
"respond",
"with",
"False"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L12-L39 |
zhebrak/raftos | raftos/state.py | validate_commit_index | def validate_commit_index(func):
"""Apply to State Machine everything up to commit index"""
@functools.wraps(func)
def wrapped(self, *args, **kwargs):
for not_applied in range(self.log.last_applied + 1, self.log.commit_index + 1):
self.state_machine.apply(self.log[not_applied]['command'... | python | def validate_commit_index(func):
"""Apply to State Machine everything up to commit index"""
@functools.wraps(func)
def wrapped(self, *args, **kwargs):
for not_applied in range(self.log.last_applied + 1, self.log.commit_index + 1):
self.state_machine.apply(self.log[not_applied]['command'... | [
"def",
"validate_commit_index",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"not_applied",
"in",
"range",
"(",
"self",
".",
"log",... | Apply to State Machine everything up to commit index | [
"Apply",
"to",
"State",
"Machine",
"everything",
"up",
"to",
"commit",
"index"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L42-L57 |
zhebrak/raftos | raftos/state.py | Leader.append_entries | async def append_entries(self, destination=None):
"""AppendEntries RPC — replicate log entries / heartbeat
Args:
destination — destination id
Request params:
term — leader’s term
leader_id — so follower can redirect clients
prev_log_index — index ... | python | async def append_entries(self, destination=None):
"""AppendEntries RPC — replicate log entries / heartbeat
Args:
destination — destination id
Request params:
term — leader’s term
leader_id — so follower can redirect clients
prev_log_index — index ... | [
"async",
"def",
"append_entries",
"(",
"self",
",",
"destination",
"=",
"None",
")",
":",
"# Send AppendEntries RPC to destination if specified or broadcast to everyone",
"destination_list",
"=",
"[",
"destination",
"]",
"if",
"destination",
"else",
"self",
".",
"state",
... | AppendEntries RPC — replicate log entries / heartbeat
Args:
destination — destination id
Request params:
term — leader’s term
leader_id — so follower can redirect clients
prev_log_index — index of log entry immediately preceding new ones
prev_... | [
"AppendEntries",
"RPC",
"—",
"replicate",
"log",
"entries",
"/",
"heartbeat",
"Args",
":",
"destination",
"—",
"destination",
"id"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L166-L208 |
zhebrak/raftos | raftos/state.py | Leader.execute_command | async def execute_command(self, command):
"""Write to log & send AppendEntries RPC"""
self.apply_future = asyncio.Future(loop=self.loop)
entry = self.log.write(self.storage.term, command)
asyncio.ensure_future(self.append_entries(), loop=self.loop)
await self.apply_future | python | async def execute_command(self, command):
"""Write to log & send AppendEntries RPC"""
self.apply_future = asyncio.Future(loop=self.loop)
entry = self.log.write(self.storage.term, command)
asyncio.ensure_future(self.append_entries(), loop=self.loop)
await self.apply_future | [
"async",
"def",
"execute_command",
"(",
"self",
",",
"command",
")",
":",
"self",
".",
"apply_future",
"=",
"asyncio",
".",
"Future",
"(",
"loop",
"=",
"self",
".",
"loop",
")",
"entry",
"=",
"self",
".",
"log",
".",
"write",
"(",
"self",
".",
"stora... | Write to log & send AppendEntries RPC | [
"Write",
"to",
"log",
"&",
"send",
"AppendEntries",
"RPC"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L260-L267 |
zhebrak/raftos | raftos/state.py | Candidate.start | def start(self):
"""Increment current term, vote for herself & send vote requests"""
self.storage.update({
'term': self.storage.term + 1,
'voted_for': self.id
})
self.vote_count = 1
self.request_vote()
self.election_timer.start() | python | def start(self):
"""Increment current term, vote for herself & send vote requests"""
self.storage.update({
'term': self.storage.term + 1,
'voted_for': self.id
})
self.vote_count = 1
self.request_vote()
self.election_timer.start() | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"storage",
".",
"update",
"(",
"{",
"'term'",
":",
"self",
".",
"storage",
".",
"term",
"+",
"1",
",",
"'voted_for'",
":",
"self",
".",
"id",
"}",
")",
"self",
".",
"vote_count",
"=",
"1",
"self... | Increment current term, vote for herself & send vote requests | [
"Increment",
"current",
"term",
"vote",
"for",
"herself",
"&",
"send",
"vote",
"requests"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L293-L302 |
zhebrak/raftos | raftos/state.py | Candidate.request_vote | def request_vote(self):
"""RequestVote RPC — gather votes
Arguments:
term — candidate’s term
candidate_id — candidate requesting vote
last_log_index — index of candidate’s last log entry
last_log_term — term of candidate’s last log entry
"""
... | python | def request_vote(self):
"""RequestVote RPC — gather votes
Arguments:
term — candidate’s term
candidate_id — candidate requesting vote
last_log_index — index of candidate’s last log entry
last_log_term — term of candidate’s last log entry
"""
... | [
"def",
"request_vote",
"(",
"self",
")",
":",
"data",
"=",
"{",
"'type'",
":",
"'request_vote'",
",",
"'term'",
":",
"self",
".",
"storage",
".",
"term",
",",
"'candidate_id'",
":",
"self",
".",
"id",
",",
"'last_log_index'",
":",
"self",
".",
"log",
"... | RequestVote RPC — gather votes
Arguments:
term — candidate’s term
candidate_id — candidate requesting vote
last_log_index — index of candidate’s last log entry
last_log_term — term of candidate’s last log entry | [
"RequestVote",
"RPC",
"—",
"gather",
"votes",
"Arguments",
":",
"term",
"—",
"candidate’s",
"term",
"candidate_id",
"—",
"candidate",
"requesting",
"vote",
"last_log_index",
"—",
"index",
"of",
"candidate’s",
"last",
"log",
"entry",
"last_log_term",
"—",
"term",
... | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L307-L323 |
zhebrak/raftos | raftos/state.py | Candidate.on_receive_request_vote_response | def on_receive_request_vote_response(self, data):
"""Receives response for vote request.
If the vote was granted then check if we got majority and may become Leader
"""
if data.get('vote_granted'):
self.vote_count += 1
if self.state.is_majority(self.vote_count):... | python | def on_receive_request_vote_response(self, data):
"""Receives response for vote request.
If the vote was granted then check if we got majority and may become Leader
"""
if data.get('vote_granted'):
self.vote_count += 1
if self.state.is_majority(self.vote_count):... | [
"def",
"on_receive_request_vote_response",
"(",
"self",
",",
"data",
")",
":",
"if",
"data",
".",
"get",
"(",
"'vote_granted'",
")",
":",
"self",
".",
"vote_count",
"+=",
"1",
"if",
"self",
".",
"state",
".",
"is_majority",
"(",
"self",
".",
"vote_count",
... | Receives response for vote request.
If the vote was granted then check if we got majority and may become Leader | [
"Receives",
"response",
"for",
"vote",
"request",
".",
"If",
"the",
"vote",
"was",
"granted",
"then",
"check",
"if",
"we",
"got",
"majority",
"and",
"may",
"become",
"Leader"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L326-L335 |
zhebrak/raftos | raftos/state.py | Candidate.on_receive_append_entries | def on_receive_append_entries(self, data):
"""If we discover a Leader with the same term — step down"""
if self.storage.term == data['term']:
self.state.to_follower() | python | def on_receive_append_entries(self, data):
"""If we discover a Leader with the same term — step down"""
if self.storage.term == data['term']:
self.state.to_follower() | [
"def",
"on_receive_append_entries",
"(",
"self",
",",
"data",
")",
":",
"if",
"self",
".",
"storage",
".",
"term",
"==",
"data",
"[",
"'term'",
"]",
":",
"self",
".",
"state",
".",
"to_follower",
"(",
")"
] | If we discover a Leader with the same term — step down | [
"If",
"we",
"discover",
"a",
"Leader",
"with",
"the",
"same",
"term",
"—",
"step",
"down"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L338-L341 |
zhebrak/raftos | raftos/state.py | Follower.init_storage | def init_storage(self):
"""Set current term to zero upon initialization & voted_for to None"""
if not self.storage.exists('term'):
self.storage.update({
'term': 0,
})
self.storage.update({
'voted_for': None
}) | python | def init_storage(self):
"""Set current term to zero upon initialization & voted_for to None"""
if not self.storage.exists('term'):
self.storage.update({
'term': 0,
})
self.storage.update({
'voted_for': None
}) | [
"def",
"init_storage",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"storage",
".",
"exists",
"(",
"'term'",
")",
":",
"self",
".",
"storage",
".",
"update",
"(",
"{",
"'term'",
":",
"0",
",",
"}",
")",
"self",
".",
"storage",
".",
"update",
... | Set current term to zero upon initialization & voted_for to None | [
"Set",
"current",
"term",
"to",
"zero",
"upon",
"initialization",
"&",
"voted_for",
"to",
"None"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L368-L377 |
zhebrak/raftos | raftos/state.py | State.wait_for_election_success | async def wait_for_election_success(cls):
"""Await this function if your cluster must have a leader"""
if cls.leader is None:
cls.leader_future = asyncio.Future(loop=cls.loop)
await cls.leader_future | python | async def wait_for_election_success(cls):
"""Await this function if your cluster must have a leader"""
if cls.leader is None:
cls.leader_future = asyncio.Future(loop=cls.loop)
await cls.leader_future | [
"async",
"def",
"wait_for_election_success",
"(",
"cls",
")",
":",
"if",
"cls",
".",
"leader",
"is",
"None",
":",
"cls",
".",
"leader_future",
"=",
"asyncio",
".",
"Future",
"(",
"loop",
"=",
"cls",
".",
"loop",
")",
"await",
"cls",
".",
"leader_future"
... | Await this function if your cluster must have a leader | [
"Await",
"this",
"function",
"if",
"your",
"cluster",
"must",
"have",
"a",
"leader"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L597-L601 |
zhebrak/raftos | raftos/state.py | State.wait_until_leader | async def wait_until_leader(cls, node_id):
"""Await this function if you want to do nothing until node_id becomes a leader"""
if node_id is None:
raise ValueError('Node id can not be None!')
if cls.get_leader() != node_id:
cls.wait_until_leader_id = node_id
c... | python | async def wait_until_leader(cls, node_id):
"""Await this function if you want to do nothing until node_id becomes a leader"""
if node_id is None:
raise ValueError('Node id can not be None!')
if cls.get_leader() != node_id:
cls.wait_until_leader_id = node_id
c... | [
"async",
"def",
"wait_until_leader",
"(",
"cls",
",",
"node_id",
")",
":",
"if",
"node_id",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Node id can not be None!'",
")",
"if",
"cls",
".",
"get_leader",
"(",
")",
"!=",
"node_id",
":",
"cls",
".",
"wait_... | Await this function if you want to do nothing until node_id becomes a leader | [
"Await",
"this",
"function",
"if",
"you",
"want",
"to",
"do",
"nothing",
"until",
"node_id",
"becomes",
"a",
"leader"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/state.py#L604-L615 |
zhebrak/raftos | raftos/server.py | register | async def register(*address_list, cluster=None, loop=None):
"""Start Raft node (server)
Args:
address_list — 127.0.0.1:8000 [, 127.0.0.1:8001 ...]
cluster — [127.0.0.1:8001, 127.0.0.1:8002, ...]
"""
loop = loop or asyncio.get_event_loop()
for address in address_list:
host, p... | python | async def register(*address_list, cluster=None, loop=None):
"""Start Raft node (server)
Args:
address_list — 127.0.0.1:8000 [, 127.0.0.1:8001 ...]
cluster — [127.0.0.1:8001, 127.0.0.1:8002, ...]
"""
loop = loop or asyncio.get_event_loop()
for address in address_list:
host, p... | [
"async",
"def",
"register",
"(",
"*",
"address_list",
",",
"cluster",
"=",
"None",
",",
"loop",
"=",
"None",
")",
":",
"loop",
"=",
"loop",
"or",
"asyncio",
".",
"get_event_loop",
"(",
")",
"for",
"address",
"in",
"address_list",
":",
"host",
",",
"por... | Start Raft node (server)
Args:
address_list — 127.0.0.1:8000 [, 127.0.0.1:8001 ...]
cluster — [127.0.0.1:8001, 127.0.0.1:8002, ...] | [
"Start",
"Raft",
"node",
"(",
"server",
")",
"Args",
":",
"address_list",
"—",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
"8000",
"[",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
"8001",
"...",
"]",
"cluster",
"—",
"[",
"127",
".",
"0",
".",
"... | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/server.py#L8-L26 |
zhebrak/raftos | raftos/server.py | Node.send | async def send(self, data, destination):
"""Sends data to destination Node
Args:
data — serializable object
destination — <str> '127.0.0.1:8000' or <tuple> (127.0.0.1, 8000)
"""
if isinstance(destination, str):
host, port = destination.split(':')
... | python | async def send(self, data, destination):
"""Sends data to destination Node
Args:
data — serializable object
destination — <str> '127.0.0.1:8000' or <tuple> (127.0.0.1, 8000)
"""
if isinstance(destination, str):
host, port = destination.split(':')
... | [
"async",
"def",
"send",
"(",
"self",
",",
"data",
",",
"destination",
")",
":",
"if",
"isinstance",
"(",
"destination",
",",
"str",
")",
":",
"host",
",",
"port",
"=",
"destination",
".",
"split",
"(",
"':'",
")",
"destination",
"=",
"host",
",",
"in... | Sends data to destination Node
Args:
data — serializable object
destination — <str> '127.0.0.1:8000' or <tuple> (127.0.0.1, 8000) | [
"Sends",
"data",
"to",
"destination",
"Node",
"Args",
":",
"data",
"—",
"serializable",
"object",
"destination",
"—",
"<str",
">",
"127",
".",
"0",
".",
"0",
".",
"1",
":",
"8000",
"or",
"<tuple",
">",
"(",
"127",
".",
"0",
".",
"0",
".",
"1",
"8... | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/server.py#L75-L88 |
zhebrak/raftos | raftos/server.py | Node.broadcast | def broadcast(self, data):
"""Sends data to all Nodes in cluster (cluster list does not contain self Node)"""
for destination in self.cluster:
asyncio.ensure_future(self.send(data, destination), loop=self.loop) | python | def broadcast(self, data):
"""Sends data to all Nodes in cluster (cluster list does not contain self Node)"""
for destination in self.cluster:
asyncio.ensure_future(self.send(data, destination), loop=self.loop) | [
"def",
"broadcast",
"(",
"self",
",",
"data",
")",
":",
"for",
"destination",
"in",
"self",
".",
"cluster",
":",
"asyncio",
".",
"ensure_future",
"(",
"self",
".",
"send",
"(",
"data",
",",
"destination",
")",
",",
"loop",
"=",
"self",
".",
"loop",
"... | Sends data to all Nodes in cluster (cluster list does not contain self Node) | [
"Sends",
"data",
"to",
"all",
"Nodes",
"in",
"cluster",
"(",
"cluster",
"list",
"does",
"not",
"contain",
"self",
"Node",
")"
] | train | https://github.com/zhebrak/raftos/blob/0d6f9e049b526279b1035f597291a96cf50c9b40/raftos/server.py#L90-L93 |
datajoint/datajoint-python | datajoint/declare.py | is_foreign_key | def is_foreign_key(line):
"""
:param line: a line from the table definition
:return: true if the line appears to be a foreign key definition
"""
arrow_position = line.find('->')
return arrow_position >= 0 and not any(c in line[:arrow_position] for c in '"#\'') | python | def is_foreign_key(line):
"""
:param line: a line from the table definition
:return: true if the line appears to be a foreign key definition
"""
arrow_position = line.find('->')
return arrow_position >= 0 and not any(c in line[:arrow_position] for c in '"#\'') | [
"def",
"is_foreign_key",
"(",
"line",
")",
":",
"arrow_position",
"=",
"line",
".",
"find",
"(",
"'->'",
")",
"return",
"arrow_position",
">=",
"0",
"and",
"not",
"any",
"(",
"c",
"in",
"line",
"[",
":",
"arrow_position",
"]",
"for",
"c",
"in",
"'\"#\\... | :param line: a line from the table definition
:return: true if the line appears to be a foreign key definition | [
":",
"param",
"line",
":",
"a",
"line",
"from",
"the",
"table",
"definition",
":",
"return",
":",
"true",
"if",
"the",
"line",
"appears",
"to",
"be",
"a",
"foreign",
"key",
"definition"
] | train | https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/declare.py#L72-L78 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.