Ejemplo n.º 1
0
        assert np.allclose(Z.get(), npZ)
        common.check_block_integrity(Z)

    # Power
    Z = X**Y
    npZ = npX**Y
    assert np.allclose(Z.get(), npZ)
    common.check_block_integrity(Z)
    if isinstance(Y, np.ndarray):
        with pytest.raises(TypeError):
            Z = Y**X
    else:
        Z = Y**X
        npZ = Y**npX
        assert np.allclose(Z.get(), npZ)
        common.check_block_integrity(Z)


if __name__ == "__main__":
    # pylint: disable=import-error
    import conftest

    app_inst = conftest.get_app("ray-cyclic")
    test_matmul(app_inst)
    # test_matvec(app_inst)
    # test_vecdot(app_inst)
    # test_tensordot_basic(app_inst)
    # test_tensordot_large_shape(app_inst)
    # test_bops(app_inst)
    # test_conversions(conversions_data(None, app_inst))
Ejemplo n.º 2
0
    np_arr = np.array([True, False, True, True, False, False], dtype=np.bool_)
    ba = app_inst.array(np_arr, block_shape=(2,))
    result_sum = app_inst.sum(ba, axis=0).get()
    np_sum = np.sum(np_arr)
    assert result_sum.dtype == np_sum.dtype
    assert result_sum == np_sum


def test_trans(app_inst: ArrayApplication):
    np_x = np.arange(40).reshape(10, 4)
    ba_x = app_inst.array(np_x, block_shape=(5, 2))
    assert np.array_equal(ba_x.T.get(), np_x.T)


def test_isnan(app_inst: ArrayApplication):
    assert not app_inst.isnan(app_inst.array([1.0], block_shape=(1,)))
    assert app_inst.isnan(app_inst.array([np.nan], block_shape=(1,)))


if __name__ == "__main__":
    # pylint: disable=import-error
    import conftest

    app_inst = conftest.get_app("serial")
    # test_stats(app_inst)
    # test_uops(app_inst)
    test_bops(app_inst)
    # test_bools(app_inst)
    # test_bool_reduction(app_inst)
    # test_isnan(app_inst)
Ejemplo n.º 3
0
    # Test different broadcasting behavior.
    arr_a = np.arange(np.product(shape_a)).reshape(shape_a)
    arr_b = np.random.random_sample(np.product(shape_b)).reshape(shape_b)
    ba_a = app_inst.array(arr_a, block_shape_a)
    ba_b = app_inst.array(arr_b, block_shape_b)
    assert np.allclose(arr_b[4:8, 0:3], ba_b[4:8, 0:3].get())
    arr_a[8:12, 3:6] = arr_b[4:8, 0:3, 4]
    ba_a[8:12, 3:6] = ba_b[4:8, 0:3, 4]
    assert np.allclose(arr_a, ba_a.get())
    arr_a[2, 3:6] = arr_b[8:9, 0:3, 4]
    ba_a[2, 3:6] = ba_b[8:9, 0:3, 4]
    assert np.allclose(arr_a, ba_a.get())
    arr_a[3:4, 3:6] = arr_b[3, 0:3, 4]
    ba_a[3:4, 3:6] = ba_b[3, 0:3, 4]
    assert np.allclose(arr_a, ba_a.get())


if __name__ == "__main__":
    # pylint: disable=import-error
    import conftest

    app_inst = conftest.get_app("serial", "packed")
    test_subscript(app_inst)
    # test_assign_basic(app_inst)
    # test_assign_2dim_accesses(app_inst)
    # test_assign_dependencies(app_inst)
    # test_complete_3dim_slices(app_inst)
    # test_assign_complete_2dim_slices(app_inst)
    # test_basic_assignment_broadcasting(app_inst)
    # test_ref_accessor(app_inst)
Ejemplo n.º 4
0
    real_y = np.concatenate([real_y, extra_y], axis=0)

    X = app_inst.array(real_X, block_shape=(15, 5))
    y = app_inst.array(real_y, block_shape=(15, ))
    theta = linalg.ridge_regression(app_inst, X, y, lamb=0.0)
    robust_theta = linalg.ridge_regression(app_inst, X, y, lamb=10000.0)

    # Generate a test set to evaluate robustness to outliers.
    test_X, test_y = BimodalGaussian.get_dataset(100,
                                                 num_features,
                                                 p=0.5,
                                                 theta=real_theta)
    test_X = app_inst.array(test_X, block_shape=(15, 5))
    test_y = app_inst.array(test_y, block_shape=(15, ))
    theta_error = np.sum((((test_X @ theta) - test_y)**2).get())
    robust_theta_error = np.sum((((test_X @ robust_theta) - test_y)**2).get())
    assert robust_theta_error < theta_error


if __name__ == "__main__":
    # pylint: disable=import-error
    import conftest

    app_inst = conftest.get_app("ray")
    # test_inv_assumptions(app_inst)
    # test_inv(app_inst)
    test_qr(app_inst)
    # test_svd(app_inst)
    # test_lr(app_inst)
    # test_rr(app_inst)
Ejemplo n.º 5
0
def test_transposed_block(app_inst_all: ArrayApplication):
    ba: BlockArray = app_inst_all.array(np.array([[1, 2, 3], [4, 5, 6]]),
                                        block_shape=(1, 3))
    block1: Block = ba.T.blocks[0, 1]
    assert block1.size() == 3
    assert not block1.transposed
    assert block1.grid_entry == block1.true_grid_entry()
    assert block1.grid_shape == block1.true_grid_shape()


def test_deferred_transposed_block(app_inst_all: ArrayApplication):
    ba: BlockArray = app_inst_all.array(np.array([[1, 2, 3], [4, 5, 6]]),
                                        block_shape=(1, 3))
    block1: Block = ba.transpose(defer=True).blocks[0, 1]
    assert block1.size() == 3
    assert block1.transposed
    assert block1.grid_entry == (0, 1)
    assert block1.grid_shape == (1, 2)
    assert block1.true_grid_entry() == (1, 0)
    assert block1.true_grid_shape() == (2, 1)


if __name__ == "__main__":
    # pylint: disable=import-error
    import conftest

    app_inst = conftest.get_app("ray-none")
    test_warmup(app_inst)
    test_deferred_transposed_block(app_inst)