Skip to content

Commit

Permalink
add sparse matrix test
Browse files Browse the repository at this point in the history
  • Loading branch information
acezen committed Feb 3, 2021
1 parent dbebd14 commit 2e0adf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions mars/storage/tests/test_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import numpy as np
import pandas as pd
import scipy.sparse as sps

from mars.filesystem import LocalFileSystem
from mars.lib.sparse import SparseNDArray, SparseMatrix
from mars.serialize import dataserializer
from mars.storage.base import StorageLevel
from mars.storage.filesystem import FileSystemStorage
Expand Down Expand Up @@ -107,6 +109,15 @@ async def test_base_operations(storage_context):
assert num == 2
await storage.delete(info2.object_id)

# test SparseMatrix
s1 = sps.csr_matrix([[1, 0, 1], [0, 0, 1]])
s = SparseNDArray(s1)
put_info3 = await storage.put(s)
get_data3 = await storage.get(put_info3.object_id)
assert isinstance(get_data3, SparseMatrix)
np.testing.assert_array_equal(get_data3.toarray(), s1.A)
np.testing.assert_array_equal(get_data3.todense(), s1.A)

# test writer and reader
t = np.random.random(10)
b = dataserializer.dumps(t)
Expand All @@ -120,3 +131,4 @@ async def test_base_operations(storage_context):
t2 = dataserializer.loads(content)

np.testing.assert_array_equal(t, t2)

13 changes: 8 additions & 5 deletions mars/storage/vineyard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
from typing import Dict, List, Tuple

import pyarrow as pa
import vineyard
from vineyard._C import ObjectMeta
from vineyard.core import default_builder_context, default_resolver_context
from vineyard.data.utils import from_json, to_json
from vineyard.deploy.local import start_vineyardd
try:
import vineyard
from vineyard._C import ObjectMeta
from vineyard.core import default_builder_context, default_resolver_context
from vineyard.data.utils import from_json, to_json
from vineyard.deploy.local import start_vineyardd
except ImportError:
vineyard = None

from ..lib import sparse
from .base import StorageBackend, StorageLevel, ObjectInfo
Expand Down

0 comments on commit 2e0adf8

Please sign in to comment.