cabbage972/GitChameleon-2.0 huggingface dataset:
Library: pillow==7.1.0 (Python 3.7, released 2020-04)
Additional dependencies: numpy==1.16

Problem: Implement a function to superimpose two images on top of each other using the Soft Light algorithm.

Starting code:
import numpy as np
from PIL import Image, ImageChops

def imaging(img1: Image, img2: Image) -> Image:

Solution:

    return ImageChops.soft_light(img1, img2)

Test:

def generate_random_image(width, height):
 random_data = np.random.randint(0, 256, (height, width, 3), dtype=np.uint8)
 return Image.fromarray(random_data)

np.random.seed(42)

width, height = 8, 8
img1 = generate_random_image(width, height)
img2 = generate_random_image(width, height)

gt = np.array([
    [[131, 189, 237],
     [ 88, 204, 105],
     [222, 168, 112],
     [  0,  38, 249],
     [ 19, 153, 241],
     [ 54,  68, 251],
     [ 51, 156,  62],
     [177, 203, 188]],

    [[159, 214,  77],
     [154,  36,   8],
     [220, 210,  71],
     [212, 244,  44],
     [180,  35,  33],
     [109, 209,  32],
     [251,   8, 240],
     [234, 106,  40]],

    [[ 41,  89, 223],
     [ 15, 203,  99],
     [101, 139,  38],
     [180, 203, 200],
     [ 87, 251,  87],
     [ 79, 117, 140],
     [233,  99,  50],
     [229, 132,   5]],

    [[152,  29, 109],
     [227, 109, 115],
     [124, 217, 115],
     [  7,  37,   8],
     [ 14, 254,  73],
     [ 15,   0,   0],
     [123, 252, 140],
     [239, 223, 171]],

    [[217, 238,  47],
     [198, 138, 252],
     [ 26, 226,  17],
     [190,  32,  19],
     [128,  14,  18],
     [  0, 173,  34],
     [ 97,  59, 172],
     [189,   0, 254]],

    [[ 16, 193, 247],
     [ 40, 187,  53],
     [ 33, 179, 225],
     [238, 212,  35],
     [ 71, 102, 105],
     [168,  38, 162],
     [115, 132, 250],
     [ 13, 191,   0]],

    [[241, 246, 183],
     [ 50,  45, 121],
     [226,   0,  71],
     [254, 176, 116],
     [205, 166,  42],
     [119,  69,  87],
     [131, 126, 254],
     [ 23, 110,  62]],

    [[157, 196, 191],
     [ 43, 255,  56],
     [238,  15, 188],
     [252, 226,  54],
     [236,   0, 107],
     [248, 209, 210],
     [169,  94,   5],
     [237, 116,  32]]
])
sol = imaging(img1, img2)
assert np.allclose(np.array(gt), np.array(sol))
Library: pillow==7.1.0 (Python 3.7, released 2020-04)
Additional dependencies: numpy==1.16

Problem: Implement the function to superimpose two images on top of each other using the Hard Light algorithm.

Starting code:
import numpy as np
from PIL import Image, ImageChops

def imaging(img1: Image, img2: Image) -> Image:

Solution:

    return ImageChops.hard_light(img1, img2)

Test:

def generate_random_image(width, height):
 random_data = np.random.randint(0, 256, (height, width, 3), dtype=np.uint8)
 return Image.fromarray(random_data)

np.random.seed(42)

width, height = 8, 8
img1 = generate_random_image(width, height)
img2 = generate_random_image(width, height)


