Skip to content

Ridge's test_dtype_match[sparse_cg] can fail on macOS #13868

@jnothman

Description

@jnothman

From conda-forge/scikit-learn-feedstock#93 (comment)

_________________________ test_dtype_match[sparse_cg] __________________________

solver = 'sparse_cg'

    @pytest.mark.parametrize(
        "solver", ["svd", "sparse_cg", "cholesky", "lsqr", "sag", "saga"])
    def test_dtype_match(solver):
        rng = np.random.RandomState(0)
        alpha = 1.0
    
        n_samples, n_features = 6, 5
        X_64 = rng.randn(n_samples, n_features)
        y_64 = rng.randn(n_samples)
        X_32 = X_64.astype(np.float32)
        y_32 = y_64.astype(np.float32)
    
        # Check type consistency 32bits
        ridge_32 = Ridge(alpha=alpha, solver=solver, max_iter=500, tol=1e-10,)
        ridge_32.fit(X_32, y_32)
        coef_32 = ridge_32.coef_
    
        # Check type consistency 64 bits
        ridge_64 = Ridge(alpha=alpha, solver=solver, max_iter=500, tol=1e-10,)
        ridge_64.fit(X_64, y_64)
        coef_64 = ridge_64.coef_
    
        # Do the actual checks at once for easier debug
        assert coef_32.dtype == X_32.dtype
        assert coef_64.dtype == X_64.dtype
        assert ridge_32.predict(X_32).dtype == X_32.dtype
        assert ridge_64.predict(X_64).dtype == X_64.dtype
>       assert_allclose(ridge_32.coef_, ridge_64.coef_, rtol=1e-4)
E       AssertionError: 
E       Not equal to tolerance rtol=0.0001, atol=0
E       
E       Mismatch: 100%
E       Max absolute difference: 0.00185175
E       Max relative difference: 0.03817044
E        x: array([-0.032243, -0.287511, -0.160586,  0.09311 ,  0.380112],
E             dtype=float32)
E        y: array([-0.033523, -0.2883  , -0.158735,  0.094335,  0.378418])

Ping @massich, @jeromedockes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions