uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
85d46da8d6fa5ffa85db2a72 | train | class | class CRSplineToPSF3D(CRPSFObject):
"""
A Spline based PSF Object for Cramer-Rao bounds calculations.
"""
def __init__(self, psf_filename = None, **kwds):
# Load the spline.
with open(psf_filename, 'rb') as fp:
spline_data = pickle.load(fp)
super(CRSplineToPSF3D, se... | class CRSplineToPSF3D(CRPSFObject):
| """
A Spline based PSF Object for Cramer-Rao bounds calculations.
"""
def __init__(self, psf_filename = None, **kwds):
# Load the spline.
with open(psf_filename, 'rb') as fp:
spline_data = pickle.load(fp)
super(CRSplineToPSF3D, self).__init__(psf_data = spline_data,... | rao/
Hazen 02/17
"""
import numpy
import pickle
import storm_analysis.spliner.spline3D as spline3D
# FIXME: Also handle 2D splines.
class CramerRaoException(Exception):
pass
class CRPSFObject(object):
"""
Base class for PSF objects for Cramer-Rao bounds calculations.
"""
def __init__(self, psf_... | 211 | 211 | 704 | 14 | 196 | bintulab/storm-analysis | storm_analysis/spliner/cramer_rao.py | Python | CRSplineToPSF3D | CRSplineToPSF3D | 46 | 134 | 46 | 46 | e94ab42048d9c342da21233d30597a99fb9c654b | bigcode/the-stack | train |
ffb18785e7b767e91f5983aa | train | class | class CRBound3D(object):
"""
Class for calculating a 3D Cramer-Rao bounds given a spline.
Notes:
(1) This returns the variance.
(2) The results for x,y and z are nanometers.
FIXME: Check that we have not broken the scripts provided in the
C-Spline paper, which I think is the on... | class CRBound3D(object):
| """
Class for calculating a 3D Cramer-Rao bounds given a spline.
Notes:
(1) This returns the variance.
(2) The results for x,y and z are nanometers.
FIXME: Check that we have not broken the scripts provided in the
C-Spline paper, which I think is the only reason why we
... | value being out of range for the spline when
# it is exactly at the maximum.
#
return self.zmax - 1.0e-9
def getZMin(self):
return self.zmin + 1.0e-9
class CRBound3D(object):
| 63 | 64 | 198 | 7 | 55 | bintulab/storm-analysis | storm_analysis/spliner/cramer_rao.py | Python | CRBound3D | CRBound3D | 137 | 160 | 137 | 137 | 907e2462363bed9e03affcdcab6611fe40311b20 | bigcode/the-stack | train |
b5073255900f6afe13cf661e | train | function | def calcCRBound3D(cr_psf_object, background, photons, z_value):
"""
Class for calculating a 3D Cramer-Rao bounds given a CR PSF object.
Notes:
(1) This returns the variance.
(2) The results for x,y and z are nanometers.
(3) z_value is expected to be in microns.
"""
# Convert z_v... | def calcCRBound3D(cr_psf_object, background, photons, z_value):
| """
Class for calculating a 3D Cramer-Rao bounds given a CR PSF object.
Notes:
(1) This returns the variance.
(2) The results for x,y and z are nanometers.
(3) z_value is expected to be in microns.
"""
# Convert z_value to nanometers.
z_value = z_value * 1.0e+3
# Ca... | the
C-Spline paper, which I think is the only reason why we
are maintaining this class.
"""
def __init__(self, spline_file, pixel_size = 160.0):
self.cr_psf_object = CRSplineToPSF3D(spline_file = spline_file,
pixel_size = pixel_size)
... | 149 | 151 | 504 | 18 | 131 | bintulab/storm-analysis | storm_analysis/spliner/cramer_rao.py | Python | calcCRBound3D | calcCRBound3D | 163 | 207 | 163 | 163 | 91eed8069ef5a84d88ebeaf901295cdb042bd6c0 | bigcode/the-stack | train |
bf8f6344b59f3658bf33f563 | train | class | class ShufflePixels(BaseTransform):
def __init__(self, factor: float = 1.0, seed: int = 10, p: float = 1.0):
"""
@param factor: a control parameter between 0.0 and 1.0. While a factor of
0.0 returns the original image, a factor of 1.0 performs full shuffling
@param seed: seed fo... | class ShufflePixels(BaseTransform):
| def __init__(self, factor: float = 1.0, seed: int = 10, p: float = 1.0):
"""
@param factor: a control parameter between 0.0 and 1.0. While a factor of
0.0 returns the original image, a factor of 1.0 performs full shuffling
@param seed: seed for numpy random generator to select r... | the image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or return... | 104 | 104 | 348 | 6 | 98 | anuj0456/AugLy | augly/image/transforms.py | Python | ShufflePixels | ShufflePixels | 1,444 | 1,478 | 1,444 | 1,444 | 6e51e2ad6335df3c6a849d6089f4024d4522adc4 | bigcode/the-stack | train |
321d86f73c0e28b0503def6a | train | class | class RandomAspectRatio(BaseRandomRangeTransform):
def __init__(self, min_ratio: float = 0.5, max_ratio: float = 2.0, p: float = 1.0):
"""
@param min_ratio: the lower value on the range of aspect ratio values to choose
from, i.e. the width/height ratio
@param max_ratio: the uppe... | class RandomAspectRatio(BaseRandomRangeTransform):
| def __init__(self, min_ratio: float = 0.5, max_ratio: float = 2.0, p: float = 1.0):
"""
@param min_ratio: the lower value on the range of aspect ratio values to choose
from, i.e. the width/height ratio
@param max_ratio: the upper value on the range of aspect ratio values to choo... |
specifying specific parameters for the augmentation, with these functions
you can specify a range (or a list) to randomly choose from instead.
Example:
>>> image = Image.open("....")
>>> blur_tsfm = RandomBlur(min_radius=2.0, max_radius=5.0, p=0.5)
>>> blurred_image = blur_tsfm(image)
"""
class RandomAspectRatio(B... | 87 | 87 | 290 | 9 | 78 | anuj0456/AugLy | augly/image/transforms.py | Python | RandomAspectRatio | RandomAspectRatio | 1,514 | 1,541 | 1,514 | 1,514 | 30d27002fefda0f5b0faccdecc57b40758ad1013 | bigcode/the-stack | train |
9d9de4b84d864995eccc5b4a | train | class | class EncodingQuality(BaseTransform):
def __init__(self, quality: int = 50, p: float = 1.0):
"""
@param quality: JPEG encoding quality. 0 is lowest quality, 100 is highest
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
... | class EncodingQuality(BaseTransform):
| def __init__(self, quality: int = 50, p: float = 1.0):
"""
@param quality: JPEG encoding quality. 0 is lowest quality, 100 is highest
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
self.quality = quality
de... | set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.crop(
image, x1=self.x1, y1=self.y1, x2=self.x2, y2=self.y2, metadata=metadata
)
class EncodingQuality(BaseTransform):
| 67 | 67 | 225 | 6 | 61 | anuj0456/AugLy | augly/image/transforms.py | Python | EncodingQuality | EncodingQuality | 523 | 547 | 523 | 523 | aacf94ca811a88f2c6f632219638fd65fc1623c2 | bigcode/the-stack | train |
1b124e9d9283fc3b93a67d66 | train | class | class Saturation(BaseTransform):
def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: a saturation factor of below 1.0 lowers the saturation, a
factor of 1.0 gives the original image, and a factor greater than 1.0
adds saturation
@param p: the ... | class Saturation(BaseTransform):
| def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: a saturation factor of below 1.0 lowers the saturation, a
factor of 1.0 gives the original image, and a factor greater than 1.0
adds saturation
@param p: the probability of the transform bein... | the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.rotate(image, degrees=self.degrees, metadata=metad... | 75 | 75 | 251 | 6 | 69 | anuj0456/AugLy | augly/image/transforms.py | Python | Saturation | Saturation | 1,344 | 1,370 | 1,344 | 1,344 | fd206dade77c67421942bd08bc14b8adc2feec69 | bigcode/the-stack | train |
c7844967c50bcbaa1d07c7ae | train | class | class OverlayOntoScreenshot(BaseTransform):
def __init__(
self,
template_filepath: str = utils.TEMPLATE_PATH,
template_bboxes_filepath: str = utils.BBOXES_PATH,
max_image_size_pixels: Optional[int] = None,
crop_src_to_fit: bool = False,
resize_src_to_match_template: b... | class OverlayOntoScreenshot(BaseTransform):
| def __init__(
self,
template_filepath: str = utils.TEMPLATE_PATH,
template_bboxes_filepath: str = utils.BBOXES_PATH,
max_image_size_pixels: Optional[int] = None,
crop_src_to_fit: bool = False,
resize_src_to_match_template: bool = True,
p: float = 1.0,
):
... | None
) -> Image.Image:
"""
Overlays the image onto a given background image at position
(width * x_pos, height * y_pos)
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the s... | 181 | 181 | 606 | 8 | 173 | anuj0456/AugLy | augly/image/transforms.py | Python | OverlayOntoScreenshot | OverlayOntoScreenshot | 899 | 961 | 899 | 899 | 8a7208847033da8e2e65c136dbdcc7200bdc77ec | bigcode/the-stack | train |
3b21afd7473b6b658997dc2f | train | class | class RandomRotation(BaseRandomRangeTransform):
def __init__(
self, min_degrees: float = 0.0, max_degrees: float = 180.0, p: float = 1.0
):
"""
@param min_degrees: the lower value on the range of degree values to choose from
@param max_degrees: the upper value on the range of de... | class RandomRotation(BaseRandomRangeTransform):
| def __init__(
self, min_degrees: float = 0.0, max_degrees: float = 180.0, p: float = 1.0
):
"""
@param min_degrees: the lower value on the range of degree values to choose from
@param max_degrees: the upper value on the range of degree values to choose from
@param p: th... | about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.pixelization(image, ratio=self.chosen_value,... | 80 | 80 | 267 | 8 | 72 | anuj0456/AugLy | augly/image/transforms.py | Python | RandomRotation | RandomRotation | 1,697 | 1,724 | 1,697 | 1,697 | bf2fa15d3bf599bfae3b2e66cc45e94122af541f | bigcode/the-stack | train |
15bc4a51c0f9d2b4eb197c04 | train | class | class PadSquare(BaseTransform):
def __init__(
self, color: Tuple[int, int, int] = utils.DEFAULT_COLOR, p: float = 1.0
):
"""
@param color: color of the padded border in RGB values
@param p: the probability of the transform being applied; default value is 1.0
"""
... | class PadSquare(BaseTransform):
| def __init__(
self, color: Tuple[int, int, int] = utils.DEFAULT_COLOR, p: float = 1.0
):
"""
@param color: color of the padded border in RGB values
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
self... | the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.pad(
image,
w_factor=self.w_factor,
h_factor=self.h_factor,
color=self.color,
metadata=metadata,
... | 70 | 70 | 235 | 6 | 64 | anuj0456/AugLy | augly/image/transforms.py | Python | PadSquare | PadSquare | 1,140 | 1,166 | 1,140 | 1,140 | 80bbb07d35934f1cfed83b4d4e27432c9292b867 | bigcode/the-stack | train |
549589c95a44c59bc5b67a30 | train | class | class Resize(BaseTransform):
def __init__(
self, width: Optional[int] = None, height: Optional[int] = None, p: float = 1.0
):
"""
@param width: the desired width the image should be resized to have. If None,
the original image width will be used
@param height: the de... | class Resize(BaseTransform):
| def __init__(
self, width: Optional[int] = None, height: Optional[int] = None, p: float = 1.0
):
"""
@param width: the desired width the image should be resized to have. If None,
the original image width will be used
@param height: the desired height the image should... | including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.random_noise(
image, mean=self.mean, var=self.var, seed=self.s... | 82 | 82 | 276 | 5 | 77 | anuj0456/AugLy | augly/image/transforms.py | Python | Resize | Resize | 1,283 | 1,313 | 1,283 | 1,283 | 0686c8001e77160e89ce078879d6888991409c0f | bigcode/the-stack | train |
56c7cb0b5782e2e1c99aa8d6 | train | class | class Brightness(BaseTransform):
def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: values less than 1.0 darken the image and values greater than
1.0 brighten the image. Setting factor to 1.0 will not alter the image's
brightness
@param p: th... | class Brightness(BaseTransform):
| def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: values less than 1.0 darken the image and values greater than
1.0 brighten the image. Setting factor to 1.0 will not alter the image's
brightness
@param p: the probability of the transform be... | about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.blur(image, radius=self.radius, metadata=met... | 75 | 75 | 252 | 6 | 69 | anuj0456/AugLy | augly/image/transforms.py | Python | Brightness | Brightness | 218 | 244 | 218 | 218 | 551c0fbb7a445e5c2275b411b30b922aac3b13c1 | bigcode/the-stack | train |
4ebdd489ab3ae7d8a726bd7a | train | class | class Crop(BaseTransform):
def __init__(
self,
x1: float = 0.25,
y1: float = 0.25,
x2: float = 0.75,
y2: float = 0.75,
p: float = 1.0,
):
"""
@param x1: position of the left edge of cropped image relative to the width
of the original im... | class Crop(BaseTransform):
| def __init__(
self,
x1: float = 0.25,
y1: float = 0.25,
x2: float = 0.75,
y2: float = 0.75,
p: float = 1.0,
):
"""
@param x1: position of the left edge of cropped image relative to the width
of the original image; must be a float value ... | color modes
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or retu... | 130 | 130 | 436 | 5 | 125 | anuj0456/AugLy | augly/image/transforms.py | Python | Crop | Crop | 476 | 520 | 476 | 476 | 48ddd162defce43cbcf0bea435c363625ae931e4 | bigcode/the-stack | train |
075728ef087fe496fd5af917 | train | class | class Grayscale(BaseTransform):
def __init__(self, mode: str = "luminosity", p: float = 1.0):
"""
@param mode: the type of greyscale conversion to perform; two options are
supported ("luminosity" and "average")
@param p: the probability of the transform being applied; default va... | class Grayscale(BaseTransform):
| def __init__(self, mode: str = "luminosity", p: float = 1.0):
"""
@param mode: the type of greyscale conversion to perform; two options are
supported ("luminosity" and "average")
@param p: the probability of the transform being applied; default value is 1.0
"""
s... | its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.encoding_quality(image, quality=self.quality, metadata=metadata)
class Grayscale(BaseTransform)... | 70 | 70 | 235 | 6 | 64 | anuj0456/AugLy | augly/image/transforms.py | Python | Grayscale | Grayscale | 550 | 575 | 550 | 550 | 2a6c5c6aa0a3093c831f53fa0beb14fcbae05921 | bigcode/the-stack | train |
2355494a5ca3d1849ead4353 | train | class | class ClipImageSize(BaseTransform):
def __init__(
self,
min_resolution: Optional[int] = None,
max_resolution: Optional[int] = None,
p: float = 1.0,
):
"""
@param min_resolution: the minimum resolution, i.e. width * height, that the
augmented image shou... | class ClipImageSize(BaseTransform):
| def __init__(
self,
min_resolution: Optional[int] = None,
max_resolution: Optional[int] = None,
p: float = 1.0,
):
"""
@param min_resolution: the minimum resolution, i.e. width * height, that the
augmented image should have; if the input image has a lo... | image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
... | 106 | 106 | 356 | 7 | 99 | anuj0456/AugLy | augly/image/transforms.py | Python | ClipImageSize | ClipImageSize | 274 | 316 | 274 | 274 | c13e120166f8ea3ceb2f69098a38e3abb5da2bd8 | bigcode/the-stack | train |
cf561c2be8b1daea75b0f653 | train | class | class RandomPixelization(BaseRandomRangeTransform):
def __init__(self, min_ratio: float = 0.1, max_ratio: float = 1.0, p: float = 1.0):
"""
@param min_ratio: the lower value on the range of pixelization ratio values to
choose from. Smaller values result in a more pixelated image, 1.0 ind... | class RandomPixelization(BaseRandomRangeTransform):
| def __init__(self, min_ratio: float = 0.1, max_ratio: float = 1.0, p: float = 1.0):
"""
@param min_ratio: the lower value on the range of pixelization ratio values to
choose from. Smaller values result in a more pixelated image, 1.0 indicates
no change, and any value above on... | None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
emoji_path = random.choice(self.emoji_paths)
return F.overlay_emoji(
image,
emoji_path=os.path.join(self.emoji_directory, emoji_path),
opacity=self.opacity,
... | 99 | 99 | 331 | 9 | 90 | anuj0456/AugLy | augly/image/transforms.py | Python | RandomPixelization | RandomPixelization | 1,665 | 1,694 | 1,665 | 1,665 | faa1e0e8626b20cf7f9e3970bbb2bf7664bfe374 | bigcode/the-stack | train |
4e89376065536803a1553b52 | train | class | class OverlayEmoji(BaseTransform):
def __init__(
self,
emoji_path: str = utils.EMOJI_PATH,
opacity: float = 1.0,
emoji_size: float = 0.15,
x_pos: float = 0.4,
y_pos: float = 0.8,
p: float = 1.0,
):
"""
@param emoji_path: iopath uri to the e... | class OverlayEmoji(BaseTransform):
| def __init__(
self,
emoji_path: str = utils.EMOJI_PATH,
opacity: float = 1.0,
emoji_size: float = 0.15,
x_pos: float = 0.4,
y_pos: float = 0.8,
p: float = 1.0,
):
"""
@param emoji_path: iopath uri to the emoji image
@param opacity:... | [str, Any]]] = None
) -> Image.Image:
"""
Alters the opacity of an image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
... | 122 | 122 | 407 | 6 | 116 | anuj0456/AugLy | augly/image/transforms.py | Python | OverlayEmoji | OverlayEmoji | 725 | 775 | 725 | 725 | 4eb1a1181d7651394eb8a83cfb43e04dffe4b7da | bigcode/the-stack | train |
f80473c2dcebfcc9f404b7de | train | class | class OverlayText(BaseTransform):
def __init__(
self,
text: List[Union[int, List[int]]] = utils.DEFAULT_TEXT_INDICES,
font_file: str = utils.FONT_PATH,
font_size: float = 0.15,
opacity: float = 1.0,
color: Tuple[int, int, int] = utils.RED_RGB_COLOR,
x_pos: flo... | class OverlayText(BaseTransform):
| def __init__(
self,
text: List[Union[int, List[int]]] = utils.DEFAULT_TEXT_INDICES,
font_file: str = utils.FONT_PATH,
font_size: float = 0.15,
opacity: float = 1.0,
color: Tuple[int, int, int] = utils.RED_RGB_COLOR,
x_pos: float = 0.0,
y_pos: float = 0... | :
"""
Overlay stripe pattern onto the image (by default, stripes are horizontal)
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to... | 164 | 164 | 549 | 6 | 158 | anuj0456/AugLy | augly/image/transforms.py | Python | OverlayText | OverlayText | 1,028 | 1,090 | 1,028 | 1,028 | bbce0a4b4ce18bd0d32d4607d459858e4b683cee | bigcode/the-stack | train |
ea74ec8aef4efbb4e6cd2949 | train | class | class Pixelization(BaseTransform):
def __init__(self, ratio: float = 1.0, p: float = 1.0):
"""
@param ratio: smaller values result in a more pixelated image, 1.0 indicates
no change, and any value above one doesn't have a noticeable effect
@param p: the probability of the transf... | class Pixelization(BaseTransform):
| def __init__(self, ratio: float = 1.0, p: float = 1.0):
"""
@param ratio: smaller values result in a more pixelated image, 1.0 indicates
no change, and any value above one doesn't have a noticeable effect
@param p: the probability of the transform being applied; default value is... | ted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.perspective_transform(
image,
sigma=self.sigma,
dx=self.dx,
dy=self.dy,
seed=self.seed,
metadata=metadata,
... | 72 | 72 | 241 | 6 | 66 | anuj0456/AugLy | augly/image/transforms.py | Python | Pixelization | Pixelization | 1,218 | 1,243 | 1,218 | 1,218 | 1e48cc1718efccbb8bea805ae662ab3e3f764e3c | bigcode/the-stack | train |
c3170109a05cbcbfc167d8be | train | class | class OverlayOntoBackgroundImage(BaseTransform):
def __init__(
self,
background_image: Union[str, Image.Image],
opacity: float = 1.0,
overlay_size: float = 1.0,
x_pos: float = 0.4,
y_pos: float = 0.4,
scale_bg: bool = False,
p: float = 1.0,
):
... | class OverlayOntoBackgroundImage(BaseTransform):
| def __init__(
self,
background_image: Union[str, Image.Image],
opacity: float = 1.0,
overlay_size: float = 1.0,
x_pos: float = 0.4,
y_pos: float = 0.4,
scale_bg: bool = False,
p: float = 1.0,
):
"""
@param background_image: the path... | """
Overlays an image onto another image at position (width * x_pos, height * y_pos)
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appende... | 158 | 158 | 528 | 9 | 149 | anuj0456/AugLy | augly/image/transforms.py | Python | OverlayOntoBackgroundImage | OverlayOntoBackgroundImage | 833 | 896 | 833 | 833 | b79f4ee0583fb09100c6804b62e9870776fcd813 | bigcode/the-stack | train |
d4671ee49d0da44f03b47119 | train | class | class ApplyPILFilter(BaseTransform):
def __init__(
self,
filter_type: Union[Callable, ImageFilter.Filter] = ImageFilter.EDGE_ENHANCE_MORE,
p: float = 1.0,
):
"""
@param filter_type: the PIL ImageFilter to apply to the image
@param p: the probability of the transf... | class ApplyPILFilter(BaseTransform):
| def __init__(
self,
filter_type: Union[Callable, ImageFilter.Filter] = ImageFilter.EDGE_ENHANCE_MORE,
p: float = 1.0,
):
"""
@param filter_type: the PIL ImageFilter to apply to the image
@param p: the probability of the transform being applied; default value is 1... | width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.apply_lambda(
image, aug_function=self.aug_function, metadata=metadata, **self.kwargs
)
class ApplyPILF... | 76 | 76 | 254 | 8 | 68 | anuj0456/AugLy | augly/image/transforms.py | Python | ApplyPILFilter | ApplyPILFilter | 160 | 188 | 160 | 160 | 8ab97dcca68987d50c6b3e1dd2627b1ee8658c2a | bigcode/the-stack | train |
7bd878c158af1c2d8e498c01 | train | class | class BaseTransform(object):
def __init__(self, p: float = 1.0):
"""
@param p: the probability of the transform being applied; default value is 1.0
"""
assert 0 <= p <= 1.0, "p must be a value in the range [0, 1]"
self.p = p
def __call__(
self,
image: Ima... | class BaseTransform(object):
| def __init__(self, p: float = 1.0):
"""
@param p: the probability of the transform being applied; default value is 1.0
"""
assert 0 <= p <= 1.0, "p must be a value in the range [0, 1]"
self.p = p
def __call__(
self,
image: Image.Image,
force: bool... | #!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
import os
import random
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import augly.image.functional as F
import augly.utils as utils
from PIL import Image, ImageFilter
"""
Base Classes for Transforms
"""
class BaseTrans... | 79 | 107 | 359 | 5 | 74 | anuj0456/AugLy | augly/image/transforms.py | Python | BaseTransform | BaseTransform | 18 | 60 | 18 | 18 | 0e6d272045f1220edc820335b55c3f6b6f8b7cbc | bigcode/the-stack | train |
56392e5e7c15de086896287d | train | class | class HFlip(BaseTransform):
def apply_transform(
self, image: Image.Image, metadata: Optional[List[Dict[str, Any]]] = None
) -> Image.Image:
"""
Horizontally flips an image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the ... | class HFlip(BaseTransform):
| def apply_transform(
self, image: Image.Image, metadata: Optional[List[Dict[str, Any]]] = None
) -> Image.Image:
"""
Horizontally flips an image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
... | & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.grayscale(image, mode=self.mode, metadata=metadata)
class HFlip(BaseTransform):
| 64 | 64 | 138 | 6 | 58 | anuj0456/AugLy | augly/image/transforms.py | Python | HFlip | HFlip | 578 | 593 | 578 | 578 | a3d3c45b9be04838dc827e564fad920714a5a838 | bigcode/the-stack | train |
f1415d22c5ce5a09f80f5fae | train | class | class Opacity(BaseTransform):
def __init__(self, level: float = 1.0, p: float = 1.0):
"""
@param level: the level the opacity should be set to, where 0 means completely
transparent and 1 means no transparency at all
@param p: the probability of the transform being applied; defau... | class Opacity(BaseTransform):
| def __init__(self, level: float = 1.0, p: float = 1.0):
"""
@param level: the level the opacity should be set to, where 0 means completely
transparent and 1 means no transparency at all
@param p: the probability of the transform being applied; default value is 1.0
"""
... | mented PIL Image
"""
return F.meme_format(
image,
text=self.text,
font_file=self.font_file,
opacity=self.opacity,
text_color=self.text_color,
caption_height=self.caption_height,
meme_bg_color=self.meme_bg_color,
... | 70 | 70 | 235 | 6 | 64 | anuj0456/AugLy | augly/image/transforms.py | Python | Opacity | Opacity | 697 | 722 | 697 | 697 | 37157cd5ed9486bf08d5c9338af444831849e727 | bigcode/the-stack | train |
fbf59e87effc3bf298db5768 | train | class | class RandomBlur(BaseRandomRangeTransform):
def __init__(
self, min_radius: float = 0.0, max_radius: float = 10.0, p: float = 1.0
):
"""
@param min_radius: the lower value on the range of blur values to choose
from. The larger the radius, the blurrier the image
@para... | class RandomBlur(BaseRandomRangeTransform):
| def __init__(
self, min_radius: float = 0.0, max_radius: float = 10.0, p: float = 1.0
):
"""
@param min_radius: the lower value on the range of blur values to choose
from. The larger the radius, the blurrier the image
@param max_radius: the upper value on the range o... | a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.change_aspect_ratio(image, ... | 86 | 86 | 288 | 8 | 78 | anuj0456/AugLy | augly/image/transforms.py | Python | RandomBlur | RandomBlur | 1,544 | 1,573 | 1,544 | 1,544 | 9b8579b7bd0eb378e97cae36ec301fd3189f4aad | bigcode/the-stack | train |
2d4388b2354eaa6e0f9bf5a5 | train | class | class ConvertColor(BaseTransform):
def __init__(
self,
mode: Optional[str] = None,
matrix: Union[
None,
Tuple[float, float, float, float],
Tuple[
float,
float,
float,
float,
fl... | class ConvertColor(BaseTransform):
| def __init__(
self,
mode: Optional[str] = None,
matrix: Union[
None,
Tuple[float, float, float, float],
Tuple[
float,
float,
float,
float,
float,
float,
... | of the transform being applied; default value is 1.0
"""
super().__init__(p)
self.factor = factor
def apply_transform(
self, image: Image.Image, metadata: Optional[List[Dict[str, Any]]] = None
) -> Image.Image:
"""
Alters the contrast of the image
@para... | 171 | 171 | 570 | 6 | 165 | anuj0456/AugLy | augly/image/transforms.py | Python | ConvertColor | ConvertColor | 398 | 473 | 398 | 398 | 54f012f4bc4e20d30ce5c4e92b54a5bf126313fc | bigcode/the-stack | train |
35c67ed27db15eee0948c051 | train | class | class Scale(BaseTransform):
def __init__(
self,
factor: float = 0.5,
interpolation: Optional[int] = None,
p: float = 1.0,
):
"""
@param scale_factor: the ratio by which the image should be down-scaled
or upscaled
@param interpolation: interpol... | class Scale(BaseTransform):
| def __init__(
self,
factor: float = 0.5,
interpolation: Optional[int] = None,
p: float = 1.0,
):
"""
@param scale_factor: the ratio by which the image should be down-scaled
or upscaled
@param interpolation: interpolation method. This can be on... | PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented P... | 94 | 94 | 314 | 5 | 89 | anuj0456/AugLy | augly/image/transforms.py | Python | Scale | Scale | 1,373 | 1,413 | 1,373 | 1,373 | 9b43fcb1115ea2918d02d9572a0f88e5ad19aa8c | bigcode/the-stack | train |
3c800eb4ba7184bd8d88d08d | train | class | class Rotate(BaseTransform):
def __init__(self, degrees: float = 15.0, p: float = 1.0):
"""
@param degrees: the amount of degrees that the original image will be rotated
counter clockwise
@param p: the probability of the transform being applied; default value is 1.0
"""
... | class Rotate(BaseTransform):
| def __init__(self, degrees: float = 15.0, p: float = 1.0):
"""
@param degrees: the amount of degrees that the original image will be rotated
counter clockwise
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
... | source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.resize(image, width=self.width, height=self.height, metadata=metadata)
class Rotate(BaseTransform):
| 67 | 67 | 224 | 5 | 62 | anuj0456/AugLy | augly/image/transforms.py | Python | Rotate | Rotate | 1,316 | 1,341 | 1,316 | 1,316 | c51befe9bafc28b0c1ccffbc522ce81183f2ab86 | bigcode/the-stack | train |
497933eaf914c22eb72eb92e | train | class | class MemeFormat(BaseTransform):
def __init__(
self,
text: str = "LOL",
font_file: str = utils.MEME_DEFAULT_FONT,
opacity: float = 1.0,
text_color: Tuple[int, int, int] = utils.DEFAULT_COLOR,
caption_height: int = 250,
meme_bg_color: Tuple[int, int, int] = uti... | class MemeFormat(BaseTransform):
| def __init__(
self,
text: str = "LOL",
font_file: str = utils.MEME_DEFAULT_FONT,
opacity: float = 1.0,
text_color: Tuple[int, int, int] = utils.DEFAULT_COLOR,
caption_height: int = 250,
meme_bg_color: Tuple[int, int, int] = utils.WHITE_RGB_COLOR,
p: fl... | [List[Dict[str, Any]]] = None
) -> Image.Image:
"""
Applies given augmentation function to the masked area of the image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & d... | 146 | 146 | 488 | 6 | 140 | anuj0456/AugLy | augly/image/transforms.py | Python | MemeFormat | MemeFormat | 637 | 694 | 637 | 637 | 48b791d784201b6823f9b147652096656c63ef11 | bigcode/the-stack | train |
5f4903a3576850988d874a53 | train | class | class RandomBrightness(BaseRandomRangeTransform):
def __init__(
self, min_factor: float = 0.0, max_factor: float = 2.0, p: float = 1.0
):
"""
@param min_factor: the lower value on the range of brightness values to choose
from. The lower the factor, the darker the image
... | class RandomBrightness(BaseRandomRangeTransform):
| def __init__(
self, min_factor: float = 0.0, max_factor: float = 2.0, p: float = 1.0
):
"""
@param min_factor: the lower value on the range of brightness values to choose
from. The lower the factor, the darker the image
@param max_factor: the upper value on the range... | set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.blur(image, radiu... | 86 | 86 | 289 | 8 | 78 | anuj0456/AugLy | augly/image/transforms.py | Python | RandomBrightness | RandomBrightness | 1,576 | 1,605 | 1,576 | 1,576 | 2dd3e210d0fbfee52414b92c06e2104d1aa3087a | bigcode/the-stack | train |
c152e11e69dc4146871b3ef8 | train | class | class ChangeAspectRatio(BaseTransform):
def __init__(self, ratio: float = 1.0, p: float = 1.0):
"""
@param ratio: aspect ratio, i.e. width/height, of the new image
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
... | class ChangeAspectRatio(BaseTransform):
| def __init__(self, ratio: float = 1.0, p: float = 1.0):
"""
@param ratio: aspect ratio, i.e. width/height, of the new image
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
self.ratio = ratio
def apply_transf... | name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.brightness(image, factor=self.factor, metadata=metadata)
class ChangeAspectRatio(BaseTransform):
| 69 | 69 | 231 | 7 | 62 | anuj0456/AugLy | augly/image/transforms.py | Python | ChangeAspectRatio | ChangeAspectRatio | 247 | 271 | 247 | 247 | c906ca61dd462b9af0b65e2146d52642035d30a8 | bigcode/the-stack | train |
70deaaae005df21aa8e1e466 | train | class | class RandomNoise(BaseTransform):
def __init__(
self, mean: float = 0.0, var: float = 0.01, seed: int = 42, p: float = 1.0
):
"""
@param mean: mean of the gaussian noise added
@param var: variance of the gaussian noise added
@param seed: if provided, this will set the r... | class RandomNoise(BaseTransform):
| def __init__(
self, mean: float = 0.0, var: float = 0.01, seed: int = 42, p: float = 1.0
):
"""
@param mean: mean of the gaussian noise added
@param var: variance of the gaussian noise added
@param seed: if provided, this will set the random seed before generating noise... | metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.pixe... | 87 | 87 | 290 | 6 | 81 | anuj0456/AugLy | augly/image/transforms.py | Python | RandomNoise | RandomNoise | 1,246 | 1,280 | 1,246 | 1,246 | c0faef45233bdbf03719b5ddcb563b7fa4dc8d3c | bigcode/the-stack | train |
e7201ae8aef55872af0633ad | train | class | class Blur(BaseTransform):
def __init__(self, radius: float = 2.0, p: float = 1.0):
"""
@param radius: the larger the radius, the blurrier the image
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
self.radius = r... | class Blur(BaseTransform):
| def __init__(self, radius: float = 2.0, p: float = 1.0):
"""
@param radius: the larger the radius, the blurrier the image
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
self.radius = radius
def apply_transf... | width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.apply_pil_filter(image, filter_type=self.filter_type, metadata=metadata)
class Blur(BaseTransform):
| 65 | 65 | 217 | 5 | 60 | anuj0456/AugLy | augly/image/transforms.py | Python | Blur | Blur | 191 | 215 | 191 | 191 | d120178ef99db2dd6d05b374b60ea6bac6919495 | bigcode/the-stack | train |
b9ff350056817f2b0b7b33b8 | train | class | class Pad(BaseTransform):
def __init__(
self,
w_factor: float = 0.25,
h_factor: float = 0.25,
color: Tuple[int, int, int] = utils.DEFAULT_COLOR,
p: float = 1.0,
):
"""
@param w_factor: width * w_factor pixels are padded to both left and
right o... | class Pad(BaseTransform):
| def __init__(
self,
w_factor: float = 0.25,
h_factor: float = 0.25,
color: Tuple[int, int, int] = utils.DEFAULT_COLOR,
p: float = 1.0,
):
"""
@param w_factor: width * w_factor pixels are padded to both left and
right of the image
@para... | will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.overlay_text(
image,
text=self.text,
font_file=self.font_file,
font_size=self.font_size,
... | 99 | 99 | 331 | 5 | 94 | anuj0456/AugLy | augly/image/transforms.py | Python | Pad | Pad | 1,093 | 1,137 | 1,093 | 1,093 | 65a750a8082632da295fd2c4b87431d31afc2899 | bigcode/the-stack | train |
248f7d912b628cbf92f2a8f7 | train | class | class PerspectiveTransform(BaseTransform):
def __init__(
self,
sigma: float = 50.0,
dx: float = 0.0,
dy: float = 0.0,
seed: Optional[int] = 42,
p: float = 1.0,
):
"""
@param sigma: the standard deviation of the distribution of destination
... | class PerspectiveTransform(BaseTransform):
| def __init__(
self,
sigma: float = 50.0,
dx: float = 0.0,
dy: float = 0.0,
seed: Optional[int] = 42,
p: float = 1.0,
):
"""
@param sigma: the standard deviation of the distribution of destination
coordinates. the larger the sigma value,... | the image such that it is now square-shaped
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no m... | 110 | 110 | 367 | 6 | 104 | anuj0456/AugLy | augly/image/transforms.py | Python | PerspectiveTransform | PerspectiveTransform | 1,169 | 1,215 | 1,169 | 1,169 | c194448f58ce21fe1ce065f8ef3da4cb62b6ac7a | bigcode/the-stack | train |
7360a907608bc11a84358f42 | train | class | class Sharpen(BaseTransform):
def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: a factor of below 1.0 blurs the image, a factor of 1.0 gives
the original image, and a factor greater than 1.0 sharpens the image
@param p: the probability of the transform ... | class Sharpen(BaseTransform):
| def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: a factor of below 1.0 blurs the image, a factor of 1.0 gives
the original image, and a factor greater than 1.0 sharpens the image
@param p: the probability of the transform being applied; default value i... | & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.scale(
image,
factor=self.factor,
interpolation=self.interpolation,
... | 75 | 75 | 253 | 6 | 69 | anuj0456/AugLy | augly/image/transforms.py | Python | Sharpen | Sharpen | 1,416 | 1,441 | 1,416 | 1,416 | 2d655d1d88c8df6174c1e1973663c7c53e228862 | bigcode/the-stack | train |
05b152f4e04d584270d199be | train | class | class OverlayImage(BaseTransform):
def __init__(
self,
overlay: Union[str, Image.Image],
opacity: float = 1.0,
overlay_size: float = 1.0,
x_pos: float = 0.4,
y_pos: float = 0.4,
p: float = 1.0,
):
"""
@param overlay: the path to an image or... | class OverlayImage(BaseTransform):
| def __init__(
self,
overlay: Union[str, Image.Image],
opacity: float = 1.0,
overlay_size: float = 1.0,
x_pos: float = 0.4,
y_pos: float = 0.4,
p: float = 1.0,
):
"""
@param overlay: the path to an image or a variable of type PIL.Image.Image... | augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
... | 128 | 128 | 427 | 6 | 122 | anuj0456/AugLy | augly/image/transforms.py | Python | OverlayImage | OverlayImage | 778 | 830 | 778 | 778 | 9aff4d1379b8a834711912e283f5e34b1bd9e6b8 | bigcode/the-stack | train |
8299b11cc23e15131c38a4ff | train | class | class ApplyLambda(BaseTransform):
def __init__(
self,
aug_function: Callable[..., Image.Image] = lambda x: x,
p: float = 1.0,
**kwargs,
):
"""
@param aug_function: the augmentation function to be applied onto the image
(should expect a PIL image as inp... | class ApplyLambda(BaseTransform):
| def __init__(
self,
aug_function: Callable[..., Image.Image] = lambda x: x,
p: float = 1.0,
**kwargs,
):
"""
@param aug_function: the augmentation function to be applied onto the image
(should expect a PIL image as input and return one)
@param... | such that they can
be used with Composition operators (such as `torchvision`'s) and to support
use cases where a specific transform with specific attributes needs to be
applied multiple times.
Example:
>>> image = Image.open("....")
>>> blur_tsfm = Blur(radius=5.0, p=0.5)
>>> blurred_image = blur_tsfm(image)
"""
c... | 88 | 88 | 294 | 6 | 82 | anuj0456/AugLy | augly/image/transforms.py | Python | ApplyLambda | ApplyLambda | 121 | 157 | 121 | 121 | a22bbbaaee8af14cd067b26ccce4734ddd4e2219 | bigcode/the-stack | train |
5ef9bfdd21df275220123a54 | train | class | class RandomEmojiOverlay(BaseTransform):
def __init__(
self,
emoji_directory: str = utils.SMILEY_EMOJI_DIR,
opacity: float = 1.0,
emoji_size: float = 0.15,
x_pos: float = 0.4,
y_pos: float = 0.4,
p: float = 1.0,
):
"""
@param emoji_director... | class RandomEmojiOverlay(BaseTransform):
| def __init__(
self,
emoji_directory: str = utils.SMILEY_EMOJI_DIR,
opacity: float = 1.0,
emoji_size: float = 0.15,
x_pos: float = 0.4,
y_pos: float = 0.4,
p: float = 1.0,
):
"""
@param emoji_directory: iopath directory uri containing the em... | : Optional[List[Dict[str, Any]]] = None
) -> Image.Image:
"""
Transform that randomly changes the brightness of an image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & ... | 134 | 134 | 448 | 7 | 127 | anuj0456/AugLy | augly/image/transforms.py | Python | RandomEmojiOverlay | RandomEmojiOverlay | 1,608 | 1,662 | 1,608 | 1,608 | 48139a6617fea2acca41c8e38eb017617bbb6fc2 | bigcode/the-stack | train |
8b3f1429bc6bc5dd9ca446df | train | class | class OverlayStripes(BaseTransform):
def __init__(
self,
line_width: float = 0.5,
line_color: Tuple[int, int, int] = utils.WHITE_RGB_COLOR,
line_angle: float = 0,
line_density: float = 0.5,
line_type: Optional[str] = "solid",
line_opacity: float = 1.0,
... | class OverlayStripes(BaseTransform):
| def __init__(
self,
line_width: float = 0.5,
line_color: Tuple[int, int, int] = utils.WHITE_RGB_COLOR,
line_angle: float = 0,
line_density: float = 0.5,
line_type: Optional[str] = "solid",
line_opacity: float = 1.0,
p: float = 1.0
):
"""
... | screenshotted on Instagram
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata wi... | 165 | 165 | 553 | 7 | 158 | anuj0456/AugLy | augly/image/transforms.py | Python | OverlayStripes | OverlayStripes | 964 | 1,025 | 964 | 964 | af6924f598042b56e77fc235e45f36ed0f2daf38 | bigcode/the-stack | train |
62cf7d7be56c0a488a42fb97 | train | class | class BaseRandomRangeTransform(BaseTransform):
def __init__(self, min_val: float, max_val: float, p: float = 1.0):
"""
@param min_val: the lower value of the range
@param max_val: the upper value of the range
@param p: the probability of the transform being applied; default value i... | class BaseRandomRangeTransform(BaseTransform):
| def __init__(self, min_val: float, max_val: float, p: float = 1.0):
"""
@param min_val: the lower value of the range
@param max_val: the upper value of the range
@param p: the probability of the transform being applied; default value is 1.0
"""
super().__init__(p)
... | force`"
if not force and random.random() > self.p:
return image
return self.apply_transform(image, metadata)
def apply_transform(
self, image: Image.Image, metadata: Optional[List[Dict[str, Any]]] = None
) -> Image.Image:
"""
This function is to be implemen... | 106 | 106 | 355 | 8 | 98 | anuj0456/AugLy | augly/image/transforms.py | Python | BaseRandomRangeTransform | BaseRandomRangeTransform | 63 | 102 | 63 | 63 | 3114248c5fad4a10354e290e46e554490e92303d | bigcode/the-stack | train |
576b1cdece3b76e72c30e11d | train | class | class VFlip(BaseTransform):
def apply_transform(
self, image: Image.Image, metadata: Optional[List[Dict[str, Any]]] = None
) -> Image.Image:
"""
Vertically flips an image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the fu... | class VFlip(BaseTransform):
| def apply_transform(
self, image: Image.Image, metadata: Optional[List[Dict[str, Any]]] = None
) -> Image.Image:
"""
Vertically flips an image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
... | will be appended to
the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.shuffle_pixels(
image, factor=self.factor, seed=self.seed, metadata=metadata
)
class VFlip(BaseTransform):
| 64 | 64 | 137 | 6 | 58 | anuj0456/AugLy | augly/image/transforms.py | Python | VFlip | VFlip | 1,481 | 1,496 | 1,481 | 1,481 | e73486ea9d53e6530e8004f924a56ba8d1739290 | bigcode/the-stack | train |
c62461c51182d7b5dadcb2ca | train | class | class ColorJitter(BaseTransform):
def __init__(
self,
brightness_factor: float = 1.0,
contrast_factor: float = 1.0,
saturation_factor: float = 1.0,
p: float = 1.0,
):
"""
@param brightness_factor: a brightness factor below 1.0 darkens the image,
... | class ColorJitter(BaseTransform):
| def __init__(
self,
brightness_factor: float = 1.0,
contrast_factor: float = 1.0,
saturation_factor: float = 1.0,
p: float = 1.0,
):
"""
@param brightness_factor: a brightness factor below 1.0 darkens the image,
a factor of 1.0 does not alter t... | given min and max
resolution
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata... | 125 | 125 | 418 | 7 | 118 | anuj0456/AugLy | augly/image/transforms.py | Python | ColorJitter | ColorJitter | 319 | 366 | 319 | 319 | d6a6ff26047d0df9c8993315071034c1ebc76eb6 | bigcode/the-stack | train |
b180dc5c516712408c7635d3 | train | class | class MaskedComposite(BaseTransform):
def __init__(
self, transform_function: BaseTransform, mask: Image.Image, p: float = 1.0
):
"""
@param mask: the path to an image or a variable of type PIL.Image.Image for
masking. This image can have mode “1”, “L”, or “RGBA”, and must ha... | class MaskedComposite(BaseTransform):
| def __init__(
self, transform_function: BaseTransform, mask: Image.Image, p: float = 1.0
):
"""
@param mask: the path to an image or a variable of type PIL.Image.Image for
masking. This image can have mode “1”, “L”, or “RGBA”, and must have the
same size as the ot... | an image
@param image: PIL Image to be augmented
@param metadata: if set to be a list, metadata about the function execution
including its name, the source & dest width, height, etc. will be appended to
the inputted list. If set to None, no metadata will be appended or returne... | 100 | 100 | 334 | 7 | 93 | anuj0456/AugLy | augly/image/transforms.py | Python | MaskedComposite | MaskedComposite | 596 | 634 | 596 | 596 | 9b7e4337f5e1c38e592984a79e2223e8b9378c34 | bigcode/the-stack | train |
f7058ebf30f9deacb8ae5dd1 | train | class | class Contrast(BaseTransform):
def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: zero gives a grayscale image, values below 1.0 decrease contrast,
a factor of 1.0 gives the original image, and a factor greater than 1.0
increases contrast
@pa... | class Contrast(BaseTransform):
| def __init__(self, factor: float = 1.0, p: float = 1.0):
"""
@param factor: zero gives a grayscale image, values below 1.0 decrease contrast,
a factor of 1.0 gives the original image, and a factor greater than 1.0
increases contrast
@param p: the probability of the t... | the inputted list. If set to None, no metadata will be appended or returned
@returns: Augmented PIL Image
"""
return F.color_jitter(
image,
brightness_factor=self.brightness_factor,
contrast_factor=self.contrast_factor,
saturation_factor=self.sat... | 75 | 75 | 251 | 5 | 70 | anuj0456/AugLy | augly/image/transforms.py | Python | Contrast | Contrast | 369 | 395 | 369 | 369 | a0b1bae4404c610235757f23bed462cb28b9f5a0 | bigcode/the-stack | train |
8ca01e4ee78cb49353eff9c2 | train | function | def get_samples(data_prefix, name):
# This should be a barrier but nccl barrier assumes
# device_index=rank which is not the case for model
# parallel case
counts = torch.cuda.LongTensor([1])
torch.distributed.all_reduce(counts, group=mpu.get_data_parallel_group())
torch.distributed.all_reduce(c... | def get_samples(data_prefix, name):
# This should be a barrier but nccl barrier assumes
# device_index=rank which is not the case for model
# parallel case
| counts = torch.cuda.LongTensor([1])
torch.distributed.all_reduce(counts, group=mpu.get_data_parallel_group())
torch.distributed.all_reduce(counts, group=mpu.get_pipeline_model_parallel_group())
assert counts[0].item() == (
torch.distributed.get_world_size() //
torch.distributed.get_world... | start = int(ind * self.step * self.fs)
noisy_input[ind] = noisy_np[0, start:start + self.step_samples]
clean_input[ind] = clean_np[0, start:start + self.step_samples]
train_sample = {
'noisy_signal': noisy_input,
'clean_signal': clean_input,
... | 122 | 122 | 408 | 40 | 81 | iphysresearch/megatron-gw | megatron/data/gw_dataset.py | Python | get_samples | get_samples | 70 | 105 | 70 | 73 | b1c8c1c45a73263deb80b86b79dad32c6e7299b4 | bigcode/the-stack | train |
8386d0182b8fd1bfe6eb618c | train | class | class GwDataset(torch.utils.data.Dataset):
def __init__(self, name, data_prefix, seed=1234):
# Params to store.
self.name = name
self.seed = seed
# Build the samples.
self.samples = get_samples(data_prefix, self.name)
self.noisy = self.samples['noisy']
self... | class GwDataset(torch.utils.data.Dataset):
| def __init__(self, name, data_prefix, seed=1234):
# Params to store.
self.name = name
self.seed = seed
# Build the samples.
self.samples = get_samples(data_prefix, self.name)
self.noisy = self.samples['noisy']
self.clean = self.samples['clean']
self.... |
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
... | 110 | 110 | 368 | 8 | 102 | iphysresearch/megatron-gw | megatron/data/gw_dataset.py | Python | GwDataset | GwDataset | 27 | 68 | 27 | 28 | abd82d8639e19e1582eeff777295d561b2eb864f | bigcode/the-stack | train |
5cf58b37fe110051bf3a9244 | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_allowed_context():
context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, allowed_contexts=[context]
)
command = Command(name=COMMAND1)
return command_bu... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_allowed_context():
| context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, allowed_contexts=[context]
)
command = Command(name=COMMAND1)
return command_builder, [context], command
| command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, version=version
)
contexts = []
command = Command(name=COMMAND1)
return command_builder, contexts, command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_allowed_context():
| 64 | 64 | 81 | 16 | 47 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_allowed_context | case_command_builder_with_allowed_context | 66 | 74 | 66 | 67 | b5a4cf37146e8e2e1e3d823ec77d717a3ccc893b | bigcode/the-stack | train |
7179eea6d6d4e34bf36de819 | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_add_and_clear_contexts():
context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
def... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_add_and_clear_contexts():
| context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={
context1: Con... | Command(
name=COMMAND1,
args=[ARG1, ARG2, ARG3, ARG4, ARG5, ARG6],
)
return command_builder, [context1, context2], command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_add_and_clear_contexts():
| 64 | 64 | 145 | 19 | 44 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_add_and_clear_contexts | case_command_builder_with_add_and_clear_contexts | 164 | 179 | 164 | 165 | 0d93cb90097c43566c0ee2b01bfb0134395f2230 | bigcode/the-stack | train |
47a7bc2bf9db03adfcb7068f | train | function | @parametrize_with_cases(
argnames=["command_builder", "contexts", "command"],
cases=THIS_MODULE,
has_tag=SUCCESSFUL_TAG,
)
def test_command_builder_match_contexts(command_builder, contexts, command):
assert command_builder.match_contexts(*contexts)
| @parametrize_with_cases(
argnames=["command_builder", "contexts", "command"],
cases=THIS_MODULE,
has_tag=SUCCESSFUL_TAG,
)
def test_command_builder_match_contexts(command_builder, contexts, command):
| assert command_builder.match_contexts(*contexts)
| , contexts, command):
assert command_builder.build_command(*contexts) == command
@parametrize_with_cases(
argnames=["command_builder", "contexts", "command"],
cases=THIS_MODULE,
has_tag=SUCCESSFUL_TAG,
)
def test_command_builder_match_contexts(command_builder, contexts, command):
| 64 | 64 | 57 | 47 | 16 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | test_command_builder_match_contexts | test_command_builder_match_contexts | 191 | 197 | 191 | 196 | 478f1f556cfb9dc96c9aa0b4e4fa297e6a583ae5 | bigcode/the-stack | train |
7de77e61c07b04ca9c0b5de4 | train | function | @case(tags=FAILED_TAG)
def case_command_builder_with_not_allowed_context():
context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
context3 = Context(name=CONTEXT3, help=CONTEXT_HELP_STRING3)
context4 = Context(name=CONTEXT4, help=CONTEX... | @case(tags=FAILED_TAG)
def case_command_builder_with_not_allowed_context():
| context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
context3 = Context(name=CONTEXT3, help=CONTEXT_HELP_STRING3)
context4 = Context(name=CONTEXT4, help=CONTEXT_HELP_STRING4)
command_builder = CommandBuilder(
name=COMMAND1,... | ]
)
error_message = (
f"Command `{COMMAND1}`requires the following contexts, "
f"which are missing: {CONTEXT1}"
)
return command_builder, [context2], error_message
@case(tags=FAILED_TAG)
def case_command_builder_with_not_allowed_context():
| 64 | 64 | 194 | 16 | 47 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_not_allowed_context | case_command_builder_with_not_allowed_context | 218 | 235 | 218 | 219 | b8dd8f1725bfc602b7ecd70b3a7aad833ba7a0a3 | bigcode/the-stack | train |
e9e5e219f5e4ecd4ba735fbd | train | function | @parametrize_with_cases(
argnames=["command_builder", "contexts", "error_message"],
cases=THIS_MODULE,
has_tag=FAILED_TAG,
)
def test_command_builder_build_command_failed(command_builder, contexts, error_message):
with pytest.raises(InvalidCommand, match=f"^{error_message}$"):
command_builder.bu... | @parametrize_with_cases(
argnames=["command_builder", "contexts", "error_message"],
cases=THIS_MODULE,
has_tag=FAILED_TAG,
)
def test_command_builder_build_command_failed(command_builder, contexts, error_message):
| with pytest.raises(InvalidCommand, match=f"^{error_message}$"):
command_builder.build_command(*contexts)
| )
return command_builder, [context1, context2], error_message
@parametrize_with_cases(
argnames=["command_builder", "contexts", "error_message"],
cases=THIS_MODULE,
has_tag=FAILED_TAG,
)
def test_command_builder_build_command_failed(command_builder, contexts, error_message):
| 64 | 64 | 72 | 48 | 15 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | test_command_builder_build_command_failed | test_command_builder_build_command_failed | 238 | 245 | 238 | 243 | 020db77def57d34956c246287af29683a77a5b43 | bigcode/the-stack | train |
2a64c45100cc404235550a30 | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_overriding_args():
context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={
con... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_overriding_args():
| context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={
context: ContextSpecification(args=[ARG3, ARG4, ARG5])
},
)
com... | command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, required_contexts=[context]
)
command = Command(name=COMMAND1)
return command_builder, [context], command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_overriding_args():
| 64 | 64 | 122 | 18 | 45 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_overriding_args | case_command_builder_with_overriding_args | 99 | 112 | 99 | 100 | 6e593a29265ac9e4f3360347109721af3d10ebbe | bigcode/the-stack | train |
a49594a5881007ae38f2fbd9 | train | function | @parametrize_with_cases(
argnames=["command_builder", "contexts", "command"],
cases=THIS_MODULE,
has_tag=SUCCESSFUL_TAG,
)
def test_command_builder_build_command_successfully(command_builder, contexts, command):
assert command_builder.build_command(*contexts) == command
| @parametrize_with_cases(
argnames=["command_builder", "contexts", "command"],
cases=THIS_MODULE,
has_tag=SUCCESSFUL_TAG,
)
def test_command_builder_build_command_successfully(command_builder, contexts, command):
| assert command_builder.build_command(*contexts) == command
| 1)
return command_builder, [context1, context2], command
@parametrize_with_cases(
argnames=["command_builder", "contexts", "command"],
cases=THIS_MODULE,
has_tag=SUCCESSFUL_TAG,
)
def test_command_builder_build_command_successfully(command_builder, contexts, command):
| 64 | 64 | 60 | 48 | 15 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | test_command_builder_build_command_successfully | test_command_builder_build_command_successfully | 182 | 188 | 182 | 187 | 55caff59615687428ba4778b8fbf0aacfd816902 | bigcode/the-stack | train |
93fd87bcaac7973642664cce | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_default_args():
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, default_args=[ARG1, ARG2]
)
contexts = []
command = Command(name=COMMAND1, args=[ARG1, ARG2])
return command_builder, contexts, command
| @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_default_args():
| command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, default_args=[ARG1, ARG2]
)
contexts = []
command = Command(name=COMMAND1, args=[ARG1, ARG2])
return command_builder, contexts, command
| _TAG)
def case_simple_command_builder():
command_builder = CommandBuilder(name=COMMAND1, help=COMMAND_HELP_STRING1)
contexts = []
command = Command(name=COMMAND1)
return command_builder, contexts, command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_default_args():
| 64 | 64 | 77 | 16 | 47 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_default_args | case_command_builder_with_default_args | 43 | 51 | 43 | 44 | 3fd57a4893615cdc3bff0d986a732e46ac740b27 | bigcode/the-stack | train |
31ce7a6acb20d720eb81cff7 | train | function | @case(tags=FAILED_TAG)
def case_command_builder_missing_required_context():
context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, required_contexts=[context... | @case(tags=FAILED_TAG)
def case_command_builder_missing_required_context():
| context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, required_contexts=[context1]
)
error_message = (
f"Command `{COMMAND1}`requires the fo... | "contexts", "command"],
cases=THIS_MODULE,
has_tag=SUCCESSFUL_TAG,
)
def test_command_builder_match_contexts(command_builder, contexts, command):
assert command_builder.match_contexts(*contexts)
# Failure tests
@case(tags=FAILED_TAG)
def case_command_builder_missing_required_context():
| 64 | 64 | 127 | 15 | 48 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_missing_required_context | case_command_builder_missing_required_context | 203 | 215 | 203 | 204 | d51e01fbb9b1b1146021aa1e8d4ab94d46312f11 | bigcode/the-stack | train |
d46b67946ce8aaba44dac188 | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_allowed_context_by_default():
command_builder = CommandBuilder(name=COMMAND1, help=COMMAND_HELP_STRING1)
contexts = [
Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1, allowed_by_default=True)
]
command = Command(name=COMMAND1)
return... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_allowed_context_by_default():
| command_builder = CommandBuilder(name=COMMAND1, help=COMMAND_HELP_STRING1)
contexts = [
Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1, allowed_by_default=True)
]
command = Command(name=COMMAND1)
return command_builder, contexts, command
| command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, allowed_contexts=[context]
)
command = Command(name=COMMAND1)
return command_builder, [context], command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_allowed_context_by_default():
| 64 | 64 | 81 | 18 | 45 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_allowed_context_by_default | case_command_builder_with_allowed_context_by_default | 77 | 85 | 77 | 78 | c1b23ffa23a3de29bb805e5605752242e7c384d0 | bigcode/the-stack | train |
519b8de373d7ada82ada6337 | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_added_args():
context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={context: ContextSpeci... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_added_args():
| context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={context: ContextSpecification(add_args=[ARG3, ARG4])},
)
command = Command(name=COMM... | : ContextSpecification(args=[ARG3, ARG4, ARG5])
},
)
command = Command(name=COMMAND1, args=[ARG3, ARG4, ARG5])
return command_builder, [context], command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_added_args():
| 64 | 64 | 119 | 16 | 47 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_added_args | case_command_builder_with_added_args | 115 | 126 | 115 | 116 | db3a3a4a9ad7bd9f32836dbfb9277ff76e0f38a4 | bigcode/the-stack | train |
bc450f2dbe7026a1cc926cf8 | train | function | @case(tags=SUCCESSFUL_TAG)
def case_simple_command_builder():
command_builder = CommandBuilder(name=COMMAND1, help=COMMAND_HELP_STRING1)
contexts = []
command = Command(name=COMMAND1)
return command_builder, contexts, command
| @case(tags=SUCCESSFUL_TAG)
def case_simple_command_builder():
| command_builder = CommandBuilder(name=COMMAND1, help=COMMAND_HELP_STRING1)
contexts = []
command = Command(name=COMMAND1)
return command_builder, contexts, command
| ,
CONTEXT_HELP_STRING1,
CONTEXT_HELP_STRING2,
CONTEXT_HELP_STRING3,
CONTEXT_HELP_STRING4,
FAILED_TAG,
SUCCESSFUL_TAG,
)
# Successful tests
from tests.util import dummy_version
@case(tags=SUCCESSFUL_TAG)
def case_simple_command_builder():
| 64 | 64 | 54 | 14 | 49 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_simple_command_builder | case_simple_command_builder | 34 | 40 | 34 | 35 | 0682bd5ca13957c9b46ed80c8031b0f579f4be75 | bigcode/the-stack | train |
6eebbc046ca57c090305623b | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_clear_args():
context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={context: ContextSpeci... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_clear_args():
| context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={context: ContextSpecification(clear_args=True)},
)
command = Command(name=COMMAND1)
... | : ContextSpecification(add_args=[ARG3, ARG4])},
)
command = Command(name=COMMAND1, args=[ARG1, ARG2, ARG3, ARG4])
return command_builder, [context], command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_clear_args():
| 64 | 64 | 99 | 16 | 47 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_clear_args | case_command_builder_with_clear_args | 129 | 140 | 129 | 130 | 7db3ecc8c1e8763cafeb9e06269b7d2c6b9a985c | bigcode/the-stack | train |
50371b3b8bcdb135c3aa40ce | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_two_added_args_contexts():
context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
de... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_two_added_args_contexts():
| context1 = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
context2 = Context(name=CONTEXT2, help=CONTEXT_HELP_STRING2)
command_builder = CommandBuilder(
name=COMMAND1,
help=COMMAND_HELP_STRING1,
default_args=[ARG1, ARG2],
contexts_specifications={
context1: Con... | ,
default_args=[ARG1, ARG2],
contexts_specifications={context: ContextSpecification(clear_args=True)},
)
command = Command(name=COMMAND1)
return command_builder, [context], command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_two_added_args_contexts():
| 64 | 64 | 175 | 19 | 44 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_two_added_args_contexts | case_command_builder_with_two_added_args_contexts | 143 | 161 | 143 | 144 | 86f0229f9a70353cccc22da018b0174d0b762ade | bigcode/the-stack | train |
0497cd4d596d7e9baab93adf | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_version():
version = dummy_version()
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, version=version
)
contexts = []
command = Command(name=COMMAND1)
return command_builder, contexts, command
| @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_version():
| version = dummy_version()
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, version=version
)
contexts = []
command = Command(name=COMMAND1)
return command_builder, contexts, command
| , help=COMMAND_HELP_STRING1, default_args=[ARG1, ARG2]
)
contexts = []
command = Command(name=COMMAND1, args=[ARG1, ARG2])
return command_builder, contexts, command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_version():
| 64 | 64 | 69 | 15 | 48 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_version | case_command_builder_with_version | 54 | 63 | 54 | 55 | 1f7338f5dc54c57fa4e212635e6ad1b52914bd4d | bigcode/the-stack | train |
3aad4a86720adc6f1d1cc9fd | train | function | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_required_context():
context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, required_contexts=[context]
)
command = Command(name=COMMAND1)
return command_... | @case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_required_context():
| context = Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1)
command_builder = CommandBuilder(
name=COMMAND1, help=COMMAND_HELP_STRING1, required_contexts=[context]
)
command = Command(name=COMMAND1)
return command_builder, [context], command
| _STRING1)
contexts = [
Context(name=CONTEXT1, help=CONTEXT_HELP_STRING1, allowed_by_default=True)
]
command = Command(name=COMMAND1)
return command_builder, contexts, command
@case(tags=SUCCESSFUL_TAG)
def case_command_builder_with_required_context():
| 64 | 64 | 81 | 16 | 47 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | case_command_builder_with_required_context | case_command_builder_with_required_context | 88 | 96 | 88 | 89 | 28ee18a6986d58b8c4b803f0c8a4c84d013a0d98 | bigcode/the-stack | train |
16db8f9f9de173a2c54e4748 | train | function | @parametrize_with_cases(
argnames=["command_builder", "contexts", "error_message"],
cases=THIS_MODULE,
has_tag=FAILED_TAG,
)
def test_command_builder_does_not_match_contexts(
command_builder, contexts, error_message
):
assert not command_builder.match_contexts(*contexts)
| @parametrize_with_cases(
argnames=["command_builder", "contexts", "error_message"],
cases=THIS_MODULE,
has_tag=FAILED_TAG,
)
def test_command_builder_does_not_match_contexts(
command_builder, contexts, error_message
):
| assert not command_builder.match_contexts(*contexts)
| }$"):
command_builder.build_command(*contexts)
@parametrize_with_cases(
argnames=["command_builder", "contexts", "error_message"],
cases=THIS_MODULE,
has_tag=FAILED_TAG,
)
def test_command_builder_does_not_match_contexts(
command_builder, contexts, error_message
):
| 64 | 64 | 65 | 54 | 10 | EddLabs/eddington-static | tests/command_builder/test_command_builder_build_command.py | Python | test_command_builder_does_not_match_contexts | test_command_builder_does_not_match_contexts | 248 | 256 | 248 | 255 | 8b618182bad30757b5db15649accabfb96536b05 | bigcode/the-stack | train |
76a1c1b0febcdd456423ad23 | train | class | class PluginAntispamResultsRequest(RpcRequest):
def __init__(self):
RpcRequest.__init__(self, 'Green', '2016-11-15', 'PluginAntispamResults','green')
self.set_method('POST')
def get_BizScene(self):
return self.get_query_params().get('BizScene')
def set_BizScene(self,BizScene):
self.add_query_param('BizSce... | class PluginAntispamResultsRequest(RpcRequest):
| def __init__(self):
RpcRequest.__init__(self, 'Green', '2016-11-15', 'PluginAntispamResults','green')
self.set_method('POST')
def get_BizScene(self):
return self.get_query_params().get('BizScene')
def set_BizScene(self,BizScene):
self.add_query_param('BizScene',BizScene)
def get_ClientVersion(self):
re... | writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from aliyunsdkcore.request import RpcRequest
class ... | 76 | 76 | 256 | 11 | 64 | xiaozhao1/aliyun-openapi-python-sdk | aliyun-python-sdk-green/aliyunsdkgreen/request/v20161115/PluginAntispamResultsRequest.py | Python | PluginAntispamResultsRequest | PluginAntispamResultsRequest | 21 | 55 | 21 | 22 | ac40f66e94b3a53069906fa4f969d06bce841895 | bigcode/the-stack | train |
c6273893c42f89b8197b6062 | train | function | @auth.get_password
def get_password(username):
if username == 'admin':
return 'admin'
return None
| @auth.get_password
def get_password(username):
| if username == 'admin':
return 'admin'
return None
| from flask import jsonify, make_response
from app import auth
@auth.get_password
def get_password(username):
| 23 | 64 | 26 | 10 | 12 | BamX/dota2-matches-statistic | app/authinfo.py | Python | get_password | get_password | 4 | 8 | 4 | 5 | 760652afba0d1fe371438f4f1a767ab7afa7ba30 | bigcode/the-stack | train |
329cc4c289f463109abc8327 | train | function | @auth.error_handler
def unauthorized():
return make_response(jsonify({'error': 'Unauthorized access'}), 403)
| @auth.error_handler
def unauthorized():
| return make_response(jsonify({'error': 'Unauthorized access'}), 403)
| from flask import jsonify, make_response
from app import auth
@auth.get_password
def get_password(username):
if username == 'admin':
return 'admin'
return None
@auth.error_handler
def unauthorized():
| 47 | 64 | 25 | 8 | 38 | BamX/dota2-matches-statistic | app/authinfo.py | Python | unauthorized | unauthorized | 10 | 12 | 10 | 11 | 3c4a643a96487ec43438b2356ffd1951753b15aa | bigcode/the-stack | train |
1e236f19b3b36bd1a6a02196 | train | function | def get_country_code(country_name):
"""Return the Pygal 2-digit country code for the given country."""
for code, name in COUNTRIES.items():
if name == country_name:
return code
# If the country wasn't found, return None
return None
| def get_country_code(country_name):
| """Return the Pygal 2-digit country code for the given country."""
for code, name in COUNTRIES.items():
if name == country_name:
return code
# If the country wasn't found, return None
return None
|
from pygal.maps.world import COUNTRIES
def get_country_code(country_name):
| 17 | 64 | 59 | 7 | 9 | dantin/python-by-example | crash_course/ch16/exec/country_codes.py | Python | get_country_code | get_country_code | 5 | 12 | 5 | 5 | b7e6c3b12799cdb1cb2e3377865e3d53bc5a5e48 | bigcode/the-stack | train |
4500616797339dbac67b83ea | train | function | def generate_date_intervals(
from_date: datetime.date,
to_date: datetime.date,
output_period: datetime.timedelta=datetime.timedelta(days=1),
start_with_end: bool = True,
) -> List[datetime.date]:
dates = []
comparison : Callable[[datetime.date, datetime.date], bool]
if start_with_end:
... | def generate_date_intervals(
from_date: datetime.date,
to_date: datetime.date,
output_period: datetime.timedelta=datetime.timedelta(days=1),
start_with_end: bool = True,
) -> List[datetime.date]:
| dates = []
comparison : Callable[[datetime.date, datetime.date], bool]
if start_with_end:
start_date = to_date
end_date = from_date
delta = -output_period
comparison = lambda x, y: x >= y
else:
start_date = from_date
end_date = to_date
delta = outp... | dates.append(current_date)
current_date += delta
return dates
def generate_date_intervals(
from_date: datetime.date,
to_date: datetime.date,
output_period: datetime.timedelta=datetime.timedelta(days=1),
start_with_end: bool = True,
) -> List[datetime.date]:
| 64 | 64 | 170 | 48 | 15 | webclinic017/invertimo | finance/utils.py | Python | generate_date_intervals | generate_date_intervals | 32 | 55 | 32 | 37 | c36c41d4c13c985e1d0ab4c5dee8a2c6008e3119 | bigcode/the-stack | train |
da7217aa09344e58d3f9be4b | train | function | def generate_datetime_intervals(
from_date: datetime.datetime,
to_date: datetime.datetime,
output_period: datetime.timedelta,
start_with_end: bool = True,
) -> List[datetime.datetime]:
dates = []
comparison : Callable[[datetime.datetime, datetime.datetime], bool]
if start_with_end:
s... | def generate_datetime_intervals(
from_date: datetime.datetime,
to_date: datetime.datetime,
output_period: datetime.timedelta,
start_with_end: bool = True,
) -> List[datetime.datetime]:
| dates = []
comparison : Callable[[datetime.datetime, datetime.datetime], bool]
if start_with_end:
start_date = to_date
end_date = from_date
delta = -output_period
comparison = lambda x, y: x >= y
else:
start_date = from_date
end_date = to_date
delt... | import datetime
from typing import List
from typing import Callable
def generate_datetime_intervals(
from_date: datetime.datetime,
to_date: datetime.datetime,
output_period: datetime.timedelta,
start_with_end: bool = True,
) -> List[datetime.datetime]:
| 56 | 64 | 166 | 43 | 12 | webclinic017/invertimo | finance/utils.py | Python | generate_datetime_intervals | generate_datetime_intervals | 6 | 29 | 6 | 11 | a81c5fcc974653fda1f134ecdd79ca5f6265993f | bigcode/the-stack | train |
b9d7a836e5795410504771b3 | train | class | class TestLeakyReLUFrontExtractorOp(unittest.TestCase):
def test_extract_leaky_relu_layer(self):
graph = build_graph(
{'node_1': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'},
'act_node': {'type': 'LeakyReLU', 'kind': 'op', 'op': 'LeakyReLU', },
'node_2': {'typ... | class TestLeakyReLUFrontExtractorOp(unittest.TestCase):
| def test_extract_leaky_relu_layer(self):
graph = build_graph(
{'node_1': {'type': 'Parameter', 'kind': 'op', 'op': 'Parameter'},
'act_node': {'type': 'LeakyReLU', 'kind': 'op', 'op': 'LeakyReLU', },
'node_2': {'type': 'Identity', 'kind': 'op'},
},
... | """
Copyright (C) 2018-2021 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to i... | 177 | 199 | 665 | 13 | 163 | calvinfeng/openvino | model-optimizer/extensions/front/mxnet/leaky_relu_test.py | Python | TestLeakyReLUFrontExtractorOp | TestLeakyReLUFrontExtractorOp | 26 | 88 | 26 | 26 | 4009ad2535e61b0f9397054857562780f7c51ba1 | bigcode/the-stack | train |
0beb736e2b53a53740234e6b | train | function | def parse_csv_value(value: str, col_type: str) -> Union[str, float, int, bool]:
"""Parse string value from csv, according to COLUMN_TYPES"""
rv: Union[str, float, int, bool] = value
try:
if col_type == "d":
rv = float(value)
elif col_type == "l":
rv = int(round(float(... | def parse_csv_value(value: str, col_type: str) -> Union[str, float, int, bool]:
| """Parse string value from csv, according to COLUMN_TYPES"""
rv: Union[str, float, int, bool] = value
try:
if col_type == "d":
rv = float(value)
elif col_type == "l":
rv = int(round(float(value)))
elif col_type == "b":
rv = bool(value)
except V... | , for integer numbers
# s: StringColumn, for text
# b: BoolColumn, for true/false
COLUMN_TYPES = ["d", "l", "s", "b"]
def parse_csv_value(value: str, col_type: str) -> Union[str, float, int, bool]:
| 63 | 64 | 110 | 23 | 40 | glyg/ome-zarr-py | ome_zarr/csv.py | Python | parse_csv_value | parse_csv_value | 16 | 28 | 16 | 16 | 116a9723df374727aca893b330a885afd7d9f338 | bigcode/the-stack | train |
1dcdc0549ab535225b19285e | train | function | def csv_to_zarr(
csv_path: str, csv_id: str, csv_keys: str, zarr_path: str, zarr_id: str
) -> None:
"""
Add keys:values from a CSV file to the label properties of a Plate or Image
For each labels properties dict in the Plate or Image at zarr_path, we pick the
value of the property named zarr_id. Th... | def csv_to_zarr(
csv_path: str, csv_id: str, csv_keys: str, zarr_path: str, zarr_id: str
) -> None:
| """
Add keys:values from a CSV file to the label properties of a Plate or Image
For each labels properties dict in the Plate or Image at zarr_path, we pick the
value of the property named zarr_id. This value should match a value from a row of
the CSV table, with the column name given by csv_id. The... | integer numbers
# s: StringColumn, for text
# b: BoolColumn, for true/false
COLUMN_TYPES = ["d", "l", "s", "b"]
def parse_csv_value(value: str, col_type: str) -> Union[str, float, int, bool]:
"""Parse string value from csv, according to COLUMN_TYPES"""
rv: Union[str, float, int, bool] = value
try:
... | 187 | 187 | 626 | 38 | 148 | glyg/ome-zarr-py | ome_zarr/csv.py | Python | csv_to_zarr | csv_to_zarr | 31 | 89 | 31 | 33 | 73c7e0da52b3f1f60bb30185f5dbc7e99f050249 | bigcode/the-stack | train |
7cdd31f195c6ca03e1ebf579 | train | function | def dict_to_zarr(
props_to_add: Dict[Union[str, int], Dict], zarr_path: str, zarr_id: str
) -> None:
"""
Add keys:values to the label properties of a ome-zarr Plate or Image.
For each labels properties dict in the Plate or Image at zarr_path, we pick the
value of the property named zarr_id. This va... | def dict_to_zarr(
props_to_add: Dict[Union[str, int], Dict], zarr_path: str, zarr_id: str
) -> None:
| """
Add keys:values to the label properties of a ome-zarr Plate or Image.
For each labels properties dict in the Plate or Image at zarr_path, we pick the
value of the property named zarr_id. This value should match a key of the
props_to_add Dict to find a Dict who's keys and values are added to the... | "csv column name: {csv_columns}"
)
id_column = csv_columns.index(csv_id)
else:
row_id = row[id_column]
row_props = {}
for col_name, value in zip(csv_columns, row):
if col_name in cols_types_by_name:
... | 147 | 147 | 492 | 36 | 111 | glyg/ome-zarr-py | ome_zarr/csv.py | Python | dict_to_zarr | dict_to_zarr | 92 | 144 | 92 | 94 | ff6137416b59a72db5b02498a204d4df0416c32a | bigcode/the-stack | train |
ca6d00f78bd1fe175e0fec2f | train | class | class msg_cfcheckpt:
__slots__ = ("filter_type", "stop_hash", "headers")
msgtype = b"cfcheckpt"
def __init__(self, filter_type=None, stop_hash=None, headers=None):
self.filter_type = filter_type
self.stop_hash = stop_hash
self.headers = headers
def deserialize(self, f):
... | class msg_cfcheckpt:
| __slots__ = ("filter_type", "stop_hash", "headers")
msgtype = b"cfcheckpt"
def __init__(self, filter_type=None, stop_hash=None, headers=None):
self.filter_type = filter_type
self.stop_hash = stop_hash
self.headers = headers
def deserialize(self, f):
self.filter_type = ... | ", self.filter_type)
r += ser_uint256(self.stop_hash)
return r
def __repr__(self):
return "msg_getcfcheckpt(filter_type={:#x}, stop_hash={:x})".format(
self.filter_type, self.stop_hash)
class msg_cfcheckpt:
| 64 | 64 | 202 | 6 | 58 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_cfcheckpt | msg_cfcheckpt | 1,812 | 1,835 | 1,812 | 1,812 | 40f92f2ba3cededf8276d84c0a820b528b0a6fab | bigcode/the-stack | train |
eb51826760ab88f8e80fba00 | train | function | def deser_string(f):
nit = deser_compact_size(f)
return f.read(nit)
| def deser_string(f):
| nit = deser_compact_size(f)
return f.read(nit)
| .unpack("<H", f.read(2))[0]
elif nit == 254:
nit = struct.unpack("<I", f.read(4))[0]
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
return nit
def deser_string(f):
| 64 | 64 | 21 | 5 | 58 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | deser_string | deser_string | 96 | 98 | 96 | 96 | 528b93c5ba25eed124ba00dea862cf54614ca9b4 | bigcode/the-stack | train |
9bb23592909d419455ca825a | train | class | class msg_pong:
__slots__ = ("nonce",)
msgtype = b"pong"
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
d... | class msg_pong:
| __slots__ = ("nonce",)
msgtype = b"pong"
def __init__(self, nonce=0):
self.nonce = nonce
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self... | serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
r += struct.pack("<i", self.height)
return r
def __repr__(self):
return "msg_ping(nonce=%08x)" % self.nonce
class msg_pong:
| 64 | 64 | 115 | 5 | 58 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_pong | msg_pong | 1,374 | 1,390 | 1,374 | 1,374 | 83452d9701ba4f3fd64c9ecbc29a4412e2025616 | bigcode/the-stack | train |
b1275a3be19d4bb832c4f386 | train | function | def from_hex(obj, hex_string):
"""Deserialize from a hex string representation (e.g. from RPC)
Note that there is no complementary helper like e.g. `to_hex` for the
inverse operation. To serialize a message object to a hex string, simply
use obj.serialize().hex()"""
obj.deserialize(BytesIO(bytes.fr... | def from_hex(obj, hex_string):
| """Deserialize from a hex string representation (e.g. from RPC)
Note that there is no complementary helper like e.g. `to_hex` for the
inverse operation. To serialize a message object to a hex string, simply
use obj.serialize().hex()"""
obj.deserialize(BytesIO(bytes.fromhex(hex_string)))
return ... | _ in range(nit):
t = deser_string(f)
r.append(t)
return r
def ser_string_vector(l):
r = ser_compact_size(len(l))
for sv in l:
r += ser_string(sv)
return r
def from_hex(obj, hex_string):
| 64 | 64 | 81 | 8 | 55 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | from_hex | from_hex | 193 | 200 | 193 | 193 | d62b1e0c0af3afa86e04cc03f17d814b04121828 | bigcode/the-stack | train |
5c83e2c0657886c7b42822b0 | train | class | class msg_version:
__slots__ = ("addrFrom", "addrTo", "nNonce", "relay", "nServices",
"nStartingHeight", "nTime", "nVersion", "strSubVer")
msgtype = b"version"
def __init__(self):
self.nVersion = 0
self.nServices = 0
self.nTime = int(time.time())
self.addrTo... | class msg_version:
| __slots__ = ("addrFrom", "addrTo", "nNonce", "relay", "nServices",
"nStartingHeight", "nTime", "nVersion", "strSubVer")
msgtype = b"version"
def __init__(self):
self.nVersion = 0
self.nServices = 0
self.nTime = int(time.time())
self.addrTo = CAddress()
... | return "CPartialMerkleTree(nTransactions=%d, vHash=%s, vBits=%s)" % (self.nTransactions, repr(self.vHash), repr(self.vBits))
class CMerkleBlock:
__slots__ = ("header", "txn")
def __init__(self):
self.header = CBlockHeader()
self.txn = CPartialMerkleTree()
def deserialize(self, f)... | 179 | 179 | 599 | 4 | 174 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_version | msg_version | 1,064 | 1,121 | 1,064 | 1,064 | 1afb0b34d3227e7013b087325476d402e323709f | bigcode/the-stack | train |
f079c2e2627c6e21aec6d6df | train | class | class CTxInWitness:
__slots__ = ("scriptWitness",)
def __init__(self):
self.scriptWitness = CScriptWitness()
def deserialize(self, f):
self.scriptWitness.stack = deser_string_vector(f)
def serialize(self):
return ser_string_vector(self.scriptWitness.stack)
def __repr__(se... | class CTxInWitness:
| __slots__ = ("scriptWitness",)
def __init__(self):
self.scriptWitness = CScriptWitness()
def deserialize(self, f):
self.scriptWitness.stack = deser_string_vector(f)
def serialize(self):
return ser_string_vector(self.scriptWitness.stack)
def __repr__(self):
return ... | strings
self.stack = []
def __repr__(self):
return "CScriptWitness(%s)" % \
(",".join([x.hex() for x in self.stack]))
def is_null(self):
if self.stack:
return False
return True
class CTxInWitness:
| 64 | 64 | 93 | 6 | 57 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | CTxInWitness | CTxInWitness | 454 | 470 | 454 | 454 | da68a4a05859819f9797c65288e5f32ef6362570 | bigcode/the-stack | train |
173cff16c9f2e259f01e24da | train | class | class msg_getcfcheckpt:
__slots__ = ("filter_type", "stop_hash")
msgtype = b"getcfcheckpt"
def __init__(self, filter_type, stop_hash):
self.filter_type = filter_type
self.stop_hash = stop_hash
def deserialize(self, f):
self.filter_type = struct.unpack("<B", f.read(1))[0]
... | class msg_getcfcheckpt:
| __slots__ = ("filter_type", "stop_hash")
msgtype = b"getcfcheckpt"
def __init__(self, filter_type, stop_hash):
self.filter_type = filter_type
self.stop_hash = stop_hash
def deserialize(self, f):
self.filter_type = struct.unpack("<B", f.read(1))[0]
self.stop_hash = dese... | 256(self.prev_header)
r += ser_uint256_vector(self.hashes)
return r
def __repr__(self):
return "msg_cfheaders(filter_type={:#x}, stop_hash={:x})".format(
self.filter_type, self.stop_hash)
class msg_getcfcheckpt:
| 64 | 64 | 171 | 7 | 57 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_getcfcheckpt | msg_getcfcheckpt | 1,790 | 1,810 | 1,790 | 1,790 | da3df1ea950212f2483a49ba4c7876f41d222f16 | bigcode/the-stack | train |
f881c974203ad82969aea9b5 | train | function | def ser_string_vector(l):
r = ser_compact_size(len(l))
for sv in l:
r += ser_string(sv)
return r
| def ser_string_vector(l):
| r = ser_compact_size(len(l))
for sv in l:
r += ser_string(sv)
return r
| in l:
r += ser_uint256(i)
return r
def deser_string_vector(f):
nit = deser_compact_size(f)
r = []
for _ in range(nit):
t = deser_string(f)
r.append(t)
return r
def ser_string_vector(l):
| 64 | 64 | 34 | 6 | 57 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | ser_string_vector | ser_string_vector | 186 | 190 | 186 | 186 | 5a41ca47fb6eef35bdb0a3a44942d40eb03d2033 | bigcode/the-stack | train |
ea3ddfeefbca698d0014ff83 | train | class | class CTxOut:
__slots__ = ("nValue", "scriptPubKey")
def __init__(self, nValue=0, scriptPubKey=b""):
self.nValue = nValue
self.scriptPubKey = scriptPubKey
def deserialize(self, f):
self.nValue = struct.unpack("<q", f.read(8))[0]
self.scriptPubKey = deser_string(f)
def ... | class CTxOut:
| __slots__ = ("nValue", "scriptPubKey")
def __init__(self, nValue=0, scriptPubKey=b""):
self.nValue = nValue
self.scriptPubKey = scriptPubKey
def deserialize(self, f):
self.nValue = struct.unpack("<q", f.read(8))[0]
self.scriptPubKey = deser_string(f)
def serialize(self... | += struct.pack("<I", self.nSequence)
return r
def __repr__(self):
return "CTxIn(prevout=%s scriptSig=%s nSequence=%i)" \
% (repr(self.prevout), self.scriptSig.hex(),
self.nSequence)
class CTxOut:
| 64 | 64 | 177 | 5 | 59 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | CTxOut | CTxOut | 414 | 434 | 414 | 414 | 847e32b9c740c0ab05df1f9dd7ade7545779caf3 | bigcode/the-stack | train |
7b1038d45cb1fecc3d478014 | train | class | class msg_tx:
__slots__ = ("tx",)
msgtype = b"tx"
def __init__(self, tx=CTransaction()):
self.tx = tx
def deserialize(self, f):
self.tx.deserialize(f)
def serialize(self):
return self.tx.serialize_with_witness()
def __repr__(self):
return "msg_tx(tx=%s)" % (re... | class msg_tx:
| __slots__ = ("tx",)
msgtype = b"tx"
def __init__(self, tx=CTransaction()):
self.tx = tx
def deserialize(self, f):
self.tx.deserialize(f)
def serialize(self):
return self.tx.serialize_with_witness()
def __repr__(self):
return "msg_tx(tx=%s)" % (repr(self.tx))
| b""
r += self.locator.serialize()
r += ser_uint256(self.hashstop)
return r
def __repr__(self):
return "msg_getblocks(locator=%s hashstop=%064x)" \
% (repr(self.locator), self.hashstop)
class msg_tx:
| 64 | 64 | 87 | 4 | 60 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_tx | msg_tx | 1,253 | 1,267 | 1,253 | 1,253 | cb87f1c93f939e292e356d604427d4ac15716024 | bigcode/the-stack | train |
ae066b7c640d8bb1af43df66 | train | class | class CBlockLocator:
__slots__ = ("nVersion", "vHave")
def __init__(self):
self.vHave = []
def deserialize(self, f):
struct.unpack("<i", f.read(4))[0] # Ignore version field.
self.vHave = deser_uint256_vector(f)
def serialize(self):
r = b""
r += struct.pack("<... | class CBlockLocator:
| __slots__ = ("nVersion", "vHave")
def __init__(self):
self.vHave = []
def deserialize(self, f):
struct.unpack("<i", f.read(4))[0] # Ignore version field.
self.vHave = deser_uint256_vector(f)
def serialize(self):
r = b""
r += struct.pack("<i", 0) # Bitcoin Cor... | __(self):
return "CInv(type=%s hash=%064x)" \
% (self.typemap[self.type], self.hash)
def __eq__(self, other):
return isinstance(other, CInv) and self.hash == other.hash and self.type == other.type
class CBlockLocator:
| 64 | 64 | 144 | 5 | 58 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | CBlockLocator | CBlockLocator | 343 | 360 | 343 | 343 | 5d84a6a29b5b477d6632110528998681a8f7964c | bigcode/the-stack | train |
7eb608c7dcfa4c0e01e32612 | train | class | class msg_ping:
__slots__ = ("nonce", "height")
msgtype = b"ping"
def __init__(self, nonce=0, height=0):
self.nonce = nonce
self.height = height
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
self.height = struct.unpack("<i", f.read(4))[0]
... | class msg_ping:
| __slots__ = ("nonce", "height")
msgtype = b"ping"
def __init__(self, nonce=0, height=0):
self.nonce = nonce
self.height = height
def deserialize(self, f):
self.nonce = struct.unpack("<Q", f.read(8))[0]
self.height = struct.unpack("<i", f.read(4))[0]
def serialize(s... | __slots__ = ()
msgtype = b"getaddr"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_getaddr()"
class msg_ping:
| 64 | 64 | 152 | 4 | 59 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_ping | msg_ping | 1,352 | 1,371 | 1,352 | 1,352 | 64a2295ed3f2866012991063a1ed8324e2e1253c | bigcode/the-stack | train |
d4ecbdfa01f9a40d87fead50 | train | class | class BlockTransactionsRequest:
__slots__ = ("blockhash", "indexes")
def __init__(self, blockhash=0, indexes = None):
self.blockhash = blockhash
self.indexes = indexes if indexes is not None else []
def deserialize(self, f):
self.blockhash = deser_uint256(f)
indexes_length ... | class BlockTransactionsRequest:
| __slots__ = ("blockhash", "indexes")
def __init__(self, blockhash=0, indexes = None):
self.blockhash = blockhash
self.indexes = indexes if indexes is not None else []
def deserialize(self, f):
self.blockhash = deser_uint256(f)
indexes_length = deser_compact_size(f)
... | tx[i].calc_sha256(with_witness=True)
self.shortids.append(calculate_shortid(k0, k1, tx_hash))
def __repr__(self):
return "HeaderAndShortIDs(header=%s, nonce=%d, shortids=%s, prefilledtxn=%s" % (repr(self.header), self.nonce, repr(self.shortids), repr(self.prefilled_txn))
class BlockTransact... | 89 | 89 | 299 | 5 | 84 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | BlockTransactionsRequest | BlockTransactionsRequest | 947 | 985 | 947 | 947 | 8b84d255de5b793de0fd7dc4fcd0f6a301a8ecf0 | bigcode/the-stack | train |
c0cffd0cd612896707c82197 | train | class | class CAddress:
__slots__ = ("net", "ip", "nServices", "port", "time")
# see https://github.com/bitcoin/bips/blob/master/bip-0155.mediawiki
NET_IPV4 = 1
NET_I2P = 5
ADDRV2_NET_NAME = {
NET_IPV4: "IPv4",
NET_I2P: "I2P"
}
ADDRV2_ADDRESS_LENGTH = {
NET_IPV4: 4,
... | class CAddress:
| __slots__ = ("net", "ip", "nServices", "port", "time")
# see https://github.com/bitcoin/bips/blob/master/bip-0155.mediawiki
NET_IPV4 = 1
NET_I2P = 5
ADDRV2_NET_NAME = {
NET_IPV4: "IPv4",
NET_I2P: "I2P"
}
ADDRV2_ADDRESS_LENGTH = {
NET_IPV4: 4,
NET_I2P: 32
... | deser_uint256(f)
r.append(t)
return r
def ser_uint256_vector(l):
r = ser_compact_size(len(l))
for i in l:
r += ser_uint256(i)
return r
def deser_string_vector(f):
nit = deser_compact_size(f)
r = []
for _ in range(nit):
t = deser_string(f)
r.append(t)
... | 256 | 256 | 907 | 4 | 251 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | CAddress | CAddress | 211 | 304 | 211 | 211 | 18ffdf767230df5a87a6fb12153364f1f7924828 | bigcode/the-stack | train |
44f3b73650dbdfba99323235 | train | function | def ser_uint256_vector(l):
r = ser_compact_size(len(l))
for i in l:
r += ser_uint256(i)
return r
| def ser_uint256_vector(l):
| r = ser_compact_size(len(l))
for i in l:
r += ser_uint256(i)
return r
| else:
r += i.serialize()
return r
def deser_uint256_vector(f):
nit = deser_compact_size(f)
r = []
for _ in range(nit):
t = deser_uint256(f)
r.append(t)
return r
def ser_uint256_vector(l):
| 64 | 64 | 35 | 7 | 56 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | ser_uint256_vector | ser_uint256_vector | 170 | 174 | 170 | 170 | 452b4dee118cc6918c1199f2539f7636914db813 | bigcode/the-stack | train |
6f3a35ec4e0cb236b6be701e | train | function | def deser_uint256(f):
r = 0
for i in range(8):
t = struct.unpack("<I", f.read(4))[0]
r += t << (i * 32)
return r
| def deser_uint256(f):
| r = 0
for i in range(8):
t = struct.unpack("<I", f.read(4))[0]
r += t << (i * 32)
return r
| :
nit = struct.unpack("<Q", f.read(8))[0]
return nit
def deser_string(f):
nit = deser_compact_size(f)
return f.read(nit)
def ser_string(s):
return ser_compact_size(len(s)) + s
def deser_uint256(f):
| 64 | 64 | 50 | 6 | 57 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | deser_uint256 | deser_uint256 | 103 | 108 | 103 | 103 | 29b391a33e2abf0e99e3f8b2a85c2d8a503d57b0 | bigcode/the-stack | train |
445d09130da16d903e8b66fb | train | class | class P2PHeaderAndShortWitnessIDs(P2PHeaderAndShortIDs):
__slots__ = ()
def serialize(self):
return super().serialize(with_witness=True)
| class P2PHeaderAndShortWitnessIDs(P2PHeaderAndShortIDs):
| __slots__ = ()
def serialize(self):
return super().serialize(with_witness=True)
| self.shortids_length, repr(self.shortids), self.prefilled_txn_length, repr(self.prefilled_txn))
# P2P version of the above that will use witness serialization (for compact
# block version 2)
class P2PHeaderAndShortWitnessIDs(P2PHeaderAndShortIDs):
| 64 | 64 | 38 | 17 | 47 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | P2PHeaderAndShortWitnessIDs | P2PHeaderAndShortWitnessIDs | 868 | 871 | 868 | 868 | 9c1056f3c4dc331253e23737a044ccb75b6de893 | bigcode/the-stack | train |
32d1dded64e441383317c979 | train | class | class msg_cfilter:
__slots__ = ("filter_type", "block_hash", "filter_data")
msgtype = b"cfilter"
def __init__(self, filter_type=None, block_hash=None, filter_data=None):
self.filter_type = filter_type
self.block_hash = block_hash
self.filter_data = filter_data
def deserialize(... | class msg_cfilter:
| __slots__ = ("filter_type", "block_hash", "filter_data")
msgtype = b"cfilter"
def __init__(self, filter_type=None, block_hash=None, filter_data=None):
self.filter_type = filter_type
self.block_hash = block_hash
self.filter_data = filter_data
def deserialize(self, f):
s... | r += ser_uint256(self.stop_hash)
return r
def __repr__(self):
return "msg_getcfilters(filter_type={:#x}, start_height={}, stop_hash={:x})".format(
self.filter_type, self.start_height, self.stop_hash)
class msg_cfilter:
| 64 | 64 | 201 | 5 | 59 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_cfilter | msg_cfilter | 1,712 | 1,735 | 1,712 | 1,712 | 9f560f49735f8f1a7429e7c07f48ef5394576d5a | bigcode/the-stack | train |
2379bc86b311be21528e58ee | train | function | def ser_vector(l, ser_function_name=None):
r = ser_compact_size(len(l))
for i in l:
if ser_function_name:
r += getattr(i, ser_function_name)()
else:
r += i.serialize()
return r
| def ser_vector(l, ser_function_name=None):
| r = ser_compact_size(len(l))
for i in l:
if ser_function_name:
r += getattr(i, ser_function_name)()
else:
r += i.serialize()
return r
| else:
t.deserialize(f)
r.append(t)
return r
# ser_function_name: Allow for an alternate serialization function on the
# entries in the vector (we use this for serializing the vector of transactions
# for a witness block).
def ser_vector(l, ser_function_name=None):
| 64 | 64 | 56 | 10 | 54 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | ser_vector | ser_vector | 151 | 158 | 151 | 151 | 19e4aecdc931c8630409a2c9d479d717469ab4ba | bigcode/the-stack | train |
e4db9a16e0a62ced1fafaae1 | train | class | class msg_mempool:
__slots__ = ()
msgtype = b"mempool"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_mempool()"
| class msg_mempool:
| __slots__ = ()
msgtype = b"mempool"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_mempool()"
| f.read(8))[0]
def serialize(self):
r = b""
r += struct.pack("<Q", self.nonce)
return r
def __repr__(self):
return "msg_pong(nonce=%08x)" % self.nonce
class msg_mempool:
| 64 | 64 | 68 | 6 | 57 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_mempool | msg_mempool | 1,393 | 1,407 | 1,393 | 1,393 | d42347c3549d5105216f4c304ac86b153fedca91 | bigcode/the-stack | train |
76a4d074bc69f1fc050e0c69 | train | class | class msg_verack:
__slots__ = ()
msgtype = b"verack"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_verack()"
| class msg_verack:
| __slots__ = ()
msgtype = b"verack"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_verack()"
| s nStartingHeight=%i relay=%i)' \
% (self.nVersion, self.nServices, time.ctime(self.nTime),
repr(self.addrTo), repr(self.addrFrom), self.nNonce,
self.strSubVer, self.nStartingHeight, self.relay)
class msg_verack:
| 64 | 64 | 65 | 5 | 59 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_verack | msg_verack | 1,124 | 1,138 | 1,124 | 1,124 | cfa67cfdcf682f1b8b7323b3627b6ff825b3db78 | bigcode/the-stack | train |
7bbd2bfd2b30b5ba8c2baf1c | train | class | class msg_notfound:
__slots__ = ("vec", )
msgtype = b"notfound"
def __init__(self, vec=None):
self.vec = vec or []
def deserialize(self, f):
self.vec = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.vec)
def __repr__(self):
return "msg_notfo... | class msg_notfound:
| __slots__ = ("vec", )
msgtype = b"notfound"
def __init__(self, vec=None):
self.vec = vec or []
def deserialize(self, f):
self.vec = deser_vector(f, CInv)
def serialize(self):
return ser_vector(self.vec)
def __repr__(self):
return "msg_notfound(vec=%s)" % (repr... | __ = ()
msgtype = b"mempool"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_mempool()"
class msg_notfound:
| 64 | 64 | 93 | 5 | 58 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_notfound | msg_notfound | 1,410 | 1,424 | 1,410 | 1,410 | 8516f9930a54ec78b9bcd1b6ce4d0fed9899da3c | bigcode/the-stack | train |
5157e3709b226f71eb919305 | train | function | def deser_compact_size(f):
nit = struct.unpack("<B", f.read(1))[0]
if nit == 253:
nit = struct.unpack("<H", f.read(2))[0]
elif nit == 254:
nit = struct.unpack("<I", f.read(4))[0]
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
return nit
| def deser_compact_size(f):
| nit = struct.unpack("<B", f.read(1))[0]
if nit == 253:
nit = struct.unpack("<H", f.read(2))[0]
elif nit == 254:
nit = struct.unpack("<I", f.read(4))[0]
elif nit == 255:
nit = struct.unpack("<Q", f.read(8))[0]
return nit
| r = struct.pack("<BH", 253, l)
elif l < 0x100000000:
r = struct.pack("<BI", 254, l)
else:
r = struct.pack("<BQ", 255, l)
return r
def deser_compact_size(f):
| 64 | 64 | 92 | 7 | 56 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | deser_compact_size | deser_compact_size | 86 | 94 | 86 | 86 | dedae7345a74cc649c750e8a983214460f73a205 | bigcode/the-stack | train |
76bc054d7173cce04c4e0ffd | train | class | class CPartialMerkleTree:
__slots__ = ("nTransactions", "vBits", "vHash")
def __init__(self):
self.nTransactions = 0
self.vHash = []
self.vBits = []
def deserialize(self, f):
self.nTransactions = struct.unpack("<i", f.read(4))[0]
self.vHash = deser_uint256_vector(f)... | class CPartialMerkleTree:
| __slots__ = ("nTransactions", "vBits", "vHash")
def __init__(self):
self.nTransactions = 0
self.vHash = []
self.vBits = []
def deserialize(self, f):
self.nTransactions = struct.unpack("<i", f.read(4))[0]
self.vHash = deser_uint256_vector(f)
vBytes = deser_st... | += ser_uint256(self.blockhash)
if with_witness:
r += ser_vector(self.transactions, "serialize_with_witness")
else:
r += ser_vector(self.transactions, "serialize_without_witness")
return r
def __repr__(self):
return "BlockTransactions(hash=%064x transactions=... | 86 | 86 | 289 | 7 | 79 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | CPartialMerkleTree | CPartialMerkleTree | 1,012 | 1,039 | 1,012 | 1,012 | b298058d0e0a4256a3d238efca29f8b864efd529 | bigcode/the-stack | train |
d545fb739bd843799164b298 | train | class | class CBlock(CBlockHeader):
__slots__ = ("vtx",)
def __init__(self, header=None):
super().__init__(header)
self.vtx = []
def deserialize(self, f):
super().deserialize(f)
self.vtx = deser_vector(f, CTransaction)
def serialize(self, with_witness=True):
r = b""
... | class CBlock(CBlockHeader):
| __slots__ = ("vtx",)
def __init__(self, header=None):
super().__init__(header)
self.vtx = []
def deserialize(self, f):
super().deserialize(f)
self.vtx = deser_vector(f, CTransaction)
def serialize(self, with_witness=True):
r = b""
r += super().serialize... | WitnessMerkleRoot)
r += struct.pack("<I", self.nTime)
r += struct.pack("<I", self.nBits)
r += struct.pack("<I", self.nNonce)
self.sha256 = uint256_from_str(hash256(r))
self.hash = hash256(r)[::-1].hex()
def rehash(self):
self.sha256 = None
... | 200 | 200 | 668 | 7 | 193 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | CBlock | CBlock | 711 | 789 | 711 | 711 | e5b2f01ea19f45e01137adba40d41735218e1bd7 | bigcode/the-stack | train |
ee21735ee0581b14f8d2b6a1 | train | class | class msg_getaddr:
__slots__ = ()
msgtype = b"getaddr"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_getaddr()"
| class msg_getaddr:
| __slots__ = ()
msgtype = b"getaddr"
def __init__(self):
pass
def deserialize(self, f):
pass
def serialize(self):
return b""
def __repr__(self):
return "msg_getaddr()"
| self.data = data
def serialize(self):
return self.data
def __repr__(self):
return "msg_generic()"
class msg_no_witness_block(msg_block):
__slots__ = ()
def serialize(self):
return self.block.serialize(with_witness=False)
class msg_getaddr:
| 64 | 64 | 65 | 5 | 59 | dmuralov/particl-core | test/functional/test_framework/messages.py | Python | msg_getaddr | msg_getaddr | 1,335 | 1,349 | 1,335 | 1,335 | 446371470a2678c7c3cd18c0c1773081937f46a9 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.