gt = np.array([
    [[176,   0, 241],
     [ 86, 216, 249],
     [ 90,  36, 152],
     [  1,   0, 250],
     [130, 159, 150],
     [ 96,  41, 252],
     [ 22,  75,  59],
     [ 11, 238, 151]],

    [[ 79, 234, 119],
     [156, 233,   1],
     [225, 252,  50],
     [207, 245,  79],
     [248, 150,  33],
     [106, 211,  22],
     [252,   3, 247],
     [ 24,  43, 192]],

    [[ 29,  17, 225],
     [ 66, 205, 131],
     [ 45, 167,  13],
     [173, 210,  74],
     [ 65, 253,  71],
     [ 76, 146,  75],
     [235,  19,  13],
     [157, 116,   0]],

    [[154,  20, 225],
     [248,  90,  42],
     [ 65, 246,  69],
     [ 87,  27, 240],
     [  5, 254,  44],
     [ 45, 227,   0],
     [239, 253, 248],
     [240, 227, 141]],

    [[ 14,  82, 248],
     [129, 110, 185],
     [ 11,   7,  15],
     [ 17,   0,  10],
     [130, 186,  10],
     [  0, 124, 207],
     [ 45, 124, 133],
     [222, 103, 122]],

    [[ 17, 222, 248],
     [ 40, 205,  48],
     [216, 194, 232],
     [246, 108,  18],
     [125, 163,  46],
     [178, 250, 231],
     [176, 132,  13],
     [ 12, 123, 171]],

    [[243, 247, 213],
     [  6,  23, 145],
     [176,   1, 174],
     [112, 207, 223],
     [137, 170,  19],
     [105, 113,  81],
     [ 80,  81,  98],
     [  3, 143,  36]],

    [[137,  26, 197],
     [107, 255,  51],
     [181, 136,   1],
     [151, 234,  46],
     [254,   0, 198],
     [211, 209,  80],
     [ 55, 100,   5],
     [239,  69,  24]]
])
sol = imaging(img1, img2)
assert np.allclose(np.array(gt), np.array(sol))
Library: tqdm==4.28 (Python 3.7, released 2018-10)

Problem: Iterate over an infinite iterable.

Starting code:
from tqdm import tqdm

def infinite():
    i = 0
    while True:
        yield i
        i += 1
        if i == 1000:
          return

# Define the total in sol_dict['total'] and use it.
sol_dict = {"total":0}

Solution:

sol_dict['total'] = None
progress_bar = tqdm(infinite(), total=sol_dict['total'])
for progress in progress_bar:
    progress_bar.set_description(f"Processing {progress}")

Test:
assertion_value = sol_dict['total'] is None
assert assertion_value
Library: tqdm==4.29 (Python 3.7, released 2019-01)

Problem: Iterate over an infinite iterable.

Starting code:
from tqdm import tqdm

def infinite():
    i = 0
    while True:
        yield i
        i += 1
        if i == 1000:
          return

# Define the total in sol_dict['total'] and use it.
sol_dict = {"total":0}

Solution:

sol_dict['total'] = float('inf')
progress_bar = tqdm(infinite(), total=sol_dict['total'])
for progress in progress_bar:
    progress_bar.set_description(f"Processing {progress}")

Test:
assertion_value = sol_dict['total'] == float('inf')
assert assertion_value
Library: kymatio==0.3.0 (Python 3.7, released 2022-09)
Additional dependencies: torch==1.4.0

Problem: Implement the function to define and run a 2d scattering transform in Torch. Return a tuple of the Scattering object and the result of Scattering on a.

Starting code:
import kymatio
import torch
from kymatio import Scattering2D
from kymatio.scattering2d.frontend.torch_frontend import ScatteringTorch2D
from typing import Tuple

def compute_scattering(a: torch.Tensor) -> Tuple[torch.Tensor, ScatteringTorch2D]:
    

Solution:


    S = Scattering2D(2, (32, 32), frontend='torch')
    S_a = S(a)
    return S, S_a

Test:
import kymatio
a = torch.ones((1, 3, 32, 32))
S, S_a = compute_scattering(a)
assertion_value = isinstance(S_a, torch.Tensor)
assert assertion_value
assertion_value = isinstance(S, kymatio.scattering2d.frontend.torch_frontend.ScatteringTorch2D)
assert assertion_value
Library: matplotlib==3.4.0 (Python 3.7, released 2021-03)
Additional dependencies: numpy==1.18.1 pyparsing==2.3.1 packaging==19.0

