Skip to content

Commit

Permalink
scipy
Browse files Browse the repository at this point in the history
  • Loading branch information
luweizheng committed Nov 5, 2024
1 parent a327f2e commit 17d41ba
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ jobs:
include:
- { os: ubuntu-latest, module: _mars/dataframe, python-version: 3.11 }
- { os: ubuntu-latest, module: learn, python-version: 3.11 }
- { os: ubuntu-latest, module: mars-core, python-version: 3.12 }
- { os: ubuntu-latest, module: mars-core, python-version: 3.9 }
- { os: ubuntu-20.04, module: hadoop, python-version: 3.9 }
- { os: ubuntu-latest, module: vineyard, python-version: 3.11 }
- { os: ubuntu-latest, module: external-storage, python-version: 3.11 }
# always test compatibility with the latest version
# - { os: ubuntu-latest, module: compatibility, python-version: 3.9 }
- { os: ubuntu-latest, module: doc-build, python-version: 3.11 }
- { os: self-hosted, module: gpu, python-version: 3.11}
- { os: ubuntu-latest, module: jax, python-version: 3.11 }
- { os: ubuntu-latest, module: jax, python-version: 3.9 }
# a self-hosted runner which needs computing resources, activate when necessary
# - { os: juicefs-ci, module: kubernetes-juicefs, python-version: 3.9 }
# - { os: ubuntu-latest, module: slurm, python-version: 3.9 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def test_arctan2_execution(setup):

assert y.issparse() is True
result = y.execute().fetch()
np.testing.assert_equal(result, np.arctan2(raw2.A, raw2.A))
np.testing.assert_equal(result, np.arctan2(raw2.todense(), raw2.todense()))

y = arctan2(0, raw2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def test_fill_diagonal_execution(setup):
def copy(x):
if hasattr(x, "nnz"):
# sparse
return x.A
return x.todense()
else:
return x.copy()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def test_lu_execution(setup):

t = P.dot(L).dot(U)
res = t.execute().fetch()
np.testing.assert_array_almost_equal(data.A, res)
np.testing.assert_array_almost_equal(data.todense(), res)


def test_solve_triangular(setup):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def test_concatenate_execution(setup):

d = concatenate([a, b, c], axis=-1)
res = d.execute().fetch()
expected = np.concatenate([a_data.A, b_data.A, c_data.A], axis=-1)
expected = np.concatenate(
[a_data.todense(), b_data.todense(), c_data.todense()], axis=-1
)
np.testing.assert_array_equal(res.toarray(), expected)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def test_max_min_execution(setup):
assert raw.min() == arr.min().execute().fetch()

np.testing.assert_almost_equal(
raw.max(axis=1).A.ravel(), arr.max(axis=1).execute().fetch().toarray()
raw.max(axis=1).todense().ravel(), arr.max(axis=1).execute().fetch().toarray()
)
assert arr.max(axis=1).issparse() is True
np.testing.assert_almost_equal(
raw.min(axis=1).A.ravel(), arr.min(axis=1).execute().fetch().toarray()
raw.min(axis=1).todense().ravel(), arr.min(axis=1).execute().fetch().toarray()
)
assert arr.min(axis=1).issparse() is True

Expand Down Expand Up @@ -435,18 +435,20 @@ def test_nan_reduction(setup):
raw[:3, :3] = np.nan
arr = tensor(raw, chunk_size=6)

assert pytest.approx(np.nansum(raw.A)) == nansum(arr).execute().fetch()
assert pytest.approx(np.nanprod(raw.A)) == nanprod(arr).execute().fetch()
assert pytest.approx(np.nanmax(raw.A)) == nanmax(arr).execute().fetch()
assert pytest.approx(np.nanmin(raw.A)) == nanmin(arr).execute().fetch()
assert pytest.approx(np.nanmean(raw.A)) == nanmean(arr).execute().fetch()
assert pytest.approx(np.nanvar(raw.A)) == nanvar(arr).execute().fetch()
assert pytest.approx(np.nansum(raw.todense())) == nansum(arr).execute().fetch()
assert pytest.approx(np.nanprod(raw.todense())) == nanprod(arr).execute().fetch()
assert pytest.approx(np.nanmax(raw.todense())) == nanmax(arr).execute().fetch()
assert pytest.approx(np.nanmin(raw.todense())) == nanmin(arr).execute().fetch()
assert pytest.approx(np.nanmean(raw.todense())) == nanmean(arr).execute().fetch()
assert pytest.approx(np.nanvar(raw.todense())) == nanvar(arr).execute().fetch()
assert (
pytest.approx(np.nanvar(raw.A, ddof=1)) == nanvar(arr, ddof=1).execute().fetch()
pytest.approx(np.nanvar(raw.todense(), ddof=1))
== nanvar(arr, ddof=1).execute().fetch()
)
assert pytest.approx(np.nanstd(raw.A)) == nanstd(arr).execute().fetch()
assert pytest.approx(np.nanstd(raw.todense())) == nanstd(arr).execute().fetch()
assert (
pytest.approx(np.nanstd(raw.A, ddof=1)) == nanstd(arr, ddof=1).execute().fetch()
pytest.approx(np.nanstd(raw.todense(), ddof=1))
== nanstd(arr, ddof=1).execute().fetch()
)

arr = nansum(1)
Expand All @@ -471,8 +473,8 @@ def test_cum_reduction(setup):

res1 = arr.cumsum(axis=1).execute().fetch()
res2 = arr.cumprod(axis=1).execute().fetch()
expected1 = raw.A.cumsum(axis=1)
expected2 = raw.A.cumprod(axis=1)
expected1 = raw.todense().cumsum(axis=1)
expected2 = raw.todense().cumprod(axis=1)
assert np.allclose(res1, expected1)
assert np.allclose(res2, expected2)

Expand Down Expand Up @@ -530,8 +532,8 @@ def test_nan_cum_reduction(setup):

res1 = nancumsum(arr, axis=1).execute().fetch()
res2 = nancumprod(arr, axis=1).execute().fetch()
expected1 = np.nancumsum(raw.A, axis=1)
expected2 = np.nancumprod(raw.A, axis=1)
expected1 = np.nancumsum(raw.todense(), axis=1)
expected2 = np.nancumprod(raw.todense(), axis=1)
assert np.allclose(res1, expected1) is True
assert np.allclose(res2, expected2) is True

Expand Down Expand Up @@ -596,19 +598,19 @@ def test_count_nonzero_execution(setup):
t = count_nonzero(arr)

res = t.execute().fetch()
expected = np.count_nonzero(raw.A)
expected = np.count_nonzero(raw.todense())
np.testing.assert_equal(res, expected)

t = count_nonzero(arr, axis=0)

res = t.execute().fetch()
expected = np.count_nonzero(raw.A, axis=0)
expected = np.count_nonzero(raw.todense(), axis=0)
np.testing.assert_equal(res, expected)

t = count_nonzero(arr, axis=1)

res = t.execute().fetch()
expected = np.count_nonzero(raw.A, axis=1)
expected = np.count_nonzero(raw.todense(), axis=1)
np.testing.assert_equal(res, expected)

# test string dtype
Expand Down

0 comments on commit 17d41ba

Please sign in to comment.