Ejemplo n.º 1
0
def test_Ridge(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.linear_model")
    else:
        m = importlib.import_module("cuml")

    def compute_func(data):
        kwargs = {"fit_intercept": False, "normalize": True, "alpha": 0.1}

        if data["module"] == "cuml":
            kwargs["solver"] = "svd"

        X_train = data["data"]["X_train"]
        y_train = data["data"]["y_train"]

        ridge = m.Ridge(**kwargs)

        ridge.fit(X_train, y_train)

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data,
            "train_split": 0.8,
            "label_col": 4,
        },
    )
Ejemplo n.º 2
0
def test_LinearRegression(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.linear_model")
    else:
        m = importlib.import_module("cuml")

    def compute_func(data):
        kwargs = {"fit_intercept": True, "normalize": True}

        if data["module"] == "cuml":
            kwargs["algorithm"] = "eig"

        X_train = data["data"]["X_train"]
        y_train = data["data"]["y_train"]

        lr = m.LinearRegression(**kwargs)

        lr.fit(X_train, y_train)

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data,
            "train_split": 0.8,
            "label_col": 4,
        },
    )
Ejemplo n.º 3
0
def test_TSVD(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.decomposition")
    else:
        m = importlib.import_module("cuml")

    def compute_func(data):
        kwargs = {"n_components": 10, "random_state": 42}

        if data["module"] == "sklearn":
            kwargs["algorithm"] = "arpack"
        elif data["module"] == "cuml":
            kwargs["algorithm"] = "full"

        tsvd = m.TruncatedSVD(**kwargs)

        tsvd.fit_transform(data["data"])

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data
        },
    )
Ejemplo n.º 4
0
def test_KNN(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.neighbors")
    else:
        m = importlib.import_module("cuml.neighbors.nearest_neighbors")

    def compute_func(data):
        kwargs = {}

        n_neighbors = 10

        if data["module"] == "sklearn":
            kwargs["metric"] = "sqeuclidean"
            kwargs["n_jobs"] = -1

        knn = m.NearestNeighbors(**kwargs)

        knn.fit(data["data"])

        knn.kneighbors(data["data"], n_neighbors)

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data
        },
    )
Ejemplo n.º 5
0
def test_PCA(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.decomposition")
    else:
        m = importlib.import_module("cuml")

    def compute_func(data):
        kwargs = {
            "n_components": 10,
            "whiten": False,
            "random_state": 42,
            "svd_solver": "full",
        }

        pca = m.PCA(**kwargs)

        pca.fit_transform(data["data"])

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data
        },
    )
Ejemplo n.º 6
0
def test_DBSCAN(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.cluster")
    else:
        m = importlib.import_module("cuml")

    def compute_func(data):
        kwargs = {"eps": 3, "min_samples": 2}

        if data["module"] == "sklearn":
            kwargs["n_jobs"] = -1
            kwargs["algorithm"] = "brute"

        dbscan = m.DBSCAN(**kwargs)

        dbscan.fit(data["data"])

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data
        },
    )
Ejemplo n.º 7
0
def test_Merge_DataFrames(benchmark, module, data_path, nrows):
    m = importlib.import_module(module)

    data_func = lambda data: [
        m.read_csv(p, nrows=data["nrows"]) for p in data["path"]
    ]
    compute_func = lambda data: data[0].merge(data[1], on="trip_distance")
    run_benchmark(benchmark, m, compute_func, data_func, {
        "path": data_path,
        "nrows": nrows
    })
Ejemplo n.º 8
0
def test_Read_CSV(benchmark, module, data_path, nrows):
    m = importlib.import_module(module)

    compute_func = lambda data: m.read_csv(data["path"], nrows=data["nrows"])
    run_benchmark(
        benchmark,
        m,
        compute_func,
        lambda data: data,
        {
            "path": data_path,
            "nrows": nrows
        },
    )
Ejemplo n.º 9
0
def test_SGD(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.linear_model")
    else:
        m = importlib.import_module("cuml.solvers")

    def compute_func(data):
        kwargs = {
            "learning_rate": "adaptive",
            "eta0": 0.07,
            "penalty": "elasticnet",
            "loss": "squared_loss",
            "tol": 0.0,
        }

        if data["module"] == "sklearn":
            kwargs["max_iter"] = 10
            kwargs["fit_intercept"] = True

            sgd = m.SGDRegressor(**kwargs)

        elif data["module"] == "cuml":
            kwargs["epochs"] = 10
            kwargs["batch_size"] = 512

            sgd = m.SGD(**kwargs)

        X_train = data["data"]["X_train"]
        y_train = data["data"]["y_train"]

        sgd.fit(X_train, y_train)

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data,
            "train_split": 0.8,
            "label_col": 4,
        },
    )