Problem: Implement the function to modify the axis of the figure to not visualize ticks on the x and y axis.

Starting code:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.axes import Axes

def modify(fig: Figure, ax: Axes) -> None:
    

Solution:

    ax.set_xticks([], minor=False)
    ax.set_yticks([], minor=False)

Test:
import numpy as np 

fig, ax = plt.subplots()
modify(fig, ax)
assertion_value =  np.array_equal(ax.get_xticks(), np.array([]))
assert assertion_value
assertion_value = (ax.get_xticks() == np.array([])).all()
assert assertion_value
assertion_value =  np.array_equal(ax.get_xticklabels(), np.array([]))
assert assertion_value
assertion_value = (ax.get_xticklabels() == np.array([])).all()
assert assertion_value
Library: matplotlib==3.2.0 (Python 3.7, released 2020-03)
Additional dependencies: numpy==1.18.1 pyparsing==2.3.1 packaging==19.0

Problem: Implement the function to modify the axis of the figure to not visualize major and minor ticks on the x and y axis, with no labels.

Starting code:
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.axes import Axes

def modify(fig: Figure, ax: Axes) -> None:


Solution:

    ax.set_xticks([], False)
    ax.set_yticks([], False)

Test:
import numpy as np 

fig, ax = plt.subplots()
modify(fig, ax)

assertion_value = np.array_equal(ax.get_xticks(), np.array([]))

assert  assertion_value
assertion_value = (ax.get_xticks() == np.array([])).all()
assert assertion_value
assertion_value = np.array_equal(ax.get_xticklabels(), np.array([]))
assert assertion_value
assertion_value = (ax.get_xticklabels() == np.array([])).all()
assert assertion_value
Library: matplotlib==3.5.0 (Python 3.7, released 2021-11)
Additional dependencies: numpy==1.18.1 pyparsing==2.3.1

Problem: Implement the function to modify the axis of the figure to not visualize major and minor ticks on the x and y axis, with no labels.

Starting code:
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.axes import Axes

def modify(fig: Figure, ax: Axes) -> None:


Solution:

    ax.set_xticks([], [], minor=False)
    ax.set_yticks([], [], minor=False)

Test:
import numpy as np 

fig, ax = plt.subplots()
modify(fig, ax)
assertion_value = np.array_equal(ax.get_xticks(), np.array([]))
assert assertion_value
assertion_value = (ax.get_xticks() == np.array([])).all()
assert assertion_value

assertion_value = np.array_equal(ax.get_xticklabels(), np.array([]))
assert assertion_value

assertion_value = (ax.get_xticklabels() == np.array([])).all()
assert assertion_value
Library: matplotlib==3.5.0 (Python 3.7, released 2021-11)
Additional dependencies: numpy==1.18.1 pyparsing==2.3.1

Problem: Implement a function to use Seaborn style.

Starting code:
import matplotlib.pyplot as plt

def use_seaborn() -> None:
    

Solution:

    plt.style.use("seaborn")

Test:
use_seaborn()

cycle = plt.rcParams['axes.prop_cycle']
from cycler import cycler
a = cycler('color', ['#4C72B0', '#55A868', '#C44E52', '#8172B2', '#CCB974', '#64B5CD'])
assert cycle==a
Library: matplotlib==3.8.0 (Python 3.10, released 2023-09)
Additional dependencies: pyparsing==2.3.1

Problem: Implement a function to use Seaborn style.

Starting code:
import matplotlib.pyplot as plt

def use_seaborn() -> None:
    

Solution:

    plt.style.use("seaborn-v0_8")


Test:
use_seaborn()

cycle = plt.rcParams['axes.prop_cycle']
from cycler import cycler
a = cycler('color', ['#4C72B0', '#55A868', '#C44E52', '#8172B2', '#CCB974', '#64B5CD'])
assert cycle==a