Ejemplo n.º 10
0
def test_Stencil(benchmark, module, shape):

    m = importlib.import_module(module)

    @numba.stencil
    def _smooth(x):
        return (x[-1, -1] + x[-1, 0] + x[-1, 1] + x[0, -1] + x[0, 0] +
                x[0, 1] + x[1, -1] + x[1, 0] + x[1, 1]) // 9

    @numba.njit
    def smooth_cpu(x, out):
        out = _smooth(x)

    @numba.cuda.jit
    def _smooth_gpu(x, out):
        i, j = numba.cuda.grid(2)
        n, m = x.shape
        if 1 <= i < n - 1 and 1 <= j < m - 1:
            out[i, j] = (x[i - 1, j - 1] + x[i - 1, j] + x[i - 1, j + 1] +
                         x[i, j - 1] + x[i, j] + x[i, j + 1] +
                         x[i + 1, j - 1] + x[i + 1, j] + x[i + 1, j + 1]) // 9

    def smooth_gpu(x, out):
        import math

        threadsperblock = (16, 16)
        blockspergrid_x = math.ceil(x.shape[0] / threadsperblock[0])
        blockspergrid_y = math.ceil(x.shape[1] / threadsperblock[1])
        blockspergrid = (blockspergrid_x, blockspergrid_y)

        _smooth_gpu[blockspergrid, threadsperblock](x, out)

    data_func = lambda shape: {
        "in": m.ones(shape, dtype="int8"),
        "out": m.zeros(shape, dtype="int8"),
    }
    f = smooth_cpu if module == "numpy" else smooth_gpu
    compute_func = lambda data: f(data["in"], data["out"])

    run_benchmark(benchmark, m, compute_func, data_func, shape)
Ejemplo n.º 11
0
def test_ElasticNet(benchmark, module, shape, data):
    if module == "sklearn":
        m = importlib.import_module("sklearn.linear_model")
    else:
        m = importlib.import_module("cuml")

    def compute_func(data):
        kwargs = {
            "alpha": np.array([0.001]),
            "fit_intercept": True,
            "normalize": False,
            "max_iter": 1000,
            "selection": "cyclic",
            "tol": 1e-10,
        }

        X_train = data["data"]["X_train"]
        y_train = data["data"]["y_train"]

        lasso = m.Lasso(**kwargs)

        lasso.fit(X_train, y_train)

    run_benchmark(
        benchmark,
        m,
        compute_func,
        load_mortgage,
        {
            "module": module,
            "shape": shape,
            "data": data,
            "train_split": 0.8,
            "label_col": 4,
        },
    )
Ejemplo n.º 12
0
def test_Sum(benchmark, module, shape):
    m = importlib.import_module(module)

    run_benchmark(benchmark, m, m.sum, m.random.random, shape)
Ejemplo n.º 13
0
def test_SVD(benchmark, module, shape):
    m = importlib.import_module(module)

    run_benchmark(benchmark, m, m.linalg.svd, m.random.random, shape)
Ejemplo n.º 14
0
def test_Array_Slicing(benchmark, module, shape):
    m = importlib.import_module(module)

    compute_func = lambda data: data[::3].copy()
    run_benchmark(benchmark, m, compute_func, m.random.random, shape)
Ejemplo n.º 15
0
def test_Matrix_Multiplication(benchmark, module, shape):
    m = importlib.import_module(module)

    compute_func = lambda data: data.dot(data)
    run_benchmark(benchmark, m, compute_func, m.random.random, shape)
Ejemplo n.º 16
0
def test_Elementwise(benchmark, module, shape):
    m = importlib.import_module(module)

    compute_func = lambda data: m.sin(data)**2 + m.cos(data)**2
    run_benchmark(benchmark, m, compute_func, m.random.random, shape)
Ejemplo n.º 17
0
def test_Standard_Deviation(benchmark, module, shape):
    m = importlib.import_module(module)

    run_benchmark(benchmark, m, m.std, m.random.random, shape)
Ejemplo n.º 18
0
def test_FFT(benchmark, module, shape):
    m = importlib.import_module(module)

    data_func = lambda shape: m.exp(2j * m.pi * m.random.random(shape))
    run_benchmark(benchmark, m, m.fft.fft, data_func, shape)